diff options
| -rw-r--r-- | embassy-nrf/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-nrf/src/chips/nrf52820.rs | 1 | ||||
| -rw-r--r-- | embassy-nrf/src/chips/nrf52833.rs | 1 | ||||
| -rw-r--r-- | embassy-nrf/src/chips/nrf52840.rs | 1 | ||||
| -rw-r--r-- | embassy-nrf/src/chips/nrf5340_app.rs | 1 | ||||
| -rw-r--r-- | embassy-nrf/src/lib.rs | 1 | ||||
| -rw-r--r-- | embassy-nrf/src/usb.rs | 11 | ||||
| -rw-r--r-- | embassy-usb-serial/Cargo.toml | 11 | ||||
| -rw-r--r-- | embassy-usb-serial/src/fmt.rs | 225 | ||||
| -rw-r--r-- | embassy-usb-serial/src/lib.rs (renamed from examples/nrf/src/bin/usb/cdc_acm.rs) | 13 | ||||
| -rw-r--r-- | embassy-usb/Cargo.toml | 2 | ||||
| -rw-r--r-- | embassy-usb/src/descriptor.rs | 1 | ||||
| -rw-r--r-- | embassy-usb/src/lib.rs | 10 | ||||
| -rw-r--r-- | examples/nrf/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb_serial.rs (renamed from examples/nrf/src/bin/usb/main.rs) | 9 |
15 files changed, 265 insertions, 27 deletions
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 36c61c651..858ff1f6e 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml | |||
| @@ -18,7 +18,7 @@ flavors = [ | |||
| 18 | [features] | 18 | [features] |
| 19 | 19 | ||
| 20 | # Enable nightly-only features | 20 | # Enable nightly-only features |
| 21 | nightly = ["embassy/nightly", "embedded-hal-1", "embedded-hal-async"] | 21 | nightly = ["embassy/nightly", "embedded-hal-1", "embedded-hal-async", "embassy-usb"] |
| 22 | 22 | ||
| 23 | # Reexport the PAC for the currently enabled chip at `embassy_nrf::pac`. | 23 | # Reexport the PAC for the currently enabled chip at `embassy_nrf::pac`. |
| 24 | # This is unstable because semver-minor (non-breaking) releases of embassy-nrf may major-bump (breaking) the PAC version. | 24 | # This is unstable because semver-minor (non-breaking) releases of embassy-nrf may major-bump (breaking) the PAC version. |
| @@ -64,7 +64,7 @@ _gpio-p1 = [] | |||
| 64 | embassy = { version = "0.1.0", path = "../embassy" } | 64 | embassy = { version = "0.1.0", path = "../embassy" } |
| 65 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]} | 65 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]} |
| 66 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } | 66 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } |
| 67 | embassy-usb = {version = "0.1.0", path = "../embassy-usb" } | 67 | embassy-usb = {version = "0.1.0", path = "../embassy-usb", optional=true } |
| 68 | 68 | ||
| 69 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } | 69 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } |
| 70 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.7", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy2", optional = true} | 70 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.7", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy2", optional = true} |
diff --git a/embassy-nrf/src/chips/nrf52820.rs b/embassy-nrf/src/chips/nrf52820.rs index aa2b2e61d..136ef4ec9 100644 --- a/embassy-nrf/src/chips/nrf52820.rs +++ b/embassy-nrf/src/chips/nrf52820.rs | |||
| @@ -125,6 +125,7 @@ embassy_hal_common::peripherals! { | |||
| 125 | TEMP, | 125 | TEMP, |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | #[cfg(feature = "nightly")] | ||
| 128 | impl_usb!(USBD, USBD, USBD); | 129 | impl_usb!(USBD, USBD, USBD); |
| 129 | 130 | ||
| 130 | impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); | 131 | impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); |
diff --git a/embassy-nrf/src/chips/nrf52833.rs b/embassy-nrf/src/chips/nrf52833.rs index 498a3c307..35cf4224d 100644 --- a/embassy-nrf/src/chips/nrf52833.rs +++ b/embassy-nrf/src/chips/nrf52833.rs | |||
| @@ -157,6 +157,7 @@ embassy_hal_common::peripherals! { | |||
| 157 | TEMP, | 157 | TEMP, |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | #[cfg(feature = "nightly")] | ||
| 160 | impl_usb!(USBD, USBD, USBD); | 161 | impl_usb!(USBD, USBD, USBD); |
| 161 | 162 | ||
| 162 | impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); | 163 | impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); |
diff --git a/embassy-nrf/src/chips/nrf52840.rs b/embassy-nrf/src/chips/nrf52840.rs index 411768146..d20abbfbd 100644 --- a/embassy-nrf/src/chips/nrf52840.rs +++ b/embassy-nrf/src/chips/nrf52840.rs | |||
| @@ -160,6 +160,7 @@ embassy_hal_common::peripherals! { | |||
| 160 | TEMP, | 160 | TEMP, |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | #[cfg(feature = "nightly")] | ||
| 163 | impl_usb!(USBD, USBD, USBD); | 164 | impl_usb!(USBD, USBD, USBD); |
| 164 | 165 | ||
| 165 | impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); | 166 | impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); |
diff --git a/embassy-nrf/src/chips/nrf5340_app.rs b/embassy-nrf/src/chips/nrf5340_app.rs index ae6887b3c..89579b69f 100644 --- a/embassy-nrf/src/chips/nrf5340_app.rs +++ b/embassy-nrf/src/chips/nrf5340_app.rs | |||
| @@ -348,6 +348,7 @@ embassy_hal_common::peripherals! { | |||
| 348 | P1_15, | 348 | P1_15, |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | #[cfg(feature = "nightly")] | ||
| 351 | impl_usb!(USBD, USBD, USBD); | 352 | impl_usb!(USBD, USBD, USBD); |
| 352 | 353 | ||
| 353 | impl_uarte!(UARTETWISPI0, UARTE0, SERIAL0); | 354 | impl_uarte!(UARTETWISPI0, UARTE0, SERIAL0); |
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 06e8235e3..667e8ea38 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -91,6 +91,7 @@ pub mod uarte; | |||
| 91 | feature = "nrf52833", | 91 | feature = "nrf52833", |
| 92 | feature = "nrf52840" | 92 | feature = "nrf52840" |
| 93 | ))] | 93 | ))] |
| 94 | #[cfg(feature = "nightly")] | ||
| 94 | pub mod usb; | 95 | pub mod usb; |
| 95 | #[cfg(not(feature = "_nrf5340"))] | 96 | #[cfg(not(feature = "_nrf5340"))] |
| 96 | pub mod wdt; | 97 | pub mod wdt; |
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 1cd5a9ebb..b26e40272 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -4,6 +4,7 @@ use core::marker::PhantomData; | |||
| 4 | use core::mem::MaybeUninit; | 4 | use core::mem::MaybeUninit; |
| 5 | use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; | 5 | use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; |
| 6 | use core::task::Poll; | 6 | use core::task::Poll; |
| 7 | use cortex_m::peripheral::NVIC; | ||
| 7 | use embassy::interrupt::InterruptExt; | 8 | use embassy::interrupt::InterruptExt; |
| 8 | use embassy::time::{with_timeout, Duration}; | 9 | use embassy::time::{with_timeout, Duration}; |
| 9 | use embassy::util::Unborrow; | 10 | use embassy::util::Unborrow; |
| @@ -14,7 +15,6 @@ use embassy_usb::driver::{self, Event, ReadError, WriteError}; | |||
| 14 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; | 15 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; |
| 15 | use futures::future::poll_fn; | 16 | use futures::future::poll_fn; |
| 16 | use futures::Future; | 17 | use futures::Future; |
| 17 | use pac::NVIC; | ||
| 18 | 18 | ||
| 19 | pub use embassy_usb; | 19 | pub use embassy_usb; |
| 20 | 20 | ||
| @@ -617,7 +617,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 617 | fn data_out<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::DataOutFuture<'a> { | 617 | fn data_out<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::DataOutFuture<'a> { |
| 618 | async move { | 618 | async move { |
| 619 | let req = self.request.unwrap(); | 619 | let req = self.request.unwrap(); |
| 620 | assert_eq!(req.direction, UsbDirection::Out); | 620 | assert!(req.direction == UsbDirection::Out); |
| 621 | assert!(req.length > 0); | 621 | assert!(req.length > 0); |
| 622 | 622 | ||
| 623 | let req_length = usize::from(req.length); | 623 | let req_length = usize::from(req.length); |
| @@ -644,9 +644,12 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 644 | 644 | ||
| 645 | fn accept_in<'a>(&'a mut self, buf: &'a [u8]) -> Self::AcceptInFuture<'a> { | 645 | fn accept_in<'a>(&'a mut self, buf: &'a [u8]) -> Self::AcceptInFuture<'a> { |
| 646 | async move { | 646 | async move { |
| 647 | info!("control accept {=[u8]:x}", buf); | 647 | #[cfg(feature = "defmt")] |
| 648 | info!("control accept {:x}", buf); | ||
| 649 | #[cfg(not(feature = "defmt"))] | ||
| 650 | info!("control accept {:x?}", buf); | ||
| 648 | let req = self.request.unwrap(); | 651 | let req = self.request.unwrap(); |
| 649 | assert_eq!(req.direction, UsbDirection::In); | 652 | assert!(req.direction == UsbDirection::In); |
| 650 | 653 | ||
| 651 | let req_len = usize::from(req.length); | 654 | let req_len = usize::from(req.length); |
| 652 | let len = buf.len().min(req_len); | 655 | let len = buf.len().min(req_len); |
diff --git a/embassy-usb-serial/Cargo.toml b/embassy-usb-serial/Cargo.toml new file mode 100644 index 000000000..16e03046e --- /dev/null +++ b/embassy-usb-serial/Cargo.toml | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | [package] | ||
| 2 | name = "embassy-usb-serial" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | |||
| 6 | [dependencies] | ||
| 7 | embassy = { version = "0.1.0", path = "../embassy" } | ||
| 8 | embassy-usb = { version = "0.1.0", path = "../embassy-usb" } | ||
| 9 | |||
| 10 | defmt = { version = "0.3", optional = true } | ||
| 11 | log = { version = "0.4.14", optional = true } | ||
diff --git a/embassy-usb-serial/src/fmt.rs b/embassy-usb-serial/src/fmt.rs new file mode 100644 index 000000000..066970813 --- /dev/null +++ b/embassy-usb-serial/src/fmt.rs | |||
| @@ -0,0 +1,225 @@ | |||
| 1 | #![macro_use] | ||
| 2 | #![allow(unused_macros)] | ||
| 3 | |||
| 4 | #[cfg(all(feature = "defmt", feature = "log"))] | ||
| 5 | compile_error!("You may not enable both `defmt` and `log` features."); | ||
| 6 | |||
| 7 | macro_rules! assert { | ||
| 8 | ($($x:tt)*) => { | ||
| 9 | { | ||
| 10 | #[cfg(not(feature = "defmt"))] | ||
| 11 | ::core::assert!($($x)*); | ||
| 12 | #[cfg(feature = "defmt")] | ||
| 13 | ::defmt::assert!($($x)*); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 17 | |||
| 18 | macro_rules! assert_eq { | ||
| 19 | ($($x:tt)*) => { | ||
| 20 | { | ||
| 21 | #[cfg(not(feature = "defmt"))] | ||
| 22 | ::core::assert_eq!($($x)*); | ||
| 23 | #[cfg(feature = "defmt")] | ||
| 24 | ::defmt::assert_eq!($($x)*); | ||
| 25 | } | ||
| 26 | }; | ||
| 27 | } | ||
| 28 | |||
| 29 | macro_rules! assert_ne { | ||
| 30 | ($($x:tt)*) => { | ||
| 31 | { | ||
| 32 | #[cfg(not(feature = "defmt"))] | ||
| 33 | ::core::assert_ne!($($x)*); | ||
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | ::defmt::assert_ne!($($x)*); | ||
| 36 | } | ||
| 37 | }; | ||
| 38 | } | ||
| 39 | |||
| 40 | macro_rules! debug_assert { | ||
| 41 | ($($x:tt)*) => { | ||
| 42 | { | ||
| 43 | #[cfg(not(feature = "defmt"))] | ||
| 44 | ::core::debug_assert!($($x)*); | ||
| 45 | #[cfg(feature = "defmt")] | ||
| 46 | ::defmt::debug_assert!($($x)*); | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | } | ||
| 50 | |||
| 51 | macro_rules! debug_assert_eq { | ||
| 52 | ($($x:tt)*) => { | ||
| 53 | { | ||
| 54 | #[cfg(not(feature = "defmt"))] | ||
| 55 | ::core::debug_assert_eq!($($x)*); | ||
| 56 | #[cfg(feature = "defmt")] | ||
| 57 | ::defmt::debug_assert_eq!($($x)*); | ||
| 58 | } | ||
| 59 | }; | ||
| 60 | } | ||
| 61 | |||
| 62 | macro_rules! debug_assert_ne { | ||
| 63 | ($($x:tt)*) => { | ||
| 64 | { | ||
| 65 | #[cfg(not(feature = "defmt"))] | ||
| 66 | ::core::debug_assert_ne!($($x)*); | ||
| 67 | #[cfg(feature = "defmt")] | ||
| 68 | ::defmt::debug_assert_ne!($($x)*); | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | } | ||
| 72 | |||
| 73 | macro_rules! todo { | ||
| 74 | ($($x:tt)*) => { | ||
| 75 | { | ||
| 76 | #[cfg(not(feature = "defmt"))] | ||
| 77 | ::core::todo!($($x)*); | ||
| 78 | #[cfg(feature = "defmt")] | ||
| 79 | ::defmt::todo!($($x)*); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
| 83 | |||
| 84 | macro_rules! unreachable { | ||
| 85 | ($($x:tt)*) => { | ||
| 86 | { | ||
| 87 | #[cfg(not(feature = "defmt"))] | ||
| 88 | ::core::unreachable!($($x)*); | ||
| 89 | #[cfg(feature = "defmt")] | ||
| 90 | ::defmt::unreachable!($($x)*); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 94 | |||
| 95 | macro_rules! panic { | ||
| 96 | ($($x:tt)*) => { | ||
| 97 | { | ||
| 98 | #[cfg(not(feature = "defmt"))] | ||
| 99 | ::core::panic!($($x)*); | ||
| 100 | #[cfg(feature = "defmt")] | ||
| 101 | ::defmt::panic!($($x)*); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 105 | |||
| 106 | macro_rules! trace { | ||
| 107 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 108 | { | ||
| 109 | #[cfg(feature = "log")] | ||
| 110 | ::log::trace!($s $(, $x)*); | ||
| 111 | #[cfg(feature = "defmt")] | ||
| 112 | ::defmt::trace!($s $(, $x)*); | ||
| 113 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 114 | let _ = ($( & $x ),*); | ||
| 115 | } | ||
| 116 | }; | ||
| 117 | } | ||
| 118 | |||
| 119 | macro_rules! debug { | ||
| 120 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 121 | { | ||
| 122 | #[cfg(feature = "log")] | ||
| 123 | ::log::debug!($s $(, $x)*); | ||
| 124 | #[cfg(feature = "defmt")] | ||
| 125 | ::defmt::debug!($s $(, $x)*); | ||
| 126 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 127 | let _ = ($( & $x ),*); | ||
| 128 | } | ||
| 129 | }; | ||
| 130 | } | ||
| 131 | |||
| 132 | macro_rules! info { | ||
| 133 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 134 | { | ||
| 135 | #[cfg(feature = "log")] | ||
| 136 | ::log::info!($s $(, $x)*); | ||
| 137 | #[cfg(feature = "defmt")] | ||
| 138 | ::defmt::info!($s $(, $x)*); | ||
| 139 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 140 | let _ = ($( & $x ),*); | ||
| 141 | } | ||
| 142 | }; | ||
| 143 | } | ||
| 144 | |||
| 145 | macro_rules! warn { | ||
| 146 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 147 | { | ||
| 148 | #[cfg(feature = "log")] | ||
| 149 | ::log::warn!($s $(, $x)*); | ||
| 150 | #[cfg(feature = "defmt")] | ||
| 151 | ::defmt::warn!($s $(, $x)*); | ||
| 152 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 153 | let _ = ($( & $x ),*); | ||
| 154 | } | ||
| 155 | }; | ||
| 156 | } | ||
| 157 | |||
| 158 | macro_rules! error { | ||
| 159 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 160 | { | ||
| 161 | #[cfg(feature = "log")] | ||
| 162 | ::log::error!($s $(, $x)*); | ||
| 163 | #[cfg(feature = "defmt")] | ||
| 164 | ::defmt::error!($s $(, $x)*); | ||
| 165 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 166 | let _ = ($( & $x ),*); | ||
| 167 | } | ||
| 168 | }; | ||
| 169 | } | ||
| 170 | |||
| 171 | #[cfg(feature = "defmt")] | ||
| 172 | macro_rules! unwrap { | ||
| 173 | ($($x:tt)*) => { | ||
| 174 | ::defmt::unwrap!($($x)*) | ||
| 175 | }; | ||
| 176 | } | ||
| 177 | |||
| 178 | #[cfg(not(feature = "defmt"))] | ||
| 179 | macro_rules! unwrap { | ||
| 180 | ($arg:expr) => { | ||
| 181 | match $crate::fmt::Try::into_result($arg) { | ||
| 182 | ::core::result::Result::Ok(t) => t, | ||
| 183 | ::core::result::Result::Err(e) => { | ||
| 184 | ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e); | ||
| 185 | } | ||
| 186 | } | ||
| 187 | }; | ||
| 188 | ($arg:expr, $($msg:expr),+ $(,)? ) => { | ||
| 189 | match $crate::fmt::Try::into_result($arg) { | ||
| 190 | ::core::result::Result::Ok(t) => t, | ||
| 191 | ::core::result::Result::Err(e) => { | ||
| 192 | ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
| 199 | pub struct NoneError; | ||
| 200 | |||
| 201 | pub trait Try { | ||
| 202 | type Ok; | ||
| 203 | type Error; | ||
| 204 | fn into_result(self) -> Result<Self::Ok, Self::Error>; | ||
| 205 | } | ||
| 206 | |||
| 207 | impl<T> Try for Option<T> { | ||
| 208 | type Ok = T; | ||
| 209 | type Error = NoneError; | ||
| 210 | |||
| 211 | #[inline] | ||
| 212 | fn into_result(self) -> Result<T, NoneError> { | ||
| 213 | self.ok_or(NoneError) | ||
| 214 | } | ||
| 215 | } | ||
| 216 | |||
| 217 | impl<T, E> Try for Result<T, E> { | ||
| 218 | type Ok = T; | ||
| 219 | type Error = E; | ||
| 220 | |||
| 221 | #[inline] | ||
| 222 | fn into_result(self) -> Self { | ||
| 223 | self | ||
| 224 | } | ||
| 225 | } | ||
diff --git a/examples/nrf/src/bin/usb/cdc_acm.rs b/embassy-usb-serial/src/lib.rs index c28681dc4..d6c31c86e 100644 --- a/examples/nrf/src/bin/usb/cdc_acm.rs +++ b/embassy-usb-serial/src/lib.rs | |||
| @@ -1,7 +1,13 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![feature(generic_associated_types)] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | // This mod MUST go first, so that the others see its macros. | ||
| 6 | pub(crate) mod fmt; | ||
| 7 | |||
| 1 | use core::cell::Cell; | 8 | use core::cell::Cell; |
| 2 | use core::mem::{self, MaybeUninit}; | 9 | use core::mem::{self, MaybeUninit}; |
| 3 | use core::sync::atomic::{AtomicBool, Ordering}; | 10 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 4 | use defmt::info; | ||
| 5 | use embassy::blocking_mutex::CriticalSectionMutex; | 11 | use embassy::blocking_mutex::CriticalSectionMutex; |
| 6 | use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; | 12 | use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; |
| 7 | use embassy_usb::driver::{Endpoint, EndpointIn, EndpointOut, ReadError, WriteError}; | 13 | use embassy_usb::driver::{Endpoint, EndpointIn, EndpointOut, ReadError, WriteError}; |
| @@ -291,11 +297,6 @@ impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> { | |||
| 291 | pub async fn read_packet(&mut self, data: &mut [u8]) -> Result<usize, ReadError> { | 297 | pub async fn read_packet(&mut self, data: &mut [u8]) -> Result<usize, ReadError> { |
| 292 | self.read_ep.read(data).await | 298 | self.read_ep.read(data).await |
| 293 | } | 299 | } |
| 294 | |||
| 295 | /// Gets the address of the IN endpoint. | ||
| 296 | pub(crate) fn write_ep_address(&self) -> EndpointAddress { | ||
| 297 | self.write_ep.info().addr | ||
| 298 | } | ||
| 299 | } | 300 | } |
| 300 | 301 | ||
| 301 | /// Number of stop bits for LineCoding | 302 | /// Number of stop bits for LineCoding |
diff --git a/embassy-usb/Cargo.toml b/embassy-usb/Cargo.toml index af5986c15..01bf5ef6f 100644 --- a/embassy-usb/Cargo.toml +++ b/embassy-usb/Cargo.toml | |||
| @@ -8,6 +8,4 @@ embassy = { version = "0.1.0", path = "../embassy" } | |||
| 8 | 8 | ||
| 9 | defmt = { version = "0.3", optional = true } | 9 | defmt = { version = "0.3", optional = true } |
| 10 | log = { version = "0.4.14", optional = true } | 10 | log = { version = "0.4.14", optional = true } |
| 11 | cortex-m = "0.7.3" | ||
| 12 | num-traits = { version = "0.2.14", default-features = false } | ||
| 13 | heapless = "0.7.10" \ No newline at end of file | 11 | heapless = "0.7.10" \ No newline at end of file |
diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs index 746c6b828..5f8b0d560 100644 --- a/embassy-usb/src/descriptor.rs +++ b/embassy-usb/src/descriptor.rs | |||
| @@ -136,6 +136,7 @@ impl<'a> DescriptorWriter<'a> { | |||
| 136 | ) | 136 | ) |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | #[allow(unused)] | ||
| 139 | pub(crate) fn end_class(&mut self) { | 140 | pub(crate) fn end_class(&mut self) { |
| 140 | self.num_endpoints_mark = None; | 141 | self.num_endpoints_mark = None; |
| 141 | } | 142 | } |
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index cbb909244..5a6b21906 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs | |||
| @@ -302,7 +302,6 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 302 | 302 | ||
| 303 | async fn handle_get_descriptor(&mut self, req: Request) { | 303 | async fn handle_get_descriptor(&mut self, req: Request) { |
| 304 | let (dtype, index) = req.descriptor_type_index(); | 304 | let (dtype, index) = req.descriptor_type_index(); |
| 305 | let config = self.config.clone(); | ||
| 306 | 305 | ||
| 307 | match dtype { | 306 | match dtype { |
| 308 | descriptor_type::BOS => self.control.accept_in(self.bos_descriptor).await, | 307 | descriptor_type::BOS => self.control.accept_in(self.bos_descriptor).await, |
| @@ -321,13 +320,10 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 321 | 2 => self.config.product, | 320 | 2 => self.config.product, |
| 322 | 3 => self.config.serial_number, | 321 | 3 => self.config.serial_number, |
| 323 | _ => { | 322 | _ => { |
| 324 | let index = StringIndex::new(index); | 323 | let _index = StringIndex::new(index); |
| 325 | let lang_id = req.index; | 324 | let _lang_id = req.index; |
| 325 | // TODO | ||
| 326 | None | 326 | None |
| 327 | //classes | ||
| 328 | // .iter() | ||
| 329 | // .filter_map(|cls| cls.get_string(index, lang_id)) | ||
| 330 | // .nth(0) | ||
| 331 | } | 327 | } |
| 332 | }; | 328 | }; |
| 333 | 329 | ||
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index 59e5de026..58450a045 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml | |||
| @@ -12,6 +12,7 @@ nightly = ["embassy-nrf/nightly", "embassy-nrf/unstable-traits"] | |||
| 12 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] } | 12 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] } |
| 13 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } | 13 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } |
| 14 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 14 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 15 | embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } | ||
| 15 | 16 | ||
| 16 | defmt = "0.3" | 17 | defmt = "0.3" |
| 17 | defmt-rtt = "0.3" | 18 | defmt-rtt = "0.3" |
diff --git a/examples/nrf/src/bin/usb/main.rs b/examples/nrf/src/bin/usb_serial.rs index c4b9c0176..0a4ff9489 100644 --- a/examples/nrf/src/bin/usb/main.rs +++ b/examples/nrf/src/bin/usb_serial.rs | |||
| @@ -3,11 +3,6 @@ | |||
| 3 | #![feature(generic_associated_types)] | 3 | #![feature(generic_associated_types)] |
| 4 | #![feature(type_alias_impl_trait)] | 4 | #![feature(type_alias_impl_trait)] |
| 5 | 5 | ||
| 6 | #[path = "../../example_common.rs"] | ||
| 7 | mod example_common; | ||
| 8 | |||
| 9 | mod cdc_acm; | ||
| 10 | |||
| 11 | use core::mem; | 6 | use core::mem; |
| 12 | use defmt::*; | 7 | use defmt::*; |
| 13 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| @@ -18,9 +13,11 @@ use embassy_nrf::usb::Driver; | |||
| 18 | use embassy_nrf::Peripherals; | 13 | use embassy_nrf::Peripherals; |
| 19 | use embassy_usb::driver::{EndpointIn, EndpointOut}; | 14 | use embassy_usb::driver::{EndpointIn, EndpointOut}; |
| 20 | use embassy_usb::{Config, UsbDeviceBuilder}; | 15 | use embassy_usb::{Config, UsbDeviceBuilder}; |
| 16 | use embassy_usb_serial::{CdcAcmClass, State}; | ||
| 21 | use futures::future::join3; | 17 | use futures::future::join3; |
| 22 | 18 | ||
| 23 | use crate::cdc_acm::{CdcAcmClass, State}; | 19 | use defmt_rtt as _; // global logger |
| 20 | use panic_probe as _; | ||
| 24 | 21 | ||
| 25 | #[embassy::main] | 22 | #[embassy::main] |
| 26 | async fn main(_spawner: Spawner, p: Peripherals) { | 23 | async fn main(_spawner: Spawner, p: Peripherals) { |
