diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-09-26 12:35:33 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-09-26 12:35:33 +0200 |
| commit | f4f58249722bc656a13865e06535d208440c3e4a (patch) | |
| tree | e5fd41f7c32bb479791d2ec16327e938efce0501 /embassy-usb-driver | |
| parent | 7f7c14b7bce5b84eb27c8122535a96a6f0e5dd77 (diff) | |
usb: do not allow converting Directon to/from u8
Diffstat (limited to 'embassy-usb-driver')
| -rw-r--r-- | embassy-usb-driver/src/lib.rs | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/embassy-usb-driver/src/lib.rs b/embassy-usb-driver/src/lib.rs index 051190a48..fc29786fc 100644 --- a/embassy-usb-driver/src/lib.rs +++ b/embassy-usb-driver/src/lib.rs | |||
| @@ -8,20 +8,13 @@ use core::future::Future; | |||
| 8 | /// | 8 | /// |
| 9 | /// The values of the enum also match the direction bit used in endpoint addresses and control | 9 | /// The values of the enum also match the direction bit used in endpoint addresses and control |
| 10 | /// request types. | 10 | /// request types. |
| 11 | #[repr(u8)] | ||
| 12 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | 11 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] |
| 13 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 12 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 14 | pub enum Direction { | 13 | pub enum Direction { |
| 15 | /// Host to device (OUT) | 14 | /// Host to device (OUT) |
| 16 | Out = 0x00, | 15 | Out, |
| 17 | /// Device to host (IN) | 16 | /// Device to host (IN) |
| 18 | In = 0x80, | 17 | In, |
| 19 | } | ||
| 20 | |||
| 21 | impl From<u8> for Direction { | ||
| 22 | fn from(value: u8) -> Self { | ||
| 23 | unsafe { core::mem::transmute(value & 0x80) } | ||
| 24 | } | ||
| 25 | } | 18 | } |
| 26 | 19 | ||
| 27 | /// USB endpoint transfer type. The values of this enum can be directly cast into `u8` to get the | 20 | /// USB endpoint transfer type. The values of this enum can be directly cast into `u8` to get the |
