usbh_cp210x.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2024, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef USBH_CP210X_H
  7. #define USBH_CP210X_H
  8. #include "usb_cdc.h"
  9. /* Requests */
  10. #define CP210X_IFC_ENABLE 0x00
  11. #define CP210X_SET_BAUDDIV 0x01
  12. #define CP210X_GET_BAUDDIV 0x02
  13. #define CP210X_SET_LINE_CTL 0x03 // Set parity, data bits, stop bits
  14. #define CP210X_GET_LINE_CTL 0x04
  15. #define CP210X_SET_BREAK 0x05
  16. #define CP210X_IMM_CHAR 0x06
  17. #define CP210X_SET_MHS 0x07 // Set DTR, RTS
  18. #define CP210X_GET_MDMSTS 0x08
  19. #define CP210X_SET_XON 0x09
  20. #define CP210X_SET_XOFF 0x0A
  21. #define CP210X_SET_EVENTMASK 0x0B
  22. #define CP210X_GET_EVENTMASK 0x0C
  23. #define CP210X_SET_CHAR 0x0D
  24. #define CP210X_GET_CHARS 0x0E
  25. #define CP210X_GET_PROPS 0x0F
  26. #define CP210X_GET_COMM_STATUS 0x10
  27. #define CP210X_RESET 0x11
  28. #define CP210X_PURGE 0x12
  29. #define CP210X_SET_FLOW 0x13
  30. #define CP210X_GET_FLOW 0x14
  31. #define CP210X_EMBED_EVENTS 0x15
  32. #define CP210X_GET_EVENTSTATE 0x16
  33. #define CP210X_SET_CHARS 0x19
  34. #define CP210X_GET_BAUDRATE 0x1D
  35. #define CP210X_SET_BAUDRATE 0x1E // Set baudrate
  36. #define CP210X_VENDOR_SPECIFIC 0xFF
  37. struct usbh_cp210x {
  38. struct usbh_hubport *hport;
  39. struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
  40. struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
  41. struct usbh_urb bulkout_urb;
  42. struct usbh_urb bulkin_urb;
  43. struct cdc_line_coding line_coding;
  44. uint8_t intf;
  45. uint8_t minor;
  46. void *user_data;
  47. };
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. int usbh_cp210x_set_line_coding(struct usbh_cp210x *ftdi_class, struct cdc_line_coding *line_coding);
  52. int usbh_cp210x_get_line_coding(struct usbh_cp210x *ftdi_class, struct cdc_line_coding *line_coding);
  53. int usbh_cp210x_set_line_state(struct usbh_cp210x *ftdi_class, bool dtr, bool rts);
  54. int usbh_cp210x_bulk_in_transfer(struct usbh_cp210x *cp210x_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
  55. int usbh_cp210x_bulk_out_transfer(struct usbh_cp210x *cp210x_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
  56. void usbh_cp210x_run(struct usbh_cp210x *cp210x_class);
  57. void usbh_cp210x_stop(struct usbh_cp210x *cp210x_class);
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif /* USBH_CP210X_H */