Merge branch 'embassy-rs:main' into main

This commit is contained in:
Badr Bouslikhin 2024-09-06 18:37:30 +02:00 committed by GitHub
commit 55f41da66c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 64 additions and 15 deletions

4
.github/ci/test.sh vendored
View File

@ -8,6 +8,10 @@ export RUSTUP_HOME=/ci/cache/rustup
export CARGO_HOME=/ci/cache/cargo
export CARGO_TARGET_DIR=/ci/cache/target
# needed for "dumb HTTP" transport support
# used when pointing stm32-metapac to a CI-built one.
export CARGO_NET_GIT_FETCH_WITH_CLI=true
cargo test --manifest-path ./embassy-futures/Cargo.toml
cargo test --manifest-path ./embassy-sync/Cargo.toml
cargo test --manifest-path ./embassy-embedded-hal/Cargo.toml

1
ci.sh
View File

@ -305,6 +305,7 @@ rm out/tests/stm32u5a5zj/usart
# flaky, probably due to bad ringbuffered dma code.
rm out/tests/stm32l152re/usart_rx_ringbuffered
rm out/tests/stm32f207zg/usart_rx_ringbuffered
rm out/tests/stm32wl55jc/usart_rx_ringbuffered
if [[ -z "${TELEPROBE_TOKEN-}" ]]; then
echo No teleprobe token found, skipping running HIL tests

View File

@ -27,7 +27,7 @@ features = ["defmt"]
defmt = { version = "0.3", optional = true }
digest = "0.10"
log = { version = "0.4", optional = true }
ed25519-dalek = { version = "2", default_features = false, features = ["digest"], optional = true }
ed25519-dalek = { version = "2", default-features = false, features = ["digest"], optional = true }
embassy-embedded-hal = { version = "0.2.0", path = "../embassy-embedded-hal" }
embassy-sync = { version = "0.6.0", path = "../embassy-sync" }
embedded-storage = "0.3.1"
@ -42,7 +42,7 @@ rand = "0.8"
futures = { version = "0.3", features = ["executor"] }
sha1 = "0.10.5"
critical-section = { version = "1.1.1", features = ["std"] }
ed25519-dalek = { version = "2", default_features = false, features = ["std", "rand_core", "digest"] }
ed25519-dalek = { version = "2", default-features = false, features = ["std", "rand_core", "digest"] }
[features]
ed25519-dalek = ["dep:ed25519-dalek", "_verify"]

View File

@ -79,7 +79,7 @@ arch-cortex-m = ["_arch", "dep:cortex-m"]
## RISC-V 32
arch-riscv32 = ["_arch"]
## WASM
arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys"]
arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys", "critical-section/std"]
## AVR
arch-avr = ["_arch", "dep:portable-atomic", "dep:avr-device"]

View File

@ -1,5 +1,4 @@
#![cfg_attr(not(any(feature = "arch-std", feature = "arch-wasm")), no_std)]
#![cfg_attr(feature = "nightly", feature(waker_getters))]
#![allow(clippy::new_without_default)]
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]

View File

@ -50,8 +50,7 @@ pub fn task_from_waker(waker: &Waker) -> TaskRef {
#[cfg(feature = "nightly")]
{
let raw_waker = waker.as_raw();
(raw_waker.vtable(), raw_waker.data())
(waker.vtable(), waker.data())
}
};

View File

@ -41,12 +41,24 @@ pub const MAX_PACKET_SIZE: u8 = 64;
/// The logger handle, which contains a pipe with configurable size for buffering log messages.
pub struct UsbLogger<const N: usize> {
buffer: Pipe<CS, N>,
custom_style: Option<fn(&Record, &mut Writer<'_, N>) -> ()>,
}
impl<const N: usize> UsbLogger<N> {
/// Create a new logger instance.
pub const fn new() -> Self {
Self { buffer: Pipe::new() }
Self {
buffer: Pipe::new(),
custom_style: None,
}
}
/// Create a new logger instance with a custom formatter.
pub const fn with_custom_style(custom_style: fn(&Record, &mut Writer<'_, N>) -> ()) -> Self {
Self {
buffer: Pipe::new(),
custom_style: Some(custom_style),
}
}
/// Run the USB logger using the state and USB driver. Never returns.
@ -137,14 +149,19 @@ impl<const N: usize> log::Log for UsbLogger<N> {
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
let _ = write!(Writer(&self.buffer), "{}\r\n", record.args());
if let Some(custom_style) = self.custom_style {
custom_style(record, &mut Writer(&self.buffer));
} else {
let _ = write!(Writer(&self.buffer), "{}\r\n", record.args());
}
}
}
fn flush(&self) {}
}
struct Writer<'d, const N: usize>(&'d Pipe<CS, N>);
/// A writer that writes to the USB logger buffer.
pub struct Writer<'d, const N: usize>(&'d Pipe<CS, N>);
impl<'d, const N: usize> core::fmt::Write for Writer<'d, N> {
fn write_str(&mut self, s: &str) -> Result<(), core::fmt::Error> {
@ -210,3 +227,33 @@ macro_rules! with_class {
LOGGER.create_future_from_class($p)
}};
}
/// Initialize the USB serial logger from a serial class and return the future to run it.
/// This version of the macro allows for a custom style function to be passed in.
/// The custom style function will be called for each log record and is responsible for writing the log message to the buffer.
///
/// Arguments specify the buffer size, log level, the serial class and the custom style function, respectively.
///
/// # Usage
///
/// ```
/// let log_fut = embassy_usb_logger::with_custom_style!(1024, log::LevelFilter::Info, logger_class, |record, writer| {
/// use core::fmt::Write;
/// let level = record.level().as_str();
/// write!(writer, "[{level}] {}\r\n", record.args()).unwrap();
/// });
/// ```
///
/// # Safety
///
/// This macro should only be invoked only once since it is setting the global logging state of the application.
#[macro_export]
macro_rules! with_custom_style {
( $x:expr, $l:expr, $p:ident, $s:expr ) => {{
static LOGGER: ::embassy_usb_logger::UsbLogger<$x> = ::embassy_usb_logger::UsbLogger::with_custom_style($s);
unsafe {
let _ = ::log::set_logger_racy(&LOGGER).map(|()| log::set_max_level_racy($l));
}
LOGGER.create_future_from_class($p)
}};
}

View File

@ -35,8 +35,8 @@ async fn main(spawner: Spawner) {
loop {
match CHANNEL.receive().await {
LedState::On => led.set_high(),
LedState::Off => led.set_low(),
LedState::On => led.set_low(),
LedState::Off => led.set_high(),
}
}
}

View File

@ -33,8 +33,8 @@ async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedSta
loop {
match receiver.receive().await {
LedState::On => led.set_high(),
LedState::Off => led.set_low(),
LedState::On => led.set_low(),
LedState::Off => led.set_high(),
}
}
}

View File

@ -16,7 +16,6 @@ wasm-logger = "0.2.0"
wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] }
log = "0.4.11"
critical-section = { version = "1.1", features = ["std"] }
[profile.release]
debug = 2

View File

@ -1,5 +1,5 @@
[toolchain]
channel = "nightly-2024-07-16"
channel = "nightly-2024-09-06"
components = [ "rust-src", "rustfmt", "llvm-tools", "miri" ]
targets = [
"thumbv7em-none-eabi",