diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-09-26 11:32:41 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-09-26 11:32:41 +0000 |
| commit | 49070c75b6de7581e418f00e37540a34e0bf1dab (patch) | |
| tree | 2036bafea0ec082a57cd6f741b9414a025da7b61 | |
| parent | dc376a23909b1def19b64f65d954995330870fe7 (diff) | |
| parent | f27a47a37b59bf3b9079f4d4d5f43caf7b7872f8 (diff) | |
Merge #972
972: Restructure USB crates r=Dirbaio a=Dirbaio
- Split driver from `embassy-usb` to a separate crate. This allows making breaking changes to `embassy-usb` without having to bump all the crates with driver impls, such as HALs.
- Merge classes into `embassy-usb`. Now that breaking changes to `embassy-usb` aren't that bad, having everything in a single crate is much easier.
Co-authored-by: Dario Nieuwenhuis <[email protected]>
38 files changed, 218 insertions, 951 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 0685d419c..20510eb49 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -10,8 +10,9 @@ use cortex_m::peripheral::NVIC; | |||
| 10 | use embassy_hal_common::{into_ref, PeripheralRef}; | 10 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 11 | use embassy_sync::waitqueue::AtomicWaker; | 11 | use embassy_sync::waitqueue::AtomicWaker; |
| 12 | pub use embassy_usb; | 12 | pub use embassy_usb; |
| 13 | use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; | 13 | use embassy_usb::driver::{ |
| 14 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; | 14 | self, Direction, EndpointAddress, EndpointError, EndpointInfo, EndpointType, Event, Unsupported, |
| 15 | }; | ||
| 15 | use pac::usbd::RegisterBlock; | 16 | use pac::usbd::RegisterBlock; |
| 16 | 17 | ||
| 17 | use crate::interrupt::{Interrupt, InterruptExt}; | 18 | use crate::interrupt::{Interrupt, InterruptExt}; |
| @@ -243,7 +244,7 @@ impl<'d, T: Instance, P: UsbSupply + 'd> driver::Driver<'d> for Driver<'d, T, P> | |||
| 243 | interval: u8, | 244 | interval: u8, |
| 244 | ) -> Result<Self::EndpointIn, driver::EndpointAllocError> { | 245 | ) -> Result<Self::EndpointIn, driver::EndpointAllocError> { |
| 245 | let index = self.alloc_in.allocate(ep_type)?; | 246 | let index = self.alloc_in.allocate(ep_type)?; |
| 246 | let ep_addr = EndpointAddress::from_parts(index, UsbDirection::In); | 247 | let ep_addr = EndpointAddress::from_parts(index, Direction::In); |
| 247 | Ok(Endpoint::new(EndpointInfo { | 248 | Ok(Endpoint::new(EndpointInfo { |
| 248 | addr: ep_addr, | 249 | addr: ep_addr, |
| 249 | ep_type, | 250 | ep_type, |
| @@ -259,7 +260,7 @@ impl<'d, T: Instance, P: UsbSupply + 'd> driver::Driver<'d> for Driver<'d, T, P> | |||
| 259 | interval: u8, | 260 | interval: u8, |
| 260 | ) -> Result<Self::EndpointOut, driver::EndpointAllocError> { | 261 | ) -> Result<Self::EndpointOut, driver::EndpointAllocError> { |
| 261 | let index = self.alloc_out.allocate(ep_type)?; | 262 | let index = self.alloc_out.allocate(ep_type)?; |
| 262 | let ep_addr = EndpointAddress::from_parts(index, UsbDirection::Out); | 263 | let ep_addr = EndpointAddress::from_parts(index, Direction::Out); |
| 263 | Ok(Endpoint::new(EndpointInfo { | 264 | Ok(Endpoint::new(EndpointInfo { |
| 264 | addr: ep_addr, | 265 | addr: ep_addr, |
| 265 | ep_type, | 266 | ep_type, |
| @@ -428,8 +429,8 @@ impl<'d, T: Instance, P: UsbSupply> driver::Bus for Bus<'d, T, P> { | |||
| 428 | let regs = T::regs(); | 429 | let regs = T::regs(); |
| 429 | let i = ep_addr.index(); | 430 | let i = ep_addr.index(); |
| 430 | match ep_addr.direction() { | 431 | match ep_addr.direction() { |
| 431 | UsbDirection::Out => regs.halted.epout[i].read().getstatus().is_halted(), | 432 | Direction::Out => regs.halted.epout[i].read().getstatus().is_halted(), |
| 432 | UsbDirection::In => regs.halted.epin[i].read().getstatus().is_halted(), | 433 | Direction::In => regs.halted.epin[i].read().getstatus().is_halted(), |
| 433 | } | 434 | } |
| 434 | } | 435 | } |
| 435 | 436 | ||
| @@ -442,7 +443,7 @@ impl<'d, T: Instance, P: UsbSupply> driver::Bus for Bus<'d, T, P> { | |||
| 442 | debug!("endpoint_set_enabled {:?} {}", ep_addr, enabled); | 443 | debug!("endpoint_set_enabled {:?} {}", ep_addr, enabled); |
| 443 | 444 | ||
| 444 | match ep_addr.direction() { | 445 | match ep_addr.direction() { |
| 445 | UsbDirection::In => { | 446 | Direction::In => { |
| 446 | let mut was_enabled = false; | 447 | let mut was_enabled = false; |
| 447 | regs.epinen.modify(|r, w| { | 448 | regs.epinen.modify(|r, w| { |
| 448 | let mut bits = r.bits(); | 449 | let mut bits = r.bits(); |
| @@ -466,7 +467,7 @@ impl<'d, T: Instance, P: UsbSupply> driver::Bus for Bus<'d, T, P> { | |||
| 466 | 467 | ||
| 467 | In::waker(i).wake(); | 468 | In::waker(i).wake(); |
| 468 | } | 469 | } |
| 469 | UsbDirection::Out => { | 470 | Direction::Out => { |
| 470 | regs.epouten.modify(|r, w| { | 471 | regs.epouten.modify(|r, w| { |
| 471 | let mut bits = r.bits(); | 472 | let mut bits = r.bits(); |
| 472 | if enabled { | 473 | if enabled { |
diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index a7ec5fb79..ce473b21d 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs | |||
| @@ -7,8 +7,9 @@ use core::task::Poll; | |||
| 7 | use atomic_polyfill::compiler_fence; | 7 | use atomic_polyfill::compiler_fence; |
| 8 | use embassy_hal_common::into_ref; | 8 | use embassy_hal_common::into_ref; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported}; | 10 | use embassy_usb::driver::{ |
| 11 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; | 11 | self, Direction, EndpointAddress, EndpointAllocError, EndpointError, EndpointInfo, EndpointType, Event, Unsupported, |
| 12 | }; | ||
| 12 | 13 | ||
| 13 | use crate::interrupt::{Interrupt, InterruptExt}; | 14 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 14 | use crate::{pac, peripherals, Peripheral, RegExt}; | 15 | use crate::{pac, peripherals, Peripheral, RegExt}; |
| @@ -204,8 +205,8 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 204 | ); | 205 | ); |
| 205 | 206 | ||
| 206 | let alloc = match D::dir() { | 207 | let alloc = match D::dir() { |
| 207 | UsbDirection::Out => &mut self.ep_out, | 208 | Direction::Out => &mut self.ep_out, |
| 208 | UsbDirection::In => &mut self.ep_in, | 209 | Direction::In => &mut self.ep_in, |
| 209 | }; | 210 | }; |
| 210 | 211 | ||
| 211 | let index = alloc.iter_mut().enumerate().find(|(i, ep)| { | 212 | let index = alloc.iter_mut().enumerate().find(|(i, ep)| { |
| @@ -254,7 +255,7 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 254 | }; | 255 | }; |
| 255 | 256 | ||
| 256 | match D::dir() { | 257 | match D::dir() { |
| 257 | UsbDirection::Out => unsafe { | 258 | Direction::Out => unsafe { |
| 258 | T::dpram().ep_out_control(index - 1).write(|w| { | 259 | T::dpram().ep_out_control(index - 1).write(|w| { |
| 259 | w.set_enable(false); | 260 | w.set_enable(false); |
| 260 | w.set_buffer_address(addr); | 261 | w.set_buffer_address(addr); |
| @@ -262,7 +263,7 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 262 | w.set_endpoint_type(ep_type_reg); | 263 | w.set_endpoint_type(ep_type_reg); |
| 263 | }) | 264 | }) |
| 264 | }, | 265 | }, |
| 265 | UsbDirection::In => unsafe { | 266 | Direction::In => unsafe { |
| 266 | T::dpram().ep_in_control(index - 1).write(|w| { | 267 | T::dpram().ep_in_control(index - 1).write(|w| { |
| 267 | w.set_enable(false); | 268 | w.set_enable(false); |
| 268 | w.set_buffer_address(addr); | 269 | w.set_buffer_address(addr); |
| @@ -429,14 +430,14 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 429 | 430 | ||
| 430 | let n = ep_addr.index(); | 431 | let n = ep_addr.index(); |
| 431 | match ep_addr.direction() { | 432 | match ep_addr.direction() { |
| 432 | UsbDirection::In => unsafe { | 433 | Direction::In => unsafe { |
| 433 | T::dpram().ep_in_control(n - 1).modify(|w| w.set_enable(enabled)); | 434 | T::dpram().ep_in_control(n - 1).modify(|w| w.set_enable(enabled)); |
| 434 | T::dpram().ep_in_buffer_control(ep_addr.index()).write(|w| { | 435 | T::dpram().ep_in_buffer_control(ep_addr.index()).write(|w| { |
| 435 | w.set_pid(0, true); // first packet is DATA0, but PID is flipped before | 436 | w.set_pid(0, true); // first packet is DATA0, but PID is flipped before |
| 436 | }); | 437 | }); |
| 437 | EP_IN_WAKERS[n].wake(); | 438 | EP_IN_WAKERS[n].wake(); |
| 438 | }, | 439 | }, |
| 439 | UsbDirection::Out => unsafe { | 440 | Direction::Out => unsafe { |
| 440 | T::dpram().ep_out_control(n - 1).modify(|w| w.set_enable(enabled)); | 441 | T::dpram().ep_out_control(n - 1).modify(|w| w.set_enable(enabled)); |
| 441 | 442 | ||
| 442 | T::dpram().ep_out_buffer_control(ep_addr.index()).write(|w| { | 443 | T::dpram().ep_out_buffer_control(ep_addr.index()).write(|w| { |
| @@ -474,14 +475,14 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 474 | } | 475 | } |
| 475 | 476 | ||
| 476 | trait Dir { | 477 | trait Dir { |
| 477 | fn dir() -> UsbDirection; | 478 | fn dir() -> Direction; |
| 478 | fn waker(i: usize) -> &'static AtomicWaker; | 479 | fn waker(i: usize) -> &'static AtomicWaker; |
| 479 | } | 480 | } |
| 480 | 481 | ||
| 481 | pub enum In {} | 482 | pub enum In {} |
| 482 | impl Dir for In { | 483 | impl Dir for In { |
| 483 | fn dir() -> UsbDirection { | 484 | fn dir() -> Direction { |
| 484 | UsbDirection::In | 485 | Direction::In |
| 485 | } | 486 | } |
| 486 | 487 | ||
| 487 | #[inline] | 488 | #[inline] |
| @@ -492,8 +493,8 @@ impl Dir for In { | |||
| 492 | 493 | ||
| 493 | pub enum Out {} | 494 | pub enum Out {} |
| 494 | impl Dir for Out { | 495 | impl Dir for Out { |
| 495 | fn dir() -> UsbDirection { | 496 | fn dir() -> Direction { |
| 496 | UsbDirection::Out | 497 | Direction::Out |
| 497 | } | 498 | } |
| 498 | 499 | ||
| 499 | #[inline] | 500 | #[inline] |
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index e5ee1181c..39809a3e1 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs | |||
| @@ -9,8 +9,9 @@ use atomic_polyfill::{AtomicBool, AtomicU8}; | |||
| 9 | use embassy_hal_common::into_ref; | 9 | use embassy_hal_common::into_ref; |
| 10 | use embassy_sync::waitqueue::AtomicWaker; | 10 | use embassy_sync::waitqueue::AtomicWaker; |
| 11 | use embassy_time::{block_for, Duration}; | 11 | use embassy_time::{block_for, Duration}; |
| 12 | use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported}; | 12 | use embassy_usb::driver::{ |
| 13 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; | 13 | self, Direction, EndpointAddress, EndpointAllocError, EndpointError, EndpointInfo, EndpointType, Event, Unsupported, |
| 14 | }; | ||
| 14 | use pac::common::{Reg, RW}; | 15 | use pac::common::{Reg, RW}; |
| 15 | use pac::usb::vals::{EpType, Stat}; | 16 | use pac::usb::vals::{EpType, Stat}; |
| 16 | 17 | ||
| @@ -279,8 +280,8 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 279 | } | 280 | } |
| 280 | let used = ep.used_out || ep.used_in; | 281 | let used = ep.used_out || ep.used_in; |
| 281 | let used_dir = match D::dir() { | 282 | let used_dir = match D::dir() { |
| 282 | UsbDirection::Out => ep.used_out, | 283 | Direction::Out => ep.used_out, |
| 283 | UsbDirection::In => ep.used_in, | 284 | Direction::In => ep.used_in, |
| 284 | }; | 285 | }; |
| 285 | !used || (ep.ep_type == ep_type && !used_dir) | 286 | !used || (ep.ep_type == ep_type && !used_dir) |
| 286 | }); | 287 | }); |
| @@ -293,7 +294,7 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 293 | ep.ep_type = ep_type; | 294 | ep.ep_type = ep_type; |
| 294 | 295 | ||
| 295 | let buf = match D::dir() { | 296 | let buf = match D::dir() { |
| 296 | UsbDirection::Out => { | 297 | Direction::Out => { |
| 297 | assert!(!ep.used_out); | 298 | assert!(!ep.used_out); |
| 298 | ep.used_out = true; | 299 | ep.used_out = true; |
| 299 | 300 | ||
| @@ -312,7 +313,7 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 312 | _phantom: PhantomData, | 313 | _phantom: PhantomData, |
| 313 | } | 314 | } |
| 314 | } | 315 | } |
| 315 | UsbDirection::In => { | 316 | Direction::In => { |
| 316 | assert!(!ep.used_in); | 317 | assert!(!ep.used_in); |
| 317 | ep.used_in = true; | 318 | ep.used_in = true; |
| 318 | 319 | ||
| @@ -504,7 +505,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 504 | // This can race, so do a retry loop. | 505 | // This can race, so do a retry loop. |
| 505 | let reg = T::regs().epr(ep_addr.index() as _); | 506 | let reg = T::regs().epr(ep_addr.index() as _); |
| 506 | match ep_addr.direction() { | 507 | match ep_addr.direction() { |
| 507 | UsbDirection::In => { | 508 | Direction::In => { |
| 508 | loop { | 509 | loop { |
| 509 | let r = unsafe { reg.read() }; | 510 | let r = unsafe { reg.read() }; |
| 510 | match r.stat_tx() { | 511 | match r.stat_tx() { |
| @@ -523,7 +524,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 523 | } | 524 | } |
| 524 | EP_IN_WAKERS[ep_addr.index()].wake(); | 525 | EP_IN_WAKERS[ep_addr.index()].wake(); |
| 525 | } | 526 | } |
| 526 | UsbDirection::Out => { | 527 | Direction::Out => { |
| 527 | loop { | 528 | loop { |
| 528 | let r = unsafe { reg.read() }; | 529 | let r = unsafe { reg.read() }; |
| 529 | match r.stat_rx() { | 530 | match r.stat_rx() { |
| @@ -549,8 +550,8 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 549 | let regs = T::regs(); | 550 | let regs = T::regs(); |
| 550 | let epr = unsafe { regs.epr(ep_addr.index() as _).read() }; | 551 | let epr = unsafe { regs.epr(ep_addr.index() as _).read() }; |
| 551 | match ep_addr.direction() { | 552 | match ep_addr.direction() { |
| 552 | UsbDirection::In => epr.stat_tx() == Stat::STALL, | 553 | Direction::In => epr.stat_tx() == Stat::STALL, |
| 553 | UsbDirection::Out => epr.stat_rx() == Stat::STALL, | 554 | Direction::Out => epr.stat_rx() == Stat::STALL, |
| 554 | } | 555 | } |
| 555 | } | 556 | } |
| 556 | 557 | ||
| @@ -560,7 +561,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 560 | let reg = T::regs().epr(ep_addr.index() as _); | 561 | let reg = T::regs().epr(ep_addr.index() as _); |
| 561 | trace!("EPR before: {:04x}", unsafe { reg.read() }.0); | 562 | trace!("EPR before: {:04x}", unsafe { reg.read() }.0); |
| 562 | match ep_addr.direction() { | 563 | match ep_addr.direction() { |
| 563 | UsbDirection::In => { | 564 | Direction::In => { |
| 564 | loop { | 565 | loop { |
| 565 | let want_stat = match enabled { | 566 | let want_stat = match enabled { |
| 566 | false => Stat::DISABLED, | 567 | false => Stat::DISABLED, |
| @@ -576,7 +577,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 576 | } | 577 | } |
| 577 | EP_IN_WAKERS[ep_addr.index()].wake(); | 578 | EP_IN_WAKERS[ep_addr.index()].wake(); |
| 578 | } | 579 | } |
| 579 | UsbDirection::Out => { | 580 | Direction::Out => { |
| 580 | loop { | 581 | loop { |
| 581 | let want_stat = match enabled { | 582 | let want_stat = match enabled { |
| 582 | false => Stat::DISABLED, | 583 | false => Stat::DISABLED, |
| @@ -616,14 +617,14 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 616 | } | 617 | } |
| 617 | 618 | ||
| 618 | trait Dir { | 619 | trait Dir { |
| 619 | fn dir() -> UsbDirection; | 620 | fn dir() -> Direction; |
| 620 | fn waker(i: usize) -> &'static AtomicWaker; | 621 | fn waker(i: usize) -> &'static AtomicWaker; |
| 621 | } | 622 | } |
| 622 | 623 | ||
| 623 | pub enum In {} | 624 | pub enum In {} |
| 624 | impl Dir for In { | 625 | impl Dir for In { |
| 625 | fn dir() -> UsbDirection { | 626 | fn dir() -> Direction { |
| 626 | UsbDirection::In | 627 | Direction::In |
| 627 | } | 628 | } |
| 628 | 629 | ||
| 629 | #[inline] | 630 | #[inline] |
| @@ -634,8 +635,8 @@ impl Dir for In { | |||
| 634 | 635 | ||
| 635 | pub enum Out {} | 636 | pub enum Out {} |
| 636 | impl Dir for Out { | 637 | impl Dir for Out { |
| 637 | fn dir() -> UsbDirection { | 638 | fn dir() -> Direction { |
| 638 | UsbDirection::Out | 639 | Direction::Out |
| 639 | } | 640 | } |
| 640 | 641 | ||
| 641 | #[inline] | 642 | #[inline] |
diff --git a/embassy-usb-ncm/Cargo.toml b/embassy-usb-driver/Cargo.toml index 15d3db96f..b525df337 100644 --- a/embassy-usb-ncm/Cargo.toml +++ b/embassy-usb-driver/Cargo.toml | |||
| @@ -1,17 +1,16 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "embassy-usb-ncm" | 2 | name = "embassy-usb-driver" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2021" |
| 5 | 5 | ||
| 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
| 7 | |||
| 6 | [package.metadata.embassy_docs] | 8 | [package.metadata.embassy_docs] |
| 7 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-ncm-v$VERSION/embassy-usb-ncm/src/" | 9 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-driver-v$VERSION/embassy-usb/src/" |
| 8 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-ncm/src/" | 10 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-driver/src/" |
| 9 | features = ["defmt"] | 11 | features = ["defmt"] |
| 10 | target = "thumbv7em-none-eabi" | 12 | target = "thumbv7em-none-eabi" |
| 11 | 13 | ||
| 12 | [dependencies] | 14 | [dependencies] |
| 13 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } | ||
| 14 | embassy-usb = { version = "0.1.0", path = "../embassy-usb" } | ||
| 15 | |||
| 16 | defmt = { version = "0.3", optional = true } | 15 | defmt = { version = "0.3", optional = true } |
| 17 | log = { version = "0.4.14", optional = true } | 16 | log = { version = "0.4.14", optional = true } \ No newline at end of file |
diff --git a/embassy-usb/src/driver.rs b/embassy-usb-driver/src/lib.rs index 7888f1639..fc29786fc 100644 --- a/embassy-usb/src/driver.rs +++ b/embassy-usb-driver/src/lib.rs | |||
| @@ -1,6 +1,104 @@ | |||
| 1 | #![no_std] | ||
| 2 | |||
| 1 | use core::future::Future; | 3 | use core::future::Future; |
| 2 | 4 | ||
| 3 | use super::types::*; | 5 | /// Direction of USB traffic. Note that in the USB standard the direction is always indicated from |
| 6 | /// the perspective of the host, which is backward for devices, but the standard directions are used | ||
| 7 | /// for consistency. | ||
| 8 | /// | ||
| 9 | /// The values of the enum also match the direction bit used in endpoint addresses and control | ||
| 10 | /// request types. | ||
| 11 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
| 12 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 13 | pub enum Direction { | ||
| 14 | /// Host to device (OUT) | ||
| 15 | Out, | ||
| 16 | /// Device to host (IN) | ||
| 17 | In, | ||
| 18 | } | ||
| 19 | |||
| 20 | /// USB endpoint transfer type. The values of this enum can be directly cast into `u8` to get the | ||
| 21 | /// transfer bmAttributes transfer type bits. | ||
| 22 | #[repr(u8)] | ||
| 23 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
| 24 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 25 | pub enum EndpointType { | ||
| 26 | /// Control endpoint. Used for device management. Only the host can initiate requests. Usually | ||
| 27 | /// used only endpoint 0. | ||
| 28 | Control = 0b00, | ||
| 29 | /// Isochronous endpoint. Used for time-critical unreliable data. Not implemented yet. | ||
| 30 | Isochronous = 0b01, | ||
| 31 | /// Bulk endpoint. Used for large amounts of best-effort reliable data. | ||
| 32 | Bulk = 0b10, | ||
| 33 | /// Interrupt endpoint. Used for small amounts of time-critical reliable data. | ||
| 34 | Interrupt = 0b11, | ||
| 35 | } | ||
| 36 | |||
| 37 | /// Type-safe endpoint address. | ||
| 38 | #[derive(Debug, Clone, Copy, Eq, PartialEq)] | ||
| 39 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 40 | pub struct EndpointAddress(u8); | ||
| 41 | |||
| 42 | impl From<u8> for EndpointAddress { | ||
| 43 | #[inline] | ||
| 44 | fn from(addr: u8) -> EndpointAddress { | ||
| 45 | EndpointAddress(addr) | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | impl From<EndpointAddress> for u8 { | ||
| 50 | #[inline] | ||
| 51 | fn from(addr: EndpointAddress) -> u8 { | ||
| 52 | addr.0 | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | impl EndpointAddress { | ||
| 57 | const INBITS: u8 = Direction::In as u8; | ||
| 58 | |||
| 59 | /// Constructs a new EndpointAddress with the given index and direction. | ||
| 60 | #[inline] | ||
| 61 | pub fn from_parts(index: usize, dir: Direction) -> Self { | ||
| 62 | EndpointAddress(index as u8 | dir as u8) | ||
| 63 | } | ||
| 64 | |||
| 65 | /// Gets the direction part of the address. | ||
| 66 | #[inline] | ||
| 67 | pub fn direction(&self) -> Direction { | ||
| 68 | if (self.0 & Self::INBITS) != 0 { | ||
| 69 | Direction::In | ||
| 70 | } else { | ||
| 71 | Direction::Out | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | /// Returns true if the direction is IN, otherwise false. | ||
| 76 | #[inline] | ||
| 77 | pub fn is_in(&self) -> bool { | ||
| 78 | (self.0 & Self::INBITS) != 0 | ||
| 79 | } | ||
| 80 | |||
| 81 | /// Returns true if the direction is OUT, otherwise false. | ||
| 82 | #[inline] | ||
| 83 | pub fn is_out(&self) -> bool { | ||
| 84 | (self.0 & Self::INBITS) == 0 | ||
| 85 | } | ||
| 86 | |||
| 87 | /// Gets the index part of the endpoint address. | ||
| 88 | #[inline] | ||
| 89 | pub fn index(&self) -> usize { | ||
| 90 | (self.0 & !Self::INBITS) as usize | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
| 95 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 96 | pub struct EndpointInfo { | ||
| 97 | pub addr: EndpointAddress, | ||
| 98 | pub ep_type: EndpointType, | ||
| 99 | pub max_packet_size: u16, | ||
| 100 | pub interval: u8, | ||
| 101 | } | ||
| 4 | 102 | ||
| 5 | /// Driver for a specific USB peripheral. Implement this to add support for a new hardware | 103 | /// Driver for a specific USB peripheral. Implement this to add support for a new hardware |
| 6 | /// platform. | 104 | /// platform. |
diff --git a/embassy-usb-hid/Cargo.toml b/embassy-usb-hid/Cargo.toml deleted file mode 100644 index 2f7733dc6..000000000 --- a/embassy-usb-hid/Cargo.toml +++ /dev/null | |||
| @@ -1,24 +0,0 @@ | |||
| 1 | [package] | ||
| 2 | name = "embassy-usb-hid" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | |||
| 6 | [package.metadata.embassy_docs] | ||
| 7 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-hid-v$VERSION/embassy-usb-hid/src/" | ||
| 8 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-hid/src/" | ||
| 9 | features = ["defmt"] | ||
| 10 | target = "thumbv7em-none-eabi" | ||
| 11 | |||
| 12 | [features] | ||
| 13 | default = ["usbd-hid"] | ||
| 14 | usbd-hid = ["dep:usbd-hid", "ssmarshal"] | ||
| 15 | |||
| 16 | [dependencies] | ||
| 17 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } | ||
| 18 | embassy-usb = { version = "0.1.0", path = "../embassy-usb" } | ||
| 19 | |||
| 20 | defmt = { version = "0.3", optional = true } | ||
| 21 | log = { version = "0.4.14", optional = true } | ||
| 22 | usbd-hid = { version = "0.6.0", optional = true } | ||
| 23 | ssmarshal = { version = "1.0", default-features = false, optional = true } | ||
| 24 | futures-util = { version = "0.3.21", default-features = false } | ||
diff --git a/embassy-usb-hid/src/fmt.rs b/embassy-usb-hid/src/fmt.rs deleted file mode 100644 index 066970813..000000000 --- a/embassy-usb-hid/src/fmt.rs +++ /dev/null | |||
| @@ -1,225 +0,0 @@ | |||
| 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/embassy-usb-ncm/src/fmt.rs b/embassy-usb-ncm/src/fmt.rs deleted file mode 100644 index 066970813..000000000 --- a/embassy-usb-ncm/src/fmt.rs +++ /dev/null | |||
| @@ -1,225 +0,0 @@ | |||
| 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/embassy-usb-serial/Cargo.toml b/embassy-usb-serial/Cargo.toml deleted file mode 100644 index 9788588e9..000000000 --- a/embassy-usb-serial/Cargo.toml +++ /dev/null | |||
| @@ -1,17 +0,0 @@ | |||
| 1 | [package] | ||
| 2 | name = "embassy-usb-serial" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | |||
| 6 | [package.metadata.embassy_docs] | ||
| 7 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-serial-v$VERSION/embassy-usb-serial/src/" | ||
| 8 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-serial/src/" | ||
| 9 | features = ["defmt"] | ||
| 10 | target = "thumbv7em-none-eabi" | ||
| 11 | |||
| 12 | [dependencies] | ||
| 13 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } | ||
| 14 | embassy-usb = { version = "0.1.0", path = "../embassy-usb" } | ||
| 15 | |||
| 16 | defmt = { version = "0.3", optional = true } | ||
| 17 | log = { version = "0.4.14", optional = true } | ||
diff --git a/embassy-usb-serial/src/fmt.rs b/embassy-usb-serial/src/fmt.rs deleted file mode 100644 index 066970813..000000000 --- a/embassy-usb-serial/src/fmt.rs +++ /dev/null | |||
| @@ -1,225 +0,0 @@ | |||
| 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/embassy-usb/Cargo.toml b/embassy-usb/Cargo.toml index 8cad4d314..aad54dbaf 100644 --- a/embassy-usb/Cargo.toml +++ b/embassy-usb/Cargo.toml | |||
| @@ -9,9 +9,20 @@ src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb/s | |||
| 9 | features = ["defmt"] | 9 | features = ["defmt"] |
| 10 | target = "thumbv7em-none-eabi" | 10 | target = "thumbv7em-none-eabi" |
| 11 | 11 | ||
| 12 | [features] | ||
| 13 | defmt = ["dep:defmt", "embassy-usb-driver/defmt"] | ||
| 14 | usbd-hid = ["dep:usbd-hid", "dep:ssmarshal"] | ||
| 15 | default = ["usbd-hid"] | ||
| 16 | |||
| 12 | [dependencies] | 17 | [dependencies] |
| 13 | embassy-futures = { version = "0.1.0", path = "../embassy-futures" } | 18 | embassy-futures = { version = "0.1.0", path = "../embassy-futures" } |
| 19 | embassy-usb-driver = { version = "0.1.0", path = "../embassy-usb-driver" } | ||
| 20 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } | ||
| 14 | 21 | ||
| 15 | defmt = { version = "0.3", optional = true } | 22 | defmt = { version = "0.3", optional = true } |
| 16 | log = { version = "0.4.14", optional = true } | 23 | log = { version = "0.4.14", optional = true } |
| 17 | heapless = "0.7.10" \ No newline at end of file | 24 | heapless = "0.7.10" |
| 25 | |||
| 26 | # for HID | ||
| 27 | usbd-hid = { version = "0.6.0", optional = true } | ||
| 28 | ssmarshal = { version = "1.0", default-features = false, optional = true } | ||
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index 6be88bc76..87a8333bb 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs | |||
| @@ -1,11 +1,10 @@ | |||
| 1 | use heapless::Vec; | 1 | use heapless::Vec; |
| 2 | 2 | ||
| 3 | use super::control::ControlHandler; | 3 | use crate::control::ControlHandler; |
| 4 | use super::descriptor::{BosWriter, DescriptorWriter}; | 4 | use crate::descriptor::{BosWriter, DescriptorWriter}; |
| 5 | use super::driver::{Driver, Endpoint}; | 5 | use crate::driver::{Driver, Endpoint, EndpointType}; |
| 6 | use super::types::*; | 6 | use crate::types::*; |
| 7 | use super::{DeviceStateHandler, UsbDevice, MAX_INTERFACE_COUNT}; | 7 | use crate::{DeviceStateHandler, Interface, UsbDevice, MAX_INTERFACE_COUNT, STRING_INDEX_CUSTOM_START}; |
| 8 | use crate::{Interface, STRING_INDEX_CUSTOM_START}; | ||
| 9 | 8 | ||
| 10 | #[derive(Debug, Copy, Clone)] | 9 | #[derive(Debug, Copy, Clone)] |
| 11 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 10 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
diff --git a/embassy-usb-serial/src/lib.rs b/embassy-usb/src/class/cdc_acm.rs index 15c2bb0a7..09bb1cc8d 100644 --- a/embassy-usb-serial/src/lib.rs +++ b/embassy-usb/src/class/cdc_acm.rs | |||
| @@ -1,18 +1,13 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![feature(type_alias_impl_trait)] | ||
| 3 | |||
| 4 | // This mod MUST go first, so that the others see its macros. | ||
| 5 | pub(crate) mod fmt; | ||
| 6 | |||
| 7 | use core::cell::Cell; | 1 | use core::cell::Cell; |
| 8 | use core::mem::{self, MaybeUninit}; | 2 | use core::mem::{self, MaybeUninit}; |
| 9 | use core::sync::atomic::{AtomicBool, Ordering}; | 3 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 10 | 4 | ||
| 11 | use embassy_sync::blocking_mutex::CriticalSectionMutex; | 5 | use embassy_sync::blocking_mutex::CriticalSectionMutex; |
| 12 | use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; | 6 | |
| 13 | use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; | 7 | use crate::control::{self, ControlHandler, InResponse, OutResponse, Request}; |
| 14 | use embassy_usb::types::*; | 8 | use crate::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; |
| 15 | use embassy_usb::Builder; | 9 | use crate::types::*; |
| 10 | use crate::Builder; | ||
| 16 | 11 | ||
| 17 | /// This should be used as `device_class` when building the `UsbDevice`. | 12 | /// This should be used as `device_class` when building the `UsbDevice`. |
| 18 | pub const USB_CLASS_CDC: u8 = 0x02; | 13 | pub const USB_CLASS_CDC: u8 = 0x02; |
diff --git a/embassy-usb-ncm/src/lib.rs b/embassy-usb/src/class/cdc_ncm.rs index e796af28f..a39b87e9b 100644 --- a/embassy-usb-ncm/src/lib.rs +++ b/embassy-usb/src/class/cdc_ncm.rs | |||
| @@ -1,15 +1,10 @@ | |||
| 1 | #![no_std] | ||
| 2 | |||
| 3 | // This mod MUST go first, so that the others see its macros. | ||
| 4 | pub(crate) mod fmt; | ||
| 5 | |||
| 6 | use core::intrinsics::copy_nonoverlapping; | 1 | use core::intrinsics::copy_nonoverlapping; |
| 7 | use core::mem::{size_of, MaybeUninit}; | 2 | use core::mem::{size_of, MaybeUninit}; |
| 8 | 3 | ||
| 9 | use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; | 4 | use crate::control::{self, ControlHandler, InResponse, OutResponse, Request}; |
| 10 | use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; | 5 | use crate::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; |
| 11 | use embassy_usb::types::*; | 6 | use crate::types::*; |
| 12 | use embassy_usb::Builder; | 7 | use crate::Builder; |
| 13 | 8 | ||
| 14 | /// This should be used as `device_class` when building the `UsbDevice`. | 9 | /// This should be used as `device_class` when building the `UsbDevice`. |
| 15 | pub const USB_CLASS_CDC: u8 = 0x02; | 10 | pub const USB_CLASS_CDC: u8 = 0x02; |
diff --git a/embassy-usb-hid/src/lib.rs b/embassy-usb/src/class/hid.rs index 8b181aec8..4d1fa995f 100644 --- a/embassy-usb-hid/src/lib.rs +++ b/embassy-usb/src/class/hid.rs | |||
| @@ -1,23 +1,16 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![feature(type_alias_impl_trait)] | ||
| 3 | |||
| 4 | //! Implements HID functionality for a usb-device device. | ||
| 5 | |||
| 6 | // This mod MUST go first, so that the others see its macros. | ||
| 7 | pub(crate) mod fmt; | ||
| 8 | |||
| 9 | use core::mem::MaybeUninit; | 1 | use core::mem::MaybeUninit; |
| 10 | use core::ops::Range; | 2 | use core::ops::Range; |
| 11 | use core::sync::atomic::{AtomicUsize, Ordering}; | 3 | use core::sync::atomic::{AtomicUsize, Ordering}; |
| 12 | 4 | ||
| 13 | use embassy_usb::control::{ControlHandler, InResponse, OutResponse, Request, RequestType}; | ||
| 14 | use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; | ||
| 15 | use embassy_usb::Builder; | ||
| 16 | #[cfg(feature = "usbd-hid")] | 5 | #[cfg(feature = "usbd-hid")] |
| 17 | use ssmarshal::serialize; | 6 | use ssmarshal::serialize; |
| 18 | #[cfg(feature = "usbd-hid")] | 7 | #[cfg(feature = "usbd-hid")] |
| 19 | use usbd_hid::descriptor::AsInputReport; | 8 | use usbd_hid::descriptor::AsInputReport; |
| 20 | 9 | ||
| 10 | use crate::control::{ControlHandler, InResponse, OutResponse, Request, RequestType}; | ||
| 11 | use crate::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; | ||
| 12 | use crate::Builder; | ||
| 13 | |||
| 21 | const USB_CLASS_HID: u8 = 0x03; | 14 | const USB_CLASS_HID: u8 = 0x03; |
| 22 | const USB_SUBCLASS_NONE: u8 = 0x00; | 15 | const USB_SUBCLASS_NONE: u8 = 0x00; |
| 23 | const USB_PROTOCOL_NONE: u8 = 0x00; | 16 | const USB_PROTOCOL_NONE: u8 = 0x00; |
| @@ -204,9 +197,9 @@ pub enum ReadError { | |||
| 204 | Sync(Range<usize>), | 197 | Sync(Range<usize>), |
| 205 | } | 198 | } |
| 206 | 199 | ||
| 207 | impl From<embassy_usb::driver::EndpointError> for ReadError { | 200 | impl From<EndpointError> for ReadError { |
| 208 | fn from(val: embassy_usb::driver::EndpointError) -> Self { | 201 | fn from(val: EndpointError) -> Self { |
| 209 | use embassy_usb::driver::EndpointError::*; | 202 | use EndpointError::*; |
| 210 | match val { | 203 | match val { |
| 211 | BufferOverflow => ReadError::BufferOverflow, | 204 | BufferOverflow => ReadError::BufferOverflow, |
| 212 | Disabled => ReadError::Disabled, | 205 | Disabled => ReadError::Disabled, |
| @@ -437,7 +430,7 @@ impl<'d> ControlHandler for Control<'d> { | |||
| 437 | } | 430 | } |
| 438 | } | 431 | } |
| 439 | 432 | ||
| 440 | fn control_out(&mut self, req: embassy_usb::control::Request, data: &[u8]) -> OutResponse { | 433 | fn control_out(&mut self, req: Request, data: &[u8]) -> OutResponse { |
| 441 | trace!("HID control_out {:?} {=[u8]:x}", req, data); | 434 | trace!("HID control_out {:?} {=[u8]:x}", req, data); |
| 442 | if let RequestType::Class = req.request_type { | 435 | if let RequestType::Class = req.request_type { |
| 443 | match req.request { | 436 | match req.request { |
diff --git a/embassy-usb/src/class/mod.rs b/embassy-usb/src/class/mod.rs new file mode 100644 index 000000000..af27577a6 --- /dev/null +++ b/embassy-usb/src/class/mod.rs | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | pub mod cdc_acm; | ||
| 2 | pub mod cdc_ncm; | ||
| 3 | pub mod hid; | ||
diff --git a/embassy-usb/src/control.rs b/embassy-usb/src/control.rs index 3e5749a01..d6d0c6565 100644 --- a/embassy-usb/src/control.rs +++ b/embassy-usb/src/control.rs | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | //! USB control data types. | 1 | //! USB control data types. |
| 2 | use core::mem; | 2 | use core::mem; |
| 3 | 3 | ||
| 4 | use super::types::*; | 4 | use crate::driver::Direction; |
| 5 | use crate::types::StringIndex; | ||
| 5 | 6 | ||
| 6 | /// Control request type. | 7 | /// Control request type. |
| 7 | #[repr(u8)] | 8 | #[repr(u8)] |
| @@ -42,7 +43,7 @@ pub enum Recipient { | |||
| 42 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 43 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 43 | pub struct Request { | 44 | pub struct Request { |
| 44 | /// Direction of the request. | 45 | /// Direction of the request. |
| 45 | pub direction: UsbDirection, | 46 | pub direction: Direction, |
| 46 | /// Type of the request. | 47 | /// Type of the request. |
| 47 | pub request_type: RequestType, | 48 | pub request_type: RequestType, |
| 48 | /// Recipient of the request. | 49 | /// Recipient of the request. |
| @@ -105,7 +106,7 @@ impl Request { | |||
| 105 | let recipient = rt & 0b11111; | 106 | let recipient = rt & 0b11111; |
| 106 | 107 | ||
| 107 | Request { | 108 | Request { |
| 108 | direction: rt.into(), | 109 | direction: if rt & 0x80 == 0 { Direction::Out } else { Direction::In }, |
| 109 | request_type: unsafe { mem::transmute((rt >> 5) & 0b11) }, | 110 | request_type: unsafe { mem::transmute((rt >> 5) & 0b11) }, |
| 110 | recipient: if recipient <= 3 { | 111 | recipient: if recipient <= 3 { |
| 111 | unsafe { mem::transmute(recipient) } | 112 | unsafe { mem::transmute(recipient) } |
diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs index b94a4b161..497f03196 100644 --- a/embassy-usb/src/descriptor.rs +++ b/embassy-usb/src/descriptor.rs | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | use super::builder::Config; | 1 | use crate::builder::Config; |
| 2 | use super::types::*; | 2 | use crate::driver::EndpointInfo; |
| 3 | use super::CONFIGURATION_VALUE; | 3 | use crate::types::*; |
| 4 | use crate::CONFIGURATION_VALUE; | ||
| 4 | 5 | ||
| 5 | /// Standard descriptor types | 6 | /// Standard descriptor types |
| 6 | #[allow(missing_docs)] | 7 | #[allow(missing_docs)] |
diff --git a/embassy-usb/src/descriptor_reader.rs b/embassy-usb/src/descriptor_reader.rs index 0a12b566c..d64bcb73b 100644 --- a/embassy-usb/src/descriptor_reader.rs +++ b/embassy-usb/src/descriptor_reader.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::descriptor::descriptor_type; | 1 | use crate::descriptor::descriptor_type; |
| 2 | use crate::types::EndpointAddress; | 2 | use crate::driver::EndpointAddress; |
| 3 | 3 | ||
| 4 | #[derive(Copy, Clone, PartialEq, Eq, Debug)] | 4 | #[derive(Copy, Clone, PartialEq, Eq, Debug)] |
| 5 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 5 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 6f58c953c..661b84119 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs | |||
| @@ -4,23 +4,24 @@ | |||
| 4 | // This mod MUST go first, so that the others see its macros. | 4 | // This mod MUST go first, so that the others see its macros. |
| 5 | pub(crate) mod fmt; | 5 | pub(crate) mod fmt; |
| 6 | 6 | ||
| 7 | pub use embassy_usb_driver as driver; | ||
| 8 | |||
| 7 | mod builder; | 9 | mod builder; |
| 10 | pub mod class; | ||
| 8 | pub mod control; | 11 | pub mod control; |
| 9 | pub mod descriptor; | 12 | pub mod descriptor; |
| 10 | mod descriptor_reader; | 13 | mod descriptor_reader; |
| 11 | pub mod driver; | ||
| 12 | pub mod types; | 14 | pub mod types; |
| 13 | 15 | ||
| 14 | use embassy_futures::select::{select, Either}; | 16 | use embassy_futures::select::{select, Either}; |
| 15 | use heapless::Vec; | 17 | use heapless::Vec; |
| 16 | 18 | ||
| 17 | pub use self::builder::{Builder, Config}; | 19 | pub use crate::builder::{Builder, Config}; |
| 18 | use self::control::*; | 20 | use crate::control::*; |
| 19 | use self::descriptor::*; | 21 | use crate::descriptor::*; |
| 20 | use self::driver::{Bus, Driver, Event}; | ||
| 21 | use self::types::*; | ||
| 22 | use crate::descriptor_reader::foreach_endpoint; | 22 | use crate::descriptor_reader::foreach_endpoint; |
| 23 | use crate::driver::ControlPipe; | 23 | use crate::driver::{Bus, ControlPipe, Direction, Driver, EndpointAddress, Event}; |
| 24 | use crate::types::*; | ||
| 24 | 25 | ||
| 25 | /// The global state of the USB device. | 26 | /// The global state of the USB device. |
| 26 | /// | 27 | /// |
| @@ -250,8 +251,8 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 250 | trace!("control request: {:?}", req); | 251 | trace!("control request: {:?}", req); |
| 251 | 252 | ||
| 252 | match req.direction { | 253 | match req.direction { |
| 253 | UsbDirection::In => self.handle_control_in(req).await, | 254 | Direction::In => self.handle_control_in(req).await, |
| 254 | UsbDirection::Out => self.handle_control_out(req).await, | 255 | Direction::Out => self.handle_control_out(req).await, |
| 255 | } | 256 | } |
| 256 | 257 | ||
| 257 | if self.inner.set_address_pending { | 258 | if self.inner.set_address_pending { |
diff --git a/embassy-usb/src/types.rs b/embassy-usb/src/types.rs index b8717ffa9..aeab063d1 100644 --- a/embassy-usb/src/types.rs +++ b/embassy-usb/src/types.rs | |||
| @@ -1,108 +1,3 @@ | |||
| 1 | /// Direction of USB traffic. Note that in the USB standard the direction is always indicated from | ||
| 2 | /// the perspective of the host, which is backward for devices, but the standard directions are used | ||
| 3 | /// for consistency. | ||
| 4 | /// | ||
| 5 | /// The values of the enum also match the direction bit used in endpoint addresses and control | ||
| 6 | /// request types. | ||
| 7 | #[repr(u8)] | ||
| 8 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
| 9 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 10 | pub enum UsbDirection { | ||
| 11 | /// Host to device (OUT) | ||
| 12 | Out = 0x00, | ||
| 13 | /// Device to host (IN) | ||
| 14 | In = 0x80, | ||
| 15 | } | ||
| 16 | |||
| 17 | impl From<u8> for UsbDirection { | ||
| 18 | fn from(value: u8) -> Self { | ||
| 19 | unsafe { core::mem::transmute(value & 0x80) } | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | /// USB endpoint transfer type. The values of this enum can be directly cast into `u8` to get the | ||
| 24 | /// transfer bmAttributes transfer type bits. | ||
| 25 | #[repr(u8)] | ||
| 26 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
| 27 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 28 | pub enum EndpointType { | ||
| 29 | /// Control endpoint. Used for device management. Only the host can initiate requests. Usually | ||
| 30 | /// used only endpoint 0. | ||
| 31 | Control = 0b00, | ||
| 32 | /// Isochronous endpoint. Used for time-critical unreliable data. Not implemented yet. | ||
| 33 | Isochronous = 0b01, | ||
| 34 | /// Bulk endpoint. Used for large amounts of best-effort reliable data. | ||
| 35 | Bulk = 0b10, | ||
| 36 | /// Interrupt endpoint. Used for small amounts of time-critical reliable data. | ||
| 37 | Interrupt = 0b11, | ||
| 38 | } | ||
| 39 | |||
| 40 | /// Type-safe endpoint address. | ||
| 41 | #[derive(Debug, Clone, Copy, Eq, PartialEq)] | ||
| 42 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 43 | pub struct EndpointAddress(u8); | ||
| 44 | |||
| 45 | impl From<u8> for EndpointAddress { | ||
| 46 | #[inline] | ||
| 47 | fn from(addr: u8) -> EndpointAddress { | ||
| 48 | EndpointAddress(addr) | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | impl From<EndpointAddress> for u8 { | ||
| 53 | #[inline] | ||
| 54 | fn from(addr: EndpointAddress) -> u8 { | ||
| 55 | addr.0 | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | impl EndpointAddress { | ||
| 60 | const INBITS: u8 = UsbDirection::In as u8; | ||
| 61 | |||
| 62 | /// Constructs a new EndpointAddress with the given index and direction. | ||
| 63 | #[inline] | ||
| 64 | pub fn from_parts(index: usize, dir: UsbDirection) -> Self { | ||
| 65 | EndpointAddress(index as u8 | dir as u8) | ||
| 66 | } | ||
| 67 | |||
| 68 | /// Gets the direction part of the address. | ||
| 69 | #[inline] | ||
| 70 | pub fn direction(&self) -> UsbDirection { | ||
| 71 | if (self.0 & Self::INBITS) != 0 { | ||
| 72 | UsbDirection::In | ||
| 73 | } else { | ||
| 74 | UsbDirection::Out | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | /// Returns true if the direction is IN, otherwise false. | ||
| 79 | #[inline] | ||
| 80 | pub fn is_in(&self) -> bool { | ||
| 81 | (self.0 & Self::INBITS) != 0 | ||
| 82 | } | ||
| 83 | |||
| 84 | /// Returns true if the direction is OUT, otherwise false. | ||
| 85 | #[inline] | ||
| 86 | pub fn is_out(&self) -> bool { | ||
| 87 | (self.0 & Self::INBITS) == 0 | ||
| 88 | } | ||
| 89 | |||
| 90 | /// Gets the index part of the endpoint address. | ||
| 91 | #[inline] | ||
| 92 | pub fn index(&self) -> usize { | ||
| 93 | (self.0 & !Self::INBITS) as usize | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
| 98 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 99 | pub struct EndpointInfo { | ||
| 100 | pub addr: EndpointAddress, | ||
| 101 | pub ep_type: EndpointType, | ||
| 102 | pub max_packet_size: u16, | ||
| 103 | pub interval: u8, | ||
| 104 | } | ||
| 105 | |||
| 106 | /// A handle for a USB interface that contains its number. | 1 | /// A handle for a USB interface that contains its number. |
| 107 | #[derive(Copy, Clone, Eq, PartialEq)] | 2 | #[derive(Copy, Clone, Eq, PartialEq)] |
| 108 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 3 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index dbc659cda..a5d340c69 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml | |||
| @@ -5,7 +5,7 @@ version = "0.1.0" | |||
| 5 | 5 | ||
| 6 | [features] | 6 | [features] |
| 7 | default = ["nightly"] | 7 | default = ["nightly"] |
| 8 | nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-net/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embassy-usb-serial", "embassy-usb-hid", "embassy-usb-ncm", "embedded-io/async", "embassy-net"] | 8 | nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-net/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embedded-io/async", "embassy-net"] |
| 9 | 9 | ||
| 10 | [dependencies] | 10 | [dependencies] |
| 11 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 11 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| @@ -15,9 +15,6 @@ embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["de | |||
| 15 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } | 15 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } |
| 16 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } | 16 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } |
| 17 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } | 17 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } |
| 18 | embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"], optional = true } | ||
| 19 | embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", features = ["defmt"], optional = true } | ||
| 20 | embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", features = ["defmt"], optional = true } | ||
| 21 | embedded-io = "0.3.0" | 18 | embedded-io = "0.3.0" |
| 22 | 19 | ||
| 23 | defmt = "0.3" | 20 | defmt = "0.3" |
diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs index 33ca380ff..de93a2b45 100644 --- a/examples/nrf/src/bin/usb_ethernet.rs +++ b/examples/nrf/src/bin/usb_ethernet.rs | |||
| @@ -15,8 +15,8 @@ use embassy_nrf::usb::{Driver, PowerUsb}; | |||
| 15 | use embassy_nrf::{interrupt, pac, peripherals}; | 15 | use embassy_nrf::{interrupt, pac, peripherals}; |
| 16 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | 16 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 17 | use embassy_sync::channel::Channel; | 17 | use embassy_sync::channel::Channel; |
| 18 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, Receiver, Sender, State}; | ||
| 18 | use embassy_usb::{Builder, Config, UsbDevice}; | 19 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 19 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; | ||
| 20 | use embedded_io::asynch::Write; | 20 | use embedded_io::asynch::Write; |
| 21 | use static_cell::StaticCell; | 21 | use static_cell::StaticCell; |
| 22 | use {defmt_rtt as _, panic_probe as _}; | 22 | use {defmt_rtt as _, panic_probe as _}; |
diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs index 4eb7d37c9..76e198719 100644 --- a/examples/nrf/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf/src/bin/usb_hid_keyboard.rs | |||
| @@ -14,9 +14,9 @@ use embassy_nrf::usb::{Driver, PowerUsb}; | |||
| 14 | use embassy_nrf::{interrupt, pac}; | 14 | use embassy_nrf::{interrupt, pac}; |
| 15 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 15 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| 16 | use embassy_sync::signal::Signal; | 16 | use embassy_sync::signal::Signal; |
| 17 | use embassy_usb::class::hid::{HidReaderWriter, ReportId, RequestHandler, State}; | ||
| 17 | use embassy_usb::control::OutResponse; | 18 | use embassy_usb::control::OutResponse; |
| 18 | use embassy_usb::{Builder, Config, DeviceStateHandler}; | 19 | use embassy_usb::{Builder, Config, DeviceStateHandler}; |
| 19 | use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; | ||
| 20 | use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; | 20 | use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; |
| 21 | use {defmt_rtt as _, panic_probe as _}; | 21 | use {defmt_rtt as _, panic_probe as _}; |
| 22 | 22 | ||
| @@ -67,7 +67,7 @@ async fn main(_spawner: Spawner) { | |||
| 67 | ); | 67 | ); |
| 68 | 68 | ||
| 69 | // Create classes on the builder. | 69 | // Create classes on the builder. |
| 70 | let config = embassy_usb_hid::Config { | 70 | let config = embassy_usb::class::hid::Config { |
| 71 | report_descriptor: KeyboardReport::desc(), | 71 | report_descriptor: KeyboardReport::desc(), |
| 72 | request_handler: Some(&request_handler), | 72 | request_handler: Some(&request_handler), |
| 73 | poll_ms: 60, | 73 | poll_ms: 60, |
diff --git a/examples/nrf/src/bin/usb_hid_mouse.rs b/examples/nrf/src/bin/usb_hid_mouse.rs index 65fbda1cf..4916a38d4 100644 --- a/examples/nrf/src/bin/usb_hid_mouse.rs +++ b/examples/nrf/src/bin/usb_hid_mouse.rs | |||
| @@ -10,9 +10,9 @@ use embassy_futures::join::join; | |||
| 10 | use embassy_nrf::usb::{Driver, PowerUsb}; | 10 | use embassy_nrf::usb::{Driver, PowerUsb}; |
| 11 | use embassy_nrf::{interrupt, pac}; | 11 | use embassy_nrf::{interrupt, pac}; |
| 12 | use embassy_time::{Duration, Timer}; | 12 | use embassy_time::{Duration, Timer}; |
| 13 | use embassy_usb::class::hid::{HidWriter, ReportId, RequestHandler, State}; | ||
| 13 | use embassy_usb::control::OutResponse; | 14 | use embassy_usb::control::OutResponse; |
| 14 | use embassy_usb::{Builder, Config}; | 15 | use embassy_usb::{Builder, Config}; |
| 15 | use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; | ||
| 16 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; | 16 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 18 | ||
| @@ -59,7 +59,7 @@ async fn main(_spawner: Spawner) { | |||
| 59 | ); | 59 | ); |
| 60 | 60 | ||
| 61 | // Create classes on the builder. | 61 | // Create classes on the builder. |
| 62 | let config = embassy_usb_hid::Config { | 62 | let config = embassy_usb::class::hid::Config { |
| 63 | report_descriptor: MouseReport::desc(), | 63 | report_descriptor: MouseReport::desc(), |
| 64 | request_handler: Some(&request_handler), | 64 | request_handler: Some(&request_handler), |
| 65 | poll_ms: 60, | 65 | poll_ms: 60, |
diff --git a/examples/nrf/src/bin/usb_serial.rs b/examples/nrf/src/bin/usb_serial.rs index a740b4e0a..7c9c4184b 100644 --- a/examples/nrf/src/bin/usb_serial.rs +++ b/examples/nrf/src/bin/usb_serial.rs | |||
| @@ -9,9 +9,9 @@ use embassy_executor::Spawner; | |||
| 9 | use embassy_futures::join::join; | 9 | use embassy_futures::join::join; |
| 10 | use embassy_nrf::usb::{Driver, Instance, PowerUsb, UsbSupply}; | 10 | use embassy_nrf::usb::{Driver, Instance, PowerUsb, UsbSupply}; |
| 11 | use embassy_nrf::{interrupt, pac}; | 11 | use embassy_nrf::{interrupt, pac}; |
| 12 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | ||
| 12 | use embassy_usb::driver::EndpointError; | 13 | use embassy_usb::driver::EndpointError; |
| 13 | use embassy_usb::{Builder, Config}; | 14 | use embassy_usb::{Builder, Config}; |
| 14 | use embassy_usb_serial::{CdcAcmClass, State}; | ||
| 15 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 16 | 16 | ||
| 17 | #[embassy_executor::main] | 17 | #[embassy_executor::main] |
diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs index c646c0bbd..93efc2fe6 100644 --- a/examples/nrf/src/bin/usb_serial_multitask.rs +++ b/examples/nrf/src/bin/usb_serial_multitask.rs | |||
| @@ -8,9 +8,9 @@ use defmt::{info, panic, unwrap}; | |||
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::usb::{Driver, PowerUsb}; | 9 | use embassy_nrf::usb::{Driver, PowerUsb}; |
| 10 | use embassy_nrf::{interrupt, pac, peripherals}; | 10 | use embassy_nrf::{interrupt, pac, peripherals}; |
| 11 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | ||
| 11 | use embassy_usb::driver::EndpointError; | 12 | use embassy_usb::driver::EndpointError; |
| 12 | use embassy_usb::{Builder, Config, UsbDevice}; | 13 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 13 | use embassy_usb_serial::{CdcAcmClass, State}; | ||
| 14 | use static_cell::StaticCell; | 14 | use static_cell::StaticCell; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 16 | 16 | ||
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 24c3cdd67..3c8f923e7 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml | |||
| @@ -10,9 +10,7 @@ embassy-executor = { version = "0.1.0", path = "../../embassy-executor", feature | |||
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } |
| 11 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver"] } | 11 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver"] } |
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 13 | embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } | ||
| 14 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] } | 13 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] } |
| 15 | embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", features = ["defmt"] } | ||
| 16 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 14 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 17 | 15 | ||
| 18 | defmt = "0.3" | 16 | defmt = "0.3" |
diff --git a/examples/rp/src/bin/usb_ethernet.rs b/examples/rp/src/bin/usb_ethernet.rs index 166ffe175..1057fe7fd 100644 --- a/examples/rp/src/bin/usb_ethernet.rs +++ b/examples/rp/src/bin/usb_ethernet.rs | |||
| @@ -13,8 +13,8 @@ use embassy_rp::usb::Driver; | |||
| 13 | use embassy_rp::{interrupt, peripherals}; | 13 | use embassy_rp::{interrupt, peripherals}; |
| 14 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | 14 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 15 | use embassy_sync::channel::Channel; | 15 | use embassy_sync::channel::Channel; |
| 16 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, Receiver, Sender, State}; | ||
| 16 | use embassy_usb::{Builder, Config, UsbDevice}; | 17 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 17 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; | ||
| 18 | use embedded_io::asynch::Write; | 18 | use embedded_io::asynch::Write; |
| 19 | use static_cell::StaticCell; | 19 | use static_cell::StaticCell; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _}; |
diff --git a/examples/rp/src/bin/usb_serial.rs b/examples/rp/src/bin/usb_serial.rs index bf92a1636..b7d6493b4 100644 --- a/examples/rp/src/bin/usb_serial.rs +++ b/examples/rp/src/bin/usb_serial.rs | |||
| @@ -7,9 +7,9 @@ use embassy_executor::Spawner; | |||
| 7 | use embassy_futures::join::join; | 7 | use embassy_futures::join::join; |
| 8 | use embassy_rp::interrupt; | 8 | use embassy_rp::interrupt; |
| 9 | use embassy_rp::usb::{Driver, Instance}; | 9 | use embassy_rp::usb::{Driver, Instance}; |
| 10 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | ||
| 10 | use embassy_usb::driver::EndpointError; | 11 | use embassy_usb::driver::EndpointError; |
| 11 | use embassy_usb::{Builder, Config}; | 12 | use embassy_usb::{Builder, Config}; |
| 12 | use embassy_usb_serial::{CdcAcmClass, State}; | ||
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | #[embassy_executor::main] | 15 | #[embassy_executor::main] |
diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml index 895e043dd..e6553789a 100644 --- a/examples/stm32f1/Cargo.toml +++ b/examples/stm32f1/Cargo.toml | |||
| @@ -9,7 +9,6 @@ embassy-executor = { version = "0.1.0", path = "../../embassy-executor", feature | |||
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] } |
| 11 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 11 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 12 | embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } | ||
| 13 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 12 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 14 | 13 | ||
| 15 | defmt = "0.3" | 14 | defmt = "0.3" |
diff --git a/examples/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs index a14e728ba..ad92cdeb2 100644 --- a/examples/stm32f1/src/bin/usb_serial.rs +++ b/examples/stm32f1/src/bin/usb_serial.rs | |||
| @@ -10,9 +10,9 @@ use embassy_stm32::time::Hertz; | |||
| 10 | use embassy_stm32::usb::{Driver, Instance}; | 10 | use embassy_stm32::usb::{Driver, Instance}; |
| 11 | use embassy_stm32::{interrupt, Config}; | 11 | use embassy_stm32::{interrupt, Config}; |
| 12 | use embassy_time::{Duration, Timer}; | 12 | use embassy_time::{Duration, Timer}; |
| 13 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | ||
| 13 | use embassy_usb::driver::EndpointError; | 14 | use embassy_usb::driver::EndpointError; |
| 14 | use embassy_usb::Builder; | 15 | use embassy_usb::Builder; |
| 15 | use embassy_usb_serial::{CdcAcmClass, State}; | ||
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 17 | ||
| 18 | #[embassy_executor::main] | 18 | #[embassy_executor::main] |
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml index 27f5c260a..f5b0b880c 100644 --- a/examples/stm32f3/Cargo.toml +++ b/examples/stm32f3/Cargo.toml | |||
| @@ -9,8 +9,6 @@ embassy-executor = { version = "0.1.0", path = "../../embassy-executor", feature | |||
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } |
| 11 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 11 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 12 | embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } | ||
| 13 | embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", features = ["defmt"] } | ||
| 14 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 12 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 15 | 13 | ||
| 16 | defmt = "0.3" | 14 | defmt = "0.3" |
diff --git a/examples/stm32f3/src/bin/usb_serial.rs b/examples/stm32f3/src/bin/usb_serial.rs index b9fd20e2b..f6d27c860 100644 --- a/examples/stm32f3/src/bin/usb_serial.rs +++ b/examples/stm32f3/src/bin/usb_serial.rs | |||
| @@ -10,9 +10,9 @@ use embassy_stm32::time::mhz; | |||
| 10 | use embassy_stm32::usb::{Driver, Instance}; | 10 | use embassy_stm32::usb::{Driver, Instance}; |
| 11 | use embassy_stm32::{interrupt, Config}; | 11 | use embassy_stm32::{interrupt, Config}; |
| 12 | use embassy_time::{Duration, Timer}; | 12 | use embassy_time::{Duration, Timer}; |
| 13 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | ||
| 13 | use embassy_usb::driver::EndpointError; | 14 | use embassy_usb::driver::EndpointError; |
| 14 | use embassy_usb::Builder; | 15 | use embassy_usb::Builder; |
| 15 | use embassy_usb_serial::{CdcAcmClass, State}; | ||
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 17 | ||
| 18 | #[embassy_executor::main] | 18 | #[embassy_executor::main] |
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml index 05945f6bf..9ebab6476 100644 --- a/examples/stm32l5/Cargo.toml +++ b/examples/stm32l5/Cargo.toml | |||
| @@ -11,9 +11,6 @@ embassy-executor = { version = "0.1.0", path = "../../embassy-executor", feature | |||
| 11 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 11 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 12 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } | 12 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } |
| 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 14 | embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } | ||
| 15 | embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", features = ["defmt"] } | ||
| 16 | embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", features = ["defmt"] } | ||
| 17 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] } | 14 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] } |
| 18 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 15 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 19 | usbd-hid = "0.6.0" | 16 | usbd-hid = "0.6.0" |
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index c96a83ead..4f36d3f5a 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs | |||
| @@ -15,8 +15,8 @@ use embassy_stm32::usb::Driver; | |||
| 15 | use embassy_stm32::{interrupt, Config}; | 15 | use embassy_stm32::{interrupt, Config}; |
| 16 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | 16 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 17 | use embassy_sync::channel::Channel; | 17 | use embassy_sync::channel::Channel; |
| 18 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, Receiver, Sender, State}; | ||
| 18 | use embassy_usb::{Builder, UsbDevice}; | 19 | use embassy_usb::{Builder, UsbDevice}; |
| 19 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; | ||
| 20 | use embedded_io::asynch::Write; | 20 | use embedded_io::asynch::Write; |
| 21 | use rand_core::RngCore; | 21 | use rand_core::RngCore; |
| 22 | use static_cell::StaticCell; | 22 | use static_cell::StaticCell; |
diff --git a/examples/stm32l5/src/bin/usb_hid_mouse.rs b/examples/stm32l5/src/bin/usb_hid_mouse.rs index fa92ceae3..d38ed7496 100644 --- a/examples/stm32l5/src/bin/usb_hid_mouse.rs +++ b/examples/stm32l5/src/bin/usb_hid_mouse.rs | |||
| @@ -9,9 +9,9 @@ use embassy_stm32::rcc::*; | |||
| 9 | use embassy_stm32::usb::Driver; | 9 | use embassy_stm32::usb::Driver; |
| 10 | use embassy_stm32::{interrupt, Config}; | 10 | use embassy_stm32::{interrupt, Config}; |
| 11 | use embassy_time::{Duration, Timer}; | 11 | use embassy_time::{Duration, Timer}; |
| 12 | use embassy_usb::class::hid::{HidWriter, ReportId, RequestHandler, State}; | ||
| 12 | use embassy_usb::control::OutResponse; | 13 | use embassy_usb::control::OutResponse; |
| 13 | use embassy_usb::Builder; | 14 | use embassy_usb::Builder; |
| 14 | use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; | ||
| 15 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; | 15 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 17 | ||
| @@ -55,7 +55,7 @@ async fn main(_spawner: Spawner) { | |||
| 55 | ); | 55 | ); |
| 56 | 56 | ||
| 57 | // Create classes on the builder. | 57 | // Create classes on the builder. |
| 58 | let config = embassy_usb_hid::Config { | 58 | let config = embassy_usb::class::hid::Config { |
| 59 | report_descriptor: MouseReport::desc(), | 59 | report_descriptor: MouseReport::desc(), |
| 60 | request_handler: Some(&request_handler), | 60 | request_handler: Some(&request_handler), |
| 61 | poll_ms: 60, | 61 | poll_ms: 60, |
diff --git a/examples/stm32l5/src/bin/usb_serial.rs b/examples/stm32l5/src/bin/usb_serial.rs index 7484dc832..7562a4e96 100644 --- a/examples/stm32l5/src/bin/usb_serial.rs +++ b/examples/stm32l5/src/bin/usb_serial.rs | |||
| @@ -8,9 +8,9 @@ use embassy_futures::join::join; | |||
| 8 | use embassy_stm32::rcc::*; | 8 | use embassy_stm32::rcc::*; |
| 9 | use embassy_stm32::usb::{Driver, Instance}; | 9 | use embassy_stm32::usb::{Driver, Instance}; |
| 10 | use embassy_stm32::{interrupt, Config}; | 10 | use embassy_stm32::{interrupt, Config}; |
| 11 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | ||
| 11 | use embassy_usb::driver::EndpointError; | 12 | use embassy_usb::driver::EndpointError; |
| 12 | use embassy_usb::Builder; | 13 | use embassy_usb::Builder; |
| 13 | use embassy_usb_serial::{CdcAcmClass, State}; | ||
| 14 | use {defmt_rtt as _, panic_probe as _}; | 14 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 15 | ||
| 16 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
