Skip to content

Commit

Permalink
Merge branch 'embassy-rs:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
badrbouslikhin authored Sep 6, 2024
2 parents f6d92b7 + 1cf7789 commit 55f41da
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .github/ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions embassy-boot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion embassy-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
1 change: 0 additions & 1 deletion embassy-executor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
3 changes: 1 addition & 2 deletions embassy-executor/src/raw/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
};

Expand Down
53 changes: 50 additions & 3 deletions embassy-usb-logger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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)
}};
}
4 changes: 2 additions & 2 deletions examples/nrf52840/src/bin/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
4 changes: 2 additions & 2 deletions examples/nrf52840/src/bin/channel_sender_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion examples/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion rust-toolchain-nightly.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 55f41da

Please sign in to comment.