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.

usb1_function_sig.c 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 : usb1_function_sig.c
  25. * $Rev: 1116 $
  26. * $Date:: 2014-07-09 16:29:19 +0900#$
  27. * Device(s) : RZ/A1H
  28. * Tool-Chain :
  29. * OS : None
  30. * H/W Platform :
  31. * Description : RZ/A1H R7S72100 USB Sample Program
  32. * Operation :
  33. * Limitations :
  34. *******************************************************************************/
  35. /*******************************************************************************
  36. Includes <System Includes> , "Project Includes"
  37. *******************************************************************************/
  38. #include "usb1_function.h"
  39. /*******************************************************************************
  40. Typedef definitions
  41. *******************************************************************************/
  42. /*******************************************************************************
  43. Macro definitions
  44. *******************************************************************************/
  45. /*******************************************************************************
  46. Imported global variables and functions (from other files)
  47. *******************************************************************************/
  48. /*******************************************************************************
  49. Exported global variables and functions (to be accessed by other files)
  50. *******************************************************************************/
  51. static void usb1_function_EnableINTModule(void);
  52. /*******************************************************************************
  53. Private global variables and functions
  54. *******************************************************************************/
  55. /*******************************************************************************
  56. * Function Name: usb1_function_InitModule
  57. * Description : Initializes the USB module in the USB function mode.
  58. * Arguments : uint16_t mode ; USB_FUNCTION_HIGH_SPEED ; Hi-Speed Mode
  59. * : ; other ; Full-speed Mode
  60. * Return Value : none
  61. *******************************************************************************/
  62. void usb1_function_InitModule (uint16_t mode)
  63. {
  64. RZA_IO_RegWrite_16(&USB201.SYSCFG0,
  65. 0,
  66. USB_SYSCFG_DCFM_SHIFT,
  67. USB_SYSCFG_DCFM); /* USB function */
  68. /* USB module operation enabled */
  69. RZA_IO_RegWrite_16(&USB201.SYSCFG0,
  70. 1,
  71. USB_SYSCFG_USBE_SHIFT,
  72. USB_SYSCFG_USBE);
  73. if (mode == USB_FUNCTION_HIGH_SPEED)
  74. {
  75. RZA_IO_RegWrite_16(&USB201.SYSCFG0,
  76. 1,
  77. USB_SYSCFG_HSE_SHIFT,
  78. USB_SYSCFG_HSE); /* Hi-Speed Mode */
  79. }
  80. else
  81. {
  82. RZA_IO_RegWrite_16(&USB201.SYSCFG0,
  83. 0,
  84. USB_SYSCFG_HSE_SHIFT,
  85. USB_SYSCFG_HSE);
  86. }
  87. /* for power-on */
  88. if (usb1_function_CheckVBUStaus() == DEVDRV_USBF_ON)
  89. {
  90. usb1_function_EnableINTModule(); /* Interrupt Enable */
  91. usb1_function_USB_FUNCTION_Attach(); /* pull-up D+ and open D- */
  92. }
  93. else
  94. {
  95. usb1_function_USB_FUNCTION_Detach(); /* USB Detach */
  96. /* with Interrupt Enable */
  97. }
  98. }
  99. /*******************************************************************************
  100. * Function Name: usb1_function_CheckVBUStaus
  101. * Description : Checks the USB-VBUS state to returns the connection state to
  102. * : the USB host.
  103. * Arguments : none
  104. * Return Value : DEVDRV_USBF_ON : VBUS ON
  105. * : DEVDRV_USBF_OFF : VBUS OFF
  106. *******************************************************************************/
  107. uint16_t usb1_function_CheckVBUStaus (void)
  108. {
  109. uint16_t buf1;
  110. uint16_t buf2;
  111. uint16_t buf3;
  112. /* monitor VBUS pins */
  113. do
  114. {
  115. buf1 = RZA_IO_RegRead_16(&USB201.INTSTS0,
  116. USB_INTSTS0_VBSTS_SHIFT,
  117. USB_INTSTS0_VBSTS);
  118. Userdef_USB_usb1_function_delay_10us(1);
  119. buf2 = RZA_IO_RegRead_16(&USB201.INTSTS0,
  120. USB_INTSTS0_VBSTS_SHIFT,
  121. USB_INTSTS0_VBSTS);
  122. Userdef_USB_usb1_function_delay_10us(1);
  123. buf3 = RZA_IO_RegRead_16(&USB201.INTSTS0,
  124. USB_INTSTS0_VBSTS_SHIFT,
  125. USB_INTSTS0_VBSTS);
  126. } while ((buf1 != buf2) || (buf2 != buf3));
  127. if (buf1 == DEVDRV_USBF_OFF)
  128. {
  129. return DEVDRV_USBF_OFF; /* detach */
  130. }
  131. return DEVDRV_USBF_ON; /* attach */
  132. }
  133. /*******************************************************************************
  134. * Function Name: usb1_function_USB_FUNCTION_Attach
  135. * Description : Connects to the USB host controller.
  136. * : This function pulls up D+.
  137. * Arguments : none
  138. * Return Value : none
  139. *******************************************************************************/
  140. void usb1_function_USB_FUNCTION_Attach (void)
  141. {
  142. Userdef_USB_usb1_function_attach();
  143. Userdef_USB_usb1_function_delay_xms(10);
  144. RZA_IO_RegWrite_16(&USB201.SYSCFG0,
  145. 1,
  146. USB_SYSCFG_DPRPU_SHIFT,
  147. USB_SYSCFG_DPRPU); /* Pull-up D+ and open D- */
  148. }
  149. /*******************************************************************************
  150. * Function Name: usb1_function_USB_FUNCTION_Detach
  151. * Description : Disconnects from the USB host controller.
  152. * : This function opens D+/D-.
  153. * Arguments : none
  154. * Return Value : none
  155. *******************************************************************************/
  156. void usb1_function_USB_FUNCTION_Detach (void)
  157. {
  158. uint16_t pipe;
  159. Userdef_USB_usb1_function_detach();
  160. for (pipe = 0; pipe < (USB_FUNCTION_MAX_PIPE_NO + 1); ++pipe)
  161. {
  162. if (g_usb1_function_pipe_status[pipe] != DEVDRV_USBF_PIPE_IDLE)
  163. {
  164. usb1_function_stop_transfer(pipe);
  165. }
  166. }
  167. RZA_IO_RegWrite_16(&USB201.SYSCFG0,
  168. 0,
  169. USB_SYSCFG_DPRPU_SHIFT,
  170. USB_SYSCFG_DPRPU); /* open D+ and D- */
  171. /* Detach Recovery */
  172. Userdef_USB_usb1_function_delay_500ns(); /* need 1us=500ns * 2 wait */
  173. Userdef_USB_usb1_function_delay_500ns();
  174. RZA_IO_RegWrite_16(&USB201.SYSCFG0,
  175. 1,
  176. USB_SYSCFG_DCFM_SHIFT,
  177. USB_SYSCFG_DCFM);
  178. Userdef_USB_usb1_function_delay_500ns(); /* need 100ns wait but 500ns S/W wait */
  179. RZA_IO_RegWrite_16(&USB201.SYSCFG0,
  180. 0,
  181. USB_SYSCFG_DCFM_SHIFT,
  182. USB_SYSCFG_DCFM);
  183. RZA_IO_RegWrite_16(&USB201.SYSCFG0,
  184. 0,
  185. USB_SYSCFG_USBE_SHIFT,
  186. USB_SYSCFG_USBE); /* soft reset module */
  187. Userdef_USB_usb1_function_delay_500ns();
  188. RZA_IO_RegWrite_16(&USB201.SYSCFG0,
  189. 1,
  190. USB_SYSCFG_USBE_SHIFT,
  191. USB_SYSCFG_USBE);
  192. usb1_function_EnableINTModule(); /* Interrupt Enable */
  193. }
  194. /*******************************************************************************
  195. * Function Name: usb1_function_USB_FUNCTION_BusReset
  196. * Description : This function is executed when the USB device is transitioned
  197. * : to POWERD_STATE. Sets the device descriptor according to the
  198. * : connection speed determined by the USB reset hand shake.
  199. * Arguments : none
  200. * Return Value : none
  201. *******************************************************************************/
  202. #if 0 /*The USBHAL in mbed does not need this function*/
  203. void usb1_function_USB_FUNCTION_BusReset (void)
  204. {
  205. usb1_function_init_status(); /* memory clear */
  206. if (usb1_function_is_hispeed() == USB_FUNCTION_HIGH_SPEED)
  207. {
  208. usb1_function_ResetDescriptor(USB_FUNCTION_HIGH_SPEED); /* Device Descriptor reset */
  209. }
  210. else
  211. {
  212. usb1_function_ResetDescriptor(USB_FUNCTION_FULL_SPEED); /* Device Descriptor reset */
  213. }
  214. usb1_function_ResetDCP(); /* Default Control PIPE reset */
  215. }
  216. #endif
  217. /*******************************************************************************
  218. * Function Name: usb1_function_USB_FUNCTION_Resume
  219. * Description : This function is executed when the USB device detects a resume
  220. * : signal.
  221. * : The USB sample driver does not operate for this function.
  222. * Arguments : none
  223. * Return Value : none
  224. *******************************************************************************/
  225. #if 0 /*The USBHAL in mbed does not need this function*/
  226. void usb1_function_USB_FUNCTION_Resume (void)
  227. {
  228. /* NOP */
  229. }
  230. #endif
  231. /*******************************************************************************
  232. * Function Name: usb1_function_USB_FUNCTION_Suspend
  233. * Description : This function is executed when the USB device detects a suspend
  234. * : signal.
  235. * : The USB sample driver does not operate for this function.
  236. * Arguments : none
  237. * Return Value : none
  238. *******************************************************************************/
  239. #if 0 /*The USBHAL in mbed does not need this function*/
  240. void usb1_function_USB_FUNCTION_Suspend (void)
  241. {
  242. /* NOP */
  243. }
  244. #endif
  245. /*******************************************************************************
  246. * Function Name: usb1_function_USB_FUNCTION_TestMode
  247. * Description : This function is executed when the USB device is transitioned U
  248. * : to TEST_MODE by the USB standard request.
  249. * Arguments : none
  250. * Return Value : none
  251. *******************************************************************************/
  252. void usb1_function_USB_FUNCTION_TestMode (void)
  253. {
  254. switch (g_usb1_function_TestModeSelectors & USB_FUNCTION_FUNCTION_TEST_SELECT)
  255. {
  256. case USB_FUNCTION_FUNCTION_TEST_J:
  257. case USB_FUNCTION_FUNCTION_TEST_K:
  258. case USB_FUNCTION_FUNCTION_TEST_SE0_NAK:
  259. case USB_FUNCTION_FUNCTION_TEST_PACKET:
  260. RZA_IO_RegWrite_16(&USB201.TESTMODE,
  261. (g_usb1_function_TestModeSelectors >> 8),
  262. USB_TESTMODE_UTST_SHIFT,
  263. USB_TESTMODE_UTST);
  264. break;
  265. case USB_FUNCTION_FUNCTION_TEST_FORCE_ENABLE:
  266. default:
  267. break;
  268. }
  269. }
  270. /*******************************************************************************
  271. * Function Name: usb1_function_EnableINTModule
  272. * Description : Enables USB interrupt.
  273. * Arguments : none
  274. * Return Value : none
  275. *******************************************************************************/
  276. static void usb1_function_EnableINTModule (void)
  277. {
  278. uint16_t buf;
  279. buf = USB201.INTENB0;
  280. buf |= (USB_FUNCTION_BITVBSE | USB_FUNCTION_BITDVSE | USB_FUNCTION_BITCTRE |
  281. USB_FUNCTION_BITBEMPE | USB_FUNCTION_BITNRDYE | USB_FUNCTION_BITBRDYE);
  282. USB201.INTENB0 = buf;
  283. usb1_function_enable_bemp_int(USB_FUNCTION_PIPE0);
  284. }
  285. /* End of File */