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_function_api.h 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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_function_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_FUNCTION_API_H
  30. #define USB_FUNCTION_API_H
  31. /*******************************************************************************
  32. Includes <System Includes> , "Project Includes"
  33. *******************************************************************************/
  34. #include <MBRZA1H.h>
  35. #include "r_typedefs.h"
  36. #include "usb0_function_api.h"
  37. #include "usb1_function_api.h"
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /*******************************************************************************
  42. Typedef definitions
  43. *******************************************************************************/
  44. typedef struct
  45. {
  46. uint32_t fifo;
  47. uint32_t buffer;
  48. uint32_t bytes;
  49. uint32_t dir;
  50. uint32_t size;
  51. } USB_FUNCTION_DMA_t;
  52. /*******************************************************************************
  53. Macro definitions
  54. *******************************************************************************/
  55. #define USBFCLOCK_X1_48MHZ (0x0000u) /* USB_X1_48MHz */
  56. #define USBFCLOCK_EXTAL_12MHZ (0x0004u) /* EXTAL_12MHz */
  57. #define DEVDRV_USBF_ON (1)
  58. #define DEVDRV_USBF_OFF (0)
  59. #define DEVDRV_USBF_YES (1)
  60. #define DEVDRV_USBF_NO (0)
  61. #define DEVDRV_USBF_STALL (-2)
  62. #define DEVDRV_USBF_WRITEEND (0)
  63. #define DEVDRV_USBF_WRITESHRT (1)
  64. #define DEVDRV_USBF_WRITING (2)
  65. #define DEVDRV_USBF_WRITEDMA (3)
  66. #define DEVDRV_USBF_FIFOERROR (0xffff)
  67. #define DEVDRV_USBF_PIPE_IDLE (0x00)
  68. #define DEVDRV_USBF_PIPE_WAIT (0x01)
  69. #define DEVDRV_USBF_PIPE_DONE (0x02)
  70. #define DEVDRV_USBF_PIPE_NORES (0x03)
  71. #define DEVDRV_USBF_PIPE_STALL (0x04)
  72. #define DEVDRV_USBF_PID_NAK (0x0000u)
  73. #define DEVDRV_USBF_PID_BUF (0x0001u)
  74. #define DEVDRV_USBF_PID_STALL (0x0002u)
  75. #define DEVDRV_USBF_PID_STALL2 (0x0003u)
  76. #define USB_FUNCTION_NON_SPEED (0)
  77. #define USB_FUNCTION_LOW_SPEED (1)
  78. #define USB_FUNCTION_FULL_SPEED (2)
  79. #define USB_FUNCTION_HIGH_SPEED (3)
  80. #define USB_FUNCTION_READEND (0)
  81. #define USB_FUNCTION_READSHRT (1)
  82. #define USB_FUNCTION_READING (2)
  83. #define USB_FUNCTION_READOVER (3)
  84. #define USB_FUNCTION_READZERO (4)
  85. #define USB_FUNCTION_MAX_PIPE_NO (15u)
  86. #define USB_FUNCTION_PIPE0 (0)
  87. #define USB_FUNCTION_PIPE1 (1)
  88. #define USB_FUNCTION_PIPE2 (2)
  89. #define USB_FUNCTION_PIPE3 (3)
  90. #define USB_FUNCTION_PIPE4 (4)
  91. #define USB_FUNCTION_PIPE5 (5)
  92. #define USB_FUNCTION_PIPE6 (6)
  93. #define USB_FUNCTION_PIPE7 (7)
  94. #define USB_FUNCTION_PIPE8 (8)
  95. #define USB_FUNCTION_PIPE9 (9)
  96. #define USB_FUNCTION_PIPEA (10)
  97. #define USB_FUNCTION_PIPEB (11)
  98. #define USB_FUNCTION_PIPEC (12)
  99. #define USB_FUNCTION_PIPED (13)
  100. #define USB_FUNCTION_PIPEE (14)
  101. #define USB_FUNCTION_PIPEF (15)
  102. #define USB_FUNCTION_ISO (0xc000u)
  103. #define USB_FUNCTION_INTERRUPT (0x8000u)
  104. #define USB_FUNCTION_BULK (0x4000u)
  105. #define USB_FUNCTION_NONE (0x0000u)
  106. #define USB_FUNCTON_BFREFIELD (0x0400u)
  107. #define USB_FUNCTION_BFREON (0x0400u)
  108. #define USB_FUNCTION_BFREOFF (0x0000u)
  109. #define USB_FUNCTION_DBLBFIELD (0x0200u)
  110. #define USB_FUNCTION_DBLBON (0x0200u)
  111. #define USB_FUNCTION_DBLBOFF (0x0000u)
  112. #define USB_FUNCTION_CNTMDFIELD (0x0100u)
  113. #define USB_FUNCTION_CNTMDON (0x0100u)
  114. #define USB_FUNCTION_CNTMDOFF (0x0000u)
  115. #define USB_FUNCTION_SHTNAKON (0x0080u)
  116. #define USB_FUNCTION_SHTNAKOFF (0x0000u)
  117. #define USB_FUNCTION_DIRFIELD (0x0010u)
  118. #define USB_FUNCTION_DIR_P_OUT (0x0000u)
  119. #define USB_FUNCTION_DIR_P_IN (0x0010u)
  120. #define USB_FUNCTION_EPNUMFIELD (0x000fu)
  121. #define USB_FUNCTION_MAX_EP_NO (15u)
  122. #define USB_FUNCTION_EP0 (0u)
  123. #define USB_FUNCTION_EP1 (1u)
  124. #define USB_FUNCTION_EP2 (2u)
  125. #define USB_FUNCTION_EP3 (3u)
  126. #define USB_FUNCTION_EP4 (4u)
  127. #define USB_FUNCTION_EP5 (5u)
  128. #define USB_FUNCTION_EP6 (6u)
  129. #define USB_FUNCTION_EP7 (7u)
  130. #define USB_FUNCTION_EP8 (8u)
  131. #define USB_FUNCTION_EP9 (9u)
  132. #define USB_FUNCTION_EP10 (10u)
  133. #define USB_FUNCTION_EP11 (11u)
  134. #define USB_FUNCTION_EP12 (12u)
  135. #define USB_FUNCTION_EP13 (13u)
  136. #define USB_FUNCTION_EP14 (14u)
  137. #define USB_FUNCTION_EP15 (15u)
  138. #define USB_FUNCTION_EPTABLE_LENGTH (5u)
  139. #define USB_FUNCTION_CUSE (0)
  140. #define USB_FUNCTION_D0USE (1)
  141. #define USB_FUNCTION_D0DMA (2)
  142. #define USB_FUNCTION_D1USE (3)
  143. #define USB_FUNCTION_D1DMA (4)
  144. #define USB_FUNCTION_CFIFO_USE (0x0000)
  145. #define USB_FUNCTION_D0FIFO_USE (0x1000)
  146. #define USB_FUNCTION_D1FIFO_USE (0x2000)
  147. #define USB_FUNCTION_D0FIFO_DMA (0x5000)
  148. #define USB_FUNCTION_D1FIFO_DMA (0x6000)
  149. #define USB_FUNCTION_BUF2FIFO (0)
  150. #define USB_FUNCTION_FIFO2BUF (1)
  151. #define USB_FUNCTION_DVST_POWERED (0x0001)
  152. #define USB_FUNCTION_DVST_DEFAULT (0x0002)
  153. #define USB_FUNCTION_DVST_ADDRESS (0x0003)
  154. #define USB_FUNCTION_DVST_CONFIGURED (0x0004)
  155. #define USB_FUNCTION_DVST_SUSPEND (0x0005)
  156. #define USB_FUNCTION_DVST_CONFIGURED_SUSPEND (0x0006)
  157. #define USB_FUNCTION_FUNCTION_TEST_SELECT (0xff00u)
  158. #define USB_FUNCTION_FUNCTION_TEST_J (0x0100u)
  159. #define USB_FUNCTION_FUNCTION_TEST_K (0x0200u)
  160. #define USB_FUNCTION_FUNCTION_TEST_SE0_NAK (0x0300u)
  161. #define USB_FUNCTION_FUNCTION_TEST_PACKET (0x0400u)
  162. #define USB_FUNCTION_FUNCTION_TEST_FORCE_ENABLE (0x0500u)
  163. #define USB_FUNCTION_FUNCTION_TEST_STSelectors (0x0600u)
  164. #define USB_FUNCTION_FUNCTION_TEST_Reserved (0x4000u)
  165. #define USB_FUNCTION_FUNCTION_TEST_VSTModes (0xc000u)
  166. #define USB_FUNCTION_DT_TYPE (0xff00u)
  167. #define USB_FUNCTION_DT_INDEX (0xff)
  168. #define USB_FUNCTION_DT_DEVICE (0x01)
  169. #define USB_FUNCTION_DT_CONFIGURATION (0x02)
  170. #define USB_FUNCTION_DT_STRING (0x03)
  171. #define USB_FUNCTION_DT_INTERFACE (0x04)
  172. #define USB_FUNCTION_DT_ENDPOINT (0x05)
  173. #define USB_FUNCTION_DT_DEVICE_QUALIFIER (0x06)
  174. #define USB_FUNCTION_DT_OTHER_SPEED_CONFIGURATION (0x07)
  175. #define USB_FUNCTION_DT_INTERFACE_POWER (0x08)
  176. #define USB_FUNCTION_CF_RESERVED (0x80)
  177. #define USB_FUNCTION_CF_SELF (0x40)
  178. #define USB_FUNCTION_CF_RWUP (0x20)
  179. #define USB_FUNCTION_CF_NORWUP (0x00)
  180. #define USB_FUNCTION_EP_ERROR (0xff)
  181. #define USB_FUNCTION_EP_OUT (0x00)
  182. #define USB_FUNCTION_EP_IN (0x80)
  183. #define USB_FUNCTION_EP_CNTRL (0x00)
  184. #define USB_FUNCTION_EP_ISO (0x01)
  185. #define USB_FUNCTION_EP_BULK (0x02)
  186. #define USB_FUNCTION_EP_INT (0x03)
  187. #define USB_FUNCTION_STANDARD_REQUEST (0x0000u)
  188. #define USB_FUNCTION_CLASS_REQUEST (0x0020u)
  189. #define USB_FUNCTION_VENDOR_REQUEST (0x0040u)
  190. #define USB_FUNCTION_DEVICE_REQUEST (0x0000u)
  191. #define USB_FUNCTION_INTERFACE_REQUEST (0x0001u)
  192. #define USB_FUNCTION_ENDPOINT_REQUEST (0x0002u)
  193. #define USB_FUNCTION_GETSTATUS_BUSPOWERD (0x0000u)
  194. #define USB_FUNCTION_GETSTATUS_SELFPOWERD (0x0001u)
  195. #define USB_FUNCTION_GETSTATUS_REMOTEWAKEUP (0x0002u)
  196. #define USB_FUNCTION_GETSTATUS_NOTHALT (0x0000u)
  197. #define USB_FUNCTION_GETSTATUS_HALT (0x0001u)
  198. #define USB_FUNCTION_FEATURE_ENDPOINT_HALT (0x0000u)
  199. #define USB_FUNCTION_FEATURE_REMOTE_WAKEUP (0x0001u)
  200. #define USB_FUNCTION_FEATURE_TEST_MODE (0x0002u)
  201. #define USB_FUNCTION_bRequest (0xff00u) /* b15-8:bRequest */
  202. #define USB_FUNCTION_bmRequestType (0x00ffu) /* b7-0: bmRequestType */
  203. #define USB_FUNCTION_bmRequestTypeDir (0x0080u) /* b7 : Data transfer direction */
  204. #define USB_FUNCTION_bmRequestTypeType (0x0060u) /* b6-5: Type */
  205. #define USB_FUNCTION_bmRequestTypeRecip (0x001fu) /* b4-0: Recipient */
  206. /*******************************************************************************
  207. Variable Externs
  208. *******************************************************************************/
  209. /*******************************************************************************
  210. Functions Prototypes
  211. *******************************************************************************/
  212. #if 0
  213. void R_USB_api_function_init(uint16_t root, uint8_t int_level, uint16_t mode, uint16_t clockmode);
  214. uint16_t R_USB_api_function_IsConfigured(uint16_t root);
  215. uint16_t R_USB_api_function_CtrlReadStart(uint16_t root, uint32_t size, uint8_t *data);
  216. void R_USB_api_function_CtrlWriteStart(uint16_t root, uint32_t size, uint8_t *data);
  217. uint16_t R_USB_api_function_start_send_transfer(uint16_t root, uint16_t pipe, uint32_t size, uint8_t *data);
  218. uint16_t R_USB_api_function_check_pipe_status(uint16_t root, uint16_t pipe, uint32_t *size);
  219. void R_USB_api_function_clear_pipe_status(uint16_t root, uint16_t pipe);
  220. void R_USB_api_function_start_receive_transfer(uint16_t root, uint16_t pipe, uint32_t size, uint8_t *data);
  221. void R_USB_api_function_set_pid_buf(uint16_t root, uint16_t pipe);
  222. void R_USB_api_function_set_pid_nak(uint16_t root, uint16_t pipe);
  223. void R_USB_api_function_set_pid_stall(uint16_t root, uint16_t pipe);
  224. void R_USB_api_function_clear_pid_stall(uint16_t root, uint16_t pipe);
  225. uint16_t R_USB_api_function_get_pid(uint16_t root, uint16_t pipe);
  226. int32_t R_USB_api_function_check_stall(uint16_t root, uint16_t pipe);
  227. void R_USB_api_function_set_sqclr(uint16_t root, uint16_t pipe);
  228. void R_USB_api_function_set_sqset(uint16_t root, uint16_t pipe);
  229. void R_USB_api_function_set_csclr(uint16_t root, uint16_t pipe);
  230. void R_USB_api_function_set_curpipe(uint16_t root, uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw);
  231. void R_USB_api_function_clear_brdy_sts(uint16_t root, uint16_t pipe);
  232. void R_USB_api_function_clear_bemp_sts(uint16_t root, uint16_t pipe);
  233. void R_USB_api_function_clear_nrdy_sts(uint16_t root, uint16_t pipe);
  234. void R_USB_api_function_enable_brdy_int(uint16_t root, uint16_t pipe);
  235. void R_USB_api_function_disable_brdy_int(uint16_t root, uint16_t pipe);
  236. void R_USB_api_function_enable_bemp_int(uint16_t root, uint16_t pipe);
  237. void R_USB_api_function_disable_bemp_int(uint16_t root, uint16_t pipe);
  238. void R_USB_api_function_enable_nrdy_int(uint16_t root, uint16_t pipe);
  239. void R_USB_api_function_disable_nrdy_int(uint16_t root, uint16_t pipe);
  240. void R_USB_api_function_stop_transfer(uint16_t root, uint16_t pipe);
  241. #endif
  242. #ifdef USB0_FUNCTION_API_H
  243. void usb0_function_interrupt(uint32_t int_sense);
  244. void usb0_function_dma_interrupt_d0fifo(uint32_t int_sense);
  245. void usb0_function_dma_interrupt_d1fifo(uint32_t int_sense);
  246. void usb0_function_Class0(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  247. void usb0_function_Class1(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  248. void usb0_function_Class2(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  249. void usb0_function_Class3(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  250. void usb0_function_Class4(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  251. void usb0_function_Class5(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  252. void usb0_function_Vendor0(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  253. void usb0_function_Vendor1(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  254. void usb0_function_Vendor2(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  255. void usb0_function_Vendor3(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  256. void usb0_function_Vendor4(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  257. void usb0_function_Vendor5(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  258. void usb0_function_ResetDescriptor(uint16_t mode);
  259. IRQn_Type Userdef_USB_usb0_function_d0fifo_dmaintid(void);
  260. IRQn_Type Userdef_USB_usb0_function_d1fifo_dmaintid(void);
  261. void Userdef_USB_usb0_function_attach(void);
  262. void Userdef_USB_usb0_function_detach(void);
  263. void Userdef_USB_usb0_function_delay_1ms(void);
  264. void Userdef_USB_usb0_function_delay_xms(uint32_t msec);
  265. void Userdef_USB_usb0_function_delay_10us(uint32_t usec);
  266. void Userdef_USB_usb0_function_delay_500ns(void);
  267. void Userdef_USB_usb0_function_start_dma(USB_FUNCTION_DMA_t *dma, uint16_t dfacc);
  268. uint32_t Userdef_USB_usb0_function_stop_dma0(void);
  269. uint32_t Userdef_USB_usb0_function_stop_dma1(void);
  270. void usb0_function_stop_transfer(uint16_t pipe);
  271. void usb0_function_enable_brdy_int(uint16_t pipe);
  272. void usb0_function_disable_brdy_int(uint16_t pipe);
  273. void usb0_function_enable_bemp_int(uint16_t pipe);
  274. void usb0_function_disable_bemp_int(uint16_t pipe);
  275. void usb0_function_enable_nrdy_int(uint16_t pipe);
  276. void usb0_function_disable_nrdy_int(uint16_t pipe);
  277. #endif
  278. #ifdef USB1_FUNCTION_API_H
  279. void usb1_function_interrupt(uint32_t int_sense);
  280. void usb1_function_dma_interrupt_d0fifo(uint32_t int_sense);
  281. void usb1_function_dma_interrupt_d1fifo(uint32_t int_sense);
  282. void usb1_function_Class0(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  283. void usb1_function_Class1(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  284. void usb1_function_Class2(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  285. void usb1_function_Class3(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  286. void usb1_function_Class4(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  287. void usb1_function_Class5(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  288. void usb1_function_Vendor0(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  289. void usb1_function_Vendor1(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  290. void usb1_function_Vendor2(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  291. void usb1_function_Vendor3(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  292. void usb1_function_Vendor4(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  293. void usb1_function_Vendor5(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
  294. void usb1_function_ResetDescriptor(uint16_t mode);
  295. uint16_t Userdef_USB_usb1_function_d0fifo_dmaintid(void);
  296. uint16_t Userdef_USB_usb1_function_d1fifo_dmaintid(void);
  297. void Userdef_USB_usb1_function_attach(void);
  298. void Userdef_USB_usb1_function_detach(void);
  299. void Userdef_USB_usb1_function_delay_1ms(void);
  300. void Userdef_USB_usb1_function_delay_xms(uint32_t msec);
  301. void Userdef_USB_usb1_function_delay_10us(uint32_t usec);
  302. void Userdef_USB_usb1_function_delay_500ns(void);
  303. void Userdef_USB_usb1_function_start_dma(USB_FUNCTION_DMA_t *dma, uint16_t dfacc);
  304. uint32_t Userdef_USB_usb1_function_stop_dma0(void);
  305. uint32_t Userdef_USB_usb1_function_stop_dma1(void);
  306. void usb1_function_stop_transfer(uint16_t pipe);
  307. void usb1_function_enable_brdy_int(uint16_t pipe);
  308. void usb1_function_disable_brdy_int(uint16_t pipe);
  309. void usb1_function_enable_bemp_int(uint16_t pipe);
  310. void usb1_function_disable_bemp_int(uint16_t pipe);
  311. void usb1_function_enable_nrdy_int(uint16_t pipe);
  312. void usb1_function_disable_nrdy_int(uint16_t pipe);
  313. #endif
  314. #ifdef __cplusplus
  315. }
  316. #endif
  317. #endif /* USB_FUNCTION_API_H */
  318. /* End of File */