usbh_ftdi.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. struct usbh_ftdi {
  37. struct usbh_hubport *hport;
  38. struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
  39. struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
  40. struct usbh_urb bulkout_urb;
  41. struct usbh_urb bulkin_urb;
  42. struct cdc_line_coding line_coding;
  43. uint8_t intf;
  44. uint8_t minor;
  45. uint8_t modem_status[2];
  46. void *user_data;
  47. };
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. int usbh_ftdi_set_line_coding(struct usbh_ftdi *ftdi_class, struct cdc_line_coding *line_coding);
  52. int usbh_ftdi_get_line_coding(struct usbh_ftdi *ftdi_class, struct cdc_line_coding *line_coding);
  53. int usbh_ftdi_set_line_state(struct usbh_ftdi *ftdi_class, bool dtr, bool rts);
  54. int usbh_ftdi_bulk_in_transfer(struct usbh_ftdi *ftdi_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
  55. int usbh_ftdi_bulk_out_transfer(struct usbh_ftdi *ftdi_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
  56. void usbh_ftdi_run(struct usbh_ftdi *ftdi_class);
  57. void usbh_ftdi_stop(struct usbh_ftdi *ftdi_class);
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif /* USBH_FTDI_H */