diff options
| author | Jacob Rosenthal <[email protected]> | 2021-12-14 16:48:48 -0700 |
|---|---|---|
| committer | Jacob Rosenthal <[email protected]> | 2021-12-14 16:48:48 -0700 |
| commit | 3debe604fbff1789794b452e630c0186836c1756 (patch) | |
| tree | a3e0d4d9cbc8ce824ba9de1554f29b1c20abf0a2 | |
| parent | 07cbd41131a89ec0982f0ac6a3237d0544375f97 (diff) | |
sorta works, too many interupts?
| -rw-r--r-- | embassy-nrf/src/usb.rs | 49 | ||||
| -rw-r--r-- | examples/nrf/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb_uart.rs | 6 |
3 files changed, 16 insertions, 40 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 6776d5696..5008b8e65 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -1,14 +1,8 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | 3 | pub use embassy_hal_common::usb::*; |
| 4 | use embassy::util::Unborrow; | ||
| 5 | |||
| 6 | use crate::interrupt::Interrupt; | ||
| 7 | use crate::pac; | ||
| 8 | use embassy_hal_common::usb::{ClassSet, IntoClassSet, USBInterrupt}; | ||
| 9 | pub use embassy_hal_common::usb::{ReadInterface, State, UsbSerial, WriteInterface}; | ||
| 10 | use nrf_usbd::{UsbPeripheral, Usbd}; | 4 | use nrf_usbd::{UsbPeripheral, Usbd}; |
| 11 | use usb_device::{bus::UsbBusAllocator, class_prelude::UsbBus, device::UsbDevice}; | 5 | use usb_device::bus::UsbBusAllocator; |
| 12 | 6 | ||
| 13 | pub struct UsbThing; | 7 | pub struct UsbThing; |
| 14 | unsafe impl UsbPeripheral for UsbThing { | 8 | unsafe impl UsbPeripheral for UsbThing { |
| @@ -17,37 +11,20 @@ unsafe impl UsbPeripheral for UsbThing { | |||
| 17 | } | 11 | } |
| 18 | 12 | ||
| 19 | impl UsbThing { | 13 | impl UsbThing { |
| 14 | // todo should it consume a USBD peripheral? | ||
| 20 | pub fn new() -> UsbBusAllocator<Usbd<UsbThing>> { | 15 | pub fn new() -> UsbBusAllocator<Usbd<UsbThing>> { |
| 16 | unsafe { | ||
| 17 | (*crate::pac::USBD::ptr()).intenset.write(|w| { | ||
| 18 | w.sof().set_bit(); | ||
| 19 | w.usbevent().set_bit(); | ||
| 20 | w.ep0datadone().set_bit(); | ||
| 21 | w.ep0setup().set_bit(); | ||
| 22 | w.usbreset().set_bit() | ||
| 23 | }) | ||
| 24 | }; | ||
| 25 | |||
| 21 | Usbd::new(UsbThing) | 26 | Usbd::new(UsbThing) |
| 22 | } | 27 | } |
| 23 | } | 28 | } |
| 24 | 29 | ||
| 25 | unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {} | 30 | unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {} |
| 26 | |||
| 27 | pub struct Usb<'bus, B, T, I> | ||
| 28 | where | ||
| 29 | B: UsbBus, | ||
| 30 | T: ClassSet<B>, | ||
| 31 | I: USBInterrupt, | ||
| 32 | { | ||
| 33 | // Don't you dare moving out `PeripheralMutex` | ||
| 34 | usb: embassy_hal_common::usb::Usb<'bus, B, T, I>, | ||
| 35 | } | ||
| 36 | |||
| 37 | impl<'bus, B, T, I> Usb<'bus, B, T, I> | ||
| 38 | where | ||
| 39 | B: UsbBus, | ||
| 40 | T: ClassSet<B>, | ||
| 41 | I: USBInterrupt, | ||
| 42 | { | ||
| 43 | pub unsafe fn new<S: IntoClassSet<B, T>>( | ||
| 44 | state: &'bus mut State<'bus, B, T, I>, | ||
| 45 | device: UsbDevice<'bus, B>, | ||
| 46 | class_set: S, | ||
| 47 | irq: I, | ||
| 48 | ) -> Self { | ||
| 49 | let usb = embassy_hal_common::usb::Usb::new(state, device, class_set, irq); | ||
| 50 | |||
| 51 | Self { usb } | ||
| 52 | } | ||
| 53 | } | ||
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index 646ba496f..a144cb715 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml | |||
| @@ -9,7 +9,6 @@ version = "0.1.0" | |||
| 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } | 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } |
| 10 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | 10 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 11 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } | 11 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } |
| 12 | embassy-hal-common = { version = "0.1.0", path = "../../embassy-hal-common" } | ||
| 13 | 12 | ||
| 14 | defmt = "0.3" | 13 | defmt = "0.3" |
| 15 | defmt-rtt = "0.3" | 14 | defmt-rtt = "0.3" |
diff --git a/examples/nrf/src/bin/usb_uart.rs b/examples/nrf/src/bin/usb_uart.rs index 9313fdb1e..84bce65e5 100644 --- a/examples/nrf/src/bin/usb_uart.rs +++ b/examples/nrf/src/bin/usb_uart.rs | |||
| @@ -16,18 +16,19 @@ use panic_probe as _; // print out panic messages | |||
| 16 | use embassy::executor::Spawner; | 16 | use embassy::executor::Spawner; |
| 17 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; | 17 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; |
| 18 | use embassy::time::{Duration, Timer}; | 18 | use embassy::time::{Duration, Timer}; |
| 19 | use embassy_nrf::usb::{ReadInterface, State, Usb, UsbSerial, UsbThing, WriteInterface}; | 19 | use embassy_nrf::usb::{State, Usb, UsbSerial, UsbThing}; |
| 20 | use embassy_nrf::{interrupt, Peripherals}; | 20 | use embassy_nrf::{interrupt, Peripherals}; |
| 21 | use usb_device::device::{UsbDeviceBuilder, UsbVidPid}; | 21 | use usb_device::device::{UsbDeviceBuilder, UsbVidPid}; |
| 22 | 22 | ||
| 23 | #[embassy::main] | 23 | #[embassy::main] |
| 24 | async fn main(_spawner: Spawner, p: Peripherals) { | 24 | async fn main(_spawner: Spawner, _p: Peripherals) { |
| 25 | let mut tx_buffer = [0u8; 1024]; | 25 | let mut tx_buffer = [0u8; 1024]; |
| 26 | let mut rx_buffer = [0u8; 640]; | 26 | let mut rx_buffer = [0u8; 640]; |
| 27 | 27 | ||
| 28 | let usb_bus = UsbThing::new(); | 28 | let usb_bus = UsbThing::new(); |
| 29 | 29 | ||
| 30 | let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer); | 30 | let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer); |
| 31 | |||
| 31 | let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd)) | 32 | let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd)) |
| 32 | .manufacturer("Fake company") | 33 | .manufacturer("Fake company") |
| 33 | .product("Serial port") | 34 | .product("Serial port") |
| @@ -42,7 +43,6 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 42 | 43 | ||
| 43 | let usb = unsafe { Usb::new(&mut state, device, serial, irq) }; | 44 | let usb = unsafe { Usb::new(&mut state, device, serial, irq) }; |
| 44 | pin_mut!(usb); | 45 | pin_mut!(usb); |
| 45 | // usb.start(); | ||
| 46 | 46 | ||
| 47 | let (mut read_interface, mut write_interface) = usb.as_ref().take_serial_0(); | 47 | let (mut read_interface, mut write_interface) = usb.as_ref().take_serial_0(); |
| 48 | 48 | ||
