aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-12-19 16:58:46 +0100
committerGitHub <[email protected]>2023-12-19 16:58:46 +0100
commit41c3c26beb5d9ef683073c257c1269307be6ad43 (patch)
treee4196f7c610199dd63f9eaca2bf5007138690052
parent7ec1ed4de3bc8a7ed4e737e28c56f0c54c117382 (diff)
parent9ddf8b08e448caca3825fc47aa737247323d8725 (diff)
Merge pull request #2323 from embassy-rs/embassy-usb-stuffs
docs: document usb-logger and usb-dfu
-rw-r--r--embassy-usb-dfu/README.md20
-rw-r--r--embassy-usb-dfu/src/application.rs1
-rw-r--r--embassy-usb-dfu/src/consts.rs12
-rw-r--r--embassy-usb-dfu/src/dfu.rs (renamed from embassy-usb-dfu/src/bootloader.rs)1
-rw-r--r--embassy-usb-dfu/src/lib.rs11
-rw-r--r--embassy-usb-logger/README.md14
6 files changed, 53 insertions, 6 deletions
diff --git a/embassy-usb-dfu/README.md b/embassy-usb-dfu/README.md
new file mode 100644
index 000000000..d8bc19bfd
--- /dev/null
+++ b/embassy-usb-dfu/README.md
@@ -0,0 +1,20 @@
1# embassy-usb-dfu
2
3An implementation of the USB DFU 1.1 protocol using embassy-boot. It has 2 components depending on which feature is enabled by the user.
4
5* DFU protocol mode, enabled by the `dfu` feature. This mode corresponds to the transfer phase DFU protocol described by the USB IF. It supports DFU_DNLOAD requests if marked by the user, and will automatically reset the chip once a DFU transaction has been completed. It also responds to DFU_GETSTATUS, DFU_GETSTATE, DFU_ABORT, and DFU_CLRSTATUS with no user intervention.
6* DFU runtime mode, enabled by the `application feature`. This mode allows users to expose a DFU interface on their USB device, informing the host of the capability to DFU over USB, and allowing the host to reset the device into its bootloader to complete a DFU operation. Supports DFU_GETSTATUS and DFU_DETACH. When detach/reset is seen by the device as described by the standard, will write a new DFU magic number into the bootloader state in flash, and reset the system.
7
8## Minimum supported Rust version (MSRV)
9
10Embassy is guaranteed to compile on the latest stable Rust version at the time of release. It might compile with older versions but that may change in any new patch release.
11
12## License
13
14This work is licensed under either of
15
16- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
17 <http://www.apache.org/licenses/LICENSE-2.0>)
18- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
19
20at your option.
diff --git a/embassy-usb-dfu/src/application.rs b/embassy-usb-dfu/src/application.rs
index 75689db26..f0d7626f6 100644
--- a/embassy-usb-dfu/src/application.rs
+++ b/embassy-usb-dfu/src/application.rs
@@ -24,6 +24,7 @@ pub struct Control<'d, STATE: NorFlash, RST: Reset> {
24} 24}
25 25
26impl<'d, STATE: NorFlash, RST: Reset> Control<'d, STATE, RST> { 26impl<'d, STATE: NorFlash, RST: Reset> Control<'d, STATE, RST> {
27 /// Create a new DFU instance to expose a DFU interface.
27 pub fn new(firmware_state: BlockingFirmwareState<'d, STATE>, attrs: DfuAttributes) -> Self { 28 pub fn new(firmware_state: BlockingFirmwareState<'d, STATE>, attrs: DfuAttributes) -> Self {
28 Control { 29 Control {
29 firmware_state, 30 firmware_state,
diff --git a/embassy-usb-dfu/src/consts.rs b/embassy-usb-dfu/src/consts.rs
index b359a107e..f8a056e5c 100644
--- a/embassy-usb-dfu/src/consts.rs
+++ b/embassy-usb-dfu/src/consts.rs
@@ -1,3 +1,4 @@
1//! USB DFU constants.
1pub(crate) const USB_CLASS_APPN_SPEC: u8 = 0xFE; 2pub(crate) const USB_CLASS_APPN_SPEC: u8 = 0xFE;
2pub(crate) const APPN_SPEC_SUBCLASS_DFU: u8 = 0x01; 3pub(crate) const APPN_SPEC_SUBCLASS_DFU: u8 = 0x01;
3#[allow(unused)] 4#[allow(unused)]
@@ -18,10 +19,15 @@ defmt::bitflags! {
18 19
19#[cfg(not(feature = "defmt"))] 20#[cfg(not(feature = "defmt"))]
20bitflags::bitflags! { 21bitflags::bitflags! {
22 /// Attributes supported by the DFU controller.
21 pub struct DfuAttributes: u8 { 23 pub struct DfuAttributes: u8 {
24 /// Generate WillDetache sequence on bus.
22 const WILL_DETACH = 0b0000_1000; 25 const WILL_DETACH = 0b0000_1000;
26 /// Device can communicate during manifestation phase.
23 const MANIFESTATION_TOLERANT = 0b0000_0100; 27 const MANIFESTATION_TOLERANT = 0b0000_0100;
28 /// Capable of upload.
24 const CAN_UPLOAD = 0b0000_0010; 29 const CAN_UPLOAD = 0b0000_0010;
30 /// Capable of download.
25 const CAN_DOWNLOAD = 0b0000_0001; 31 const CAN_DOWNLOAD = 0b0000_0001;
26 } 32 }
27} 33}
@@ -29,7 +35,7 @@ bitflags::bitflags! {
29#[derive(Copy, Clone, PartialEq, Eq)] 35#[derive(Copy, Clone, PartialEq, Eq)]
30#[repr(u8)] 36#[repr(u8)]
31#[allow(unused)] 37#[allow(unused)]
32pub enum State { 38pub(crate) enum State {
33 AppIdle = 0, 39 AppIdle = 0,
34 AppDetach = 1, 40 AppDetach = 1,
35 DfuIdle = 2, 41 DfuIdle = 2,
@@ -46,7 +52,7 @@ pub enum State {
46#[derive(Copy, Clone, PartialEq, Eq)] 52#[derive(Copy, Clone, PartialEq, Eq)]
47#[repr(u8)] 53#[repr(u8)]
48#[allow(unused)] 54#[allow(unused)]
49pub enum Status { 55pub(crate) enum Status {
50 Ok = 0x00, 56 Ok = 0x00,
51 ErrTarget = 0x01, 57 ErrTarget = 0x01,
52 ErrFile = 0x02, 58 ErrFile = 0x02,
@@ -67,7 +73,7 @@ pub enum Status {
67 73
68#[derive(Copy, Clone, PartialEq, Eq)] 74#[derive(Copy, Clone, PartialEq, Eq)]
69#[repr(u8)] 75#[repr(u8)]
70pub enum Request { 76pub(crate) enum Request {
71 Detach = 0, 77 Detach = 0,
72 Dnload = 1, 78 Dnload = 1,
73 Upload = 2, 79 Upload = 2,
diff --git a/embassy-usb-dfu/src/bootloader.rs b/embassy-usb-dfu/src/dfu.rs
index d41e6280d..e99aa70c3 100644
--- a/embassy-usb-dfu/src/bootloader.rs
+++ b/embassy-usb-dfu/src/dfu.rs
@@ -23,6 +23,7 @@ pub struct Control<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_S
23} 23}
24 24
25impl<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> Control<'d, DFU, STATE, RST, BLOCK_SIZE> { 25impl<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> Control<'d, DFU, STATE, RST, BLOCK_SIZE> {
26 /// Create a new DFU instance to handle DFU transfers.
26 pub fn new(updater: BlockingFirmwareUpdater<'d, DFU, STATE>, attrs: DfuAttributes) -> Self { 27 pub fn new(updater: BlockingFirmwareUpdater<'d, DFU, STATE>, attrs: DfuAttributes) -> Self {
27 Self { 28 Self {
28 updater, 29 updater,
diff --git a/embassy-usb-dfu/src/lib.rs b/embassy-usb-dfu/src/lib.rs
index 389bb33f2..eaa4b6e33 100644
--- a/embassy-usb-dfu/src/lib.rs
+++ b/embassy-usb-dfu/src/lib.rs
@@ -1,12 +1,14 @@
1#![no_std] 1#![no_std]
2#![doc = include_str!("../README.md")]
3#![warn(missing_docs)]
2mod fmt; 4mod fmt;
3 5
4pub mod consts; 6pub mod consts;
5 7
6#[cfg(feature = "dfu")] 8#[cfg(feature = "dfu")]
7mod bootloader; 9mod dfu;
8#[cfg(feature = "dfu")] 10#[cfg(feature = "dfu")]
9pub use self::bootloader::*; 11pub use self::dfu::*;
10 12
11#[cfg(feature = "application")] 13#[cfg(feature = "application")]
12mod application; 14mod application;
@@ -17,7 +19,7 @@ pub use self::application::*;
17 all(feature = "dfu", feature = "application"), 19 all(feature = "dfu", feature = "application"),
18 not(any(feature = "dfu", feature = "application")) 20 not(any(feature = "dfu", feature = "application"))
19))] 21))]
20compile_error!("usb-dfu must be compiled with exactly one of `bootloader`, or `application` features"); 22compile_error!("usb-dfu must be compiled with exactly one of `dfu`, or `application` features");
21 23
22/// Provides a platform-agnostic interface for initiating a system reset. 24/// Provides a platform-agnostic interface for initiating a system reset.
23/// 25///
@@ -26,9 +28,11 @@ compile_error!("usb-dfu must be compiled with exactly one of `bootloader`, or `a
26/// 28///
27/// If alternate behaviour is desired, a custom implementation of Reset can be provided as a type argument to the usb_dfu function. 29/// If alternate behaviour is desired, a custom implementation of Reset can be provided as a type argument to the usb_dfu function.
28pub trait Reset { 30pub trait Reset {
31 /// Reset the device.
29 fn sys_reset() -> !; 32 fn sys_reset() -> !;
30} 33}
31 34
35/// Reset immediately.
32#[cfg(feature = "esp32c3-hal")] 36#[cfg(feature = "esp32c3-hal")]
33pub struct ResetImmediate; 37pub struct ResetImmediate;
34 38
@@ -40,6 +44,7 @@ impl Reset for ResetImmediate {
40 } 44 }
41} 45}
42 46
47/// Reset immediately.
43#[cfg(feature = "cortex-m")] 48#[cfg(feature = "cortex-m")]
44pub struct ResetImmediate; 49pub struct ResetImmediate;
45 50
diff --git a/embassy-usb-logger/README.md b/embassy-usb-logger/README.md
index 81b0dcd0e..6cb18e87d 100644
--- a/embassy-usb-logger/README.md
+++ b/embassy-usb-logger/README.md
@@ -13,3 +13,17 @@ async fn logger_task(driver: Driver<'static, USB>) {
13 embassy_usb_logger::run!(1024, log::LevelFilter::Info, driver); 13 embassy_usb_logger::run!(1024, log::LevelFilter::Info, driver);
14} 14}
15``` 15```
16
17## Minimum supported Rust version (MSRV)
18
19Embassy is guaranteed to compile on the latest stable Rust version at the time of release. It might compile with older versions but that may change in any new patch release.
20
21## License
22
23This work is licensed under either of
24
25- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
26 <http://www.apache.org/licenses/LICENSE-2.0>)
27- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
28
29at your option.