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