You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

cdcprolific.h 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
  2. This software may be distributed and modified under the terms of the GNU
  3. General Public License version 2 (GPL2) as published by the Free Software
  4. Foundation and appearing in the file GPL2.TXT included in the packaging of
  5. this file. Please note that GPL2 Section 2[b] requires that all works based
  6. on this software must also be made publicly available under the terms of
  7. the GPL2 ("Copyleft").
  8. Contact information
  9. -------------------
  10. Circuits At Home, LTD
  11. Web : http://www.circuitsathome.com
  12. e-mail : [email protected]
  13. */
  14. #if !defined(__CDCPROLIFIC_H__)
  15. #define __CDCPROLIFIC_H__
  16. #include "cdcacm.h"
  17. //#define PL2303_COMPAT // Uncomment it if you have compatibility problems
  18. #define PL_VID 0x067B
  19. #define CHECK_PID(pid) ( pid != 0x2303 && pid != 0x0609 )
  20. //#define PL_PID 0x0609
  21. #define PROLIFIC_REV_H 0x0202
  22. #define PROLIFIC_REV_X 0x0300
  23. #define PROLIFIC_REV_HX_CHIP_D 0x0400
  24. #define PROLIFIC_REV_1 0x0001
  25. #define kXOnChar '\x11'
  26. #define kXOffChar '\x13'
  27. #define SPECIAL_SHIFT (5)
  28. #define SPECIAL_MASK ((1<<SPECIAL_SHIFT) - 1)
  29. #define STATE_ALL ( PD_RS232_S_MASK | PD_S_MASK )
  30. #define FLOW_RX_AUTO ( PD_RS232_A_RFR | PD_RS232_A_DTR | PD_RS232_A_RXO )
  31. #define FLOW_TX_AUTO ( PD_RS232_A_CTS | PD_RS232_A_DSR | PD_RS232_A_TXO | PD_RS232_A_DCD )
  32. #define CAN_BE_AUTO ( FLOW_RX_AUTO | FLOW_TX_AUTO )
  33. #define CAN_NOTIFY ( PD_RS232_N_MASK )
  34. #define EXTERNAL_MASK ( PD_S_MASK | (PD_RS232_S_MASK & ~PD_RS232_S_LOOP) )
  35. #define INTERNAL_DELAY ( PD_RS232_S_LOOP )
  36. #define DEFAULT_AUTO ( PD_RS232_A_DTR | PD_RS232_A_RFR | PD_RS232_A_CTS | PD_RS232_A_DSR )
  37. #define DEFAULT_NOTIFY 0x00
  38. #define DEFAULT_STATE ( PD_S_TX_ENABLE | PD_S_RX_ENABLE | PD_RS232_A_TXO | PD_RS232_A_RXO )
  39. #define CONTINUE_SEND 1
  40. #define PAUSE_SEND 2
  41. #define kRxAutoFlow ((UInt32)( PD_RS232_A_RFR | PD_RS232_A_DTR | PD_RS232_A_RXO ))
  42. #define kTxAutoFlow ((UInt32)( PD_RS232_A_CTS | PD_RS232_A_DSR | PD_RS232_A_TXO | PD_RS232_A_DCD ))
  43. #define kControl_StateMask ((UInt32)( PD_RS232_S_CTS | PD_RS232_S_DSR | PD_RS232_S_CAR | PD_RS232_S_RI ))
  44. #define kRxQueueState ((UInt32)( PD_S_RXQ_EMPTY | PD_S_RXQ_LOW_WATER | PD_S_RXQ_HIGH_WATER | PD_S_RXQ_FULL ))
  45. #define kTxQueueState ((UInt32)( PD_S_TXQ_EMPTY | PD_S_TXQ_LOW_WATER | PD_S_TXQ_HIGH_WATER | PD_S_TXQ_FULL ))
  46. #define kCONTROL_DTR 0x01
  47. #define kCONTROL_RTS 0x02
  48. #define kStateTransientMask 0x74
  49. #define kBreakError 0x04
  50. #define kFrameError 0x10
  51. #define kParityError 0x20
  52. #define kOverrunError 0x40
  53. #define kCTS 0x80
  54. #define kDSR 0x02
  55. #define kRI 0x08
  56. #define kDCD 0x01
  57. #define kHandshakeInMask ((UInt32)( PD_RS232_S_CTS | PD_RS232_S_DSR | PD_RS232_S_CAR | PD_RS232_S_RI ))
  58. #define VENDOR_WRITE_REQUEST_TYPE 0x40
  59. #define VENDOR_WRITE_REQUEST 0x01
  60. #define VENDOR_READ_REQUEST_TYPE 0xc0
  61. #define VENDOR_READ_REQUEST 0x01
  62. // Device Configuration Registers (DCR0, DCR1, DCR2)
  63. #define SET_DCR0 0x00
  64. #define GET_DCR0 0x80
  65. #define DCR0_INIT 0x01
  66. #define DCR0_INIT_H 0x41
  67. #define DCR0_INIT_X 0x61
  68. #define SET_DCR1 0x01
  69. #define GET_DCR1 0x81
  70. #define DCR1_INIT_H 0x80
  71. #define DCR1_INIT_X 0x00
  72. #define SET_DCR2 0x02
  73. #define GET_DCR2 0x82
  74. #define DCR2_INIT_H 0x24
  75. #define DCR2_INIT_X 0x44
  76. // On-chip Data Buffers:
  77. #define RESET_DOWNSTREAM_DATA_PIPE 0x08
  78. #define RESET_UPSTREAM_DATA_PIPE 0x09
  79. #define PL_MAX_ENDPOINTS 4
  80. enum tXO_State {
  81. kXOnSent = -2,
  82. kXOffSent = -1,
  83. kXO_Idle = 0,
  84. kXOffNeeded = 1,
  85. kXOnNeeded = 2
  86. };
  87. enum pl2303_type {
  88. unknown,
  89. type_0, /* don't know the difference between type 0 and */
  90. type_1, /* type 1, until someone from prolific tells us... */
  91. rev_X,
  92. rev_HX, /* HX version of the pl2303 chip */
  93. rev_H
  94. };
  95. class PL2303 : public ACM {
  96. uint16_t wPLType; // Type of chip
  97. public:
  98. PL2303(USB *pusb, CDCAsyncOper *pasync);
  99. // USBDeviceConfig implementation
  100. uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
  101. //virtual uint8_t Release();
  102. //virtual uint8_t Poll();
  103. //virtual uint8_t GetAddress() { return bAddress; };
  104. //// UsbConfigXtracter implementation
  105. //virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
  106. #ifdef PL2303_COMPAT
  107. private:
  108. /* Prolific proprietary requests */
  109. uint8_t vendorRead( uint8_t val_lo, uint8_t val_hi, uint16_t index, uint8_t* buf );
  110. uint8_t vendorWrite( uint8_t val_lo, uint8_t val_hi, uint8_t index );
  111. #endif
  112. };
  113. #ifdef PL2303_COMPAT
  114. /* vendor read request */
  115. inline uint8_t PL2303::vendorRead( uint8_t val_lo, uint8_t val_hi, uint16_t index, uint8_t* buf )
  116. {
  117. return( pUsb->ctrlReq(bAddress, 0, VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, val_lo, val_hi, index, 1, 1, buf, NULL ));
  118. }
  119. /* vendor write request */
  120. inline uint8_t PL2303::vendorWrite( uint8_t val_lo, uint8_t val_hi, uint8_t index )
  121. {
  122. return( pUsb->ctrlReq(bAddress, 0, VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, val_lo, val_hi, index, 0, 0, NULL, NULL ));
  123. }
  124. #endif
  125. #endif // __CDCPROLIFIC_H__