aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Rosenthal <[email protected]>2021-12-14 16:48:48 -0700
committerJacob Rosenthal <[email protected]>2021-12-14 16:48:48 -0700
commit3debe604fbff1789794b452e630c0186836c1756 (patch)
treea3e0d4d9cbc8ce824ba9de1554f29b1c20abf0a2
parent07cbd41131a89ec0982f0ac6a3237d0544375f97 (diff)
sorta works, too many interupts?
-rw-r--r--embassy-nrf/src/usb.rs49
-rw-r--r--examples/nrf/Cargo.toml1
-rw-r--r--examples/nrf/src/bin/usb_uart.rs6
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
3use core::marker::PhantomData; 3pub use embassy_hal_common::usb::*;
4use embassy::util::Unborrow;
5
6use crate::interrupt::Interrupt;
7use crate::pac;
8use embassy_hal_common::usb::{ClassSet, IntoClassSet, USBInterrupt};
9pub use embassy_hal_common::usb::{ReadInterface, State, UsbSerial, WriteInterface};
10use nrf_usbd::{UsbPeripheral, Usbd}; 4use nrf_usbd::{UsbPeripheral, Usbd};
11use usb_device::{bus::UsbBusAllocator, class_prelude::UsbBus, device::UsbDevice}; 5use usb_device::bus::UsbBusAllocator;
12 6
13pub struct UsbThing; 7pub struct UsbThing;
14unsafe impl UsbPeripheral for UsbThing { 8unsafe impl UsbPeripheral for UsbThing {
@@ -17,37 +11,20 @@ unsafe impl UsbPeripheral for UsbThing {
17} 11}
18 12
19impl UsbThing { 13impl 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
25unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {} 30unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
26
27pub struct Usb<'bus, B, T, I>
28where
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
37impl<'bus, B, T, I> Usb<'bus, B, T, I>
38where
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"
9embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } 9embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
10embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } 10embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
11embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } 11embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] }
12embassy-hal-common = { version = "0.1.0", path = "../../embassy-hal-common" }
13 12
14defmt = "0.3" 13defmt = "0.3"
15defmt-rtt = "0.3" 14defmt-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
16use embassy::executor::Spawner; 16use embassy::executor::Spawner;
17use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; 17use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
18use embassy::time::{Duration, Timer}; 18use embassy::time::{Duration, Timer};
19use embassy_nrf::usb::{ReadInterface, State, Usb, UsbSerial, UsbThing, WriteInterface}; 19use embassy_nrf::usb::{State, Usb, UsbSerial, UsbThing};
20use embassy_nrf::{interrupt, Peripherals}; 20use embassy_nrf::{interrupt, Peripherals};
21use usb_device::device::{UsbDeviceBuilder, UsbVidPid}; 21use usb_device::device::{UsbDeviceBuilder, UsbVidPid};
22 22
23#[embassy::main] 23#[embassy::main]
24async fn main(_spawner: Spawner, p: Peripherals) { 24async 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