usb: add -usb-serial crate, fix warnings and stable build.

This commit is contained in:
Dario Nieuwenhuis
2022-03-30 01:18:37 +02:00
parent c06488eb29
commit d1e4b3d7d5
15 changed files with 265 additions and 27 deletions

View File

@ -18,7 +18,7 @@ flavors = [
[features]
# Enable nightly-only features
nightly = ["embassy/nightly", "embedded-hal-1", "embedded-hal-async"]
nightly = ["embassy/nightly", "embedded-hal-1", "embedded-hal-async", "embassy-usb"]
# Reexport the PAC for the currently enabled chip at `embassy_nrf::pac`.
# This is unstable because semver-minor (non-breaking) releases of embassy-nrf may major-bump (breaking) the PAC version.
@ -64,7 +64,7 @@ _gpio-p1 = []
embassy = { version = "0.1.0", path = "../embassy" }
embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]}
embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" }
embassy-usb = {version = "0.1.0", path = "../embassy-usb" }
embassy-usb = {version = "0.1.0", path = "../embassy-usb", optional=true }
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.7", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy2", optional = true}

View File

@ -125,6 +125,7 @@ embassy_hal_common::peripherals! {
TEMP,
}
#[cfg(feature = "nightly")]
impl_usb!(USBD, USBD, USBD);
impl_uarte!(UARTE0, UARTE0, UARTE0_UART0);

View File

@ -157,6 +157,7 @@ embassy_hal_common::peripherals! {
TEMP,
}
#[cfg(feature = "nightly")]
impl_usb!(USBD, USBD, USBD);
impl_uarte!(UARTE0, UARTE0, UARTE0_UART0);

View File

@ -160,6 +160,7 @@ embassy_hal_common::peripherals! {
TEMP,
}
#[cfg(feature = "nightly")]
impl_usb!(USBD, USBD, USBD);
impl_uarte!(UARTE0, UARTE0, UARTE0_UART0);

View File

@ -348,6 +348,7 @@ embassy_hal_common::peripherals! {
P1_15,
}
#[cfg(feature = "nightly")]
impl_usb!(USBD, USBD, USBD);
impl_uarte!(UARTETWISPI0, UARTE0, SERIAL0);

View File

@ -91,6 +91,7 @@ pub mod uarte;
feature = "nrf52833",
feature = "nrf52840"
))]
#[cfg(feature = "nightly")]
pub mod usb;
#[cfg(not(feature = "_nrf5340"))]
pub mod wdt;

View File

@ -4,6 +4,7 @@ use core::marker::PhantomData;
use core::mem::MaybeUninit;
use core::sync::atomic::{compiler_fence, AtomicU32, Ordering};
use core::task::Poll;
use cortex_m::peripheral::NVIC;
use embassy::interrupt::InterruptExt;
use embassy::time::{with_timeout, Duration};
use embassy::util::Unborrow;
@ -14,7 +15,6 @@ use embassy_usb::driver::{self, Event, ReadError, WriteError};
use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection};
use futures::future::poll_fn;
use futures::Future;
use pac::NVIC;
pub use embassy_usb;
@ -617,7 +617,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
fn data_out<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::DataOutFuture<'a> {
async move {
let req = self.request.unwrap();
assert_eq!(req.direction, UsbDirection::Out);
assert!(req.direction == UsbDirection::Out);
assert!(req.length > 0);
let req_length = usize::from(req.length);
@ -644,9 +644,12 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
fn accept_in<'a>(&'a mut self, buf: &'a [u8]) -> Self::AcceptInFuture<'a> {
async move {
info!("control accept {=[u8]:x}", buf);
#[cfg(feature = "defmt")]
info!("control accept {:x}", buf);
#[cfg(not(feature = "defmt"))]
info!("control accept {:x?}", buf);
let req = self.request.unwrap();
assert_eq!(req.direction, UsbDirection::In);
assert!(req.direction == UsbDirection::In);
let req_len = usize::from(req.length);
let len = buf.len().min(req_len);