SCU_LPC18xx.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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.0
  20. *
  21. * Project: SCU Driver Definitions for NXP LPC18xx
  22. * -------------------------------------------------------------------------- */
  23. #ifndef __SCU_LPC18XX_H
  24. #define __SCU_LPC18XX_H
  25. #include <stdint.h>
  26. // Pin identifier
  27. typedef struct _PIN_ID {
  28. uint8_t port;
  29. uint8_t num;
  30. uint32_t config_val;
  31. } PIN_ID;
  32. //------------------------------------------------------------------------------
  33. // SCU REGISTER BIT DEFINITIONS
  34. //------------------------------------------------------------------------------
  35. // SCU Pin configuration register for normal-drive pins
  36. #define SCU_SFS_MODE_POS ( 0 )
  37. #define SCU_SFS_MODE_MSK (7 << SCU_SFS_MODE_POS)
  38. #define SCU_SFS_EPD (1 << 3)
  39. #define SCU_SFS_EPUN (1 << 4)
  40. #define SCU_SFS_EHS (1 << 5)
  41. #define SCU_SFS_EZI (1 << 6)
  42. #define SCU_SFS_ZIF (1 << 7)
  43. // SCU Pin configuration register for high-drive pins
  44. // P1_17
  45. // P2_3 to P2_5
  46. // P8_0 to P8_2
  47. // PA_1 to PA_3
  48. #define SCU_SFS_EHD_POS ( 8 )
  49. #define SCU_SFS_EHD_MSK (3 << SCU_SFS_EHD_POS)
  50. // SCU Pin configuration register for USB1 pins USB1_DP/USB1_DM
  51. #define SCU_SFSUSB_AIM (1 << 0)
  52. #define SCU_SFSUSB_ESEA (1 << 1)
  53. #define SCU_SFSUSB_EPD (1 << 2)
  54. #define SCU_SFSUSB_EPWR (1 << 4)
  55. #define SCU_SFSUSB_VBUS (1 << 5)
  56. // SCU Pin configuration for open-drain I2C pins
  57. #define SCU_SFSI2C_SCL_EFP (1 << 0)
  58. #define SCU_SFSI2C_SCL_EHD (1 << 2)
  59. #define SCU_SFSI2C_SCL_EZI (1 << 3)
  60. #define SCU_SFSI2C_SCL_ZIF (1 << 7)
  61. #define SCU_SFSI2C_SDA_EFP (1 << 8)
  62. #define SCU_SFSI2C_SDA_EHD (1 << 10)
  63. #define SCU_SFSI2C_SDA_EZI (1 << 11)
  64. #define SCU_SFSI2C_SDA_ZIF (1 << 15)
  65. // SCU Analog function select register ENAIO2
  66. #define SCU_ENAIO2_DAC (1 << 0)
  67. #define SCU_ENAIO2_BG (1 << 4)
  68. //------------------------------------------------------------------------------
  69. // SCU FUNCTION PARAMETER DEFINITIONS
  70. //------------------------------------------------------------------------------
  71. // SCU_PIN_CFG_MODE(mode)
  72. #define SCU_CFG_MODE_FUNC0 (0)
  73. #define SCU_CFG_MODE_FUNC1 (1)
  74. #define SCU_CFG_MODE_FUNC2 (2)
  75. #define SCU_CFG_MODE_FUNC3 (3)
  76. #define SCU_CFG_MODE_FUNC4 (4)
  77. #define SCU_CFG_MODE_FUNC5 (5)
  78. #define SCU_CFG_MODE_FUNC6 (6)
  79. #define SCU_CFG_MODE_FUNC7 (7)
  80. // SCU_PIN_CFG_DRIVER_STRENGTH(ehd) (only for high drive pins)
  81. #define SCU_CFG_EHD_4mA (0)
  82. #define SCU_CFG_EHD_8mA (1)
  83. #define SCU_CFG_EHD_14mA (2)
  84. #define SCU_CFG_EHD_20mA (3)
  85. // pin_cfg (configuration bit mask)
  86. #define SCU_PIN_CFG_MODE(mode) (((mode) & SCU_SFS_MODE_MSK) << SCU_SFS_MODE_POS)
  87. #define SCU_PIN_CFG_PULLDOWN_EN ( SCU_SFS_EPD )
  88. #define SCU_PIN_CFG_PULLUP_DIS ( SCU_SFS_EPUN)
  89. #define SCU_PIN_CFG_HIGH_SPEED_SLEW_RATE_EN ( SCU_SFS_EHS )
  90. #define SCU_PIN_CFG_INPUT_BUFFER_EN ( SCU_SFS_EZI )
  91. #define SCU_PIN_CFG_INPUT_FILTER_DIS ( SCU_SFS_ZIF )
  92. // additional pin_cfg for high-drive pins only
  93. #define SCU_PIN_CFG_DRIVER_STRENGTH(ehd) ((val & SCU_SFS_EHD_MSK) << SCU_SFS_EHD_POS)
  94. // USB1_pin_cfg (configuration bit mask)
  95. #define SCU_USB1_PIN_CFG_AIM (SCU_SFSUSB_AIM )
  96. #define SCU_USB1_PIN_CFG_ESEA (SCU_SFSUSB_ESEA)
  97. #define SCU_USB1_PIN_CFG_EPD (SCU_SFSUSB_EPD )
  98. #define SCU_USB1_PIN_CFG_EPWR (SCU_SFSUSB_EPWR)
  99. #define SCU_USB1_PIN_CFG_VBUS (SCU_SFSUSB_VBUS)
  100. // I2C_mode
  101. #define SCU_I2C_PIN_MODE_DISABLED (0)
  102. #define SCU_I2C_PIN_MODE_STANDARD_FAST (SCU_SFSI2C_SCL_EZI | SCU_SFSI2C_SDA_EZI)
  103. #define SCU_I2C_PIN_MODE_FAST_PLUS (SCU_SFSI2C_SCL_EHD | SCU_SFSI2C_SCL_EZI | \
  104. SCU_SFSI2C_SCL_EZI | SCU_SFSI2C_SDA_EHD | \
  105. SCU_SFSI2C_SDA_EZI)
  106. /**
  107. \fn int32_t SCU_PinConfiguare (uint8_t port, uint8_t pin, uint32_t pin_cfg)
  108. \brief Set pin function and electrical characteristics
  109. \param[in] port Port number (0..15)
  110. \param[in] pin Pin number (0..31)
  111. \param[in] pin_cfg pin_cfg configuration bit mask
  112. - \b 0: function succeeded
  113. - \b -1: function failed
  114. */
  115. extern int32_t SCU_PinConfigure (uint8_t port, uint8_t pin, uint32_t pin_cfg);
  116. /**
  117. \fn int32_t SCU_CLK_PinConfigure (uint8_t clk_pin, uint32_t pin_cfg)
  118. \brief Set pin function and electrical characteristics for CLK pins
  119. \param[in] clk_pin Clock pin number should be 0..3
  120. \param[in] pin_cfg pin_cfg
  121. - \b 0: function succeeded
  122. - \b -1: function failed
  123. */
  124. extern int32_t SCU_CLK_PinConfigure (uint8_t pin_clk, uint32_t pin_cfg);
  125. /**
  126. \fn int32_t SCU_USB1_PinConfigure (uint32_t USB1_pin_cfg)
  127. \brief Pin configuration for USB1 USB_DP/USBDM pins
  128. \param[in] USB1_pin_cfg USB1_pin_cfg configuration bit mask
  129. - \b 0: function succeeded
  130. - \b -1: function failed
  131. */
  132. extern int32_t SCU_USB1_PinConfigure (uint32_t USB1_pin_cfg);
  133. /**
  134. \fn int32_t SCU_I2C_PinConfigure (uint32_t I2C_mode)
  135. \brief Set I2C pin configuration
  136. \param[in] I2C_mode: SCU_I2C_PIN_MODE_DISABLED
  137. SCU_I2C_PIN_MODE_STANDARD_FAST
  138. SCU_I2C_PIN_MODE_FAST_PLUS
  139. - \b 0: function succeeded
  140. - \b -1: function failed
  141. */
  142. extern int32_t SCU_I2C_PinConfigure (uint32_t I2C_mode);
  143. /**
  144. \fn int32_t SCU_ADC_ChannelPinConfigure (uint8_t ADC_num, uint8_t channel, uint32_t cmd)
  145. \brief ADC Channel configuration
  146. \param[in] ADC_num: 0 = ADC0, 1 = ADC1
  147. \param[in] channel: channel number 0..7
  148. \param[in] cmd: 1 - enabled, 0 - disabled
  149. - \b 0: function succeeded
  150. - \b -1: function failed
  151. */
  152. extern int32_t SCU_ADC_ChannelPinConfigure (uint8_t ADC_num, uint8_t channel, uint32_t cmd);
  153. /**
  154. \fn int32_t SCU_DAC_PinConfigure (uint32_t cmd)
  155. \brief Analog function on P4_4
  156. \param[in] cmd: 1 - enabled, 0 - disabled
  157. - \b 0: function succeeded
  158. - \b -1: function failed
  159. */
  160. extern int32_t SCU_DAC_PinConfigure (uint32_t cmd);
  161. /**
  162. \fn int32_t SCU_PinInterruptSourceSelect (uint8_t pin_int, uint8_t port, uint8_t pin)
  163. \brief Select interrupt source pin
  164. \param[in] pin_int: pin interrupt 0..7
  165. \param[in] port: GPIO port number 0..7
  166. \param[in] pin: GPIO pin number 0..31
  167. \returns
  168. - \b 0: function succeeded
  169. - \b -1: function failed
  170. */
  171. extern int32_t SCU_PinInterruptSourceSelect (uint8_t pin_int, uint8_t port, uint8_t pin);
  172. #endif /* __SCU_LPC18XX_H */