2 #if (USE_STM32_USB_HOST_MODE || USE_STM32_USB_USE_DEVICE_MODE || USE_STM32_USB_OTG_MODE)
8 #include "config/usb_conf.h"
9 #if defined(USE_DEVICE_MODE)
14 #include "stm32/usb/usbd_cdc_core.h"
15 #include "stm32/usb/usb_core.h"
16 #include "stm32/usb/usbd_usr.h"
17 #include "stm32/usb/usbd_desc.h"
18 #include "stm32/usb/usb_dcd_int.h"
19 #include "stm32/usb/usb_hcd_int.h"
23 static uint16_t cdc_init(
void)
28 static uint16_t cdc_deinit(
void)
33 static uint16_t cdc_ctrl(uint32_t cmd,
const uint8_t* buf, uint32_t len)
42 static status_e(*cdc_user_rx)(USB_OTG_CORE_HANDLE *dev,
const uint32_t *buffer,
size_t len);
44 static uint16_t cdc_rx(
const uint32_t* buf, uint32_t len)
46 cdc_user_rx(&USB_OTG_Core, buf, len);
57 static volatile enum state_e state;
59 static uint16_t cdc_data_tx_emtpy(
void)
65 const CDC_IF_Prop_TypeDef APP_FOPS =
68 .pIf_DeInit = cdc_deinit,
71 .pIf_DataTxEmpty = cdc_data_tx_emtpy,
74 static void do_nothing(
void)
79 static void do_nothing_u8(uint8_t _unused)
84 static USBD_Usr_cb_TypeDef default_USR_cb =
87 .DeviceReset = do_nothing_u8,
88 .DeviceConfigured = do_nothing,
89 .DeviceSuspended = do_nothing,
90 .DeviceResumed = do_nothing,
92 .DeviceConnected = do_nothing,
93 .DeviceDisconnected = do_nothing,
96 status_e usbd_cdc_init(usbd_cdc_rx_t rx, USBD_Usr_cb_TypeDef *usr_cb)
105 usr_cb = &default_USR_cb;
112 USBD_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, usr_cb);
117 const uint32_t max_size = 0x10000;
118 size_t usbd_cdc_tx_nowait_maxsize(
void)
123 status_e usbd_cdc_tx(
const void *data,
size_t len,
enum usb_cdc_wait_e wait)
127 if (wait == WAIT_NO_WAIT && state != STATE_IDLE)
133 while (state == STATE_SENDING)
146 if (len > max_size && wait == WAIT_NO_WAIT)
151 while (len > max_size)
153 state = STATE_SENDING;
154 DCD_EP_Tx(&USB_OTG_Core, CDC_IN_EP, (
void *)data, max_size);
157 while (state == STATE_SENDING)
168 state = STATE_SENDING;
169 DCD_EP_Tx(&USB_OTG_Core, CDC_IN_EP, (
void *)data, len);
170 if (!(wait & WAIT_TX_FINISHED))
176 while (state == STATE_SENDING)
libheivs configuration file
static uint32_t time_elapsed(timeout_t timeout)
Is this time passed?
USB device CDC (virtural com port) interface.
timeout_t time_set_timeout_ms(uint32_t ms)
Set an obscure time at least ms milliseconds in the future.