diff --git a/lib/usb_cdcacm.c b/lib/usb_cdcacm.c index 27f3859..43f9059 100644 --- a/lib/usb_cdcacm.c +++ b/lib/usb_cdcacm.c @@ -181,6 +181,9 @@ static usbd_device *usb_device; static uint8_t rx_buffer[CDCACM_BUFFER] = {0}; static volatile uint8_t rx_i = 0; static volatile uint8_t rx_used = 0; +static uint8_t tx_buffer[CDCACM_BUFFER] = {0}; +static volatile uint8_t tx_i = 0; +static volatile uint8_t tx_used = 0; /* show the user how much data received over USB is ready */ volatile uint8_t cdcacm_received = 0; // same as rx_used, but since the user can write this variable we don't rely on it @@ -191,30 +194,33 @@ static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data * (void)usbd_dev; switch (req->bRequest) { - case USB_CDC_REQ_SET_CONTROL_LINE_STATE: { - /* - * This Linux cdc_acm driver requires this to be implemented - * even though it's optional in the CDC spec, and we don't - * advertise it in the ACM functional descriptor. - */ - char local_buf[10]; - struct usb_cdc_notification *notif = (void *)local_buf; + case USB_CDC_REQ_SET_CONTROL_LINE_STATE: { + /* + * This Linux cdc_acm driver requires this to be implemented + * even though it's optional in the CDC spec, and we don't + * advertise it in the ACM functional descriptor. + */ + char local_buf[10]; + struct usb_cdc_notification *notif = (void *)local_buf; - /* We echo signals back to host as notification. */ - notif->bmRequestType = 0xA1; - notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE; - notif->wValue = 0; - notif->wIndex = 0; - notif->wLength = 2; - local_buf[8] = req->wValue & 3; - local_buf[9] = 0; - // usbd_ep_write_packet(0x83, buf, 10); - return 1; + /* We echo signals back to host as notification. */ + notif->bmRequestType = 0xA1; + notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE; + notif->wValue = 0; + notif->wIndex = 0; + notif->wLength = 2; + local_buf[8] = req->wValue & 3; + local_buf[9] = 0; + usbd_ep_write_packet(usbd_dev, 0x83, local_buf, 10); + return 1; } - case USB_CDC_REQ_SET_LINE_CODING: - if (*len < sizeof(struct usb_cdc_line_coding)) + case USB_CDC_REQ_SET_LINE_CODING: + if (*len < sizeof(struct usb_cdc_line_coding)) { + return 0; + } + return 1; + default: return 0; - return 1; } return 0; } @@ -238,13 +244,32 @@ static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) } } +static void cdcacm_data_tx_cb(usbd_device *usbd_dev, uint8_t ep) +{ + (void)ep; + (void)usbd_dev; + + char usb_data[64] = {0}; // buffer to send data + uint16_t usb_length = 0; // length of transmitted data + + /* transmit data */ + if (tx_used) { // copy received data + for (usb_length=0; usb_length