USB Host Shield 2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
max3421e.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(_usb_h_) || defined(_max3421e_h_)
18 #error "Never include max3421e.h directly; include Usb.h instead"
19 #else
20 
21 #define _max3421e_h_
22 
23 /* MAX3421E register/bit names and bitmasks */
24 
25 /* Arduino pin definitions */
26 /* pin numbers to port numbers */
27 
28 
29 //#define MAX_INT 9 // Duemielanove
30 
31 //#define MAX_GPX 8
32 
33 #define SE0 0
34 #define SE1 1
35 #define FSHOST 2
36 #define LSHOST 3
37 
38 /* MAX3421E command byte format: rrrrr0wa where 'r' is register number */
39 //
40 // MAX3421E Registers in HOST mode.
41 //
42 #define rRCVFIFO 0x08 //1<<3
43 #define rSNDFIFO 0x10 //2<<3
44 #define rSUDFIFO 0x20 //4<<3
45 #define rRCVBC 0x30 //6<<3
46 #define rSNDBC 0x38 //7<<3
47 
48 #define rUSBIRQ 0x68 //13<<3
49 /* USBIRQ Bits */
50 #define bmVBUSIRQ 0x40 //b6
51 #define bmNOVBUSIRQ 0x20 //b5
52 #define bmOSCOKIRQ 0x01 //b0
53 
54 #define rUSBIEN 0x70 //14<<3
55 /* USBIEN Bits */
56 #define bmVBUSIE 0x40 //b6
57 #define bmNOVBUSIE 0x20 //b5
58 #define bmOSCOKIE 0x01 //b0
59 
60 #define rUSBCTL 0x78 //15<<3
61 /* USBCTL Bits */
62 #define bmCHIPRES 0x20 //b5
63 #define bmPWRDOWN 0x10 //b4
64 
65 #define rCPUCTL 0x80 //16<<3
66 /* CPUCTL Bits */
67 #define bmPUSLEWID1 0x80 //b7
68 #define bmPULSEWID0 0x40 //b6
69 #define bmIE 0x01 //b0
70 
71 #define rPINCTL 0x88 //17<<3
72 /* PINCTL Bits */
73 #define bmFDUPSPI 0x10 //b4
74 #define bmINTLEVEL 0x08 //b3
75 #define bmPOSINT 0x04 //b2
76 #define bmGPXB 0x02 //b1
77 #define bmGPXA 0x01 //b0
78 // GPX pin selections
79 #define GPX_OPERATE 0x00
80 #define GPX_VBDET 0x01
81 #define GPX_BUSACT 0x02
82 #define GPX_SOF 0x03
83 
84 #define rREVISION 0x90 //18<<3
85 
86 #define rIOPINS1 0xa0 //20<<3
87 
88 /* IOPINS1 Bits */
89 #define bmGPOUT0 0x01
90 #define bmGPOUT1 0x02
91 #define bmGPOUT2 0x04
92 #define bmGPOUT3 0x08
93 #define bmGPIN0 0x10
94 #define bmGPIN1 0x20
95 #define bmGPIN2 0x40
96 #define bmGPIN3 0x80
97 
98 #define rIOPINS2 0xa8 //21<<3
99 /* IOPINS2 Bits */
100 #define bmGPOUT4 0x01
101 #define bmGPOUT5 0x02
102 #define bmGPOUT6 0x04
103 #define bmGPOUT7 0x08
104 #define bmGPIN4 0x10
105 #define bmGPIN5 0x20
106 #define bmGPIN6 0x40
107 #define bmGPIN7 0x80
108 
109 #define rGPINIRQ 0xb0 //22<<3
110 /* GPINIRQ Bits */
111 #define bmGPINIRQ0 0x01
112 #define bmGPINIRQ1 0x02
113 #define bmGPINIRQ2 0x04
114 #define bmGPINIRQ3 0x08
115 #define bmGPINIRQ4 0x10
116 #define bmGPINIRQ5 0x20
117 #define bmGPINIRQ6 0x40
118 #define bmGPINIRQ7 0x80
119 
120 #define rGPINIEN 0xb8 //23<<3
121 /* GPINIEN Bits */
122 #define bmGPINIEN0 0x01
123 #define bmGPINIEN1 0x02
124 #define bmGPINIEN2 0x04
125 #define bmGPINIEN3 0x08
126 #define bmGPINIEN4 0x10
127 #define bmGPINIEN5 0x20
128 #define bmGPINIEN6 0x40
129 #define bmGPINIEN7 0x80
130 
131 #define rGPINPOL 0xc0 //24<<3
132 /* GPINPOL Bits */
133 #define bmGPINPOL0 0x01
134 #define bmGPINPOL1 0x02
135 #define bmGPINPOL2 0x04
136 #define bmGPINPOL3 0x08
137 #define bmGPINPOL4 0x10
138 #define bmGPINPOL5 0x20
139 #define bmGPINPOL6 0x40
140 #define bmGPINPOL7 0x80
141 
142 #define rHIRQ 0xc8 //25<<3
143 /* HIRQ Bits */
144 #define bmBUSEVENTIRQ 0x01 // indicates BUS Reset Done or BUS Resume
145 #define bmRWUIRQ 0x02
146 #define bmRCVDAVIRQ 0x04
147 #define bmSNDBAVIRQ 0x08
148 #define bmSUSDNIRQ 0x10
149 #define bmCONDETIRQ 0x20
150 #define bmFRAMEIRQ 0x40
151 #define bmHXFRDNIRQ 0x80
152 
153 #define rHIEN 0xd0 //26<<3
154 
155 /* HIEN Bits */
156 #define bmBUSEVENTIE 0x01
157 #define bmRWUIE 0x02
158 #define bmRCVDAVIE 0x04
159 #define bmSNDBAVIE 0x08
160 #define bmSUSDNIE 0x10
161 #define bmCONDETIE 0x20
162 #define bmFRAMEIE 0x40
163 #define bmHXFRDNIE 0x80
164 
165 #define rMODE 0xd8 //27<<3
166 
167 /* MODE Bits */
168 #define bmHOST 0x01
169 #define bmLOWSPEED 0x02
170 #define bmHUBPRE 0x04
171 #define bmSOFKAENAB 0x08
172 #define bmSEPIRQ 0x10
173 #define bmDELAYISO 0x20
174 #define bmDMPULLDN 0x40
175 #define bmDPPULLDN 0x80
176 
177 #define rPERADDR 0xe0 //28<<3
178 
179 #define rHCTL 0xe8 //29<<3
180 /* HCTL Bits */
181 #define bmBUSRST 0x01
182 #define bmFRMRST 0x02
183 #define bmSAMPLEBUS 0x04
184 #define bmSIGRSM 0x08
185 #define bmRCVTOG0 0x10
186 #define bmRCVTOG1 0x20
187 #define bmSNDTOG0 0x40
188 #define bmSNDTOG1 0x80
189 
190 #define rHXFR 0xf0 //30<<3
191 /* Host transfer token values for writing the HXFR register (R30) */
192 /* OR this bit field with the endpoint number in bits 3:0 */
193 #define tokSETUP 0x10 // HS=0, ISO=0, OUTNIN=0, SETUP=1
194 #define tokIN 0x00 // HS=0, ISO=0, OUTNIN=0, SETUP=0
195 #define tokOUT 0x20 // HS=0, ISO=0, OUTNIN=1, SETUP=0
196 #define tokINHS 0x80 // HS=1, ISO=0, OUTNIN=0, SETUP=0
197 #define tokOUTHS 0xA0 // HS=1, ISO=0, OUTNIN=1, SETUP=0
198 #define tokISOIN 0x40 // HS=0, ISO=1, OUTNIN=0, SETUP=0
199 #define tokISOOUT 0x60 // HS=0, ISO=1, OUTNIN=1, SETUP=0
200 
201 #define rHRSL 0xf8 //31<<3
202 
203 /* HRSL Bits */
204 #define bmRCVTOGRD 0x10
205 #define bmSNDTOGRD 0x20
206 #define bmKSTATUS 0x40
207 #define bmJSTATUS 0x80
208 #define bmSE0 0x00 //SE0 - disconnect state
209 #define bmSE1 0xc0 //SE1 - illegal state
210 
211 /* Host error result codes, the 4 LSB's in the HRSL register */
212 #define hrSUCCESS 0x00
213 #define hrBUSY 0x01
214 #define hrBADREQ 0x02
215 #define hrUNDEF 0x03
216 #define hrNAK 0x04
217 #define hrSTALL 0x05
218 #define hrTOGERR 0x06
219 #define hrWRONGPID 0x07
220 #define hrBADBC 0x08
221 #define hrPIDERR 0x09
222 #define hrPKTERR 0x0A
223 #define hrCRCERR 0x0B
224 #define hrKERR 0x0C
225 #define hrJERR 0x0D
226 #define hrTIMEOUT 0x0E
227 #define hrBABBLE 0x0F
228 
229 #define MODE_FS_HOST (bmDPPULLDN|bmDMPULLDN|bmHOST|bmSOFKAENAB)
230 #define MODE_LS_HOST (bmDPPULLDN|bmDMPULLDN|bmHOST|bmLOWSPEED|bmSOFKAENAB)
231 
232 
233 #endif //_max3421e_h_