Working CDC-ACM host->device
This commit is contained in:
@ -38,14 +38,15 @@ const REQ_SET_CONTROL_LINE_STATE: u8 = 0x22;
|
||||
/// 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>> {
|
||||
comm_if: InterfaceNumber,
|
||||
comm_ep: D::EndpointIn,
|
||||
data_if: InterfaceNumber,
|
||||
read_ep: D::EndpointOut,
|
||||
write_ep: D::EndpointIn,
|
||||
line_coding: LineCoding,
|
||||
dtr: bool,
|
||||
rts: bool,
|
||||
// TODO not pub
|
||||
pub comm_if: InterfaceNumber,
|
||||
pub comm_ep: D::EndpointIn,
|
||||
pub data_if: InterfaceNumber,
|
||||
pub read_ep: D::EndpointOut,
|
||||
pub write_ep: D::EndpointIn,
|
||||
pub line_coding: LineCoding,
|
||||
pub dtr: bool,
|
||||
pub rts: bool,
|
||||
}
|
||||
|
||||
impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> {
|
||||
|
@ -14,7 +14,9 @@ use embassy_nrf::interrupt;
|
||||
use embassy_nrf::pac;
|
||||
use embassy_nrf::usb::{self, Driver};
|
||||
use embassy_nrf::Peripherals;
|
||||
use embassy_usb::driver::EndpointOut;
|
||||
use embassy_usb::{Config, UsbDeviceBuilder};
|
||||
use futures::future::{join, select};
|
||||
|
||||
use crate::cdc_acm::CdcAcmClass;
|
||||
|
||||
@ -49,5 +51,16 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let mut class = CdcAcmClass::new(&mut builder, 64);
|
||||
|
||||
let mut usb = builder.build();
|
||||
usb.run().await;
|
||||
|
||||
let fut1 = usb.run();
|
||||
let fut2 = async {
|
||||
let mut buf = [0; 64];
|
||||
loop {
|
||||
let n = class.read_ep.read(&mut buf).await.unwrap();
|
||||
let data = &buf[..n];
|
||||
info!("data: {:x}", data);
|
||||
}
|
||||
};
|
||||
|
||||
join(fut1, fut2).await;
|
||||
}
|
||||
|
Reference in New Issue
Block a user