usbh_ftdi.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2024, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef USBH_FTDI_H
  7. #define USBH_FTDI_H
  8. #include "usb_cdc.h"
  9. /* Requests */
  10. #define SIO_RESET_REQUEST 0x00 /* Reset the port */
  11. #define SIO_SET_MODEM_CTRL_REQUEST 0x01 /* Set the modem control register */
  12. #define SIO_SET_FLOW_CTRL_REQUEST 0x02 /* Set flow control register */
  13. #define SIO_SET_BAUDRATE_REQUEST 0x03 /* Set baud rate */
  14. #define SIO_SET_DATA_REQUEST 0x04 /* Set the data characteristics of the port */
  15. #define SIO_POLL_MODEM_STATUS_REQUEST 0x05
  16. #define SIO_SET_EVENT_CHAR_REQUEST 0x06
  17. #define SIO_SET_ERROR_CHAR_REQUEST 0x07
  18. #define SIO_SET_LATENCY_TIMER_REQUEST 0x09
  19. #define SIO_GET_LATENCY_TIMER_REQUEST 0x0A
  20. #define SIO_SET_BITMODE_REQUEST 0x0B
  21. #define SIO_READ_PINS_REQUEST 0x0C
  22. #define SIO_READ_EEPROM_REQUEST 0x90
  23. #define SIO_WRITE_EEPROM_REQUEST 0x91
  24. #define SIO_ERASE_EEPROM_REQUEST 0x92
  25. #define SIO_DISABLE_FLOW_CTRL 0x0
  26. #define SIO_RTS_CTS_HS (0x1 << 8)
  27. #define SIO_DTR_DSR_HS (0x2 << 8)
  28. #define SIO_XON_XOFF_HS (0x4 << 8)
  29. #define SIO_SET_DTR_MASK 0x1
  30. #define SIO_SET_DTR_HIGH (1 | (SIO_SET_DTR_MASK << 8))
  31. #define SIO_SET_DTR_LOW (0 | (SIO_SET_DTR_MASK << 8))
  32. #define SIO_SET_RTS_MASK 0x2
  33. #define SIO_SET_RTS_HIGH (2 | (SIO_SET_RTS_MASK << 8))
  34. #define SIO_SET_RTS_LOW (0 | (SIO_SET_RTS_MASK << 8))
  35. #define SIO_RTS_CTS_HS (0x1 << 8)
  36. enum ftdi_chip_type {
  37. SIO,
  38. FT232A,
  39. FT232B,
  40. FT2232C,
  41. FT232R,
  42. FT232H,
  43. FT2232H,
  44. FT4232H,
  45. FT4232HA,
  46. FT232HP,
  47. FT233HP,
  48. FT2232HP,
  49. FT2233HP,
  50. FT4232HP,
  51. FT4233HP,
  52. FTX,
  53. };
  54. struct usbh_ftdi {
  55. struct usbh_hubport *hport;
  56. struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
  57. struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
  58. struct usbh_urb bulkout_urb;
  59. struct usbh_urb bulkin_urb;
  60. struct cdc_line_coding line_coding;
  61. uint8_t intf;
  62. uint8_t minor;
  63. uint8_t modem_status[2];
  64. enum ftdi_chip_type chip_type;
  65. void *user_data;
  66. };
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70. int usbh_ftdi_set_line_coding(struct usbh_ftdi *ftdi_class, struct cdc_line_coding *line_coding);
  71. int usbh_ftdi_get_line_coding(struct usbh_ftdi *ftdi_class, struct cdc_line_coding *line_coding);
  72. int usbh_ftdi_set_line_state(struct usbh_ftdi *ftdi_class, bool dtr, bool rts);
  73. int usbh_ftdi_bulk_in_transfer(struct usbh_ftdi *ftdi_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
  74. int usbh_ftdi_bulk_out_transfer(struct usbh_ftdi *ftdi_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
  75. void usbh_ftdi_run(struct usbh_ftdi *ftdi_class);
  76. void usbh_ftdi_stop(struct usbh_ftdi *ftdi_class);
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif /* USBH_FTDI_H */