diff options
Diffstat (limited to 'embassy-usb-dfu/src/consts.rs')
| -rw-r--r-- | embassy-usb-dfu/src/consts.rs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/embassy-usb-dfu/src/consts.rs b/embassy-usb-dfu/src/consts.rs new file mode 100644 index 000000000..b083af9de --- /dev/null +++ b/embassy-usb-dfu/src/consts.rs | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | |||
| 2 | pub(crate) const USB_CLASS_APPN_SPEC: u8 = 0xFE; | ||
| 3 | pub(crate) const APPN_SPEC_SUBCLASS_DFU: u8 = 0x01; | ||
| 4 | #[allow(unused)] | ||
| 5 | pub(crate) const DFU_PROTOCOL_DFU: u8 = 0x02; | ||
| 6 | #[allow(unused)] | ||
| 7 | pub(crate) const DFU_PROTOCOL_RT: u8 = 0x01; | ||
| 8 | pub(crate) const DESC_DFU_FUNCTIONAL: u8 = 0x21; | ||
| 9 | |||
| 10 | #[cfg(feature = "defmt")] | ||
| 11 | defmt::bitflags! { | ||
| 12 | pub struct DfuAttributes: u8 { | ||
| 13 | const WILL_DETACH = 0b0000_1000; | ||
| 14 | const MANIFESTATION_TOLERANT = 0b0000_0100; | ||
| 15 | const CAN_UPLOAD = 0b0000_0010; | ||
| 16 | const CAN_DOWNLOAD = 0b0000_0001; | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | #[cfg(not(feature = "defmt"))] | ||
| 21 | bitflags::bitflags! { | ||
| 22 | pub struct DfuAttributes: u8 { | ||
| 23 | const WILL_DETACH = 0b0000_1000; | ||
| 24 | const MANIFESTATION_TOLERANT = 0b0000_0100; | ||
| 25 | const CAN_UPLOAD = 0b0000_0010; | ||
| 26 | const CAN_DOWNLOAD = 0b0000_0001; | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | #[derive(Copy, Clone, PartialEq, Eq)] | ||
| 31 | #[repr(u8)] | ||
| 32 | #[allow(unused)] | ||
| 33 | pub enum State { | ||
| 34 | AppIdle = 0, | ||
| 35 | AppDetach = 1, | ||
| 36 | DfuIdle = 2, | ||
| 37 | DlSync = 3, | ||
| 38 | DlBusy = 4, | ||
| 39 | Download = 5, | ||
| 40 | ManifestSync = 6, | ||
| 41 | Manifest = 7, | ||
| 42 | ManifestWaitReset = 8, | ||
| 43 | UploadIdle = 9, | ||
| 44 | Error = 10, | ||
| 45 | } | ||
| 46 | |||
| 47 | #[derive(Copy, Clone, PartialEq, Eq)] | ||
| 48 | #[repr(u8)] | ||
| 49 | #[allow(unused)] | ||
| 50 | pub enum Status { | ||
| 51 | Ok = 0x00, | ||
| 52 | ErrTarget = 0x01, | ||
| 53 | ErrFile = 0x02, | ||
| 54 | ErrWrite = 0x03, | ||
| 55 | ErrErase = 0x04, | ||
| 56 | ErrCheckErased = 0x05, | ||
| 57 | ErrProg = 0x06, | ||
| 58 | ErrVerify = 0x07, | ||
| 59 | ErrAddress = 0x08, | ||
| 60 | ErrNotDone = 0x09, | ||
| 61 | ErrFirmware = 0x0A, | ||
| 62 | ErrVendor = 0x0B, | ||
| 63 | ErrUsbr = 0x0C, | ||
| 64 | ErrPor = 0x0D, | ||
| 65 | ErrUnknown = 0x0E, | ||
| 66 | ErrStalledPkt = 0x0F, | ||
| 67 | } | ||
| 68 | |||
| 69 | #[derive(Copy, Clone, PartialEq, Eq)] | ||
| 70 | #[repr(u8)] | ||
| 71 | pub enum Request { | ||
| 72 | Detach = 0, | ||
| 73 | Dnload = 1, | ||
| 74 | Upload = 2, | ||
| 75 | GetStatus = 3, | ||
| 76 | ClrStatus = 4, | ||
| 77 | GetState = 5, | ||
| 78 | Abort = 6, | ||
| 79 | } | ||
| 80 | |||
| 81 | impl TryFrom<u8> for Request { | ||
| 82 | type Error = (); | ||
| 83 | |||
| 84 | fn try_from(value: u8) -> Result<Self, Self::Error> { | ||
| 85 | match value { | ||
| 86 | 0 => Ok(Request::Detach), | ||
| 87 | 1 => Ok(Request::Dnload), | ||
| 88 | 2 => Ok(Request::Upload), | ||
| 89 | 3 => Ok(Request::GetStatus), | ||
| 90 | 4 => Ok(Request::ClrStatus), | ||
| 91 | 5 => Ok(Request::GetState), | ||
| 92 | 6 => Ok(Request::Abort), | ||
| 93 | _ => Err(()), | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
