From 3dbdbb473d2a2e74a76dd9adba017e4347d9f8da Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Sun, 13 Feb 2022 20:28:04 +0100 Subject: [PATCH] Update bbqueue in demo --- demos/demo-utils/Cargo.toml | 2 +- demos/demo-utils/src/logging.rs | 12 ++++++------ demos/nrf52-demo/Cargo.toml | 2 +- demos/nrf52-demo/src/logger.rs | 14 +++++++------- demos/nrf52-demo/src/main.rs | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/demos/demo-utils/Cargo.toml b/demos/demo-utils/Cargo.toml index 59e8238ca..a6ab024ce 100644 --- a/demos/demo-utils/Cargo.toml +++ b/demos/demo-utils/Cargo.toml @@ -14,4 +14,4 @@ publish = false rubble = { path = "../../rubble", default-features = false } cortex-m = "0.7.2" log = "0.4.8" -bbqueue = "0.4.1" +bbqueue = "0.5.1" diff --git a/demos/demo-utils/src/logging.rs b/demos/demo-utils/src/logging.rs index af4086122..666c61300 100644 --- a/demos/demo-utils/src/logging.rs +++ b/demos/demo-utils/src/logging.rs @@ -1,6 +1,6 @@ //! Logging-related utilities and adapters. -use bbqueue::{ArrayLength, GrantW, Producer}; +use bbqueue::{GrantW, Producer}; use core::{cell::RefCell, fmt}; use cortex_m::interrupt::{self, Mutex}; use log::{Log, Metadata, Record}; @@ -40,12 +40,12 @@ impl fmt::Write for StampedLogger { /// /// The sink will panic when the `BBBuffer` doesn't have enough space to the data. This is to ensure /// that we never block or drop data. -pub struct BbqLogger<'a, N: ArrayLength> { +pub struct BbqLogger<'a, const N: usize> { p: Producer<'a, N>, data_lost: bool, } -impl<'a, N: ArrayLength> BbqLogger<'a, N> { +impl<'a, const N: usize> BbqLogger<'a, N> { pub fn new(p: Producer<'a, N>) -> Self { Self { p, @@ -54,7 +54,7 @@ impl<'a, N: ArrayLength> BbqLogger<'a, N> { } } -impl> fmt::Write for BbqLogger<'_, N> { +impl fmt::Write for BbqLogger<'_, N> { fn write_str(&mut self, msg: &str) -> fmt::Result { let mut msg_bytes = msg.as_bytes(); while !msg_bytes.is_empty() { @@ -88,12 +88,12 @@ impl> fmt::Write for BbqLogger<'_, N> { } /// Wraps a granted buffer and provides convenience methods to append data and commit -struct GrantedBuffer<'a, N: ArrayLength> { +struct GrantedBuffer<'a, const N: usize> { grant: GrantW<'a, N>, written: usize, } -impl<'a, N: ArrayLength> GrantedBuffer<'a, N> { +impl<'a, const N: usize> GrantedBuffer<'a, N> { pub fn new(grant: GrantW<'a, N>) -> Self { GrantedBuffer { grant, written: 0 } } diff --git a/demos/nrf52-demo/Cargo.toml b/demos/nrf52-demo/Cargo.toml index 89357a836..9fb98402e 100644 --- a/demos/nrf52-demo/Cargo.toml +++ b/demos/nrf52-demo/Cargo.toml @@ -17,7 +17,7 @@ demo-utils = { path = "../demo-utils" } cortex-m = "0.7.2" cortex-m-rtic = { version = "0.5.8", default-features = false, features = ["cortex-m-7"] } cortex-m-rt = "0.7.0" -bbqueue = "0.4" +bbqueue = "0.5.1" rtt-target = { version = "0.3.0", features = ["cortex-m"] } panic-rtt-target = { version = "0.1.1", features = ["cortex-m"] } diff --git a/demos/nrf52-demo/src/logger.rs b/demos/nrf52-demo/src/logger.rs index bac812a61..d06323f58 100644 --- a/demos/nrf52-demo/src/logger.rs +++ b/demos/nrf52-demo/src/logger.rs @@ -1,20 +1,20 @@ #![cfg_attr(not(feature = "log"), allow(unused))] -use bbqueue::{BBBuffer, ConstBBBuffer, Consumer}; +use bbqueue::{BBBuffer, Consumer}; use cortex_m::interrupt; use demo_utils::logging::{BbqLogger, StampedLogger, WriteLogger}; use rubble_nrf5x::timer::StampSource; #[cfg(feature = "log")] -pub(crate) use bbqueue::consts::U10000 as BufferSize; +pub(crate) const BUFFER_SIZE: usize = 10000; #[cfg(not(feature = "log"))] -pub(crate) use bbqueue::consts::U1 as BufferSize; +pub(crate) const BUFFER_SIZE: usize = 1; #[cfg(feature = "log")] use log::LevelFilter; -type Logger = StampedLogger, BbqLogger<'static, BufferSize>>; +type Logger = StampedLogger, BbqLogger<'static, BUFFER_SIZE>>; type LogTimer = crate::hal::pac::TIMER0; @@ -22,10 +22,10 @@ type LogTimer = crate::hal::pac::TIMER0; static mut LOGGER: Option> = None; /// Stores the global BBBuffer for the log queue. -static BUFFER: BBBuffer = BBBuffer(ConstBBBuffer::new()); +static BUFFER: BBBuffer = BBBuffer::::new(); #[cfg(feature = "log")] -pub fn init(timer: StampSource) -> Consumer<'static, BufferSize> { +pub fn init(timer: StampSource) -> Consumer<'static, { BUFFER_SIZE }> { let (tx, log_sink) = BUFFER.try_split().unwrap(); let logger = StampedLogger::new(BbqLogger::new(tx), timer); @@ -43,6 +43,6 @@ pub fn init(timer: StampSource) -> Consumer<'static, BufferSize> { } #[cfg(not(feature = "log"))] -pub fn init(timer: StampSource) -> Consumer<'static, BufferSize> { +pub fn init(timer: StampSource) -> Consumer<'static, { BUFFER_SIZE }> { BUFFER.try_split().unwrap().1 } diff --git a/demos/nrf52-demo/src/main.rs b/demos/nrf52-demo/src/main.rs index cbe784e3b..abeed33d0 100644 --- a/demos/nrf52-demo/src/main.rs +++ b/demos/nrf52-demo/src/main.rs @@ -65,7 +65,7 @@ const APP: () = { ble_r: Responder, radio: BleRadio, log_channel: UpChannel, - log_sink: Consumer<'static, logger::BufferSize>, + log_sink: Consumer<'static, { logger::BUFFER_SIZE }>, } #[init(resources = [ble_tx_buf, ble_rx_buf, tx_queue, rx_queue])]