Skip to content

Commit

Permalink
Update rust (#198)
Browse files Browse the repository at this point in the history
* Use toml rust toolchain format

* Remove async feature

* Use stable toolchain in ci

* Update README.md

* Use nightly for examples

* Allow examples to compile using stable compiler

* Update embassy.rs
  • Loading branch information
rmja authored Jan 9, 2024
1 parent fe971a4 commit 21247f9
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 40 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
override: true
components: rustfmt

Expand All @@ -50,7 +50,7 @@ jobs:
# uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: nightly
# toolchain: stable
# override: true

# - name: Install tomlfmt
Expand All @@ -77,7 +77,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
override: true
components: clippy

Expand All @@ -97,8 +97,6 @@ jobs:
[
"",
"derive",
"async",
"derive,async",
]
include:
- target: "x86_64-unknown-linux-gnu"
Expand All @@ -113,7 +111,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
target: thumbv6m-none-eabi
override: true

Expand All @@ -133,7 +131,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
target: thumbv6m-none-eabi
override: true
- name: Library tests
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
// with these changes RA will call `cargo check --bins` on save
"rust-analyzer.checkOnSave.allTargets": false,
"rust-analyzer.cargo.target": "thumbv6m-none-eabi",
"rust-analyzer.cargo.features": ["async"],
"rust-analyzer.diagnostics.disabled": [
"unresolved-import"
]
}
}
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ opt-level = "s" # <-
overflow-checks = false # <-

[patch.crates-io]
embassy-executor = { version = "0.3", git = "https://github.com/embassy-rs/embassy", rev = "5f7cd82" }
embassy-rp = { version = "0.1", git = "https://github.com/embassy-rs/embassy", rev = "5f7cd82" }
embassy-time = { version = "0.2", git = "https://github.com/embassy-rs/embassy", rev = "5f7cd82" }
embassy-executor = { version = "0.4", git = "https://github.com/embassy-rs/embassy", rev = "49ee0564" }
embassy-rp = { version = "0.1", git = "https://github.com/embassy-rs/embassy", rev = "49ee0564" }
embassy-time = { version = "0.2", git = "https://github.com/embassy-rs/embassy", rev = "49ee0564" }
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ The following dependent crates provide platform-agnostic device drivers built on
- `log`: Disabled by default. Enable log statements on various log levels to aid debugging. Powered by `log`.
- `defmt`: Disabled by default. Enable defmt log statements on various log levels to aid debugging. Powered by `defmt`.
- `custom-error-messages`: Disabled by default. Allows errors to contain custom error messages up to 64 characters, parsed by `AtDigest::custom_error`.
- `async`: Enable the async interfaces on both `Ingress` and `Client`.
- `hex_str_arrays`: Disabled by default. Needs `#![feature(generic_const_exprs)]` Nightly feature. This allows for hex strings to be serialized to a fix-width byte array.

## Chat / Getting Help
Expand Down
5 changes: 2 additions & 3 deletions atat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ name = "atat"

[dependencies]
embedded-io = "0.6.0"
embedded-io-async = { version = "0.6.0", optional = true }
futures = { version = "0.3", default-features = false, optional = true }
embedded-io-async = "0.6.0"
futures = { version = "0.3", default-features = false }
embassy-sync = "0.5"
embassy-time = "0.2"
heapless = { version = "^0.8", features = ["serde"] }
Expand Down Expand Up @@ -48,6 +48,5 @@ defmt = ["dep:defmt", "embedded-io-async/defmt-03", "heapless/defmt-03"]
derive = ["atat_derive", "serde_at"]
bytes = ["heapless-bytes", "serde_bytes"]
custom-error-messages = []
async = ["embedded-io-async", "futures"]
std = ["serde_at/std", "nom/std", "embassy-time/std", "embedded-io/std"]
hex_str_arrays = []
4 changes: 0 additions & 4 deletions atat/src/ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub trait AtatIngress {
fn try_advance(&mut self, commit: usize) -> Result<(), Error>;

/// Commit a given number of written bytes to the ingress and make them visible to the digester.
#[cfg(feature = "async")]
async fn advance(&mut self, commit: usize);

/// Write a buffer to the ingress and return how many bytes were written.
Expand All @@ -42,7 +41,6 @@ pub trait AtatIngress {
}

/// Write a buffer to the ingress
#[cfg(feature = "async")]
async fn write(&mut self, buf: &[u8]) {
let mut buf = buf;
while !buf.is_empty() {
Expand All @@ -56,7 +54,6 @@ pub trait AtatIngress {

/// Read all bytes from the provided serial and ingest the read bytes into
/// the ingress from where they will be processed
#[cfg(feature = "async")]
async fn read_from(&mut self, serial: &mut impl embedded_io_async::Read) -> ! {
use embedded_io::Error;
loop {
Expand Down Expand Up @@ -214,7 +211,6 @@ impl<
Ok(())
}

#[cfg(feature = "async")]
async fn advance(&mut self, commit: usize) {
self.pos += commit;
assert!(self.pos <= self.buf.len());
Expand Down
6 changes: 2 additions & 4 deletions atat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
#![allow(clippy::type_complexity)]
#![allow(clippy::fallible_impl_from)]
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
#![cfg_attr(feature = "async", allow(async_fn_in_trait))]
#![allow(async_fn_in_trait)]

// This mod MUST go first, so that the others see its macros.
pub(crate) mod fmt;
Expand All @@ -241,10 +241,8 @@ mod tx_mock;
pub mod urc_channel;
pub use nom;

pub mod blocking;

#[cfg(feature = "async")]
pub mod asynch;
pub mod blocking;

#[cfg(feature = "bytes")]
pub use serde_bytes;
Expand Down
1 change: 0 additions & 1 deletion atat/src/tx_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ impl embedded_io::Write for TxMock<'_> {
}
}

#[cfg(feature = "async")]
impl embedded_io_async::Write for TxMock<'_> {
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
for c in buf {
Expand Down
7 changes: 3 additions & 4 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ name = "std-tokio"
required-features = ["std"]

[dependencies]
atat = { path = "../atat", features = ["async"] }
atat = { path = "../atat" }
embedded-io = "0.6"
embedded-io-async = "0.6"
embedded-io-adapters = { version = "0.6", optional = true }
Expand All @@ -30,9 +30,8 @@ cortex-m = { version = "0.7.6", optional = true }
cortex-m-rt = { version = "0.7.3", optional = true }
defmt-rtt = { version = "0.4", optional = true }
panic-probe = { version = "0.3.0", features = ["print-defmt"], optional = true }
embassy-executor = { version = "0.3", features = [
embassy-executor = { version = "0.4", features = [
"defmt",
"nightly",
"arch-cortex-m",
"executor-thread",
"integrated-timers",
Expand All @@ -51,7 +50,7 @@ tokio = { version = "1.26", default-features = false, features = [
"macros",
], optional = true }
tokio-serial = { version = "5.4.4", optional = true }
static_cell = { version = "2", features = ["nightly"] }
static_cell = "2"
portable-atomic = "1.6.0"

[features]
Expand Down
19 changes: 12 additions & 7 deletions examples/src/bin/embassy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]

use atat::{
asynch::{AtatClient, Client},
Expand All @@ -13,6 +12,7 @@ use embassy_rp::{
peripherals::UART0,
uart::{self, BufferedInterruptHandler, BufferedUart, BufferedUartRx},
};
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};

const INGRESS_BUF_SIZE: usize = 1024;
Expand All @@ -29,15 +29,15 @@ async fn main(spawner: Spawner) {

let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0);

let tx_buf = static_cell::make_static!([0u8; 16]);
let rx_buf = static_cell::make_static!([0u8; 16]);
static TX_BUF: StaticCell<[u8; 16]> = StaticCell::new();
static RX_BUF: StaticCell<[u8; 16]> = StaticCell::new();
let uart = BufferedUart::new(
uart,
Irqs,
tx_pin,
rx_pin,
tx_buf,
rx_buf,
TX_BUF.init([0; 16]),
RX_BUF.init([0; 16]),
uart::Config::default(),
);
let (reader, writer) = uart.split();
Expand All @@ -49,8 +49,13 @@ async fn main(spawner: Spawner) {
&RES_SLOT,
&URC_CHANNEL,
);
let buf = static_cell::make_static!([0; 1024]);
let mut client = Client::new(writer, &RES_SLOT, buf, atat::Config::default());
static BUF: StaticCell<[u8; 1024]> = StaticCell::new();
let mut client = Client::new(
writer,
&RES_SLOT,
BUF.init([0; 1024]),
atat::Config::default(),
);

spawner.spawn(ingress_task(ingress, reader)).unwrap();

Expand Down
6 changes: 3 additions & 3 deletions examples/src/bin/std-tokio.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
use atat_examples::common;

use atat::{
asynch::{AtatClient, Client},
AtatIngress, Config, DefaultDigester, Ingress, ResponseSlot, UrcChannel,
};
use embedded_io_adapters::tokio_1::FromTokio;
use static_cell::StaticCell;
use std::process::exit;
use tokio_serial::SerialStream;

Expand All @@ -27,7 +26,8 @@ async fn main() -> ! {
&RES_SLOT,
&URC_CHANNEL,
);
let buf = static_cell::make_static!([0; 1024]);
static BUF: StaticCell<[u8; 1024]> = StaticCell::new();
let buf = BUF.init([0; 1024]);
let mut client = Client::new(FromTokio::new(writer), &RES_SLOT, buf, Config::default());

tokio::spawn(ingress_task(ingress, FromTokio::new(reader)));
Expand Down
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.75"
components = ["clippy"]

0 comments on commit 21247f9

Please sign in to comment.