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
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. */
25 #define FSL_FLEXIO_DRIVER_VERSION (MAKE_VERSION(2, 0, 4))
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 * Variables
284 ******************************************************************************/
285 /*! @brief Pointers to flexio bases for each instance. */
286 extern FLEXIO_Type *const s_flexioBases[];
287
288 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
289 /*! @brief Pointers to flexio clocks for each instance. */
290 extern const clock_ip_name_t s_flexioClocks[];
291 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
292 /*******************************************************************************
293 * API
294 ******************************************************************************/
295
296 #if defined(__cplusplus)
297 extern "C" {
298 #endif /*_cplusplus*/
299
300 /*!
301 * @name FlexIO Initialization and De-initialization
302 * @{
303 */
304
305 /*!
306 * @brief Gets the default configuration to configure the FlexIO module. The configuration
307 * can used directly to call the FLEXIO_Configure().
308 *
309 * Example:
310 @code
311 flexio_config_t config;
312 FLEXIO_GetDefaultConfig(&config);
313 @endcode
314 *
315 * @param userConfig pointer to flexio_config_t structure
316 */
317 void FLEXIO_GetDefaultConfig(flexio_config_t *userConfig);
318
319 /*!
320 * @brief Configures the FlexIO with a FlexIO configuration. The configuration structure
321 * can be filled by the user or be set with default values by FLEXIO_GetDefaultConfig().
322 *
323 * Example
324 @code
325 flexio_config_t config = {
326 .enableFlexio = true,
327 .enableInDoze = false,
328 .enableInDebug = true,
329 .enableFastAccess = false
330 };
331 FLEXIO_Configure(base, &config);
332 @endcode
333 *
334 * @param base FlexIO peripheral base address
335 * @param userConfig pointer to flexio_config_t structure
336 */
337 void FLEXIO_Init(FLEXIO_Type *base, const flexio_config_t *userConfig);
338
339 /*!
340 * @brief Gates the FlexIO clock. Call this API to stop the FlexIO clock.
341 *
342 * @note After calling this API, call the FLEXO_Init to use the FlexIO module.
343 *
344 * @param base FlexIO peripheral base address
345 */
346 void FLEXIO_Deinit(FLEXIO_Type *base);
347
348 /*!
349 * @brief Get instance number for FLEXIO module.
350 *
351 * @param base FLEXIO peripheral base address.
352 */
353 uint32_t FLEXIO_GetInstance(FLEXIO_Type *base);
354
355 /* @} */
356
357 /*!
358 * @name FlexIO Basic Operation
359 * @{
360 */
361
362 /*!
363 * @brief Resets the FlexIO module.
364 *
365 * @param base FlexIO peripheral base address
366 */
367 void FLEXIO_Reset(FLEXIO_Type *base);
368
369 /*!
370 * @brief Enables the FlexIO module operation.
371 *
372 * @param base FlexIO peripheral base address
373 * @param enable true to enable, false to disable.
374 */
FLEXIO_Enable(FLEXIO_Type * base,bool enable)375 static inline void FLEXIO_Enable(FLEXIO_Type *base, bool enable)
376 {
377 if (enable)
378 {
379 base->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;
380 }
381 else
382 {
383 base->CTRL &= ~FLEXIO_CTRL_FLEXEN_MASK;
384 }
385 }
386
387 #if defined(FSL_FEATURE_FLEXIO_HAS_PIN_STATUS) && FSL_FEATURE_FLEXIO_HAS_PIN_STATUS
388 /*!
389 * @brief Reads the input data on each of the FlexIO pins.
390 *
391 * @param base FlexIO peripheral base address
392 * @return FlexIO pin input data
393 */
FLEXIO_ReadPinInput(FLEXIO_Type * base)394 static inline uint32_t FLEXIO_ReadPinInput(FLEXIO_Type *base)
395 {
396 return base->PIN;
397 }
398 #endif /*FSL_FEATURE_FLEXIO_HAS_PIN_STATUS*/
399
400 #if defined(FSL_FEATURE_FLEXIO_HAS_STATE_MODE) && FSL_FEATURE_FLEXIO_HAS_STATE_MODE
401 /*!
402 * @brief Gets the current state pointer for state mode use.
403 *
404 * @param base FlexIO peripheral base address
405 * @return current State pointer
406 */
FLEXIO_GetShifterState(FLEXIO_Type * base)407 static inline uint8_t FLEXIO_GetShifterState(FLEXIO_Type *base)
408 {
409 return ((uint8_t)(base->SHIFTSTATE) & FLEXIO_SHIFTSTATE_STATE_MASK);
410 }
411 #endif /*FSL_FEATURE_FLEXIO_HAS_STATE_MODE*/
412
413 /*!
414 * @brief Configures the shifter with the shifter configuration. The configuration structure
415 * covers both the SHIFTCTL and SHIFTCFG registers. To configure the shifter to the proper
416 * mode, select which timer controls the shifter to shift, whether to generate start bit/stop
417 * bit, and the polarity of start bit and stop bit.
418 *
419 * Example
420 @code
421 flexio_shifter_config_t config = {
422 .timerSelect = 0,
423 .timerPolarity = kFLEXIO_ShifterTimerPolarityOnPositive,
424 .pinConfig = kFLEXIO_PinConfigOpenDrainOrBidirection,
425 .pinPolarity = kFLEXIO_PinActiveLow,
426 .shifterMode = kFLEXIO_ShifterModeTransmit,
427 .inputSource = kFLEXIO_ShifterInputFromPin,
428 .shifterStop = kFLEXIO_ShifterStopBitHigh,
429 .shifterStart = kFLEXIO_ShifterStartBitLow
430 };
431 FLEXIO_SetShifterConfig(base, &config);
432 @endcode
433 *
434 * @param base FlexIO peripheral base address
435 * @param index Shifter index
436 * @param shifterConfig Pointer to flexio_shifter_config_t structure
437 */
438 void FLEXIO_SetShifterConfig(FLEXIO_Type *base, uint8_t index, const flexio_shifter_config_t *shifterConfig);
439 /*!
440 * @brief Configures the timer with the timer configuration. The configuration structure
441 * covers both the TIMCTL and TIMCFG registers. To configure the timer to the proper
442 * mode, select trigger source for timer and the timer pin output and the timing for timer.
443 *
444 * Example
445 @code
446 flexio_timer_config_t config = {
447 .triggerSelect = FLEXIO_TIMER_TRIGGER_SEL_SHIFTnSTAT(0),
448 .triggerPolarity = kFLEXIO_TimerTriggerPolarityActiveLow,
449 .triggerSource = kFLEXIO_TimerTriggerSourceInternal,
450 .pinConfig = kFLEXIO_PinConfigOpenDrainOrBidirection,
451 .pinSelect = 0,
452 .pinPolarity = kFLEXIO_PinActiveHigh,
453 .timerMode = kFLEXIO_TimerModeDual8BitBaudBit,
454 .timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset,
455 .timerDecrement = kFLEXIO_TimerDecSrcOnFlexIOClockShiftTimerOutput,
456 .timerReset = kFLEXIO_TimerResetOnTimerPinEqualToTimerOutput,
457 .timerDisable = kFLEXIO_TimerDisableOnTimerCompare,
458 .timerEnable = kFLEXIO_TimerEnableOnTriggerHigh,
459 .timerStop = kFLEXIO_TimerStopBitEnableOnTimerDisable,
460 .timerStart = kFLEXIO_TimerStartBitEnabled
461 };
462 FLEXIO_SetTimerConfig(base, &config);
463 @endcode
464 *
465 * @param base FlexIO peripheral base address
466 * @param index Timer index
467 * @param timerConfig Pointer to the flexio_timer_config_t structure
468 */
469 void FLEXIO_SetTimerConfig(FLEXIO_Type *base, uint8_t index, const flexio_timer_config_t *timerConfig);
470
471 /* @} */
472
473 /*!
474 * @name FlexIO Interrupt Operation
475 * @{
476 */
477
478 /*!
479 * @brief Enables the shifter status interrupt. The interrupt generates when the corresponding SSF is set.
480 *
481 * @param base FlexIO peripheral base address
482 * @param mask The shifter status mask which can be calculated by (1 << shifter index)
483 * @note For multiple shifter status interrupt enable, for example, two shifter status enable, can calculate
484 * the mask by using ((1 << shifter index0) | (1 << shifter index1))
485 */
FLEXIO_EnableShifterStatusInterrupts(FLEXIO_Type * base,uint32_t mask)486 static inline void FLEXIO_EnableShifterStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
487 {
488 base->SHIFTSIEN |= mask;
489 }
490
491 /*!
492 * @brief Disables the shifter status interrupt. The interrupt won't generate when the corresponding SSF is set.
493 *
494 * @param base FlexIO peripheral base address
495 * @param mask The shifter status mask which can be calculated by (1 << shifter index)
496 * @note For multiple shifter status interrupt enable, for example, two shifter status enable, can calculate
497 * the mask by using ((1 << shifter index0) | (1 << shifter index1))
498 */
FLEXIO_DisableShifterStatusInterrupts(FLEXIO_Type * base,uint32_t mask)499 static inline void FLEXIO_DisableShifterStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
500 {
501 base->SHIFTSIEN &= ~mask;
502 }
503
504 /*!
505 * @brief Enables the shifter error interrupt. The interrupt generates when the corresponding SEF is set.
506 *
507 * @param base FlexIO peripheral base address
508 * @param mask The shifter error mask which can be calculated by (1 << shifter index)
509 * @note For multiple shifter error interrupt enable, for example, two shifter error enable, can calculate
510 * the mask by using ((1 << shifter index0) | (1 << shifter index1))
511 */
FLEXIO_EnableShifterErrorInterrupts(FLEXIO_Type * base,uint32_t mask)512 static inline void FLEXIO_EnableShifterErrorInterrupts(FLEXIO_Type *base, uint32_t mask)
513 {
514 base->SHIFTEIEN |= mask;
515 }
516
517 /*!
518 * @brief Disables the shifter error interrupt. The interrupt won't generate when the corresponding SEF is set.
519 *
520 * @param base FlexIO peripheral base address
521 * @param mask The shifter error mask which can be calculated by (1 << shifter index)
522 * @note For multiple shifter error interrupt enable, for example, two shifter error enable, can calculate
523 * the mask by using ((1 << shifter index0) | (1 << shifter index1))
524 */
FLEXIO_DisableShifterErrorInterrupts(FLEXIO_Type * base,uint32_t mask)525 static inline void FLEXIO_DisableShifterErrorInterrupts(FLEXIO_Type *base, uint32_t mask)
526 {
527 base->SHIFTEIEN &= ~mask;
528 }
529
530 /*!
531 * @brief Enables the timer status interrupt. The interrupt generates when the corresponding SSF is set.
532 *
533 * @param base FlexIO peripheral base address
534 * @param mask The timer status mask which can be calculated by (1 << timer index)
535 * @note For multiple timer status interrupt enable, for example, two timer status enable, can calculate
536 * the mask by using ((1 << timer index0) | (1 << timer index1))
537 */
FLEXIO_EnableTimerStatusInterrupts(FLEXIO_Type * base,uint32_t mask)538 static inline void FLEXIO_EnableTimerStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
539 {
540 base->TIMIEN |= mask;
541 }
542
543 /*!
544 * @brief Disables the timer status interrupt. The interrupt won't generate when the corresponding SSF is set.
545 *
546 * @param base FlexIO peripheral base address
547 * @param mask The timer status mask which can be calculated by (1 << timer index)
548 * @note For multiple timer status interrupt enable, for example, two timer status enable, can calculate
549 * the mask by using ((1 << timer index0) | (1 << timer index1))
550 */
FLEXIO_DisableTimerStatusInterrupts(FLEXIO_Type * base,uint32_t mask)551 static inline void FLEXIO_DisableTimerStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
552 {
553 base->TIMIEN &= ~mask;
554 }
555
556 /* @} */
557
558 /*!
559 * @name FlexIO Status Operation
560 * @{
561 */
562
563 /*!
564 * @brief Gets the shifter status flags.
565 *
566 * @param base FlexIO peripheral base address
567 * @return Shifter status flags
568 */
FLEXIO_GetShifterStatusFlags(FLEXIO_Type * base)569 static inline uint32_t FLEXIO_GetShifterStatusFlags(FLEXIO_Type *base)
570 {
571 return ((base->SHIFTSTAT) & FLEXIO_SHIFTSTAT_SSF_MASK);
572 }
573
574 /*!
575 * @brief Clears the shifter status flags.
576 *
577 * @param base FlexIO peripheral base address
578 * @param mask The shifter status mask which can be calculated by (1 << shifter index)
579 * @note For clearing multiple shifter status flags, for example, two shifter status flags, can calculate
580 * the mask by using ((1 << shifter index0) | (1 << shifter index1))
581 */
FLEXIO_ClearShifterStatusFlags(FLEXIO_Type * base,uint32_t mask)582 static inline void FLEXIO_ClearShifterStatusFlags(FLEXIO_Type *base, uint32_t mask)
583 {
584 base->SHIFTSTAT = mask;
585 }
586
587 /*!
588 * @brief Gets the shifter error flags.
589 *
590 * @param base FlexIO peripheral base address
591 * @return Shifter error flags
592 */
FLEXIO_GetShifterErrorFlags(FLEXIO_Type * base)593 static inline uint32_t FLEXIO_GetShifterErrorFlags(FLEXIO_Type *base)
594 {
595 return ((base->SHIFTERR) & FLEXIO_SHIFTERR_SEF_MASK);
596 }
597
598 /*!
599 * @brief Clears the shifter error flags.
600 *
601 * @param base FlexIO peripheral base address
602 * @param mask The shifter error mask which can be calculated by (1 << shifter index)
603 * @note For clearing multiple shifter error flags, for example, two shifter error flags, can calculate
604 * the mask by using ((1 << shifter index0) | (1 << shifter index1))
605 */
FLEXIO_ClearShifterErrorFlags(FLEXIO_Type * base,uint32_t mask)606 static inline void FLEXIO_ClearShifterErrorFlags(FLEXIO_Type *base, uint32_t mask)
607 {
608 base->SHIFTERR = mask;
609 }
610
611 /*!
612 * @brief Gets the timer status flags.
613 *
614 * @param base FlexIO peripheral base address
615 * @return Timer status flags
616 */
FLEXIO_GetTimerStatusFlags(FLEXIO_Type * base)617 static inline uint32_t FLEXIO_GetTimerStatusFlags(FLEXIO_Type *base)
618 {
619 return ((base->TIMSTAT) & FLEXIO_TIMSTAT_TSF_MASK);
620 }
621
622 /*!
623 * @brief Clears the timer status flags.
624 *
625 * @param base FlexIO peripheral base address
626 * @param mask The timer status mask which can be calculated by (1 << timer index)
627 * @note For clearing multiple timer status flags, for example, two timer status flags, can calculate
628 * the mask by using ((1 << timer index0) | (1 << timer index1))
629 */
FLEXIO_ClearTimerStatusFlags(FLEXIO_Type * base,uint32_t mask)630 static inline void FLEXIO_ClearTimerStatusFlags(FLEXIO_Type *base, uint32_t mask)
631 {
632 base->TIMSTAT = mask;
633 }
634
635 /* @} */
636
637 /*!
638 * @name FlexIO DMA Operation
639 * @{
640 */
641
642 /*!
643 * @brief Enables/disables the shifter status DMA. The DMA request generates when the corresponding SSF is set.
644 *
645 * @note For multiple shifter status DMA enables, for example, calculate
646 * the mask by using ((1 << shifter index0) | (1 << shifter index1))
647 *
648 * @param base FlexIO peripheral base address
649 * @param mask The shifter status mask which can be calculated by (1 << shifter index)
650 * @param enable True to enable, false to disable.
651 */
FLEXIO_EnableShifterStatusDMA(FLEXIO_Type * base,uint32_t mask,bool enable)652 static inline void FLEXIO_EnableShifterStatusDMA(FLEXIO_Type *base, uint32_t mask, bool enable)
653 {
654 if (enable)
655 {
656 base->SHIFTSDEN |= mask;
657 }
658 else
659 {
660 base->SHIFTSDEN &= ~mask;
661 }
662 }
663
664 /*!
665 * @brief Gets the shifter buffer address for the DMA transfer usage.
666 *
667 * @param base FlexIO peripheral base address
668 * @param type Shifter type of flexio_shifter_buffer_type_t
669 * @param index Shifter index
670 * @return Corresponding shifter buffer index
671 */
672 uint32_t FLEXIO_GetShifterBufferAddress(FLEXIO_Type *base, flexio_shifter_buffer_type_t type, uint8_t index);
673
674 /*!
675 * @brief Registers the handle and the interrupt handler for the FlexIO-simulated peripheral.
676 *
677 * @param base Pointer to the FlexIO simulated peripheral type.
678 * @param handle Pointer to the handler for FlexIO simulated peripheral.
679 * @param isr FlexIO simulated peripheral interrupt handler.
680 * @retval kStatus_Success Successfully create the handle.
681 * @retval kStatus_OutOfRange The FlexIO type/handle/ISR table out of range.
682 */
683 status_t FLEXIO_RegisterHandleIRQ(void *base, void *handle, flexio_isr_t isr);
684
685 /*!
686 * @brief Unregisters the handle and the interrupt handler for the FlexIO-simulated peripheral.
687 *
688 * @param base Pointer to the FlexIO simulated peripheral type.
689 * @retval kStatus_Success Successfully create the handle.
690 * @retval kStatus_OutOfRange The FlexIO type/handle/ISR table out of range.
691 */
692 status_t FLEXIO_UnregisterHandleIRQ(void *base);
693 /* @} */
694
695 #if defined(__cplusplus)
696 }
697 #endif /*_cplusplus*/
698 /*@}*/
699
700 #endif /*_FSL_FLEXIO_H_*/
701