align usb-2-solution and usb-3

closes #37
This commit is contained in:
Jorge Aparicio 2020-07-16 12:06:57 +02:00
parent 579b81c33f
commit 613f460978
3 changed files with 21 additions and 2 deletions

View file

@ -62,6 +62,13 @@ fn on_event(usbd: &USBD, event: Event) {
let wvalue = (u16::from(usbd.wvalueh.read().wvalueh().bits()) << 8)
| u16::from(usbd.wvaluel.read().wvaluel().bits());
// NOTE the `dk` crate contains helper functions for the above operations
// let bmrequesttype = usbd::bmrequesttype(usbd);
// let brequest = usbd::brequest(usbd);
// let wlength = usbd::wlength(usbd);
// let windex = usbd::windex(usbd);
// let wvalue = usbd::wvalue(usbd);
log::info!(
"SETUP: bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
bmrequesttype,

View file

@ -49,8 +49,8 @@ fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
Event::UsbEp0DataDone => todo!(), // <- TODO
Event::UsbEp0Setup => {
let bmrequesttype = usbd.bmrequesttype.read().bits() as u8;
let brequest = usbd.brequest.read().brequest().bits();
let bmrequesttype = usbd::bmrequesttype(usbd);
let brequest = usbd::brequest(usbd);
let wlength = usbd::wlength(usbd);
let windex = usbd::windex(usbd);
let wvalue = usbd::wvalue(usbd);

View file

@ -200,6 +200,18 @@ pub fn next_event(usbd: &USBD) -> Option<Event> {
None
}
/// Reads the BMREQUESTTYPE register and returns the 8-bit BMREQUESTTYPE component of a setup packet
pub fn bmrequesttype(usbd: &USBD) -> u8 {
// read the 32-bit register and extract the least significant byte
// (the alternative is to read the 3 bitfields of the register and merge them into one byte)
usbd.bmrequesttype.read().bits() as u8
}
/// Reads the BREQUEST register and returns the 8-bit BREQUEST component of a setup packet
pub fn brequest(usbd: &USBD) -> u8 {
usbd.brequest.read().brequest().bits()
}
/// Reads the WLENGTHL and WLENGTHH registers and returns the 16-bit WLENGTH component of a setup packet
pub fn wlength(usbd: &USBD) -> u16 {
u16::from(usbd.wlengthl.read().wlengthl().bits())