usbd_cdc_interface.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. */
  4. #ifndef MICROPY_INCLUDED_STM32_USBD_CDC_INTERFACE_H
  5. #define MICROPY_INCLUDED_STM32_USBD_CDC_INTERFACE_H
  6. /**
  7. ******************************************************************************
  8. * @file USB_Device/CDC_Standalone/Inc/usbd_cdc_interface.h
  9. * @author MCD Application Team
  10. * @version V1.0.1
  11. * @date 26-February-2014
  12. * @brief Header for usbd_cdc_interface.c file.
  13. ******************************************************************************
  14. * @attention
  15. *
  16. * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
  17. *
  18. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  19. * You may not use this file except in compliance with the License.
  20. * You may obtain a copy of the License at:
  21. *
  22. * http://www.st.com/software_license_agreement_liberty_v2
  23. *
  24. * Unless required by applicable law or agreed to in writing, software
  25. * distributed under the License is distributed on an "AS IS" BASIS,
  26. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  27. * See the License for the specific language governing permissions and
  28. * limitations under the License.
  29. *
  30. ******************************************************************************
  31. */
  32. #define USBD_CDC_RX_DATA_SIZE (1024) // this must be 2 or greater, and a power of 2
  33. #define USBD_CDC_TX_DATA_SIZE (1024) // I think this can be any value (was 2048)
  34. typedef struct _usbd_cdc_itf_t {
  35. usbd_cdc_state_t base; // state for the base CDC layer
  36. uint8_t rx_packet_buf[CDC_DATA_MAX_PACKET_SIZE]; // received data from USB OUT endpoint is stored in this buffer
  37. uint8_t rx_user_buf[USBD_CDC_RX_DATA_SIZE]; // received data is buffered here until the user reads it
  38. volatile uint16_t rx_buf_put; // circular buffer index
  39. uint16_t rx_buf_get; // circular buffer index
  40. uint8_t tx_buf[USBD_CDC_TX_DATA_SIZE]; // data for USB IN endpoind is stored in this buffer
  41. uint16_t tx_buf_ptr_in; // increment this pointer modulo USBD_CDC_TX_DATA_SIZE when new data is available
  42. volatile uint16_t tx_buf_ptr_out; // increment this pointer modulo USBD_CDC_TX_DATA_SIZE when data is drained
  43. uint16_t tx_buf_ptr_out_shadow; // shadow of above
  44. uint8_t tx_buf_ptr_wait_count; // used to implement a timeout waiting for low-level USB driver
  45. uint8_t tx_need_empty_packet; // used to flush the USB IN endpoint if the last packet was exactly the endpoint packet size
  46. volatile uint8_t dev_is_connected; // indicates if we are connected
  47. uint8_t attached_to_repl; // indicates if interface is connected to REPL
  48. } usbd_cdc_itf_t;
  49. // This is implemented in usb.c
  50. usbd_cdc_itf_t *usb_vcp_get(int idx);
  51. static inline int usbd_cdc_is_connected(usbd_cdc_itf_t *cdc) {
  52. return cdc->dev_is_connected;
  53. }
  54. int usbd_cdc_tx_half_empty(usbd_cdc_itf_t *cdc);
  55. int usbd_cdc_tx(usbd_cdc_itf_t *cdc, const uint8_t *buf, uint32_t len, uint32_t timeout);
  56. void usbd_cdc_tx_always(usbd_cdc_itf_t *cdc, const uint8_t *buf, uint32_t len);
  57. int usbd_cdc_rx_num(usbd_cdc_itf_t *cdc);
  58. int usbd_cdc_rx(usbd_cdc_itf_t *cdc, uint8_t *buf, uint32_t len, uint32_t timeout);
  59. #endif // MICROPY_INCLUDED_STM32_USBD_CDC_INTERFACE_H