fsl_flexio.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_FLEXIO_H_
  9. #define _FSL_FLEXIO_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup flexio_driver
  13. * @{
  14. */
  15. /*******************************************************************************
  16. * Definitions
  17. ******************************************************************************/
  18. /*! @name Driver version */
  19. /*@{*/
  20. /*! @brief FlexIO driver version. */
  21. #define FSL_FLEXIO_DRIVER_VERSION (MAKE_VERSION(2, 0, 4))
  22. /*@}*/
  23. /*! @brief Calculate FlexIO timer trigger.*/
  24. #define FLEXIO_TIMER_TRIGGER_SEL_PININPUT(x) ((uint32_t)(x) << 1U)
  25. #define FLEXIO_TIMER_TRIGGER_SEL_SHIFTnSTAT(x) (((uint32_t)(x) << 2U) | 0x1U)
  26. #define FLEXIO_TIMER_TRIGGER_SEL_TIMn(x) (((uint32_t)(x) << 2U) | 0x3U)
  27. /*! @brief Define time of timer trigger polarity.*/
  28. typedef enum _flexio_timer_trigger_polarity
  29. {
  30. kFLEXIO_TimerTriggerPolarityActiveHigh = 0x0U, /*!< Active high. */
  31. kFLEXIO_TimerTriggerPolarityActiveLow = 0x1U, /*!< Active low. */
  32. } flexio_timer_trigger_polarity_t;
  33. /*! @brief Define type of timer trigger source.*/
  34. typedef enum _flexio_timer_trigger_source
  35. {
  36. kFLEXIO_TimerTriggerSourceExternal = 0x0U, /*!< External trigger selected. */
  37. kFLEXIO_TimerTriggerSourceInternal = 0x1U, /*!< Internal trigger selected. */
  38. } flexio_timer_trigger_source_t;
  39. /*! @brief Define type of timer/shifter pin configuration.*/
  40. typedef enum _flexio_pin_config
  41. {
  42. kFLEXIO_PinConfigOutputDisabled = 0x0U, /*!< Pin output disabled. */
  43. kFLEXIO_PinConfigOpenDrainOrBidirection = 0x1U, /*!< Pin open drain or bidirectional output enable. */
  44. kFLEXIO_PinConfigBidirectionOutputData = 0x2U, /*!< Pin bidirectional output data. */
  45. kFLEXIO_PinConfigOutput = 0x3U, /*!< Pin output. */
  46. } flexio_pin_config_t;
  47. /*! @brief Definition of pin polarity.*/
  48. typedef enum _flexio_pin_polarity
  49. {
  50. kFLEXIO_PinActiveHigh = 0x0U, /*!< Active high. */
  51. kFLEXIO_PinActiveLow = 0x1U, /*!< Active low. */
  52. } flexio_pin_polarity_t;
  53. /*! @brief Define type of timer work mode.*/
  54. typedef enum _flexio_timer_mode
  55. {
  56. kFLEXIO_TimerModeDisabled = 0x0U, /*!< Timer Disabled. */
  57. kFLEXIO_TimerModeDual8BitBaudBit = 0x1U, /*!< Dual 8-bit counters baud/bit mode. */
  58. kFLEXIO_TimerModeDual8BitPWM = 0x2U, /*!< Dual 8-bit counters PWM mode. */
  59. kFLEXIO_TimerModeSingle16Bit = 0x3U, /*!< Single 16-bit counter mode. */
  60. } flexio_timer_mode_t;
  61. /*! @brief Define type of timer initial output or timer reset condition.*/
  62. typedef enum _flexio_timer_output
  63. {
  64. kFLEXIO_TimerOutputOneNotAffectedByReset = 0x0U, /*!< Logic one when enabled and is not affected by timer
  65. reset. */
  66. kFLEXIO_TimerOutputZeroNotAffectedByReset = 0x1U, /*!< Logic zero when enabled and is not affected by timer
  67. reset. */
  68. kFLEXIO_TimerOutputOneAffectedByReset = 0x2U, /*!< Logic one when enabled and on timer reset. */
  69. kFLEXIO_TimerOutputZeroAffectedByReset = 0x3U, /*!< Logic zero when enabled and on timer reset. */
  70. } flexio_timer_output_t;
  71. /*! @brief Define type of timer decrement.*/
  72. typedef enum _flexio_timer_decrement_source
  73. {
  74. kFLEXIO_TimerDecSrcOnFlexIOClockShiftTimerOutput = 0x0U, /*!< Decrement counter on FlexIO clock, Shift clock
  75. equals Timer output. */
  76. kFLEXIO_TimerDecSrcOnTriggerInputShiftTimerOutput = 0x1U, /*!< Decrement counter on Trigger input (both edges),
  77. Shift clock equals Timer output. */
  78. kFLEXIO_TimerDecSrcOnPinInputShiftPinInput = 0x2U, /*!< Decrement counter on Pin input (both edges),
  79. Shift clock equals Pin input. */
  80. kFLEXIO_TimerDecSrcOnTriggerInputShiftTriggerInput = 0x3U, /*!< Decrement counter on Trigger input (both edges),
  81. Shift clock equals Trigger input. */
  82. } flexio_timer_decrement_source_t;
  83. /*! @brief Define type of timer reset condition.*/
  84. typedef enum _flexio_timer_reset_condition
  85. {
  86. kFLEXIO_TimerResetNever = 0x0U, /*!< Timer never reset. */
  87. kFLEXIO_TimerResetOnTimerPinEqualToTimerOutput = 0x2U, /*!< Timer reset on Timer Pin equal to Timer Output. */
  88. kFLEXIO_TimerResetOnTimerTriggerEqualToTimerOutput = 0x3U, /*!< Timer reset on Timer Trigger equal to
  89. Timer Output. */
  90. kFLEXIO_TimerResetOnTimerPinRisingEdge = 0x4U, /*!< Timer reset on Timer Pin rising edge. */
  91. kFLEXIO_TimerResetOnTimerTriggerRisingEdge = 0x6U, /*!< Timer reset on Trigger rising edge. */
  92. kFLEXIO_TimerResetOnTimerTriggerBothEdge = 0x7U, /*!< Timer reset on Trigger rising or falling edge. */
  93. } flexio_timer_reset_condition_t;
  94. /*! @brief Define type of timer disable condition.*/
  95. typedef enum _flexio_timer_disable_condition
  96. {
  97. kFLEXIO_TimerDisableNever = 0x0U, /*!< Timer never disabled. */
  98. kFLEXIO_TimerDisableOnPreTimerDisable = 0x1U, /*!< Timer disabled on Timer N-1 disable. */
  99. kFLEXIO_TimerDisableOnTimerCompare = 0x2U, /*!< Timer disabled on Timer compare. */
  100. kFLEXIO_TimerDisableOnTimerCompareTriggerLow = 0x3U, /*!< Timer disabled on Timer compare and Trigger Low. */
  101. kFLEXIO_TimerDisableOnPinBothEdge = 0x4U, /*!< Timer disabled on Pin rising or falling edge. */
  102. kFLEXIO_TimerDisableOnPinBothEdgeTriggerHigh = 0x5U, /*!< Timer disabled on Pin rising or falling edge provided
  103. Trigger is high. */
  104. kFLEXIO_TimerDisableOnTriggerFallingEdge = 0x6U, /*!< Timer disabled on Trigger falling edge. */
  105. } flexio_timer_disable_condition_t;
  106. /*! @brief Define type of timer enable condition.*/
  107. typedef enum _flexio_timer_enable_condition
  108. {
  109. kFLEXIO_TimerEnabledAlways = 0x0U, /*!< Timer always enabled. */
  110. kFLEXIO_TimerEnableOnPrevTimerEnable = 0x1U, /*!< Timer enabled on Timer N-1 enable. */
  111. kFLEXIO_TimerEnableOnTriggerHigh = 0x2U, /*!< Timer enabled on Trigger high. */
  112. kFLEXIO_TimerEnableOnTriggerHighPinHigh = 0x3U, /*!< Timer enabled on Trigger high and Pin high. */
  113. kFLEXIO_TimerEnableOnPinRisingEdge = 0x4U, /*!< Timer enabled on Pin rising edge. */
  114. kFLEXIO_TimerEnableOnPinRisingEdgeTriggerHigh = 0x5U, /*!< Timer enabled on Pin rising edge and Trigger high. */
  115. kFLEXIO_TimerEnableOnTriggerRisingEdge = 0x6U, /*!< Timer enabled on Trigger rising edge. */
  116. kFLEXIO_TimerEnableOnTriggerBothEdge = 0x7U, /*!< Timer enabled on Trigger rising or falling edge. */
  117. } flexio_timer_enable_condition_t;
  118. /*! @brief Define type of timer stop bit generate condition.*/
  119. typedef enum _flexio_timer_stop_bit_condition
  120. {
  121. kFLEXIO_TimerStopBitDisabled = 0x0U, /*!< Stop bit disabled. */
  122. kFLEXIO_TimerStopBitEnableOnTimerCompare = 0x1U, /*!< Stop bit is enabled on timer compare. */
  123. kFLEXIO_TimerStopBitEnableOnTimerDisable = 0x2U, /*!< Stop bit is enabled on timer disable. */
  124. kFLEXIO_TimerStopBitEnableOnTimerCompareDisable = 0x3U, /*!< Stop bit is enabled on timer compare and timer
  125. disable. */
  126. } flexio_timer_stop_bit_condition_t;
  127. /*! @brief Define type of timer start bit generate condition.*/
  128. typedef enum _flexio_timer_start_bit_condition
  129. {
  130. kFLEXIO_TimerStartBitDisabled = 0x0U, /*!< Start bit disabled. */
  131. kFLEXIO_TimerStartBitEnabled = 0x1U, /*!< Start bit enabled. */
  132. } flexio_timer_start_bit_condition_t;
  133. /*! @brief Define type of timer polarity for shifter control. */
  134. typedef enum _flexio_shifter_timer_polarity
  135. {
  136. kFLEXIO_ShifterTimerPolarityOnPositive = 0x0U, /*!< Shift on positive edge of shift clock. */
  137. kFLEXIO_ShifterTimerPolarityOnNegitive = 0x1U, /*!< Shift on negative edge of shift clock. */
  138. } flexio_shifter_timer_polarity_t;
  139. /*! @brief Define type of shifter working mode.*/
  140. typedef enum _flexio_shifter_mode
  141. {
  142. kFLEXIO_ShifterDisabled = 0x0U, /*!< Shifter is disabled. */
  143. kFLEXIO_ShifterModeReceive = 0x1U, /*!< Receive mode. */
  144. kFLEXIO_ShifterModeTransmit = 0x2U, /*!< Transmit mode. */
  145. kFLEXIO_ShifterModeMatchStore = 0x4U, /*!< Match store mode. */
  146. kFLEXIO_ShifterModeMatchContinuous = 0x5U, /*!< Match continuous mode. */
  147. #if FSL_FEATURE_FLEXIO_HAS_STATE_MODE
  148. kFLEXIO_ShifterModeState = 0x6U, /*!< SHIFTBUF contents are used for storing
  149. programmable state attributes. */
  150. #endif /* FSL_FEATURE_FLEXIO_HAS_STATE_MODE */
  151. #if FSL_FEATURE_FLEXIO_HAS_LOGIC_MODE
  152. kFLEXIO_ShifterModeLogic = 0x7U, /*!< SHIFTBUF contents are used for implementing
  153. programmable logic look up table. */
  154. #endif /* FSL_FEATURE_FLEXIO_HAS_LOGIC_MODE */
  155. } flexio_shifter_mode_t;
  156. /*! @brief Define type of shifter input source.*/
  157. typedef enum _flexio_shifter_input_source
  158. {
  159. kFLEXIO_ShifterInputFromPin = 0x0U, /*!< Shifter input from pin. */
  160. kFLEXIO_ShifterInputFromNextShifterOutput = 0x1U, /*!< Shifter input from Shifter N+1. */
  161. } flexio_shifter_input_source_t;
  162. /*! @brief Define of STOP bit configuration.*/
  163. typedef enum _flexio_shifter_stop_bit
  164. {
  165. kFLEXIO_ShifterStopBitDisable = 0x0U, /*!< Disable shifter stop bit. */
  166. kFLEXIO_ShifterStopBitLow = 0x2U, /*!< Set shifter stop bit to logic low level. */
  167. kFLEXIO_ShifterStopBitHigh = 0x3U, /*!< Set shifter stop bit to logic high level. */
  168. } flexio_shifter_stop_bit_t;
  169. /*! @brief Define type of START bit configuration.*/
  170. typedef enum _flexio_shifter_start_bit
  171. {
  172. kFLEXIO_ShifterStartBitDisabledLoadDataOnEnable = 0x0U, /*!< Disable shifter start bit, transmitter loads
  173. data on enable. */
  174. kFLEXIO_ShifterStartBitDisabledLoadDataOnShift = 0x1U, /*!< Disable shifter start bit, transmitter loads
  175. data on first shift. */
  176. kFLEXIO_ShifterStartBitLow = 0x2U, /*!< Set shifter start bit to logic low level. */
  177. kFLEXIO_ShifterStartBitHigh = 0x3U, /*!< Set shifter start bit to logic high level. */
  178. } flexio_shifter_start_bit_t;
  179. /*! @brief Define FlexIO shifter buffer type*/
  180. typedef enum _flexio_shifter_buffer_type
  181. {
  182. kFLEXIO_ShifterBuffer = 0x0U, /*!< Shifter Buffer N Register. */
  183. kFLEXIO_ShifterBufferBitSwapped = 0x1U, /*!< Shifter Buffer N Bit Byte Swapped Register. */
  184. kFLEXIO_ShifterBufferByteSwapped = 0x2U, /*!< Shifter Buffer N Byte Swapped Register. */
  185. kFLEXIO_ShifterBufferBitByteSwapped = 0x3U, /*!< Shifter Buffer N Bit Swapped Register. */
  186. #if defined(FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_NIBBLE_BYTE_SWAP) && FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_NIBBLE_BYTE_SWAP
  187. kFLEXIO_ShifterBufferNibbleByteSwapped = 0x4U, /*!< Shifter Buffer N Nibble Byte Swapped Register. */
  188. #endif /*FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_NIBBLE_BYTE_SWAP*/
  189. #if defined(FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_HALF_WORD_SWAP) && FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_HALF_WORD_SWAP
  190. kFLEXIO_ShifterBufferHalfWordSwapped = 0x5U, /*!< Shifter Buffer N Half Word Swapped Register. */
  191. #endif
  192. #if defined(FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_NIBBLE_SWAP) && FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_NIBBLE_SWAP
  193. kFLEXIO_ShifterBufferNibbleSwapped = 0x6U, /*!< Shifter Buffer N Nibble Swapped Register. */
  194. #endif
  195. } flexio_shifter_buffer_type_t;
  196. /*! @brief Define FlexIO user configuration structure. */
  197. typedef struct _flexio_config_
  198. {
  199. bool enableFlexio; /*!< Enable/disable FlexIO module */
  200. bool enableInDoze; /*!< Enable/disable FlexIO operation in doze mode */
  201. bool enableInDebug; /*!< Enable/disable FlexIO operation in debug mode */
  202. bool enableFastAccess; /*!< Enable/disable fast access to FlexIO registers, fast access requires
  203. the FlexIO clock to be at least twice the frequency of the bus clock. */
  204. } flexio_config_t;
  205. /*! @brief Define FlexIO timer configuration structure. */
  206. typedef struct _flexio_timer_config
  207. {
  208. /* Trigger. */
  209. uint32_t triggerSelect; /*!< The internal trigger selection number using MACROs. */
  210. flexio_timer_trigger_polarity_t triggerPolarity; /*!< Trigger Polarity. */
  211. flexio_timer_trigger_source_t triggerSource; /*!< Trigger Source, internal (see 'trgsel') or external. */
  212. /* Pin. */
  213. flexio_pin_config_t pinConfig; /*!< Timer Pin Configuration. */
  214. uint32_t pinSelect; /*!< Timer Pin number Select. */
  215. flexio_pin_polarity_t pinPolarity; /*!< Timer Pin Polarity. */
  216. /* Timer. */
  217. flexio_timer_mode_t timerMode; /*!< Timer work Mode. */
  218. flexio_timer_output_t timerOutput; /*!< Configures the initial state of the Timer Output and
  219. whether it is affected by the Timer reset. */
  220. flexio_timer_decrement_source_t timerDecrement; /*!< Configures the source of the Timer decrement and the
  221. source of the Shift clock. */
  222. flexio_timer_reset_condition_t timerReset; /*!< Configures the condition that causes the timer counter
  223. (and optionally the timer output) to be reset. */
  224. flexio_timer_disable_condition_t timerDisable; /*!< Configures the condition that causes the Timer to be
  225. disabled and stop decrementing. */
  226. flexio_timer_enable_condition_t timerEnable; /*!< Configures the condition that causes the Timer to be
  227. enabled and start decrementing. */
  228. flexio_timer_stop_bit_condition_t timerStop; /*!< Timer STOP Bit generation. */
  229. flexio_timer_start_bit_condition_t timerStart; /*!< Timer STRAT Bit generation. */
  230. uint32_t timerCompare; /*!< Value for Timer Compare N Register. */
  231. } flexio_timer_config_t;
  232. /*! @brief Define FlexIO shifter configuration structure. */
  233. typedef struct _flexio_shifter_config
  234. {
  235. /* Timer. */
  236. uint32_t timerSelect; /*!< Selects which Timer is used for controlling the
  237. logic/shift register and generating the Shift clock. */
  238. flexio_shifter_timer_polarity_t timerPolarity; /*!< Timer Polarity. */
  239. /* Pin. */
  240. flexio_pin_config_t pinConfig; /*!< Shifter Pin Configuration. */
  241. uint32_t pinSelect; /*!< Shifter Pin number Select. */
  242. flexio_pin_polarity_t pinPolarity; /*!< Shifter Pin Polarity. */
  243. /* Shifter. */
  244. flexio_shifter_mode_t shifterMode; /*!< Configures the mode of the Shifter. */
  245. #if FSL_FEATURE_FLEXIO_HAS_PARALLEL_WIDTH
  246. uint32_t parallelWidth; /*!< Configures the parallel width when using parallel mode.*/
  247. #endif /* FSL_FEATURE_FLEXIO_HAS_PARALLEL_WIDTH */
  248. flexio_shifter_input_source_t inputSource; /*!< Selects the input source for the shifter. */
  249. flexio_shifter_stop_bit_t shifterStop; /*!< Shifter STOP bit. */
  250. flexio_shifter_start_bit_t shifterStart; /*!< Shifter START bit. */
  251. } flexio_shifter_config_t;
  252. /*! @brief typedef for FlexIO simulated driver interrupt handler.*/
  253. typedef void (*flexio_isr_t)(void *base, void *handle);
  254. /*******************************************************************************
  255. * Variables
  256. ******************************************************************************/
  257. /*! @brief Pointers to flexio bases for each instance. */
  258. extern FLEXIO_Type *const s_flexioBases[];
  259. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  260. /*! @brief Pointers to flexio clocks for each instance. */
  261. extern const clock_ip_name_t s_flexioClocks[];
  262. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  263. /*******************************************************************************
  264. * API
  265. ******************************************************************************/
  266. #if defined(__cplusplus)
  267. extern "C" {
  268. #endif /*_cplusplus*/
  269. /*!
  270. * @name FlexIO Initialization and De-initialization
  271. * @{
  272. */
  273. /*!
  274. * @brief Gets the default configuration to configure the FlexIO module. The configuration
  275. * can used directly to call the FLEXIO_Configure().
  276. *
  277. * Example:
  278. @code
  279. flexio_config_t config;
  280. FLEXIO_GetDefaultConfig(&config);
  281. @endcode
  282. *
  283. * @param userConfig pointer to flexio_config_t structure
  284. */
  285. void FLEXIO_GetDefaultConfig(flexio_config_t *userConfig);
  286. /*!
  287. * @brief Configures the FlexIO with a FlexIO configuration. The configuration structure
  288. * can be filled by the user or be set with default values by FLEXIO_GetDefaultConfig().
  289. *
  290. * Example
  291. @code
  292. flexio_config_t config = {
  293. .enableFlexio = true,
  294. .enableInDoze = false,
  295. .enableInDebug = true,
  296. .enableFastAccess = false
  297. };
  298. FLEXIO_Configure(base, &config);
  299. @endcode
  300. *
  301. * @param base FlexIO peripheral base address
  302. * @param userConfig pointer to flexio_config_t structure
  303. */
  304. void FLEXIO_Init(FLEXIO_Type *base, const flexio_config_t *userConfig);
  305. /*!
  306. * @brief Gates the FlexIO clock. Call this API to stop the FlexIO clock.
  307. *
  308. * @note After calling this API, call the FLEXO_Init to use the FlexIO module.
  309. *
  310. * @param base FlexIO peripheral base address
  311. */
  312. void FLEXIO_Deinit(FLEXIO_Type *base);
  313. /*!
  314. * @brief Get instance number for FLEXIO module.
  315. *
  316. * @param base FLEXIO peripheral base address.
  317. */
  318. uint32_t FLEXIO_GetInstance(FLEXIO_Type *base);
  319. /* @} */
  320. /*!
  321. * @name FlexIO Basic Operation
  322. * @{
  323. */
  324. /*!
  325. * @brief Resets the FlexIO module.
  326. *
  327. * @param base FlexIO peripheral base address
  328. */
  329. void FLEXIO_Reset(FLEXIO_Type *base);
  330. /*!
  331. * @brief Enables the FlexIO module operation.
  332. *
  333. * @param base FlexIO peripheral base address
  334. * @param enable true to enable, false to disable.
  335. */
  336. static inline void FLEXIO_Enable(FLEXIO_Type *base, bool enable)
  337. {
  338. if (enable)
  339. {
  340. base->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;
  341. }
  342. else
  343. {
  344. base->CTRL &= ~FLEXIO_CTRL_FLEXEN_MASK;
  345. }
  346. }
  347. #if defined(FSL_FEATURE_FLEXIO_HAS_PIN_STATUS) && FSL_FEATURE_FLEXIO_HAS_PIN_STATUS
  348. /*!
  349. * @brief Reads the input data on each of the FlexIO pins.
  350. *
  351. * @param base FlexIO peripheral base address
  352. * @return FlexIO pin input data
  353. */
  354. static inline uint32_t FLEXIO_ReadPinInput(FLEXIO_Type *base)
  355. {
  356. return base->PIN;
  357. }
  358. #endif /*FSL_FEATURE_FLEXIO_HAS_PIN_STATUS*/
  359. #if defined(FSL_FEATURE_FLEXIO_HAS_STATE_MODE) && FSL_FEATURE_FLEXIO_HAS_STATE_MODE
  360. /*!
  361. * @brief Gets the current state pointer for state mode use.
  362. *
  363. * @param base FlexIO peripheral base address
  364. * @return current State pointer
  365. */
  366. static inline uint8_t FLEXIO_GetShifterState(FLEXIO_Type *base)
  367. {
  368. return ((uint8_t)(base->SHIFTSTATE) & FLEXIO_SHIFTSTATE_STATE_MASK);
  369. }
  370. #endif /*FSL_FEATURE_FLEXIO_HAS_STATE_MODE*/
  371. /*!
  372. * @brief Configures the shifter with the shifter configuration. The configuration structure
  373. * covers both the SHIFTCTL and SHIFTCFG registers. To configure the shifter to the proper
  374. * mode, select which timer controls the shifter to shift, whether to generate start bit/stop
  375. * bit, and the polarity of start bit and stop bit.
  376. *
  377. * Example
  378. @code
  379. flexio_shifter_config_t config = {
  380. .timerSelect = 0,
  381. .timerPolarity = kFLEXIO_ShifterTimerPolarityOnPositive,
  382. .pinConfig = kFLEXIO_PinConfigOpenDrainOrBidirection,
  383. .pinPolarity = kFLEXIO_PinActiveLow,
  384. .shifterMode = kFLEXIO_ShifterModeTransmit,
  385. .inputSource = kFLEXIO_ShifterInputFromPin,
  386. .shifterStop = kFLEXIO_ShifterStopBitHigh,
  387. .shifterStart = kFLEXIO_ShifterStartBitLow
  388. };
  389. FLEXIO_SetShifterConfig(base, &config);
  390. @endcode
  391. *
  392. * @param base FlexIO peripheral base address
  393. * @param index Shifter index
  394. * @param shifterConfig Pointer to flexio_shifter_config_t structure
  395. */
  396. void FLEXIO_SetShifterConfig(FLEXIO_Type *base, uint8_t index, const flexio_shifter_config_t *shifterConfig);
  397. /*!
  398. * @brief Configures the timer with the timer configuration. The configuration structure
  399. * covers both the TIMCTL and TIMCFG registers. To configure the timer to the proper
  400. * mode, select trigger source for timer and the timer pin output and the timing for timer.
  401. *
  402. * Example
  403. @code
  404. flexio_timer_config_t config = {
  405. .triggerSelect = FLEXIO_TIMER_TRIGGER_SEL_SHIFTnSTAT(0),
  406. .triggerPolarity = kFLEXIO_TimerTriggerPolarityActiveLow,
  407. .triggerSource = kFLEXIO_TimerTriggerSourceInternal,
  408. .pinConfig = kFLEXIO_PinConfigOpenDrainOrBidirection,
  409. .pinSelect = 0,
  410. .pinPolarity = kFLEXIO_PinActiveHigh,
  411. .timerMode = kFLEXIO_TimerModeDual8BitBaudBit,
  412. .timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset,
  413. .timerDecrement = kFLEXIO_TimerDecSrcOnFlexIOClockShiftTimerOutput,
  414. .timerReset = kFLEXIO_TimerResetOnTimerPinEqualToTimerOutput,
  415. .timerDisable = kFLEXIO_TimerDisableOnTimerCompare,
  416. .timerEnable = kFLEXIO_TimerEnableOnTriggerHigh,
  417. .timerStop = kFLEXIO_TimerStopBitEnableOnTimerDisable,
  418. .timerStart = kFLEXIO_TimerStartBitEnabled
  419. };
  420. FLEXIO_SetTimerConfig(base, &config);
  421. @endcode
  422. *
  423. * @param base FlexIO peripheral base address
  424. * @param index Timer index
  425. * @param timerConfig Pointer to the flexio_timer_config_t structure
  426. */
  427. void FLEXIO_SetTimerConfig(FLEXIO_Type *base, uint8_t index, const flexio_timer_config_t *timerConfig);
  428. /* @} */
  429. /*!
  430. * @name FlexIO Interrupt Operation
  431. * @{
  432. */
  433. /*!
  434. * @brief Enables the shifter status interrupt. The interrupt generates when the corresponding SSF is set.
  435. *
  436. * @param base FlexIO peripheral base address
  437. * @param mask The shifter status mask which can be calculated by (1 << shifter index)
  438. * @note For multiple shifter status interrupt enable, for example, two shifter status enable, can calculate
  439. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  440. */
  441. static inline void FLEXIO_EnableShifterStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
  442. {
  443. base->SHIFTSIEN |= mask;
  444. }
  445. /*!
  446. * @brief Disables the shifter status interrupt. The interrupt won't generate when the corresponding SSF is set.
  447. *
  448. * @param base FlexIO peripheral base address
  449. * @param mask The shifter status mask which can be calculated by (1 << shifter index)
  450. * @note For multiple shifter status interrupt enable, for example, two shifter status enable, can calculate
  451. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  452. */
  453. static inline void FLEXIO_DisableShifterStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
  454. {
  455. base->SHIFTSIEN &= ~mask;
  456. }
  457. /*!
  458. * @brief Enables the shifter error interrupt. The interrupt generates when the corresponding SEF is set.
  459. *
  460. * @param base FlexIO peripheral base address
  461. * @param mask The shifter error mask which can be calculated by (1 << shifter index)
  462. * @note For multiple shifter error interrupt enable, for example, two shifter error enable, can calculate
  463. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  464. */
  465. static inline void FLEXIO_EnableShifterErrorInterrupts(FLEXIO_Type *base, uint32_t mask)
  466. {
  467. base->SHIFTEIEN |= mask;
  468. }
  469. /*!
  470. * @brief Disables the shifter error interrupt. The interrupt won't generate when the corresponding SEF is set.
  471. *
  472. * @param base FlexIO peripheral base address
  473. * @param mask The shifter error mask which can be calculated by (1 << shifter index)
  474. * @note For multiple shifter error interrupt enable, for example, two shifter error enable, can calculate
  475. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  476. */
  477. static inline void FLEXIO_DisableShifterErrorInterrupts(FLEXIO_Type *base, uint32_t mask)
  478. {
  479. base->SHIFTEIEN &= ~mask;
  480. }
  481. /*!
  482. * @brief Enables the timer status interrupt. The interrupt generates when the corresponding SSF is set.
  483. *
  484. * @param base FlexIO peripheral base address
  485. * @param mask The timer status mask which can be calculated by (1 << timer index)
  486. * @note For multiple timer status interrupt enable, for example, two timer status enable, can calculate
  487. * the mask by using ((1 << timer index0) | (1 << timer index1))
  488. */
  489. static inline void FLEXIO_EnableTimerStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
  490. {
  491. base->TIMIEN |= mask;
  492. }
  493. /*!
  494. * @brief Disables the timer status interrupt. The interrupt won't generate when the corresponding SSF is set.
  495. *
  496. * @param base FlexIO peripheral base address
  497. * @param mask The timer status mask which can be calculated by (1 << timer index)
  498. * @note For multiple timer status interrupt enable, for example, two timer status enable, can calculate
  499. * the mask by using ((1 << timer index0) | (1 << timer index1))
  500. */
  501. static inline void FLEXIO_DisableTimerStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
  502. {
  503. base->TIMIEN &= ~mask;
  504. }
  505. /* @} */
  506. /*!
  507. * @name FlexIO Status Operation
  508. * @{
  509. */
  510. /*!
  511. * @brief Gets the shifter status flags.
  512. *
  513. * @param base FlexIO peripheral base address
  514. * @return Shifter status flags
  515. */
  516. static inline uint32_t FLEXIO_GetShifterStatusFlags(FLEXIO_Type *base)
  517. {
  518. return ((base->SHIFTSTAT) & FLEXIO_SHIFTSTAT_SSF_MASK);
  519. }
  520. /*!
  521. * @brief Clears the shifter status flags.
  522. *
  523. * @param base FlexIO peripheral base address
  524. * @param mask The shifter status mask which can be calculated by (1 << shifter index)
  525. * @note For clearing multiple shifter status flags, for example, two shifter status flags, can calculate
  526. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  527. */
  528. static inline void FLEXIO_ClearShifterStatusFlags(FLEXIO_Type *base, uint32_t mask)
  529. {
  530. base->SHIFTSTAT = mask;
  531. }
  532. /*!
  533. * @brief Gets the shifter error flags.
  534. *
  535. * @param base FlexIO peripheral base address
  536. * @return Shifter error flags
  537. */
  538. static inline uint32_t FLEXIO_GetShifterErrorFlags(FLEXIO_Type *base)
  539. {
  540. return ((base->SHIFTERR) & FLEXIO_SHIFTERR_SEF_MASK);
  541. }
  542. /*!
  543. * @brief Clears the shifter error flags.
  544. *
  545. * @param base FlexIO peripheral base address
  546. * @param mask The shifter error mask which can be calculated by (1 << shifter index)
  547. * @note For clearing multiple shifter error flags, for example, two shifter error flags, can calculate
  548. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  549. */
  550. static inline void FLEXIO_ClearShifterErrorFlags(FLEXIO_Type *base, uint32_t mask)
  551. {
  552. base->SHIFTERR = mask;
  553. }
  554. /*!
  555. * @brief Gets the timer status flags.
  556. *
  557. * @param base FlexIO peripheral base address
  558. * @return Timer status flags
  559. */
  560. static inline uint32_t FLEXIO_GetTimerStatusFlags(FLEXIO_Type *base)
  561. {
  562. return ((base->TIMSTAT) & FLEXIO_TIMSTAT_TSF_MASK);
  563. }
  564. /*!
  565. * @brief Clears the timer status flags.
  566. *
  567. * @param base FlexIO peripheral base address
  568. * @param mask The timer status mask which can be calculated by (1 << timer index)
  569. * @note For clearing multiple timer status flags, for example, two timer status flags, can calculate
  570. * the mask by using ((1 << timer index0) | (1 << timer index1))
  571. */
  572. static inline void FLEXIO_ClearTimerStatusFlags(FLEXIO_Type *base, uint32_t mask)
  573. {
  574. base->TIMSTAT = mask;
  575. }
  576. /* @} */
  577. /*!
  578. * @name FlexIO DMA Operation
  579. * @{
  580. */
  581. /*!
  582. * @brief Enables/disables the shifter status DMA. The DMA request generates when the corresponding SSF is set.
  583. *
  584. * @note For multiple shifter status DMA enables, for example, calculate
  585. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  586. *
  587. * @param base FlexIO peripheral base address
  588. * @param mask The shifter status mask which can be calculated by (1 << shifter index)
  589. * @param enable True to enable, false to disable.
  590. */
  591. static inline void FLEXIO_EnableShifterStatusDMA(FLEXIO_Type *base, uint32_t mask, bool enable)
  592. {
  593. if (enable)
  594. {
  595. base->SHIFTSDEN |= mask;
  596. }
  597. else
  598. {
  599. base->SHIFTSDEN &= ~mask;
  600. }
  601. }
  602. /*!
  603. * @brief Gets the shifter buffer address for the DMA transfer usage.
  604. *
  605. * @param base FlexIO peripheral base address
  606. * @param type Shifter type of flexio_shifter_buffer_type_t
  607. * @param index Shifter index
  608. * @return Corresponding shifter buffer index
  609. */
  610. uint32_t FLEXIO_GetShifterBufferAddress(FLEXIO_Type *base, flexio_shifter_buffer_type_t type, uint8_t index);
  611. /*!
  612. * @brief Registers the handle and the interrupt handler for the FlexIO-simulated peripheral.
  613. *
  614. * @param base Pointer to the FlexIO simulated peripheral type.
  615. * @param handle Pointer to the handler for FlexIO simulated peripheral.
  616. * @param isr FlexIO simulated peripheral interrupt handler.
  617. * @retval kStatus_Success Successfully create the handle.
  618. * @retval kStatus_OutOfRange The FlexIO type/handle/ISR table out of range.
  619. */
  620. status_t FLEXIO_RegisterHandleIRQ(void *base, void *handle, flexio_isr_t isr);
  621. /*!
  622. * @brief Unregisters the handle and the interrupt handler for the FlexIO-simulated peripheral.
  623. *
  624. * @param base Pointer to the FlexIO simulated peripheral type.
  625. * @retval kStatus_Success Successfully create the handle.
  626. * @retval kStatus_OutOfRange The FlexIO type/handle/ISR table out of range.
  627. */
  628. status_t FLEXIO_UnregisterHandleIRQ(void *base);
  629. /* @} */
  630. #if defined(__cplusplus)
  631. }
  632. #endif /*_cplusplus*/
  633. /*@}*/
  634. #endif /*_FSL_FLEXIO_H_*/