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