mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2024-09-27 14:00:04 +00:00
parent
579b81c33f
commit
613f460978
3 changed files with 21 additions and 2 deletions
|
@ -62,6 +62,13 @@ fn on_event(usbd: &USBD, event: Event) {
|
||||||
let wvalue = (u16::from(usbd.wvalueh.read().wvalueh().bits()) << 8)
|
let wvalue = (u16::from(usbd.wvalueh.read().wvalueh().bits()) << 8)
|
||||||
| u16::from(usbd.wvaluel.read().wvaluel().bits());
|
| 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!(
|
log::info!(
|
||||||
"SETUP: bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
"SETUP: bmrequesttype: {}, brequest: {}, wlength: {}, windex: {}, wvalue: {}",
|
||||||
bmrequesttype,
|
bmrequesttype,
|
||||||
|
|
|
@ -49,8 +49,8 @@ fn on_event(usbd: &USBD, ep0in: &mut Ep0In, event: Event) {
|
||||||
Event::UsbEp0DataDone => todo!(), // <- TODO
|
Event::UsbEp0DataDone => todo!(), // <- TODO
|
||||||
|
|
||||||
Event::UsbEp0Setup => {
|
Event::UsbEp0Setup => {
|
||||||
let bmrequesttype = usbd.bmrequesttype.read().bits() as u8;
|
let bmrequesttype = usbd::bmrequesttype(usbd);
|
||||||
let brequest = usbd.brequest.read().brequest().bits();
|
let brequest = usbd::brequest(usbd);
|
||||||
let wlength = usbd::wlength(usbd);
|
let wlength = usbd::wlength(usbd);
|
||||||
let windex = usbd::windex(usbd);
|
let windex = usbd::windex(usbd);
|
||||||
let wvalue = usbd::wvalue(usbd);
|
let wvalue = usbd::wvalue(usbd);
|
||||||
|
|
|
@ -200,6 +200,18 @@ pub fn next_event(usbd: &USBD) -> Option<Event> {
|
||||||
None
|
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
|
/// Reads the WLENGTHL and WLENGTHH registers and returns the 16-bit WLENGTH component of a setup packet
|
||||||
pub fn wlength(usbd: &USBD) -> u16 {
|
pub fn wlength(usbd: &USBD) -> u16 {
|
||||||
u16::from(usbd.wlengthl.read().wlengthl().bits())
|
u16::from(usbd.wlengthl.read().wlengthl().bits())
|
||||||
|
|
Loading…
Reference in a new issue