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