fsl_flexio.h 30 KB

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