fsl_port.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_PORT_H_
  35. #define _FSL_PORT_H_
  36. #include "fsl_common.h"
  37. /*!
  38. * @addtogroup port
  39. * @{
  40. */
  41. /*******************************************************************************
  42. * Definitions
  43. ******************************************************************************/
  44. /* Component ID definition, used by tools. */
  45. #ifndef FSL_COMPONENT_ID
  46. #define FSL_COMPONENT_ID "platform.drivers.port"
  47. #endif
  48. /*! @name Driver version */
  49. /*@{*/
  50. /*! Version 2.0.2. */
  51. #define FSL_PORT_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
  52. /*@}*/
  53. #if defined(FSL_FEATURE_PORT_HAS_PULL_ENABLE) && FSL_FEATURE_PORT_HAS_PULL_ENABLE
  54. /*! @brief Internal resistor pull feature selection */
  55. enum _port_pull
  56. {
  57. kPORT_PullDisable = 0U, /*!< Internal pull-up/down resistor is disabled. */
  58. kPORT_PullDown = 2U, /*!< Internal pull-down resistor is enabled. */
  59. kPORT_PullUp = 3U, /*!< Internal pull-up resistor is enabled. */
  60. };
  61. #endif /* FSL_FEATURE_PORT_HAS_PULL_ENABLE */
  62. #if defined(FSL_FEATURE_PORT_HAS_SLEW_RATE) && FSL_FEATURE_PORT_HAS_SLEW_RATE
  63. /*! @brief Slew rate selection */
  64. enum _port_slew_rate
  65. {
  66. kPORT_FastSlewRate = 0U, /*!< Fast slew rate is configured. */
  67. kPORT_SlowSlewRate = 1U, /*!< Slow slew rate is configured. */
  68. };
  69. #endif /* FSL_FEATURE_PORT_HAS_SLEW_RATE */
  70. #if defined(FSL_FEATURE_PORT_HAS_OPEN_DRAIN) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN
  71. /*! @brief Open Drain feature enable/disable */
  72. enum _port_open_drain_enable
  73. {
  74. kPORT_OpenDrainDisable = 0U, /*!< Open drain output is disabled. */
  75. kPORT_OpenDrainEnable = 1U, /*!< Open drain output is enabled. */
  76. };
  77. #endif /* FSL_FEATURE_PORT_HAS_OPEN_DRAIN */
  78. #if defined(FSL_FEATURE_PORT_HAS_PASSIVE_FILTER) && FSL_FEATURE_PORT_HAS_PASSIVE_FILTER
  79. /*! @brief Passive filter feature enable/disable */
  80. enum _port_passive_filter_enable
  81. {
  82. kPORT_PassiveFilterDisable = 0U, /*!< Passive input filter is disabled. */
  83. kPORT_PassiveFilterEnable = 1U, /*!< Passive input filter is enabled. */
  84. };
  85. #endif
  86. #if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
  87. /*! @brief Configures the drive strength. */
  88. enum _port_drive_strength
  89. {
  90. kPORT_LowDriveStrength = 0U, /*!< Low-drive strength is configured. */
  91. kPORT_HighDriveStrength = 1U, /*!< High-drive strength is configured. */
  92. };
  93. #endif /* FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH */
  94. #if defined(FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK) && FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK
  95. /*! @brief Unlock/lock the pin control register field[15:0] */
  96. enum _port_lock_register
  97. {
  98. kPORT_UnlockRegister = 0U, /*!< Pin Control Register fields [15:0] are not locked. */
  99. kPORT_LockRegister = 1U, /*!< Pin Control Register fields [15:0] are locked. */
  100. };
  101. #endif /* FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK */
  102. #if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && FSL_FEATURE_PORT_PCR_MUX_WIDTH
  103. /*! @brief Pin mux selection */
  104. typedef enum _port_mux
  105. {
  106. kPORT_PinDisabledOrAnalog = 0U, /*!< Corresponding pin is disabled, but is used as an analog pin. */
  107. kPORT_MuxAsGpio = 1U, /*!< Corresponding pin is configured as GPIO. */
  108. kPORT_MuxAlt2 = 2U, /*!< Chip-specific */
  109. kPORT_MuxAlt3 = 3U, /*!< Chip-specific */
  110. kPORT_MuxAlt4 = 4U, /*!< Chip-specific */
  111. kPORT_MuxAlt5 = 5U, /*!< Chip-specific */
  112. kPORT_MuxAlt6 = 6U, /*!< Chip-specific */
  113. kPORT_MuxAlt7 = 7U, /*!< Chip-specific */
  114. kPORT_MuxAlt8 = 8U, /*!< Chip-specific */
  115. kPORT_MuxAlt9 = 9U, /*!< Chip-specific */
  116. kPORT_MuxAlt10 = 10U, /*!< Chip-specific */
  117. kPORT_MuxAlt11 = 11U, /*!< Chip-specific */
  118. kPORT_MuxAlt12 = 12U, /*!< Chip-specific */
  119. kPORT_MuxAlt13 = 13U, /*!< Chip-specific */
  120. kPORT_MuxAlt14 = 14U, /*!< Chip-specific */
  121. kPORT_MuxAlt15 = 15U, /*!< Chip-specific */
  122. } port_mux_t;
  123. #endif /* FSL_FEATURE_PORT_PCR_MUX_WIDTH */
  124. /*! @brief Configures the interrupt generation condition. */
  125. typedef enum _port_interrupt
  126. {
  127. kPORT_InterruptOrDMADisabled = 0x0U, /*!< Interrupt/DMA request is disabled. */
  128. #if defined(FSL_FEATURE_PORT_HAS_DMA_REQUEST) && FSL_FEATURE_PORT_HAS_DMA_REQUEST
  129. kPORT_DMARisingEdge = 0x1U, /*!< DMA request on rising edge. */
  130. kPORT_DMAFallingEdge = 0x2U, /*!< DMA request on falling edge. */
  131. kPORT_DMAEitherEdge = 0x3U, /*!< DMA request on either edge. */
  132. #endif
  133. #if defined(FSL_FEATURE_PORT_HAS_IRQC_FLAG) && FSL_FEATURE_PORT_HAS_IRQC_FLAG
  134. kPORT_FlagRisingEdge = 0x05U, /*!< Flag sets on rising edge. */
  135. kPORT_FlagFallingEdge = 0x06U, /*!< Flag sets on falling edge. */
  136. kPORT_FlagEitherEdge = 0x07U, /*!< Flag sets on either edge. */
  137. #endif
  138. kPORT_InterruptLogicZero = 0x8U, /*!< Interrupt when logic zero. */
  139. kPORT_InterruptRisingEdge = 0x9U, /*!< Interrupt on rising edge. */
  140. kPORT_InterruptFallingEdge = 0xAU, /*!< Interrupt on falling edge. */
  141. kPORT_InterruptEitherEdge = 0xBU, /*!< Interrupt on either edge. */
  142. kPORT_InterruptLogicOne = 0xCU, /*!< Interrupt when logic one. */
  143. #if defined(FSL_FEATURE_PORT_HAS_IRQC_TRIGGER) && FSL_FEATURE_PORT_HAS_IRQC_TRIGGER
  144. kPORT_ActiveHighTriggerOutputEnable = 0xDU, /*!< Enable active high-trigger output. */
  145. kPORT_ActiveLowTriggerOutputEnable = 0xEU, /*!< Enable active low-trigger output. */
  146. #endif
  147. } port_interrupt_t;
  148. #if defined(FSL_FEATURE_PORT_HAS_DIGITAL_FILTER) && FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
  149. /*! @brief Digital filter clock source selection */
  150. typedef enum _port_digital_filter_clock_source
  151. {
  152. kPORT_BusClock = 0U, /*!< Digital filters are clocked by the bus clock. */
  153. kPORT_LpoClock = 1U, /*!< Digital filters are clocked by the 1 kHz LPO clock. */
  154. } port_digital_filter_clock_source_t;
  155. /*! @brief PORT digital filter feature configuration definition */
  156. typedef struct _port_digital_filter_config
  157. {
  158. uint32_t digitalFilterWidth; /*!< Set digital filter width */
  159. port_digital_filter_clock_source_t clockSource; /*!< Set digital filter clockSource */
  160. } port_digital_filter_config_t;
  161. #endif /* FSL_FEATURE_PORT_HAS_DIGITAL_FILTER */
  162. #if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && FSL_FEATURE_PORT_PCR_MUX_WIDTH
  163. /*! @brief PORT pin configuration structure */
  164. typedef struct _port_pin_config
  165. {
  166. #if defined(FSL_FEATURE_PORT_HAS_PULL_ENABLE) && FSL_FEATURE_PORT_HAS_PULL_ENABLE
  167. uint16_t pullSelect : 2; /*!< No-pull/pull-down/pull-up select */
  168. #else
  169. uint16_t : 2;
  170. #endif /* FSL_FEATURE_PORT_HAS_PULL_ENABLE */
  171. #if defined(FSL_FEATURE_PORT_HAS_SLEW_RATE) && FSL_FEATURE_PORT_HAS_SLEW_RATE
  172. uint16_t slewRate : 1; /*!< Fast/slow slew rate Configure */
  173. #else
  174. uint16_t : 1;
  175. #endif /* FSL_FEATURE_PORT_HAS_SLEW_RATE */
  176. uint16_t : 1;
  177. #if defined(FSL_FEATURE_PORT_HAS_PASSIVE_FILTER) && FSL_FEATURE_PORT_HAS_PASSIVE_FILTER
  178. uint16_t passiveFilterEnable : 1; /*!< Passive filter enable/disable */
  179. #else
  180. uint16_t : 1;
  181. #endif /* FSL_FEATURE_PORT_HAS_PASSIVE_FILTER */
  182. #if defined(FSL_FEATURE_PORT_HAS_OPEN_DRAIN) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN
  183. uint16_t openDrainEnable : 1; /*!< Open drain enable/disable */
  184. #else
  185. uint16_t : 1;
  186. #endif /* FSL_FEATURE_PORT_HAS_OPEN_DRAIN */
  187. #if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
  188. uint16_t driveStrength : 1; /*!< Fast/slow drive strength configure */
  189. #else
  190. uint16_t : 1;
  191. #endif
  192. uint16_t : 1;
  193. #if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && (FSL_FEATURE_PORT_PCR_MUX_WIDTH == 3)
  194. uint16_t mux : 3; /*!< Pin mux Configure */
  195. uint16_t : 4;
  196. #elif defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && (FSL_FEATURE_PORT_PCR_MUX_WIDTH == 4)
  197. uint16_t mux : 4; /*!< Pin mux Configure */
  198. uint16_t : 3;
  199. #else
  200. uint16_t : 7,
  201. #endif
  202. #if defined(FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK) && FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK
  203. uint16_t lockRegister : 1; /*!< Lock/unlock the PCR field[15:0] */
  204. #else
  205. uint16_t : 1;
  206. #endif /* FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK */
  207. } port_pin_config_t;
  208. #endif /* FSL_FEATURE_PORT_PCR_MUX_WIDTH */
  209. /*******************************************************************************
  210. * API
  211. ******************************************************************************/
  212. #if defined(__cplusplus)
  213. extern "C" {
  214. #endif
  215. #if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && FSL_FEATURE_PORT_PCR_MUX_WIDTH
  216. /*! @name Configuration */
  217. /*@{*/
  218. /*!
  219. * @brief Sets the port PCR register.
  220. *
  221. * This is an example to define an input pin or output pin PCR configuration.
  222. * @code
  223. * // Define a digital input pin PCR configuration
  224. * port_pin_config_t config = {
  225. * kPORT_PullUp,
  226. * kPORT_FastSlewRate,
  227. * kPORT_PassiveFilterDisable,
  228. * kPORT_OpenDrainDisable,
  229. * kPORT_LowDriveStrength,
  230. * kPORT_MuxAsGpio,
  231. * kPORT_UnLockRegister,
  232. * };
  233. * @endcode
  234. *
  235. * @param base PORT peripheral base pointer.
  236. * @param pin PORT pin number.
  237. * @param config PORT PCR register configuration structure.
  238. */
  239. static inline void PORT_SetPinConfig(PORT_Type *base, uint32_t pin, const port_pin_config_t *config)
  240. {
  241. assert(config);
  242. uint32_t addr = (uint32_t)&base->PCR[pin];
  243. *(volatile uint16_t *)(addr) = *((const uint16_t *)config);
  244. }
  245. /*!
  246. * @brief Sets the port PCR register for multiple pins.
  247. *
  248. * This is an example to define input pins or output pins PCR configuration.
  249. * @code
  250. * // Define a digital input pin PCR configuration
  251. * port_pin_config_t config = {
  252. * kPORT_PullUp ,
  253. * kPORT_PullEnable,
  254. * kPORT_FastSlewRate,
  255. * kPORT_PassiveFilterDisable,
  256. * kPORT_OpenDrainDisable,
  257. * kPORT_LowDriveStrength,
  258. * kPORT_MuxAsGpio,
  259. * kPORT_UnlockRegister,
  260. * };
  261. * @endcode
  262. *
  263. * @param base PORT peripheral base pointer.
  264. * @param mask PORT pin number macro.
  265. * @param config PORT PCR register configuration structure.
  266. */
  267. static inline void PORT_SetMultiplePinsConfig(PORT_Type *base, uint32_t mask, const port_pin_config_t *config)
  268. {
  269. assert(config);
  270. uint16_t pcrl = *((const uint16_t *)config);
  271. if (mask & 0xffffU)
  272. {
  273. base->GPCLR = ((mask & 0xffffU) << 16) | pcrl;
  274. }
  275. if (mask >> 16)
  276. {
  277. base->GPCHR = (mask & 0xffff0000U) | pcrl;
  278. }
  279. }
  280. #if defined(FSL_FEATURE_PORT_HAS_MULTIPLE_IRQ_CONFIG) && FSL_FEATURE_PORT_HAS_MULTIPLE_IRQ_CONFIG
  281. /*!
  282. * @brief Sets the port interrupt configuration in PCR register for multiple pins.
  283. *
  284. * @param base PORT peripheral base pointer.
  285. * @param mask PORT pin number macro.
  286. * @param config PORT pin interrupt configuration.
  287. * - #kPORT_InterruptOrDMADisabled: Interrupt/DMA request disabled.
  288. * - #kPORT_DMARisingEdge : DMA request on rising edge(if the DMA requests exit).
  289. * - #kPORT_DMAFallingEdge: DMA request on falling edge(if the DMA requests exit).
  290. * - #kPORT_DMAEitherEdge : DMA request on either edge(if the DMA requests exit).
  291. * - #kPORT_FlagRisingEdge : Flag sets on rising edge(if the Flag states exit).
  292. * - #kPORT_FlagFallingEdge : Flag sets on falling edge(if the Flag states exit).
  293. * - #kPORT_FlagEitherEdge : Flag sets on either edge(if the Flag states exit).
  294. * - #kPORT_InterruptLogicZero : Interrupt when logic zero.
  295. * - #kPORT_InterruptRisingEdge : Interrupt on rising edge.
  296. * - #kPORT_InterruptFallingEdge: Interrupt on falling edge.
  297. * - #kPORT_InterruptEitherEdge : Interrupt on either edge.
  298. * - #kPORT_InterruptLogicOne : Interrupt when logic one.
  299. * - #kPORT_ActiveHighTriggerOutputEnable : Enable active high-trigger output (if the trigger states exit).
  300. * - #kPORT_ActiveLowTriggerOutputEnable : Enable active low-trigger output (if the trigger states exit)..
  301. */
  302. static inline void PORT_SetMultipleInterruptPinsConfig(PORT_Type *base, uint32_t mask, port_interrupt_t config)
  303. {
  304. assert(config);
  305. if (mask & 0xffffU)
  306. {
  307. base->GICLR = (config << 16) | (mask & 0xffffU);
  308. }
  309. mask = mask >> 16;
  310. if (mask)
  311. {
  312. base->GICHR = (config << 16) | (mask & 0xffffU);
  313. }
  314. }
  315. #endif
  316. /*!
  317. * @brief Configures the pin muxing.
  318. *
  319. * @param base PORT peripheral base pointer.
  320. * @param pin PORT pin number.
  321. * @param mux pin muxing slot selection.
  322. * - #kPORT_PinDisabledOrAnalog: Pin disabled or work in analog function.
  323. * - #kPORT_MuxAsGpio : Set as GPIO.
  324. * - #kPORT_MuxAlt2 : chip-specific.
  325. * - #kPORT_MuxAlt3 : chip-specific.
  326. * - #kPORT_MuxAlt4 : chip-specific.
  327. * - #kPORT_MuxAlt5 : chip-specific.
  328. * - #kPORT_MuxAlt6 : chip-specific.
  329. * - #kPORT_MuxAlt7 : chip-specific.
  330. * @Note : This function is NOT recommended to use together with the PORT_SetPinsConfig, because
  331. * the PORT_SetPinsConfig need to configure the pin mux anyway (Otherwise the pin mux is
  332. * reset to zero : kPORT_PinDisabledOrAnalog).
  333. * This function is recommended to use to reset the pin mux
  334. *
  335. */
  336. static inline void PORT_SetPinMux(PORT_Type *base, uint32_t pin, port_mux_t mux)
  337. {
  338. base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_MUX_MASK) | PORT_PCR_MUX(mux);
  339. }
  340. #endif /* FSL_FEATURE_PORT_PCR_MUX_WIDTH */
  341. #if defined(FSL_FEATURE_PORT_HAS_DIGITAL_FILTER) && FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
  342. /*!
  343. * @brief Enables the digital filter in one port, each bit of the 32-bit register represents one pin.
  344. *
  345. * @param base PORT peripheral base pointer.
  346. * @param mask PORT pin number macro.
  347. */
  348. static inline void PORT_EnablePinsDigitalFilter(PORT_Type *base, uint32_t mask, bool enable)
  349. {
  350. if (enable == true)
  351. {
  352. base->DFER |= mask;
  353. }
  354. else
  355. {
  356. base->DFER &= ~mask;
  357. }
  358. }
  359. /*!
  360. * @brief Sets the digital filter in one port, each bit of the 32-bit register represents one pin.
  361. *
  362. * @param base PORT peripheral base pointer.
  363. * @param config PORT digital filter configuration structure.
  364. */
  365. static inline void PORT_SetDigitalFilterConfig(PORT_Type *base, const port_digital_filter_config_t *config)
  366. {
  367. assert(config);
  368. base->DFCR = PORT_DFCR_CS(config->clockSource);
  369. base->DFWR = PORT_DFWR_FILT(config->digitalFilterWidth);
  370. }
  371. #endif /* FSL_FEATURE_PORT_HAS_DIGITAL_FILTER */
  372. /*@}*/
  373. /*! @name Interrupt */
  374. /*@{*/
  375. /*!
  376. * @brief Configures the port pin interrupt/DMA request.
  377. *
  378. * @param base PORT peripheral base pointer.
  379. * @param pin PORT pin number.
  380. * @param config PORT pin interrupt configuration.
  381. * - #kPORT_InterruptOrDMADisabled: Interrupt/DMA request disabled.
  382. * - #kPORT_DMARisingEdge : DMA request on rising edge(if the DMA requests exit).
  383. * - #kPORT_DMAFallingEdge: DMA request on falling edge(if the DMA requests exit).
  384. * - #kPORT_DMAEitherEdge : DMA request on either edge(if the DMA requests exit).
  385. * - #kPORT_FlagRisingEdge : Flag sets on rising edge(if the Flag states exit).
  386. * - #kPORT_FlagFallingEdge : Flag sets on falling edge(if the Flag states exit).
  387. * - #kPORT_FlagEitherEdge : Flag sets on either edge(if the Flag states exit).
  388. * - #kPORT_InterruptLogicZero : Interrupt when logic zero.
  389. * - #kPORT_InterruptRisingEdge : Interrupt on rising edge.
  390. * - #kPORT_InterruptFallingEdge: Interrupt on falling edge.
  391. * - #kPORT_InterruptEitherEdge : Interrupt on either edge.
  392. * - #kPORT_InterruptLogicOne : Interrupt when logic one.
  393. * - #kPORT_ActiveHighTriggerOutputEnable : Enable active high-trigger output (if the trigger states exit).
  394. * - #kPORT_ActiveLowTriggerOutputEnable : Enable active low-trigger output (if the trigger states exit).
  395. */
  396. static inline void PORT_SetPinInterruptConfig(PORT_Type *base, uint32_t pin, port_interrupt_t config)
  397. {
  398. base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_IRQC_MASK) | PORT_PCR_IRQC(config);
  399. }
  400. #if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
  401. /*!
  402. * @brief Configures the port pin drive strength.
  403. *
  404. * @param base PORT peripheral base pointer.
  405. * @param pin PORT pin number.
  406. * @param config PORT pin drive strength
  407. * - #kPORT_LowDriveStrength = 0U - Low-drive strength is configured.
  408. * - #kPORT_HighDriveStrength = 1U - High-drive strength is configured.
  409. */
  410. static inline void PORT_SetPinDriveStrength(PORT_Type* base, uint32_t pin, uint8_t strength)
  411. {
  412. base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_DSE_MASK) | PORT_PCR_DSE(strength);
  413. }
  414. #endif
  415. /*!
  416. * @brief Reads the whole port status flag.
  417. *
  418. * If a pin is configured to generate the DMA request, the corresponding flag
  419. * is cleared automatically at the completion of the requested DMA transfer.
  420. * Otherwise, the flag remains set until a logic one is written to that flag.
  421. * If configured for a level sensitive interrupt that remains asserted, the flag
  422. * is set again immediately.
  423. *
  424. * @param base PORT peripheral base pointer.
  425. * @return Current port interrupt status flags, for example, 0x00010001 means the
  426. * pin 0 and 16 have the interrupt.
  427. */
  428. static inline uint32_t PORT_GetPinsInterruptFlags(PORT_Type *base)
  429. {
  430. return base->ISFR;
  431. }
  432. /*!
  433. * @brief Clears the multiple pin interrupt status flag.
  434. *
  435. * @param base PORT peripheral base pointer.
  436. * @param mask PORT pin number macro.
  437. */
  438. static inline void PORT_ClearPinsInterruptFlags(PORT_Type *base, uint32_t mask)
  439. {
  440. base->ISFR = mask;
  441. }
  442. /*@}*/
  443. #if defined(__cplusplus)
  444. }
  445. #endif
  446. /*! @}*/
  447. #endif /* _FSL_PORT_H_ */