usb-serial: make inner guts private.
This commit is contained in:
parent
cdb7bae51a
commit
1672fdc666
@ -53,20 +53,17 @@ impl<'a> State<'a> {
|
||||
/// writing USB packets with no intermediate buffers, but it will not act like a stream-like serial
|
||||
/// port. The following constraints must be followed if you use this class directly:
|
||||
///
|
||||
/// - `read_packet` must be called with a buffer large enough to hold max_packet_size bytes, and the
|
||||
/// method will return a `WouldBlock` error if there is no packet to be read.
|
||||
/// - `write_packet` must not be called with a buffer larger than max_packet_size bytes, and the
|
||||
/// method will return a `WouldBlock` error if the previous packet has not been sent yet.
|
||||
/// - `read_packet` must be called with a buffer large enough to hold max_packet_size bytes.
|
||||
/// - `write_packet` must not be called with a buffer larger than max_packet_size bytes.
|
||||
/// - If you write a packet that is exactly max_packet_size bytes long, it won't be processed by the
|
||||
/// host operating system until a subsequent shorter packet is sent. A zero-length packet (ZLP)
|
||||
/// can be sent if there is no other data to send. This is because USB bulk transactions must be
|
||||
/// terminated with a short packet, even if the bulk endpoint is used for stream-like data.
|
||||
pub struct CdcAcmClass<'d, D: Driver<'d>> {
|
||||
// TODO not pub
|
||||
pub comm_ep: D::EndpointIn,
|
||||
pub data_if: InterfaceNumber,
|
||||
pub read_ep: D::EndpointOut,
|
||||
pub write_ep: D::EndpointIn,
|
||||
_comm_ep: D::EndpointIn,
|
||||
_data_if: InterfaceNumber,
|
||||
read_ep: D::EndpointOut,
|
||||
write_ep: D::EndpointIn,
|
||||
control: &'d ControlShared,
|
||||
}
|
||||
|
||||
@ -237,8 +234,8 @@ impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> {
|
||||
builder.config_descriptor.endpoint(read_ep.info());
|
||||
|
||||
CdcAcmClass {
|
||||
comm_ep,
|
||||
data_if,
|
||||
_comm_ep: comm_ep,
|
||||
_data_if: data_if,
|
||||
read_ep,
|
||||
write_ep,
|
||||
control: control_shared,
|
||||
|
@ -6,15 +6,13 @@
|
||||
use core::mem;
|
||||
use defmt::*;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_nrf::interrupt;
|
||||
use embassy_nrf::pac;
|
||||
use embassy_nrf::usb::Driver;
|
||||
use embassy_nrf::Peripherals;
|
||||
use embassy_usb::driver::{EndpointIn, EndpointOut};
|
||||
use embassy_usb::{Config, UsbDeviceBuilder};
|
||||
use embassy_usb_serial::{CdcAcmClass, State};
|
||||
use futures::future::join3;
|
||||
use futures::future::join;
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
use panic_probe as _;
|
||||
@ -64,28 +62,20 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let mut usb = builder.build();
|
||||
|
||||
// Run the USB device.
|
||||
let fut1 = usb.run();
|
||||
let usb_fut = usb.run();
|
||||
|
||||
// Do stuff with the classes
|
||||
let fut2 = async {
|
||||
// Do stuff with the class!
|
||||
let echo_fut = async {
|
||||
let mut buf = [0; 64];
|
||||
loop {
|
||||
let n = class.read_ep.read(&mut buf).await.unwrap();
|
||||
let n = class.read_packet(&mut buf).await.unwrap();
|
||||
let data = &buf[..n];
|
||||
info!("data: {:x}", data);
|
||||
}
|
||||
};
|
||||
let fut3 = async {
|
||||
loop {
|
||||
info!("writing...");
|
||||
class.write_ep.write(b"Hello World!\r\n").await.unwrap();
|
||||
info!("written");
|
||||
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
class.write_packet(data).await.unwrap();
|
||||
}
|
||||
};
|
||||
|
||||
// Run everything concurrently.
|
||||
// If we had made everything `'static` above instead, we could do this using separate tasks instead.
|
||||
join3(fut1, fut2, fut3).await;
|
||||
join(usb_fut, echo_fut).await;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user