// 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::Driver as StmUsbDriver; use embassy_usb::driver::{Driver as UsbDriverTrait, EndpointIn, EndpointOut}; use embassy_usb::UsbDevice; type UsbDriver = StmUsbDriver<'static, USB_OTG_FS>; pub type TypedInterIn = >::EndpointIn; pub type TypedInterOut = >::EndpointOut; pub type TypedUSB = UsbDevice<'static, UsbDriver>; pub struct UsbIO { /// Send to master pub interrupt_in: TypedInterIn, /// Recieve from master pub interrupt_out: TypedInterOut, } impl comms::Sender for T { async fn send(&mut self, msg: &[u8]) -> Result<(), comms::Reset> { self.write(msg).await.map_err(|_| comms::Reset) } } impl comms::Receiver for T { #[cfg(feature = "single-packet-msgs")] async fn receive(&mut self, buffer: &mut [u8]) -> Result<(), comms::Reset> { // This is OK when all our messages are smaller than a single packet. self.read(buffer) .await .map(|_| ()) .map_err(|_| comms::Reset) } #[cfg(not(feature = "single-packet-msgs"))] async fn receive(&mut self, buffer: &mut [u8]) -> Result<(), comms::Reset> { todo!("Decide if we want a general purpose multi-packet message receive") } }