Keyboard firmwares for Atmel AVR and Cortex-M
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.

max3421e.h 6.0KB

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