USB0_LPC18xx.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 USB0_role = ARM_USB_ROLE_NONE;
  35. volatile uint8_t USB0_state = 0U;
  36. #ifdef RTE_Drivers_USBH0
  37. extern void USBH0_IRQ (void);
  38. #endif
  39. #ifdef RTE_Drivers_USBD0
  40. extern void USBD0_IRQ (void);
  41. #endif
  42. // Common IRQ Routine **********************************************************
  43. /**
  44. \fn void USB0_IRQHandler (void)
  45. \brief USB Interrupt Routine (IRQ).
  46. */
  47. void USB0_IRQHandler (void) {
  48. #if (defined(RTE_Drivers_USBH0) && defined(RTE_Drivers_USBD0))
  49. switch (USB0_role) {
  50. #ifdef RTE_Drivers_USBH0
  51. case ARM_USB_ROLE_HOST:
  52. USBH0_IRQ ();
  53. break;
  54. #endif
  55. #ifdef RTE_Drivers_USBD0
  56. case ARM_USB_ROLE_DEVICE:
  57. USBD0_IRQ ();
  58. break;
  59. #endif
  60. default:
  61. break;
  62. }
  63. #else
  64. #ifdef RTE_Drivers_USBH0
  65. USBH0_IRQ ();
  66. #else
  67. USBD0_IRQ ();
  68. #endif
  69. #endif
  70. }
  71. // Public Functions ************************************************************
  72. /**
  73. \fn void USB0_PinsConfigure (void)
  74. \brief Configure USB pins
  75. */
  76. void USB0_PinsConfigure (void) {
  77. // Common (Device and Host) Pins
  78. #if (RTE_USB0_IND0_PIN_EN)
  79. SCU_PinConfigure(RTE_USB0_IND0_PORT, RTE_USB0_IND0_BIT, RTE_USB0_IND0_FUNC);
  80. #endif
  81. #if (RTE_USB0_IND1_PIN_EN)
  82. SCU_PinConfigure(RTE_USB0_IND1_PORT, RTE_USB0_IND1_BIT, RTE_USB0_IND1_FUNC);
  83. #endif
  84. // Host Pins
  85. if (USB0_role == ARM_USB_ROLE_HOST) {
  86. #if (RTE_USB0_PPWR_PIN_EN)
  87. SCU_PinConfigure(RTE_USB0_PPWR_PORT, RTE_USB0_PPWR_BIT, RTE_USB0_PPWR_FUNC);
  88. #endif
  89. #if (RTE_USB0_PWR_FAULT_PIN_EN)
  90. SCU_PinConfigure(RTE_USB0_PWR_FAULT_PORT, RTE_USB0_PWR_FAULT_BIT, RTE_USB0_PWR_FAULT_FUNC);
  91. #endif
  92. }
  93. }
  94. /**
  95. \fn void USB0_PinsUnconfigure (void)
  96. \brief De-configure USB pins
  97. */
  98. void USB0_PinsUnconfigure (void) {
  99. // Common (Device and Host) Pins
  100. #if (RTE_USB0_IND0_PIN_EN)
  101. SCU_PinConfigure(RTE_USB0_IND0_PORT, RTE_USB0_IND0_BIT, 0);
  102. #endif
  103. #if (RTE_USB0_IND1_PIN_EN)
  104. SCU_PinConfigure(RTE_USB0_IND1_PORT, RTE_USB0_IND1_BIT, 0);
  105. #endif
  106. // Host Pins
  107. if (USB0_role == ARM_USB_ROLE_HOST) {
  108. #if (RTE_USB0_PPWR_PIN_EN)
  109. SCU_PinConfigure(RTE_USB0_PPWR_PORT, RTE_USB0_PPWR_BIT, 0);
  110. #endif
  111. #if (RTE_USB0_PWR_FAULT_PIN_EN)
  112. SCU_PinConfigure(RTE_USB0_PWR_FAULT_PORT, RTE_USB0_PWR_FAULT_BIT, 0);
  113. #endif
  114. }
  115. }