From 181da7d94587dfaa62782bc5731e4c5fe05efdf6 Mon Sep 17 00:00:00 2001 From: Piotr Esden-Tempski Date: Sat, 27 Jan 2024 22:47:12 -0800 Subject: [PATCH 1/2] card.dfu: Added missing status mode. --- src/dfu.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dfu.rs b/src/dfu.rs index 66204f2..11a460e 100644 --- a/src/dfu.rs +++ b/src/dfu.rs @@ -172,7 +172,8 @@ pub mod res { Idle, Error, Downloading, - Ready + Ready, + Completed } #[derive(Deserialize, defmt::Format)] From 2f1b7309c900564bb517eecc883519c22a3021db Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Sun, 28 Jan 2024 15:09:46 +0100 Subject: [PATCH 2/2] resize_buf: use slice, and not experimental split_arr --- Cargo.toml | 1 + src/lib.rs | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e9cab56..6edafa3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ serde-json-core = "0.4.0" [dev-dependencies] base64 = { version = "0.13.0", default-features = false } bytemuck = "1.7.2" +embedded-hal-mock = "0.10.0" [features] default = [ ] diff --git a/src/lib.rs b/src/lib.rs index 6e180de..254cbf6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ //! Protocol for transmitting: //! API: //! -#![feature(split_array)] #![feature(type_changing_struct_update)] #![cfg_attr(not(test), no_std)] @@ -185,9 +184,8 @@ impl + Read, const BUF_SIZE: usize> if B < self.buf.len() { Err(NoteError::BufOverflow) } else { - let (buf, _) = self.buf.split_array_ref::(); Ok(Notecard { - buf: Vec::<_, B>::from_slice(buf).unwrap(), + buf: Vec::<_, B>::from_slice(&self.buf).unwrap(), ..self }) } @@ -642,4 +640,24 @@ impl< } #[cfg(test)] -mod tests {} +mod tests { + use super::*; + use embedded_hal_mock::eh0::i2c::Mock; + + pub fn new_mock() -> Notecard { + // let exp = [ Transaction::write(0x17, vec![]) ]; + let i2c = Mock::new(&[]); + Notecard::new(i2c) + } + + #[test] + fn resize_buf() { + let c = new_mock(); + assert_eq!(c.buf.capacity(), DEFAULT_BUF_SIZE); + + let mut c = c.resize_buf::<1024>().unwrap(); + assert_eq!(c.buf.capacity(), 1024); + + c.i2c.done(); + } +}