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