mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-10 08:15:36 +00:00
bump rtic
This commit is contained in:
parent
8ad5afe51b
commit
b975a07698
3 changed files with 45 additions and 21 deletions
|
@ -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<Self, ()> {
|
||||
// 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 {
|
|||
// ^
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"] }
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue