Added node comms
This commit is contained in:
28
node/src/stm32/usb.rs
Normal file
28
node/src/stm32/usb.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// The library will have build errors when built on its own (due to not having embassy-stm32 feature for a specific microcontroller)
|
||||
// but it will work fine when used as a dependency for firmware that has the feature for a specific stm32 microcontroller.
|
||||
|
||||
use crate::comms;
|
||||
use embassy_stm32::peripherals::USB_OTG_FS;
|
||||
use embassy_stm32::usb_otg::{Driver, Endpoint, In, Out};
|
||||
use embassy_usb::driver::{EndpointIn, EndpointOut};
|
||||
use embassy_usb::UsbDevice;
|
||||
|
||||
pub type TypedUSB = UsbDevice<'static, Driver<'static, USB_OTG_FS>>;
|
||||
pub type TypedInterIn = Endpoint<'static, USB_OTG_FS, In>;
|
||||
pub type TypedInterOut = Endpoint<'static, USB_OTG_FS, Out>;
|
||||
|
||||
impl comms::Sender for TypedInterIn {
|
||||
async fn send(&mut self, msg: &[u8]) -> Result<(), comms::Reset> {
|
||||
self.write(msg).await.map_err(|_| comms::Reset)
|
||||
}
|
||||
}
|
||||
|
||||
impl comms::Receiver for TypedInterOut {
|
||||
async fn receive(&mut self, buffer: &mut [u8]) -> Result<(), comms::Reset> {
|
||||
// This should be OK because all our messages are smaller than a single packet.
|
||||
self.read(buffer)
|
||||
.await
|
||||
.map(|_| ())
|
||||
.map_err(|_| comms::Reset)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user