enable USB peripheral for relevant chips
This commit is contained in:
parent
1c0a3688a4
commit
61f12324ff
@ -7,6 +7,9 @@ pub const FORCE_COPY_BUFFER_SIZE: usize = 512;
|
|||||||
pub const FLASH_SIZE: usize = 256 * 1024;
|
pub const FLASH_SIZE: usize = 256 * 1024;
|
||||||
|
|
||||||
embassy_hal_common::peripherals! {
|
embassy_hal_common::peripherals! {
|
||||||
|
// USB
|
||||||
|
USBD,
|
||||||
|
|
||||||
// RTC
|
// RTC
|
||||||
RTC0,
|
RTC0,
|
||||||
RTC1,
|
RTC1,
|
||||||
|
@ -7,6 +7,9 @@ pub const FORCE_COPY_BUFFER_SIZE: usize = 512;
|
|||||||
pub const FLASH_SIZE: usize = 512 * 1024;
|
pub const FLASH_SIZE: usize = 512 * 1024;
|
||||||
|
|
||||||
embassy_hal_common::peripherals! {
|
embassy_hal_common::peripherals! {
|
||||||
|
// USB
|
||||||
|
USBD,
|
||||||
|
|
||||||
// RTC
|
// RTC
|
||||||
RTC0,
|
RTC0,
|
||||||
RTC1,
|
RTC1,
|
||||||
@ -154,6 +157,8 @@ 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);
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@ pub const FORCE_COPY_BUFFER_SIZE: usize = 512;
|
|||||||
pub const FLASH_SIZE: usize = 1024 * 1024;
|
pub const FLASH_SIZE: usize = 1024 * 1024;
|
||||||
|
|
||||||
embassy_hal_common::peripherals! {
|
embassy_hal_common::peripherals! {
|
||||||
|
// USB
|
||||||
|
USBD,
|
||||||
|
|
||||||
// RTC
|
// RTC
|
||||||
RTC0,
|
RTC0,
|
||||||
RTC1,
|
RTC1,
|
||||||
@ -157,6 +160,8 @@ 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);
|
||||||
|
|
||||||
|
@ -211,6 +211,9 @@ pub const EASY_DMA_SIZE: usize = (1 << 16) - 1;
|
|||||||
pub const FORCE_COPY_BUFFER_SIZE: usize = 1024;
|
pub const FORCE_COPY_BUFFER_SIZE: usize = 1024;
|
||||||
|
|
||||||
embassy_hal_common::peripherals! {
|
embassy_hal_common::peripherals! {
|
||||||
|
// USB
|
||||||
|
USBD,
|
||||||
|
|
||||||
// RTC
|
// RTC
|
||||||
RTC0,
|
RTC0,
|
||||||
RTC1,
|
RTC1,
|
||||||
@ -342,6 +345,8 @@ embassy_hal_common::peripherals! {
|
|||||||
P1_15,
|
P1_15,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_usb!(USBD, USBD, USBD);
|
||||||
|
|
||||||
impl_uarte!(UARTETWISPI0, UARTE0, SERIAL0);
|
impl_uarte!(UARTETWISPI0, UARTE0, SERIAL0);
|
||||||
impl_uarte!(UARTETWISPI1, UARTE1, SERIAL1);
|
impl_uarte!(UARTETWISPI1, UARTE1, SERIAL1);
|
||||||
impl_uarte!(UARTETWISPI2, UARTE2, SERIAL2);
|
impl_uarte!(UARTETWISPI2, UARTE2, SERIAL2);
|
||||||
|
@ -48,8 +48,12 @@ pub mod temp;
|
|||||||
pub mod timer;
|
pub mod timer;
|
||||||
pub mod twim;
|
pub mod twim;
|
||||||
pub mod uarte;
|
pub mod uarte;
|
||||||
//todo add nrf52833 nrf52840
|
#[cfg(any(
|
||||||
#[cfg(feature = "nrf52840")]
|
feature = "_nrf5340-app",
|
||||||
|
feature = "nrf52820",
|
||||||
|
feature = "nrf52833",
|
||||||
|
feature = "nrf52840"
|
||||||
|
))]
|
||||||
pub mod usb;
|
pub mod usb;
|
||||||
#[cfg(not(feature = "_nrf5340"))]
|
#[cfg(not(feature = "_nrf5340"))]
|
||||||
pub mod wdt;
|
pub mod wdt;
|
||||||
|
@ -1,20 +1,27 @@
|
|||||||
#![macro_use]
|
#![macro_use]
|
||||||
|
|
||||||
pub use embassy_hal_common::usb::*;
|
use crate::interrupt::Interrupt;
|
||||||
|
use crate::pac;
|
||||||
|
|
||||||
|
use core::marker::PhantomData;
|
||||||
|
use embassy::util::Unborrow;
|
||||||
use nrf_usbd::{UsbPeripheral, Usbd};
|
use nrf_usbd::{UsbPeripheral, Usbd};
|
||||||
use usb_device::bus::UsbBusAllocator;
|
use usb_device::bus::UsbBusAllocator;
|
||||||
|
|
||||||
pub struct UsbBus;
|
pub use embassy_hal_common::usb::*;
|
||||||
unsafe impl UsbPeripheral for UsbBus {
|
|
||||||
// todo hardcoding
|
pub struct UsbBus<'d, T: Instance> {
|
||||||
const REGISTERS: *const () = crate::pac::USBD::ptr() as *const ();
|
phantom: PhantomData<&'d mut T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UsbBus {
|
unsafe impl<'d, T: Instance> UsbPeripheral for UsbBus<'d, T> {
|
||||||
// todo should it consume a USBD peripheral?
|
const REGISTERS: *const () = T::regs as *const ();
|
||||||
pub fn new() -> UsbBusAllocator<Usbd<UsbBus>> {
|
}
|
||||||
|
|
||||||
|
impl<'d, T: Instance> UsbBus<'d, T> {
|
||||||
|
pub fn new(_usb: impl Unborrow<Target = T> + 'd) -> UsbBusAllocator<Usbd<UsbBus<'d, T>>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*crate::pac::USBD::ptr()).intenset.write(|w| {
|
(*pac::USBD::ptr()).intenset.write(|w| {
|
||||||
w.sof().set_bit();
|
w.sof().set_bit();
|
||||||
w.usbevent().set_bit();
|
w.usbevent().set_bit();
|
||||||
w.ep0datadone().set_bit();
|
w.ep0datadone().set_bit();
|
||||||
@ -23,8 +30,35 @@ impl UsbBus {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
Usbd::new(UsbBus)
|
Usbd::new(UsbBus {
|
||||||
|
phantom: PhantomData,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
|
unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
|
||||||
|
|
||||||
|
pub(crate) mod sealed {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub trait Instance {
|
||||||
|
fn regs() -> &'static pac::usbd::RegisterBlock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -21,11 +21,11 @@ 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 = UsbBus::new();
|
let usb_bus = UsbBus::new(p.USBD);
|
||||||
|
|
||||||
let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer);
|
let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user