dont expose embedded_hal_common::usb
This commit is contained in:
parent
f31140a70b
commit
07cbd41131
@ -8,9 +8,6 @@ pub const FLASH_SIZE: usize = 1024 * 1024;
|
|||||||
|
|
||||||
embassy_hal_common::peripherals! {
|
embassy_hal_common::peripherals! {
|
||||||
|
|
||||||
// USB
|
|
||||||
USBD,
|
|
||||||
|
|
||||||
// RTC
|
// RTC
|
||||||
RTC0,
|
RTC0,
|
||||||
RTC1,
|
RTC1,
|
||||||
@ -161,8 +158,6 @@ embassy_hal_common::peripherals! {
|
|||||||
TEMP,
|
TEMP,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_usb!(USBD, USBD, USBD);
|
|
||||||
|
|
||||||
impl_uarte!(UARTE0, UARTE0, UARTE0_UART0);
|
impl_uarte!(UARTE0, UARTE0, UARTE0_UART0);
|
||||||
impl_uarte!(UARTE1, UARTE1, UARTE1);
|
impl_uarte!(UARTE1, UARTE1, UARTE1);
|
||||||
|
|
||||||
|
@ -5,64 +5,49 @@ use embassy::util::Unborrow;
|
|||||||
|
|
||||||
use crate::interrupt::Interrupt;
|
use crate::interrupt::Interrupt;
|
||||||
use crate::pac;
|
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;
|
use usb_device::{bus::UsbBusAllocator, class_prelude::UsbBus, device::UsbDevice};
|
||||||
|
|
||||||
// todo using different type than Usb because T isnt Send
|
pub struct UsbThing;
|
||||||
pub struct UsbBus;
|
unsafe impl UsbPeripheral for UsbThing {
|
||||||
unsafe impl UsbPeripheral for UsbBus {
|
|
||||||
// todo hardcoding
|
// todo hardcoding
|
||||||
const REGISTERS: *const () = crate::pac::USBD::ptr() as *const ();
|
const REGISTERS: *const () = crate::pac::USBD::ptr() as *const ();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UsbBus {
|
impl UsbThing {
|
||||||
pub fn new() -> UsbBusAllocator<Usbd<UsbBus>> {
|
pub fn new() -> UsbBusAllocator<Usbd<UsbThing>> {
|
||||||
Usbd::new(UsbBus)
|
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<'d, T: Instance> {
|
pub struct Usb<'bus, B, T, I>
|
||||||
phantom: PhantomData<&'d mut T>,
|
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<'d, T: Instance> Usb<'d, T> {
|
impl<'bus, B, T, I> Usb<'bus, B, T, I>
|
||||||
#[allow(unused_unsafe)]
|
where
|
||||||
pub fn new(_usb: impl Unborrow<Target = T> + 'd) -> Self {
|
B: UsbBus,
|
||||||
let r = T::regs();
|
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 {
|
Self { usb }
|
||||||
phantom: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_interrupt(_: *mut ()) {
|
|
||||||
let r = T::regs();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) mod sealed {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
pub trait Instance {
|
|
||||||
fn regs() -> &'static pac::usbd::RegisterBlock;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static {
|
|
||||||
type Interrupt: Interrupt;
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! impl_usb {
|
|
||||||
($type:ident, $pac_type:ident, $irq:ident) => {
|
|
||||||
impl crate::usb::sealed::Instance for peripherals::$type {
|
|
||||||
fn regs() -> &'static pac::usbd::RegisterBlock {
|
|
||||||
unsafe { &*pac::$pac_type::ptr() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl crate::usb::Instance for peripherals::$type {
|
|
||||||
type Interrupt = crate::interrupt::$irq;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
@ -16,8 +16,7 @@ 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_hal_common::usb::{State, Usb, UsbSerial};
|
use embassy_nrf::usb::{ReadInterface, State, Usb, UsbSerial, UsbThing, WriteInterface};
|
||||||
use embassy_nrf::usb::{Usb as UsbDevice, UsbBus};
|
|
||||||
use embassy_nrf::{interrupt, Peripherals};
|
use embassy_nrf::{interrupt, Peripherals};
|
||||||
use usb_device::device::{UsbDeviceBuilder, UsbVidPid};
|
use usb_device::device::{UsbDeviceBuilder, UsbVidPid};
|
||||||
|
|
||||||
@ -26,12 +25,9 @@ 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_dev = UsbDevice::new(p.USBD);
|
let usb_bus = UsbThing::new();
|
||||||
|
|
||||||
let usb_bus = UsbBus::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")
|
||||||
|
Loading…
Reference in New Issue
Block a user