From 27ba908eb80ef1b6fbbe877eec0221300ef77f03 Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Wed, 15 Jul 2020 15:16:38 +0200 Subject: [PATCH 1/2] radio-puzzle-help.md: add more hints to hapless constants --- embedded-workshop-book/src/radio-puzzle-help.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/embedded-workshop-book/src/radio-puzzle-help.md b/embedded-workshop-book/src/radio-puzzle-help.md index d4654ec..eba85a8 100644 --- a/embedded-workshop-book/src/radio-puzzle-help.md +++ b/embedded-workshop-book/src/radio-puzzle-help.md @@ -17,16 +17,18 @@ use heapless::consts::*; // defines U16, U32, U64... etc. to set the size of t fn main() { // A hash map with a capacity of 16 key-value pairs allocated on the stack + // note that U16 is a heapless constant, not Rust's u16 let mut my_map = FnvIndexMap::<_, _, U16>::new(); my_map.insert(b'A', b'~').unwrap(); // A vector with a fixed capacity of 8 elements allocated on the stack + // note that U8 is a heapless constant, not Rust's u8 let mut my_vec = Vec::<_, U8>::new(); my_vec.push(b'A').unwrap(); } ``` -If you haven't used a stack-allocated collection before note that you'll need to specify the capacity of the collection as a type parameter using one of the "type-level values" in the `heapless::consts` module. The [`heapless::IndexMap` documentation][indexMap] of the `heapless` crate has some usage examples, as does the [`heapless::Vec` documentation][vec]. +If you haven't used a stack-allocated collection before note that you'll need to specify the capacity of the collection as a type parameter using one of the "type-level values" in the `heapless::consts` module (e.g. `U8`, `U64` etc.). The [`heapless::IndexMap` documentation][indexMap] of the `heapless` crate has some usage examples, as does the [`heapless::Vec` documentation][vec]. [indexMap]: https://docs.rs/heapless/0.5.5/heapless/struct.IndexMap.html [vec]: https://docs.rs/heapless/0.5.5/heapless/struct.Vec.html From dc0e7b39966cf763296e6db4693f66a50ce59fa7 Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Thu, 9 Jul 2020 10:15:07 +0200 Subject: [PATCH 2/2] CI: run cargo fmt after build --- .github/workflows/rust.yml | 16 +++++++++++----- advanced/firmware/src/bin/usb-2-solution.rs | 1 - 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 17e339c..aeaaf0d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -51,12 +51,18 @@ jobs: - name: build tools working-directory: ./tools - run: cargo build --verbose + run: | + cargo build --verbose + cargo fmt --all -- --check - - name: build beginner/apps + - name: build and fmt beginner/apps working-directory: ./beginner/apps - run: cargo build --verbose + run: | + cargo build --verbose + cargo fmt --all -- --check - - name: build advanced/firmware + - name: build and fmt advanced/firmware working-directory: ./advanced/firmware - run: cargo build --verbose + run: | + cargo build --verbose + cargo fmt --all -- --check \ No newline at end of file diff --git a/advanced/firmware/src/bin/usb-2-solution.rs b/advanced/firmware/src/bin/usb-2-solution.rs index 3f8cfe4..342472a 100644 --- a/advanced/firmware/src/bin/usb-2-solution.rs +++ b/advanced/firmware/src/bin/usb-2-solution.rs @@ -44,7 +44,6 @@ fn on_event(usbd: &USBD, event: Event) { Event::UsbEp0DataDone => todo!(), Event::UsbEp0Setup => { - // the BMREQUESTTYPE register contains information about data recipient, transfer type and direction let bmrequesttype = usbd.bmrequesttype.read().bits() as u8; // the BREQUEST register stores the type of the current request (e.g. SET_ADDRESS, GET_DESCRIPTOR, ...)