usbh_pl2303.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2024, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef USBH_PL2303_H
  7. #define USBH_PL2303_H
  8. #include "usb_cdc.h"
  9. #define PL2303_SET_REQUEST 0x01
  10. #define PL2303_SET_REQUEST_PL2303HXN 0x80
  11. #define PL2303_SET_CRTSCTS 0x41
  12. #define PL2303_SET_CRTSCTS_PL2303X 0x61
  13. #define PL2303_SET_CRTSCTS_PL2303HXN 0xFA
  14. #define PL2303_CLEAR_CRTSCTS_PL2303HXN 0xFF
  15. #define PL2303_CRTSCTS_REG_PL2303HXN 0x0A
  16. #define PL2303_STATUS_REG_PL2303HX 0x8080
  17. /* Different PL2303 IC types */
  18. #define USBH_PL2303_TYPE_UNKNOWN 0
  19. #define USBH_PL2303_TYPE_PL2303 1
  20. #define USBH_PL2303_TYPE_PL2303HX 2
  21. #define USBH_PL2303_TYPE_PL2303HXD 3
  22. #define USBH_PL2303_TYPE_PL2303HXN 4
  23. struct usbh_pl2303 {
  24. struct usbh_hubport *hport;
  25. struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
  26. struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
  27. struct usbh_urb bulkout_urb;
  28. struct usbh_urb bulkin_urb;
  29. struct cdc_line_coding linecoding;
  30. uint8_t intf;
  31. uint8_t minor;
  32. uint8_t chiptype;
  33. void *user_data;
  34. };
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. int usbh_pl2303_set_line_coding(struct usbh_pl2303 *pl2303_class, struct cdc_line_coding *line_coding);
  39. int usbh_pl2303_get_line_coding(struct usbh_pl2303 *pl2303_class, struct cdc_line_coding *line_coding);
  40. int usbh_pl2303_set_line_state(struct usbh_pl2303 *pl2303_class, bool dtr, bool rts);
  41. int usbh_pl2303_bulk_in_transfer(struct usbh_pl2303 *pl2303_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
  42. int usbh_pl2303_bulk_out_transfer(struct usbh_pl2303 *pl2303_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
  43. void usbh_pl2303_run(struct usbh_pl2303 *pl2303_class);
  44. void usbh_pl2303_stop(struct usbh_pl2303 *pl2303_class);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. #endif /* USBH_PL2303_H */