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.

devdrv_usb_host_api.h 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*******************************************************************************
  2. * DISCLAIMER
  3. * This software is supplied by Renesas Electronics Corporation and is only
  4. * intended for use with Renesas products. No other uses are authorized. This
  5. * software is owned by Renesas Electronics Corporation and is protected under
  6. * all applicable laws, including copyright laws.
  7. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
  8. * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
  9. * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
  10. * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
  11. * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
  12. * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
  13. * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
  14. * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
  15. * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  16. * Renesas reserves the right, without notice, to make changes to this software
  17. * and to discontinue the availability of this software. By using this software,
  18. * you agree to the additional terms and conditions found by accessing the
  19. * following link:
  20. * http://www.renesas.com/disclaimer
  21. * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
  22. *******************************************************************************/
  23. /*******************************************************************************
  24. * File Name : devdrv_usb_host_api.h
  25. * $Rev: 1116 $
  26. * $Date:: 2014-07-09 16:29:19 +0900#$
  27. * Description : RZ/A1H R7S72100 USB Sample Program
  28. *******************************************************************************/
  29. #ifndef USB_HOST_API_H
  30. #define USB_HOST_API_H
  31. #include "r_typedefs.h"
  32. /*******************************************************************************
  33. Typedef definitions
  34. *******************************************************************************/
  35. /*******************************************************************************
  36. Macro definitions
  37. *******************************************************************************/
  38. #define USB_HOST_PORTNUM (2)
  39. #define USB_HOST_ELT_INTERRUPT_LEVEL (9)
  40. #define USBHCLOCK_X1_48MHZ (0x0000u) /* USB_X1_48MHz */
  41. #define USBHCLOCK_EXTAL_12MHZ (0x0004u) /* EXTAL_12MHz */
  42. #define USB_HOST_MAX_DEVICE (10)
  43. #define USB_HOST_ON (1)
  44. #define USB_HOST_OFF (0)
  45. #define USB_HOST_YES (1)
  46. #define USB_HOST_NO (0)
  47. #define USB_HOST_NON_SPEED (0)
  48. #define USB_HOST_LOW_SPEED (1)
  49. #define USB_HOST_FULL_SPEED (2)
  50. #define USB_HOST_HIGH_SPEED (3)
  51. /* DEVDRV_SUCCESS(0) & DEVDRV_ERROR(-1) is dev_drv.h */
  52. #define DEVDRV_USBH_STALL (-2)
  53. #define DEVDRV_USBH_TIMEOUT (-3)
  54. #define DEVDRV_USBH_NAK_TIMEOUT (-4)
  55. #define DEVDRV_USBH_DETACH_ERR (-5)
  56. #define DEVDRV_USBH_SETUP_ERR (-6)
  57. #define DEVDRV_USBH_CTRL_COM_ERR (-7)
  58. #define DEVDRV_USBH_COM_ERR (-8)
  59. #define DEVDRV_USBH_DEV_ADDR_ERR (-9)
  60. #define USB_HOST_ATTACH (1)
  61. #define USB_HOST_DETACH (0)
  62. #define USB_HOST_MAX_PIPE_NO (9u)
  63. #define USB_HOST_PIPE0 (0)
  64. #define USB_HOST_PIPE1 (1)
  65. #define USB_HOST_PIPE2 (2)
  66. #define USB_HOST_PIPE3 (3)
  67. #define USB_HOST_PIPE4 (4)
  68. #define USB_HOST_PIPE5 (5)
  69. #define USB_HOST_PIPE6 (6)
  70. #define USB_HOST_PIPE7 (7)
  71. #define USB_HOST_PIPE8 (8)
  72. #define USB_HOST_PIPE9 (9)
  73. #define USB_HOST_ISO (0xc000u)
  74. #define USB_HOST_INTERRUPT (0x8000u)
  75. #define USB_HOST_BULK (0x4000u)
  76. #define USB_HOST_PIPE_IDLE (0x00)
  77. #define USB_HOST_PIPE_WAIT (0x01)
  78. #define USB_HOST_PIPE_DONE (0x02)
  79. #define USB_HOST_PIPE_NORES (0x03)
  80. #define USB_HOST_PIPE_STALL (0x04)
  81. #define USB_HOST_PIPE_ERROR (0x05)
  82. #define USB_HOST_NONE (0x0000u)
  83. #define USB_HOST_BFREFIELD (0x0400u)
  84. #define USB_HOST_BFREON (0x0400u)
  85. #define USB_HOST_BFREOFF (0x0000u)
  86. #define USB_HOST_DBLBFIELD (0x0200u)
  87. #define USB_HOST_DBLBON (0x0200u)
  88. #define USB_HOST_DBLBOFF (0x0000u)
  89. #define USB_HOST_CNTMDFIELD (0x0100u)
  90. #define USB_HOST_CNTMDON (0x0100u)
  91. #define USB_HOST_CNTMDOFF (0x0000u)
  92. #define USB_HOST_SHTNAKON (0x0080u)
  93. #define USB_HOST_SHTNAKOFF (0x0000u)
  94. #define USB_HOST_DIRFIELD (0x0010u)
  95. #define USB_HOST_DIR_H_OUT (0x0010u)
  96. #define USB_HOST_DIR_H_IN (0x0000u)
  97. #define USB_HOST_EPNUMFIELD (0x000fu)
  98. #define USB_HOST_CUSE (0)
  99. #define USB_HOST_D0USE (1)
  100. #define USB_HOST_D0DMA (2)
  101. #define USB_HOST_D1USE (3)
  102. #define USB_HOST_D1DMA (4)
  103. #define USB_HOST_CFIFO_USE (0x0000)
  104. #define USB_HOST_D0FIFO_USE (0x1000)
  105. #define USB_HOST_D1FIFO_USE (0x2000)
  106. #define USB_HOST_D0FIFO_DMA (0x5000)
  107. #define USB_HOST_D1FIFO_DMA (0x6000)
  108. #define USB_HOST_BUF2FIFO (0)
  109. #define USB_HOST_FIFO2BUF (1)
  110. #define USB_HOST_DRV_DETACHED (0x0000)
  111. #define USB_HOST_DRV_ATTACHED (0x0001)
  112. #define USB_HOST_DRV_GET_DEVICE_DESC_64 (0x0002)
  113. #define USB_HOST_DRV_POWERED (0x0003)
  114. #define USB_HOST_DRV_DEFAULT (0x0004)
  115. #define USB_HOST_DRV_SET_ADDRESS (0x0005)
  116. #define USB_HOST_DRV_ADDRESSED (0x0006)
  117. #define USB_HOST_DRV_GET_DEVICE_DESC_18 (0x0007)
  118. #define USB_HOST_DRV_GET_CONGIG_DESC_9 (0x0008)
  119. #define USB_HOST_DRV_GET_CONGIG_DESC (0x0009)
  120. #define USB_HOST_DRV_SET_CONFIG (0x000a)
  121. #define USB_HOST_DRV_CONFIGURED (0x000b)
  122. #define USB_HOST_DRV_SUSPEND (0x1000)
  123. #define USB_HOST_DRV_NORES (0x0100)
  124. #define USB_HOST_DRV_STALL (0x0200)
  125. #define USB_HOST_TESTMODE_FORCE (0x000du)
  126. #define USB_HOST_TESTMODE_TESTPACKET (0x000cu)
  127. #define USB_HOST_TESTMODE_SE0_NAK (0x000bu)
  128. #define USB_HOST_TESTMODE_K (0x000au)
  129. #define USB_HOST_TESTMODE_J (0x0009u)
  130. #define USB_HOST_TESTMODE_NORMAL (0x0000u)
  131. #define USB_HOST_DT_DEVICE (0x01)
  132. #define USB_HOST_DT_CONFIGURATION (0x02)
  133. #define USB_HOST_DT_STRING (0x03)
  134. #define USB_HOST_DT_INTERFACE (0x04)
  135. #define USB_HOST_DT_ENDPOINT (0x05)
  136. #define USB_HOST_DT_DEVICE_QUALIFIER (0x06)
  137. #define USB_HOST_DT_OTHER_SPEED_CONFIGURATION (0x07)
  138. #define USB_HOST_DT_INTERFACE_POWER (0x08)
  139. #define USB_HOST_IF_CLS_NOT (0x00)
  140. #define USB_HOST_IF_CLS_AUDIO (0x01)
  141. #define USB_HOST_IF_CLS_CDC_CTRL (0x02)
  142. #define USB_HOST_IF_CLS_HID (0x03)
  143. #define USB_HOST_IF_CLS_PHYSICAL (0x05)
  144. #define USB_HOST_IF_CLS_IMAGE (0x06)
  145. #define USB_HOST_IF_CLS_PRINTER (0x07)
  146. #define USB_HOST_IF_CLS_MASS (0x08)
  147. #define USB_HOST_IF_CLS_HUB (0x09)
  148. #define USB_HOST_IF_CLS_CDC_DATA (0x0a)
  149. #define USB_HOST_IF_CLS_CRAD (0x0b)
  150. #define USB_HOST_IF_CLS_CONTENT (0x0d)
  151. #define USB_HOST_IF_CLS_VIDEO (0x0e)
  152. #define USB_HOST_IF_CLS_DIAG (0xdc)
  153. #define USB_HOST_IF_CLS_WIRELESS (0xe0)
  154. #define USB_HOST_IF_CLS_APL (0xfe)
  155. #define USB_HOST_IF_CLS_VENDOR (0xff)
  156. #define USB_HOST_IF_CLS_HELE (0xaa)
  157. #define USB_HOST_EP_DIR_MASK (0x80)
  158. #define USB_HOST_EP_OUT (0x00)
  159. #define USB_HOST_EP_IN (0x80)
  160. #define USB_HOST_EP_TYPE (0x03)
  161. #define USB_HOST_EP_CNTRL (0x00)
  162. #define USB_HOST_EP_ISO (0x01)
  163. #define USB_HOST_EP_BULK (0x02)
  164. #define USB_HOST_EP_INT (0x03)
  165. #define USB_HOST_EP_NUM_MASK (0x0f)
  166. #define USB_HOST_PIPE_IN (0)
  167. #define USB_HOST_PIPE_OUT (1)
  168. #define USB_END_POINT_ERROR (0xffff)
  169. #define USB_HOST_REQ_GET_STATUS (0x0000)
  170. #define USB_HOST_REQ_CLEAR_FEATURE (0x0100)
  171. #define USB_HOST_REQ_RESERVED2 (0x0200)
  172. #define USB_HOST_REQ_SET_FEATURE (0x0300)
  173. #define USB_HOST_REQ_RESERVED4 (0x0400)
  174. #define USB_HOST_REQ_SET_ADDRESS (0x0500)
  175. #define USB_HOST_REQ_GET_DESCRIPTOR (0x0600)
  176. #define USB_HOST_REQ_SET_DESCRIPTOR (0x0700)
  177. #define USB_HOST_REQ_GET_CONFIGURATION (0x0800)
  178. #define USB_HOST_REQ_SET_CONFIGURATION (0x0900)
  179. #define USB_HOST_REQ_GET_INTERFACE (0x0a00)
  180. #define USB_HOST_REQ_SET_INTERFACE (0x0b00)
  181. #define USB_HOST_REQ_SYNCH_FRAME (0x0c00)
  182. #define USB_HOST_REQTYPE_HOST_TO_DEVICE (0x0000)
  183. #define USB_HOST_REQTYPE_DEVICE_TO_HOST (0x0080)
  184. #define USB_HOST_REQTYPE_STANDARD (0x0020)
  185. #define USB_HOST_REQTYPE_CLASS (0x0040)
  186. #define USB_HOST_REQTYPE_VENDOR (0x0060)
  187. #define USB_HOST_REQTYPE_DEVICE (0x0000)
  188. #define USB_HOST_REQTYPE_INTERFACE (0x0001)
  189. #define USB_HOST_REQTYPE_ENDPOINT (0x0002)
  190. #define USB_HOST_REQTYPE_OTHER (0x0003)
  191. #define USB_HOST_DESCTYPE_DEVICE (0x0100)
  192. #define USB_HOST_DESCTYPE_CONFIGURATION (0x0200)
  193. #define USB_HOST_DESCTYPE_STRING (0x0300)
  194. #define USB_HOST_DESCTYPE_INTERFACE (0x0400)
  195. #define USB_HOST_DESCTYPE_ENDPOINT (0x0500)
  196. #define USB_HOST_DESCTYPE_DEVICE_QUALIFIER (0x0600)
  197. #define USB_HOST_DESCTYPE_OTHER_SPEED_CONFIGURATION (0x0700)
  198. #define USB_HOST_DESCTYPE_INTERFACE_POWER (0x0800)
  199. /*******************************************************************************
  200. Variable Externs
  201. *******************************************************************************/
  202. typedef struct
  203. {
  204. uint16_t pipe_number;
  205. uint16_t pipe_cfg;
  206. uint16_t pipe_buf;
  207. uint16_t pipe_max_pktsize;
  208. uint16_t pipe_cycle;
  209. uint16_t fifo_port;
  210. } USB_HOST_CFG_PIPETBL_t;
  211. typedef struct
  212. {
  213. uint32_t fifo;
  214. uint32_t buffer;
  215. uint32_t bytes;
  216. uint32_t dir;
  217. uint32_t size;
  218. } USB_HOST_DMA_t;
  219. /*******************************************************************************
  220. Imported global variables and functions (from other files)
  221. *******************************************************************************/
  222. uint16_t R_USB_api_host_init(uint16_t root, uint8_t int_level, uint16_t mode, uint16_t clockmode);
  223. int32_t R_USB_api_host_enumeration(uint16_t root, uint16_t devadr);
  224. int32_t R_USB_api_host_detach(uint16_t root);
  225. int32_t R_USB_api_host_data_in(uint16_t root, uint16_t devadr, uint16_t Pipe, uint32_t Size, uint8_t *data_buf);
  226. int32_t R_USB_api_host_data_in2(uint16_t root, uint16_t devadr, uint16_t Pipe, uint32_t Size, uint8_t *data_buf, uint32_t *bytes);
  227. int32_t R_USB_api_host_data_out(uint16_t root, uint16_t devadr, uint16_t Pipe, uint32_t Size, uint8_t *data_buf);
  228. int32_t R_USB_api_host_control_transfer(uint16_t root, uint16_t devadr, uint16_t Req, uint16_t Val, uint16_t Indx, uint16_t Len, uint8_t *Buf);
  229. int32_t R_USB_api_host_set_endpoint(uint16_t root, uint16_t devadr, USB_HOST_CFG_PIPETBL_t *user_table, uint8_t *configdescriptor);
  230. int32_t R_USB_api_host_clear_endpoint(uint16_t root, USB_HOST_CFG_PIPETBL_t *user_table);
  231. int32_t R_USB_api_host_clear_endpoint_pipe(uint16_t root, uint16_t pipe_sel, USB_HOST_CFG_PIPETBL_t *user_table);
  232. uint16_t R_USB_api_host_SetEndpointTable(uint16_t root, uint16_t devadr, USB_HOST_CFG_PIPETBL_t *user_table, uint8_t* Table);
  233. int32_t R_USB_api_host_GetDeviceDescriptor(uint16_t root, uint16_t devadr, uint16_t size, uint8_t *buf);
  234. int32_t R_USB_api_host_GetConfigDescriptor(uint16_t root, uint16_t devadr, uint16_t size, uint8_t *buf);
  235. int32_t R_USB_api_host_SetConfig(uint16_t root, uint16_t devadr, uint16_t confignum);
  236. int32_t R_USB_api_host_SetInterface(uint16_t root, uint16_t devadr, uint16_t interface_alt, uint16_t interface_index);
  237. int32_t R_USB_api_host_ClearStall(uint16_t root, uint16_t devadr, uint16_t ep_dir);
  238. uint16_t R_USB_api_host_GetUsbDeviceState(uint16_t root);
  239. void R_USB_api_host_elt_clocksel(uint16_t clockmode);
  240. void R_USB_api_host_elt_4_4(uint16_t root);
  241. void R_USB_api_host_elt_4_5(uint16_t root);
  242. void R_USB_api_host_elt_4_6(uint16_t root);
  243. void R_USB_api_host_elt_4_7(uint16_t root);
  244. void R_USB_api_host_elt_4_8(uint16_t root);
  245. void R_USB_api_host_elt_4_9(uint16_t root);
  246. void R_USB_api_host_elt_get_desc(uint16_t root);
  247. /*******************************************************************************
  248. Includes <System Includes> , "Project Includes"
  249. *******************************************************************************/
  250. #include "usb0_host_api.h"
  251. #include "usb1_host_api.h"
  252. /*******************************************************************************
  253. Imported global variables and functions (from other files)
  254. *******************************************************************************/
  255. #ifdef USB0_HOST_API_H
  256. uint16_t Userdef_USB_usb0_host_d0fifo_dmaintid(void);
  257. uint16_t Userdef_USB_usb0_host_d1fifo_dmaintid(void);
  258. void Userdef_USB_usb0_host_attach(void);
  259. void Userdef_USB_usb0_host_detach(void);
  260. void Userdef_USB_usb0_host_delay_1ms(void);
  261. void Userdef_USB_usb0_host_delay_xms(uint32_t msec);
  262. void Userdef_USB_usb0_host_delay_10us(uint32_t usec);
  263. void Userdef_USB_usb0_host_delay_500ns(void);
  264. void Userdef_USB_usb0_host_start_dma(USB_HOST_DMA_t * dma, uint16_t dfacc);
  265. uint32_t Userdef_USB_usb0_host_stop_dma0(void);
  266. uint32_t Userdef_USB_usb0_host_stop_dma1(void);
  267. void Userdef_USB_usb0_host_notice(const char * format);
  268. void Userdef_USB_usb0_host_user_rdy(const char * format, uint16_t data);
  269. #endif
  270. #ifdef USB1_HOST_API_H
  271. uint16_t Userdef_USB_usb1_host_d0fifo_dmaintid(void);
  272. uint16_t Userdef_USB_usb1_host_d1fifo_dmaintid(void);
  273. void Userdef_USB_usb1_host_attach(void);
  274. void Userdef_USB_usb1_host_detach(void);
  275. void Userdef_USB_usb1_host_delay_1ms(void);
  276. void Userdef_USB_usb1_host_delay_xms(uint32_t msec);
  277. void Userdef_USB_usb1_host_delay_10us(uint32_t usec);
  278. void Userdef_USB_usb1_host_delay_500ns(void);
  279. void Userdef_USB_usb1_host_start_dma(USB_HOST_DMA_t * dma, uint16_t dfacc);
  280. uint32_t Userdef_USB_usb1_host_stop_dma0(void);
  281. uint32_t Userdef_USB_usb1_host_stop_dma1(void);
  282. void Userdef_USB_usb1_host_notice(const char * format);
  283. void Userdef_USB_usb1_host_user_rdy(const char * format, uint16_t data);
  284. #endif
  285. #endif /* USB_HOST_API_H */
  286. /* End of File */