usbh_ch34x.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2024, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef USBH_CH34X_H
  7. #define USBH_CH34X_H
  8. #include "usb_cdc.h"
  9. /* Requests */
  10. #define CH34X_READ_VERSION 0x5F
  11. #define CH34X_WRITE_REG 0x9A
  12. #define CH34X_READ_REG 0x95
  13. #define CH34X_SERIAL_INIT 0xA1
  14. #define CH34X_MODEM_CTRL 0xA4
  15. // modem control bits
  16. #define CH34X_BIT_RTS (1 << 6)
  17. #define CH34X_BIT_DTR (1 << 5)
  18. #define CH341_CTO_O 0x10
  19. #define CH341_CTO_D 0x20
  20. #define CH341_CTO_R 0x40
  21. #define CH341_CTI_C 0x01
  22. #define CH341_CTI_DS 0x02
  23. #define CH341_CTRL_RI 0x04
  24. #define CH341_CTI_DC 0x08
  25. #define CH341_CTI_ST 0x0f
  26. #define CH341_L_ER 0x80
  27. #define CH341_L_ET 0x40
  28. #define CH341_L_PS 0x38
  29. #define CH341_L_PM 0x28
  30. #define CH341_L_PE 0x18
  31. #define CH341_L_PO 0x08
  32. #define CH341_L_SB 0x04
  33. #define CH341_L_D8 0x03
  34. #define CH341_L_D7 0x02
  35. #define CH341_L_D6 0x01
  36. #define CH341_L_D5 0x00
  37. struct usbh_ch34x {
  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_ch34x_set_line_coding(struct usbh_ch34x *ch34x_class, struct cdc_line_coding *line_coding);
  52. int usbh_ch34x_get_line_coding(struct usbh_ch34x *ch34x_class, struct cdc_line_coding *line_coding);
  53. int usbh_ch34x_set_line_state(struct usbh_ch34x *ch34x_class, bool dtr, bool rts);
  54. int usbh_ch34x_bulk_in_transfer(struct usbh_ch34x *ch34x_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
  55. int usbh_ch34x_bulk_out_transfer(struct usbh_ch34x *ch34x_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
  56. void usbh_ch34x_run(struct usbh_ch34x *ch34x_class);
  57. void usbh_ch34x_stop(struct usbh_ch34x *ch34x_class);
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif /* USBH_CH34X_H */