sorta works, too many interupts?
This commit is contained in:
parent
07cbd41131
commit
3debe604fb
@ -1,14 +1,8 @@
|
|||||||
#![macro_use]
|
#![macro_use]
|
||||||
|
|
||||||
use core::marker::PhantomData;
|
pub use embassy_hal_common::usb::*;
|
||||||
use embassy::util::Unborrow;
|
|
||||||
|
|
||||||
use crate::interrupt::Interrupt;
|
|
||||||
use crate::pac;
|
|
||||||
use embassy_hal_common::usb::{ClassSet, IntoClassSet, USBInterrupt};
|
|
||||||
pub use embassy_hal_common::usb::{ReadInterface, State, UsbSerial, WriteInterface};
|
|
||||||
use nrf_usbd::{UsbPeripheral, Usbd};
|
use nrf_usbd::{UsbPeripheral, Usbd};
|
||||||
use usb_device::{bus::UsbBusAllocator, class_prelude::UsbBus, device::UsbDevice};
|
use usb_device::bus::UsbBusAllocator;
|
||||||
|
|
||||||
pub struct UsbThing;
|
pub struct UsbThing;
|
||||||
unsafe impl UsbPeripheral for UsbThing {
|
unsafe impl UsbPeripheral for UsbThing {
|
||||||
@ -17,37 +11,20 @@ unsafe impl UsbPeripheral for UsbThing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl UsbThing {
|
impl UsbThing {
|
||||||
|
// todo should it consume a USBD peripheral?
|
||||||
pub fn new() -> UsbBusAllocator<Usbd<UsbThing>> {
|
pub fn new() -> UsbBusAllocator<Usbd<UsbThing>> {
|
||||||
|
unsafe {
|
||||||
|
(*crate::pac::USBD::ptr()).intenset.write(|w| {
|
||||||
|
w.sof().set_bit();
|
||||||
|
w.usbevent().set_bit();
|
||||||
|
w.ep0datadone().set_bit();
|
||||||
|
w.ep0setup().set_bit();
|
||||||
|
w.usbreset().set_bit()
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
Usbd::new(UsbThing)
|
Usbd::new(UsbThing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
|
unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
|
||||||
|
|
||||||
pub struct Usb<'bus, B, T, I>
|
|
||||||
where
|
|
||||||
B: UsbBus,
|
|
||||||
T: ClassSet<B>,
|
|
||||||
I: USBInterrupt,
|
|
||||||
{
|
|
||||||
// Don't you dare moving out `PeripheralMutex`
|
|
||||||
usb: embassy_hal_common::usb::Usb<'bus, B, T, I>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'bus, B, T, I> Usb<'bus, B, T, I>
|
|
||||||
where
|
|
||||||
B: UsbBus,
|
|
||||||
T: ClassSet<B>,
|
|
||||||
I: USBInterrupt,
|
|
||||||
{
|
|
||||||
pub unsafe fn new<S: IntoClassSet<B, T>>(
|
|
||||||
state: &'bus mut State<'bus, B, T, I>,
|
|
||||||
device: UsbDevice<'bus, B>,
|
|
||||||
class_set: S,
|
|
||||||
irq: I,
|
|
||||||
) -> Self {
|
|
||||||
let usb = embassy_hal_common::usb::Usb::new(state, device, class_set, irq);
|
|
||||||
|
|
||||||
Self { usb }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -9,7 +9,6 @@ version = "0.1.0"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] }
|
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] }
|
||||||
embassy-hal-common = { version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.3"
|
defmt-rtt = "0.3"
|
||||||
|
@ -16,18 +16,19 @@ use panic_probe as _; // print out panic messages
|
|||||||
use embassy::executor::Spawner;
|
use embassy::executor::Spawner;
|
||||||
use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
|
use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
|
||||||
use embassy::time::{Duration, Timer};
|
use embassy::time::{Duration, Timer};
|
||||||
use embassy_nrf::usb::{ReadInterface, State, Usb, UsbSerial, UsbThing, WriteInterface};
|
use embassy_nrf::usb::{State, Usb, UsbSerial, UsbThing};
|
||||||
use embassy_nrf::{interrupt, Peripherals};
|
use embassy_nrf::{interrupt, Peripherals};
|
||||||
use usb_device::device::{UsbDeviceBuilder, UsbVidPid};
|
use usb_device::device::{UsbDeviceBuilder, UsbVidPid};
|
||||||
|
|
||||||
#[embassy::main]
|
#[embassy::main]
|
||||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
async fn main(_spawner: Spawner, _p: Peripherals) {
|
||||||
let mut tx_buffer = [0u8; 1024];
|
let mut tx_buffer = [0u8; 1024];
|
||||||
let mut rx_buffer = [0u8; 640];
|
let mut rx_buffer = [0u8; 640];
|
||||||
|
|
||||||
let usb_bus = UsbThing::new();
|
let usb_bus = UsbThing::new();
|
||||||
|
|
||||||
let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer);
|
let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer);
|
||||||
|
|
||||||
let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
|
let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
|
||||||
.manufacturer("Fake company")
|
.manufacturer("Fake company")
|
||||||
.product("Serial port")
|
.product("Serial port")
|
||||||
@ -42,7 +43,6 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
|
|
||||||
let usb = unsafe { Usb::new(&mut state, device, serial, irq) };
|
let usb = unsafe { Usb::new(&mut state, device, serial, irq) };
|
||||||
pin_mut!(usb);
|
pin_mut!(usb);
|
||||||
// usb.start();
|
|
||||||
|
|
||||||
let (mut read_interface, mut write_interface) = usb.as_ref().take_serial_0();
|
let (mut read_interface, mut write_interface) = usb.as_ref().take_serial_0();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user