From b975a076984e4f25da3e8d75da0caa6f4ce86299 Mon Sep 17 00:00:00 2001 From: Mirabellensaft Date: Fri, 7 Jan 2022 12:34:53 +0100 Subject: [PATCH] bump rtic --- advanced/common/usb/src/lib.rs | 39 ++++++++++++++++--------- advanced/firmware/Cargo.toml | 2 +- advanced/firmware/src/bin/rtic-hello.rs | 25 ++++++++++++---- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/advanced/common/usb/src/lib.rs b/advanced/common/usb/src/lib.rs index 65fe58b..e153265 100644 --- a/advanced/common/usb/src/lib.rs +++ b/advanced/common/usb/src/lib.rs @@ -1,11 +1,11 @@ //! Some USB 2.0 data types +// NOTE this is a partial solution to exercise `usb-2` #![deny(missing_docs)] #![deny(warnings)] #![no_std] use core::num::NonZeroU8; -use defmt; /// Device address assigned by the host; will be in the range 1..=127 pub type Address = NonZeroU8; @@ -51,22 +51,33 @@ impl Request { windex: u16, wlength: u16, ) -> Result { - // Request Codes // see table 9-4 (USB specification) const SET_ADDRESS: u8 = 5; + const GET_DESCRIPTOR: u8 = 6; - // TODO implement another branch handling GET_DESCRIPTOR requests: - // - // 1. get descriptor type and descriptor index from `wValue` - // - // 2. confirm that - // - the descriptor type is DEVICE, i.e. of value 1 and - // - the descriptor index is 0 (i.e. it is the first implemented descriptor for this type) and - // - `wIndex` is 0 (i.e. no language ID since it's not a string descriptor) - // - // For more details, see https://embedded-trainings.ferrous-systems.com/setup-stage.html - if bmrequesttype == 0b00000000 && brequest == SET_ADDRESS { + if bmrequesttype == 0b10000000 && brequest == GET_DESCRIPTOR { + // see table 9-5 + const DEVICE: u8 = 1; + + // 1. get descriptor type and descriptor index from wValue + let desc_ty = (wvalue >> 8) as u8; + let desc_index = wvalue as u8; + let langid = windex; + + // 2. confirm that the descriptor + // - is of type DEVICE and + // - has descriptor index 0 (i.e. it is the first implemented descriptor for this type) and + // - has wIndex 0 (i.e. no language ID since it's not a string descriptor) + if desc_ty == DEVICE && desc_index == 0 && langid == 0 { + Ok(Request::GetDescriptor { + descriptor: Descriptor::Device, + length: wlength, + }) + } else { + Err(()) + } + } else if bmrequesttype == 0b00000000 && brequest == SET_ADDRESS { // Set the device address for all future accesses. // (Needed to successfully init when conected to Apple devices) // Section 9.4.6 Set Address of the USB specification explains which values for wvalue, @@ -79,7 +90,6 @@ impl Request { Err(()) } } else { - defmt::warn!("unhandled case in `Request` parser"); Err(()) } } @@ -198,3 +208,4 @@ mod tests { // ^ } } + diff --git a/advanced/firmware/Cargo.toml b/advanced/firmware/Cargo.toml index d2f094d..2938341 100644 --- a/advanced/firmware/Cargo.toml +++ b/advanced/firmware/Cargo.toml @@ -14,7 +14,7 @@ usb2 = "0.0.1" consts = { path = "../common/consts" } cortex-m = "0.7.3" cortex-m-rt = "0.7.1" -cortex-m-rtic = "0.5.9" +cortex-m-rtic = "1.0.0" defmt = "0.3.0" defmt-rtt = "0.3.1" dk = { path = "../../boards/dk", features = ["advanced"] } diff --git a/advanced/firmware/src/bin/rtic-hello.rs b/advanced/firmware/src/bin/rtic-hello.rs index 68869ff..9c4889c 100644 --- a/advanced/firmware/src/bin/rtic-hello.rs +++ b/advanced/firmware/src/bin/rtic-hello.rs @@ -1,25 +1,38 @@ #![no_main] #![no_std] -use cortex_m::asm; + // this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior use firmware as _; -#[rtic::app(device = dk)] -const APP: () = { +#[rtic::app(device = dk, peripherals = true)] +mod app { + use cortex_m::asm; + use dk::Peripherals; + + #[local] + struct MyLocalResources { + } + + #[shared] + struct MySharedResources { + + } + #[init] - fn init(_cx: init::Context) { + fn init(_cx: init::Context) -> (MySharedResources, MyLocalResources, init::Monotonics) { dk::init().unwrap(); defmt::info!("Hello"); + (MySharedResources {}, MyLocalResources {}, init::Monotonics()) } #[idle] - fn main(_cx: main::Context) -> ! { + fn idle(_cx: idle::Context) -> ! { defmt::info!("world!"); loop { asm::bkpt(); } } -}; +} \ No newline at end of file