diff --git a/stm32/aioc-fw/Src/usb_serial.c b/stm32/aioc-fw/Src/usb_serial.c index cfd0f7d..995e8f8 100644 --- a/stm32/aioc-fw/Src/usb_serial.c +++ b/stm32/aioc-fw/Src/usb_serial.c @@ -251,3 +251,32 @@ void USB_SerialTask(void) { } + +#include "device/usbd_pvt.h" + +bool USB_SerialSendLineState(uint8_t lineState) +{ +#if 0 + /* TODO: This causes issues with the stack if its being called before CDC was initialized? Crashes on terminal connect */ + uint8_t const rhport = 0; + static uint8_t notification[10] = { + /* bmRequestType */ 0xA1, + /* bNotification */ 0x20, + /* wValue */ 0x00, 0x00, + /* wIndex */ ITF_NUM_CDC_0, 0x00, + /* wLength */ 0x02, 0x00, + /* Data */ 0x00, 0x00 + }; + + notification[8] = lineState; + notification[9] = 0x00; + + // claim endpoint + TU_VERIFY( usbd_edpt_claim(rhport, EPNUM_CDC_0_NOTIF) ); + + return usbd_edpt_xfer(rhport, EPNUM_CDC_0_NOTIF, notification, sizeof(notification)); +#else + return true; +#endif +} + diff --git a/stm32/aioc-fw/Src/usb_serial.h b/stm32/aioc-fw/Src/usb_serial.h index 51aaaa4..27d2237 100644 --- a/stm32/aioc-fw/Src/usb_serial.h +++ b/stm32/aioc-fw/Src/usb_serial.h @@ -1,6 +1,9 @@ #ifndef USB_SERIAL_H_ #define USB_SERIAL_H_ +#include +#include + #define USB_SERIAL_UART USART1 #define USB_SERIAL_UART_IRQ USART1_IRQHandler #define USB_SERIAL_UART_PERIPHCLK RCC_PERIPHCLK_USART1 @@ -10,7 +13,14 @@ #define USB_SERIAL_UART_PIN_TX GPIO_PIN_9 #define USB_SERIAL_UART_PIN_RX GPIO_PIN_10 +#define USB_SERIAL_LINESTATE_DCD 0x01 +#define USB_SERIAL_LINESTATE_DSR 0x02 +#define USB_SERIAL_LINESTATE_BREAK 0x04 +#define USB_SERIAL_LINESTATE_RI 0x08 + void USB_SerialInit(void); void USB_SerialTask(void); +bool USB_SerialSendLineState(uint8_t lineState); + #endif /* USB_SERIAL_H_ */