usb: do not allow converting Directon to/from u8
This commit is contained in:
parent
7f7c14b7bc
commit
f4f5824972
@ -8,20 +8,13 @@ use core::future::Future;
|
|||||||
///
|
///
|
||||||
/// The values of the enum also match the direction bit used in endpoint addresses and control
|
/// The values of the enum also match the direction bit used in endpoint addresses and control
|
||||||
/// request types.
|
/// request types.
|
||||||
#[repr(u8)]
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
/// Host to device (OUT)
|
/// Host to device (OUT)
|
||||||
Out = 0x00,
|
Out,
|
||||||
/// Device to host (IN)
|
/// Device to host (IN)
|
||||||
In = 0x80,
|
In,
|
||||||
}
|
|
||||||
|
|
||||||
impl From<u8> for Direction {
|
|
||||||
fn from(value: u8) -> Self {
|
|
||||||
unsafe { core::mem::transmute(value & 0x80) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// USB endpoint transfer type. The values of this enum can be directly cast into `u8` to get the
|
/// USB endpoint transfer type. The values of this enum can be directly cast into `u8` to get the
|
||||||
|
@ -106,7 +106,7 @@ impl Request {
|
|||||||
let recipient = rt & 0b11111;
|
let recipient = rt & 0b11111;
|
||||||
|
|
||||||
Request {
|
Request {
|
||||||
direction: rt.into(),
|
direction: if rt & 0x80 == 0 { Direction::Out } else { Direction::In },
|
||||||
request_type: unsafe { mem::transmute((rt >> 5) & 0b11) },
|
request_type: unsafe { mem::transmute((rt >> 5) & 0b11) },
|
||||||
recipient: if recipient <= 3 {
|
recipient: if recipient <= 3 {
|
||||||
unsafe { mem::transmute(recipient) }
|
unsafe { mem::transmute(recipient) }
|
||||||
|
Loading…
Reference in New Issue
Block a user