USB1_LPC18xx.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* --------------------------------------------------------------------------
  2. * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * $Date: 02. March 2016
  19. * $Revision: V1.1
  20. *
  21. * Project: USB common (Device and Host) module for NXP LPC18xx
  22. * -------------------------------------------------------------------------- */
  23. /* History:
  24. * Version 1.1
  25. * Improved support for Host and Device
  26. * Version 1.0
  27. * Initial release
  28. */
  29. #include "LPC18xx.h"
  30. #include "SCU_LPC18xx.h"
  31. #include "Driver_USB.h"
  32. #include "RTE_Device.h"
  33. #include "RTE_Components.h"
  34. volatile uint8_t USB1_role = ARM_USB_ROLE_NONE;
  35. volatile uint8_t USB1_state = 0U;
  36. #ifdef RTE_Drivers_USBH1
  37. extern void USBH1_IRQ (void);
  38. #endif
  39. #ifdef RTE_Drivers_USBD1
  40. extern void USBD1_IRQ (void);
  41. #endif
  42. // Common IRQ Routine **********************************************************
  43. /**
  44. \fn void USB1_IRQHandler (void)
  45. \brief USB Interrupt Routine (IRQ).
  46. */
  47. void USB1_IRQHandler (void) {
  48. #if (defined(RTE_Drivers_USBH1) && defined(RTE_Drivers_USBD1))
  49. switch (USB1_role) {
  50. #ifdef RTE_Drivers_USBH1
  51. case ARM_USB_ROLE_HOST:
  52. USBH1_IRQ ();
  53. break;
  54. #endif
  55. #ifdef RTE_Drivers_USBD1
  56. case ARM_USB_ROLE_DEVICE:
  57. USBD1_IRQ ();
  58. break;
  59. #endif
  60. default:
  61. break;
  62. }
  63. #else
  64. #ifdef RTE_Drivers_USBH1
  65. USBH1_IRQ ();
  66. #else
  67. USBD1_IRQ ();
  68. #endif
  69. #endif
  70. }
  71. // Public Functions ************************************************************
  72. /**
  73. \fn void USB1_PinsConfigure (void)
  74. \brief Configure USB pins
  75. */
  76. void USB1_PinsConfigure (void) {
  77. // Common (Device and Host) Pins
  78. #if (RTE_USB1_IND0_PIN_EN)
  79. SCU_PinConfigure(RTE_USB1_IND0_PORT, RTE_USB1_IND0_BIT, RTE_USB1_IND0_FUNC);
  80. #endif
  81. #if (RTE_USB1_IND1_PIN_EN)
  82. SCU_PinConfigure(RTE_USB1_IND1_PORT, RTE_USB1_IND1_BIT, RTE_USB1_IND1_FUNC);
  83. #endif
  84. #if (RTE_USB_USB1_FS_PHY_EN)
  85. #if (RTE_USB1_VBUS_PIN_EN)
  86. // Device Pin
  87. if (USB1_role == ARM_USB_ROLE_DEVICE) {
  88. SCU_PinConfigure(RTE_USB1_VBUS_PORT, RTE_USB1_VBUS_BIT, RTE_USB1_VBUS_FUNC | SCU_SFS_EPD | SCU_SFS_EZI);
  89. }
  90. #endif
  91. #endif
  92. // Host Pins
  93. if (USB1_role == ARM_USB_ROLE_HOST) {
  94. #if (RTE_USB1_PPWR_PIN_EN)
  95. SCU_PinConfigure(RTE_USB1_PPWR_PORT, RTE_USB1_PPWR_BIT, RTE_USB1_PPWR_FUNC);
  96. #endif
  97. #if (RTE_USB1_PWR_FAULT_PIN_EN)
  98. SCU_PinConfigure(RTE_USB1_PWR_FAULT_PORT, RTE_USB1_PWR_FAULT_BIT, RTE_USB1_PWR_FAULT_FUNC);
  99. #endif
  100. }
  101. // ULPI Pins
  102. #if (RTE_USB_USB1_HS_PHY_EN)
  103. SCU_PinConfigure(RTE_USB1_ULPI_CLK_PORT, RTE_USB1_ULPI_CLK_BIT, RTE_USB1_ULPI_CLK_FUNC);
  104. SCU_PinConfigure(RTE_USB1_ULPI_DIR_PORT, RTE_USB1_ULPI_DIR_BIT, RTE_USB1_ULPI_DIR_FUNC);
  105. SCU_PinConfigure(RTE_USB1_ULPI_STP_PORT, RTE_USB1_ULPI_STP_BIT, RTE_USB1_ULPI_STP_FUNC);
  106. SCU_PinConfigure(RTE_USB1_ULPI_NXT_PORT, RTE_USB1_ULPI_NXT_BIT, RTE_USB1_ULPI_NXT_FUNC);
  107. SCU_PinConfigure(RTE_USB1_ULPI_D0_PORT, RTE_USB1_ULPI_D0_BIT, RTE_USB1_ULPI_D0_FUNC );
  108. SCU_PinConfigure(RTE_USB1_ULPI_D1_PORT, RTE_USB1_ULPI_D1_BIT, RTE_USB1_ULPI_D1_FUNC );
  109. SCU_PinConfigure(RTE_USB1_ULPI_D2_PORT, RTE_USB1_ULPI_D2_BIT, RTE_USB1_ULPI_D2_FUNC );
  110. SCU_PinConfigure(RTE_USB1_ULPI_D3_PORT, RTE_USB1_ULPI_D3_BIT, RTE_USB1_ULPI_D3_FUNC );
  111. SCU_PinConfigure(RTE_USB1_ULPI_D4_PORT, RTE_USB1_ULPI_D4_BIT, RTE_USB1_ULPI_D4_FUNC );
  112. SCU_PinConfigure(RTE_USB1_ULPI_D5_PORT, RTE_USB1_ULPI_D5_BIT, RTE_USB1_ULPI_D5_FUNC );
  113. SCU_PinConfigure(RTE_USB1_ULPI_D6_PORT, RTE_USB1_ULPI_D6_BIT, RTE_USB1_ULPI_D6_FUNC );
  114. SCU_PinConfigure(RTE_USB1_ULPI_D7_PORT, RTE_USB1_ULPI_D7_BIT, RTE_USB1_ULPI_D7_FUNC );
  115. #endif
  116. }
  117. /**
  118. \fn void USB1_PinsUnconfigure (void)
  119. \brief De-configure USB pins
  120. */
  121. void USB1_PinsUnconfigure (void) {
  122. // Common (Device and Host) Pins
  123. #if (RTE_USB1_IND0_PIN_EN)
  124. SCU_PinConfigure(RTE_USB1_IND0_PORT, RTE_USB1_IND0_BIT, 0);
  125. #endif
  126. #if (RTE_USB1_IND1_PIN_EN)
  127. SCU_PinConfigure(RTE_USB1_IND1_PORT, RTE_USB1_IND1_BIT, 0);
  128. #endif
  129. #if (RTE_USB_USB1_FS_PHY_EN)
  130. #if (RTE_USB1_VBUS_PIN_EN)
  131. // Device Pin
  132. if (USB1_role == ARM_USB_ROLE_DEVICE) {
  133. SCU_PinConfigure(RTE_USB1_VBUS_PORT, RTE_USB1_VBUS_BIT, 0);
  134. }
  135. #endif
  136. #endif
  137. // Host Pins
  138. if (USB1_role == ARM_USB_ROLE_HOST) {
  139. #if (RTE_USB1_PPWR_PIN_EN)
  140. SCU_PinConfigure(RTE_USB1_PPWR_PORT, RTE_USB1_PPWR_BIT, 0);
  141. #endif
  142. #if (RTE_USB1_PWR_FAULT_PIN_EN)
  143. SCU_PinConfigure(RTE_USB1_PWR_FAULT_PORT, RTE_USB1_PWR_FAULT_BIT, 0);
  144. #endif
  145. }
  146. // ULPI Pins
  147. #if (RTE_USB_USB1_HS_PHY_EN)
  148. SCU_PinConfigure(RTE_USB1_ULPI_CLK_PORT, RTE_USB1_ULPI_CLK_BIT, 0);
  149. SCU_PinConfigure(RTE_USB1_ULPI_DIR_PORT, RTE_USB1_ULPI_DIR_BIT, 0);
  150. SCU_PinConfigure(RTE_USB1_ULPI_STP_PORT, RTE_USB1_ULPI_STP_BIT, 0);
  151. SCU_PinConfigure(RTE_USB1_ULPI_NXT_PORT, RTE_USB1_ULPI_NXT_BIT, 0);
  152. SCU_PinConfigure(RTE_USB1_ULPI_D0_PORT, RTE_USB1_ULPI_D0_BIT, 0 );
  153. SCU_PinConfigure(RTE_USB1_ULPI_D1_PORT, RTE_USB1_ULPI_D1_BIT, 0 );
  154. SCU_PinConfigure(RTE_USB1_ULPI_D2_PORT, RTE_USB1_ULPI_D2_BIT, 0 );
  155. SCU_PinConfigure(RTE_USB1_ULPI_D3_PORT, RTE_USB1_ULPI_D3_BIT, 0 );
  156. SCU_PinConfigure(RTE_USB1_ULPI_D4_PORT, RTE_USB1_ULPI_D4_BIT, 0 );
  157. SCU_PinConfigure(RTE_USB1_ULPI_D5_PORT, RTE_USB1_ULPI_D5_BIT, 0 );
  158. SCU_PinConfigure(RTE_USB1_ULPI_D6_PORT, RTE_USB1_ULPI_D6_BIT, 0 );
  159. SCU_PinConfigure(RTE_USB1_ULPI_D7_PORT, RTE_USB1_ULPI_D7_BIT, 0 );
  160. #endif
  161. }