1 /*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2023 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #ifndef FSL_FLEXIO_MCULCD_H_
10 #define FSL_FLEXIO_MCULCD_H_
11
12 #include "fsl_common.h"
13 #include "fsl_flexio.h"
14
15 /*!
16 * @addtogroup flexio_mculcd
17 * @{
18 */
19
20 /*******************************************************************************
21 * Definitions
22 ******************************************************************************/
23
24 /*! @name Driver version */
25 /*! @{ */
26 /*! @brief FlexIO MCULCD driver version. */
27 #define FSL_FLEXIO_MCULCD_DRIVER_VERSION (MAKE_VERSION(2, 2, 0))
28 /*! @} */
29
30 #ifndef FLEXIO_MCULCD_WAIT_COMPLETE_TIME
31 /*!
32 * @brief The delay time to wait for FLEXIO transmit complete.
33 *
34 * Currently there is no method to detect whether the data has been
35 * sent out from the shifter, so the driver use a software delay for this. When
36 * the data is written to shifter buffer, the driver call the delay
37 * function to wait for the data shift out.
38 * If this value is too small, then the last few bytes might be lost when writing
39 * data using interrupt method or DMA method.
40 */
41 #define FLEXIO_MCULCD_WAIT_COMPLETE_TIME 512
42 #endif
43
44 #ifndef FLEXIO_MCULCD_DATA_BUS_WIDTH
45 /*!
46 * @brief The data bus width, must be 8 or 16.
47 */
48 #define FLEXIO_MCULCD_DATA_BUS_WIDTH 16UL
49 #endif
50
51 #if (16UL != FLEXIO_MCULCD_DATA_BUS_WIDTH) && (8UL != FLEXIO_MCULCD_DATA_BUS_WIDTH)
52 #error Only support data bus 8-bit or 16-bit
53 #endif
54
55 /*! @brief FlexIO LCD transfer status */
56 enum
57 {
58 kStatus_FLEXIO_MCULCD_Idle = MAKE_STATUS(kStatusGroup_FLEXIO_MCULCD, 0), /*!< FlexIO LCD is idle. */
59 kStatus_FLEXIO_MCULCD_Busy = MAKE_STATUS(kStatusGroup_FLEXIO_MCULCD, 1), /*!< FlexIO LCD is busy */
60 kStatus_FLEXIO_MCULCD_Error = MAKE_STATUS(kStatusGroup_FLEXIO_MCULCD, 2), /*!< FlexIO LCD error occurred */
61 };
62
63 /*! @brief Define FlexIO MCULCD pixel format. */
64 typedef enum _flexio_mculcd_pixel_format
65 {
66 kFLEXIO_MCULCD_RGB565 = 0, /*!< RGB565, 16-bit. */
67 kFLEXIO_MCULCD_BGR565, /*!< BGR565, 16-bit. */
68 kFLEXIO_MCULCD_RGB888, /*!< RGB888, 24-bit. */
69 kFLEXIO_MCULCD_BGR888, /*!< BGR888, 24-bit. */
70 } flexio_mculcd_pixel_format_t;
71
72 /*! @brief Define FlexIO MCULCD bus type. */
73 typedef enum _flexio_mculcd_bus
74 {
75 kFLEXIO_MCULCD_8080, /*!< Using Intel 8080 bus. */
76 kFLEXIO_MCULCD_6800, /*!< Using Motorola 6800 bus. */
77 } flexio_mculcd_bus_t;
78
79 /*! @brief Define FlexIO MCULCD interrupt mask. */
80 enum _flexio_mculcd_interrupt_enable
81 {
82 kFLEXIO_MCULCD_TxEmptyInterruptEnable = (1U << 0U), /*!< Transmit buffer empty interrupt enable. */
83 kFLEXIO_MCULCD_RxFullInterruptEnable = (1U << 1U), /*!< Receive buffer full interrupt enable. */
84 };
85
86 /*! @brief Define FlexIO MCULCD status mask. */
87 enum _flexio_mculcd_status_flags
88 {
89 kFLEXIO_MCULCD_TxEmptyFlag = (1U << 0U), /*!< Transmit buffer empty flag. */
90 kFLEXIO_MCULCD_RxFullFlag = (1U << 1U), /*!< Receive buffer full flag. */
91 };
92
93 /*! @brief Define FlexIO MCULCD DMA mask. */
94 enum _flexio_mculcd_dma_enable
95 {
96 kFLEXIO_MCULCD_TxDmaEnable = 0x1U, /*!< Tx DMA request source */
97 kFLEXIO_MCULCD_RxDmaEnable = 0x2U, /*!< Rx DMA request source */
98 };
99
100 #ifndef FLEXIO_MCULCD_LEGACY_GPIO_FUNC
101 #define FLEXIO_MCULCD_LEGACY_GPIO_FUNC 1
102 #endif
103
104 #if FLEXIO_MCULCD_LEGACY_GPIO_FUNC
105 /*! @brief Function to set or clear the CS and RS pin. */
106 typedef void (*flexio_mculcd_pin_func_t)(bool set);
107 #else
108 /*! @brief Function to set or clear the CS and RS pin. */
109 typedef void (*flexio_mculcd_pin_func_t)(bool set, void *userData);
110 #endif
111
112 /*! @brief Define FlexIO MCULCD access structure typedef. */
113 typedef struct _flexio_mculcd_type
114 {
115 FLEXIO_Type *flexioBase; /*!< FlexIO base pointer. */
116 flexio_mculcd_bus_t busType; /*!< The bus type, 8080 or 6800. */
117 uint8_t dataPinStartIndex; /*!< Start index of the data pin, the FlexIO pin dataPinStartIndex
118 to (dataPinStartIndex + FLEXIO_MCULCD_DATA_BUS_WIDTH -1)
119 will be used for data transfer. Only support data bus width 8 and 16. */
120 uint8_t ENWRPinIndex; /*!< Pin select for WR(8080 mode), EN(6800 mode). */
121 uint8_t RDPinIndex; /*!< Pin select for RD(8080 mode), not used in 6800 mode. */
122 uint8_t txShifterStartIndex; /*!< Start index of shifters used for data write, it must be 0 or 4. */
123 uint8_t txShifterEndIndex; /*!< End index of shifters used for data write. */
124 uint8_t rxShifterStartIndex; /*!< Start index of shifters used for data read. */
125 uint8_t rxShifterEndIndex; /*!< End index of shifters used for data read, it must be 3 or 7. */
126 uint8_t timerIndex; /*!< Timer index used in FlexIO MCULCD. */
127 flexio_mculcd_pin_func_t setCSPin; /*!< Function to set or clear the CS pin. */
128 flexio_mculcd_pin_func_t setRSPin; /*!< Function to set or clear the RS pin. */
129 flexio_mculcd_pin_func_t setRDWRPin; /*!< Function to set or clear the RD/WR pin, only used in 6800 mode. */
130 #if !FLEXIO_MCULCD_LEGACY_GPIO_FUNC
131 void *userData; /*!< Function parameter.*/
132 #endif
133 } FLEXIO_MCULCD_Type;
134
135 /*! @brief Define FlexIO MCULCD configuration structure. */
136 typedef struct _flexio_mculcd_config
137 {
138 bool enable; /*!< Enable/disable FlexIO MCULCD after configuration. */
139 bool enableInDoze; /*!< Enable/disable FlexIO operation in doze mode. */
140 bool enableInDebug; /*!< Enable/disable FlexIO operation in debug mode. */
141 bool enableFastAccess; /*!< Enable/disable fast access to FlexIO registers,
142 fast access requires the FlexIO clock to be at least
143 twice the frequency of the bus clock. */
144 uint32_t baudRate_Bps; /*!< Baud rate in bit-per-second for all data lines combined. */
145 } flexio_mculcd_config_t;
146
147 /*! @brief Transfer mode.*/
148 typedef enum _flexio_mculcd_transfer_mode
149 {
150 kFLEXIO_MCULCD_ReadArray, /*!< Read data into an array. */
151 kFLEXIO_MCULCD_WriteArray, /*!< Write data from an array. */
152 kFLEXIO_MCULCD_WriteSameValue, /*!< Write the same value many times. */
153 } flexio_mculcd_transfer_mode_t;
154
155 /*! @brief Define FlexIO MCULCD transfer structure. */
156 typedef struct _flexio_mculcd_transfer
157 {
158 uint32_t command; /*!< Command to send. */
159 uint32_t dataAddrOrSameValue; /*!< When sending the same value for many times,
160 this is the value to send. When writing or reading array,
161 this is the address of the data array. */
162 size_t dataSize; /*!< How many bytes to transfer. */
163 flexio_mculcd_transfer_mode_t mode; /*!< Transfer mode. */
164 bool dataOnly; /*!< Send data only when tx without the command. */
165 } flexio_mculcd_transfer_t;
166
167 /*! @brief typedef for flexio_mculcd_handle_t in advance. */
168 typedef struct _flexio_mculcd_handle flexio_mculcd_handle_t;
169
170 /*! @brief FlexIO MCULCD callback for finished transfer.
171 *
172 * When transfer finished, the callback function is called and returns the
173 * @p status as kStatus_FLEXIO_MCULCD_Idle.
174 */
175 typedef void (*flexio_mculcd_transfer_callback_t)(FLEXIO_MCULCD_Type *base,
176 flexio_mculcd_handle_t *handle,
177 status_t status,
178 void *userData);
179
180 /*! @brief Define FlexIO MCULCD handle structure. */
181 struct _flexio_mculcd_handle
182 {
183 uint32_t dataAddrOrSameValue; /*!< When sending the same value for many times,
184 this is the value to send. When writing or reading array,
185 this is the address of the data array. */
186 size_t dataCount; /*!< Total count to be transferred. */
187 volatile size_t remainingCount; /*!< Remaining count to transfer. */
188 volatile uint32_t state; /*!< FlexIO MCULCD internal state. */
189 flexio_mculcd_transfer_callback_t completionCallback; /*!< FlexIO MCULCD transfer completed callback. */
190 void *userData; /*!< Callback parameter. */
191 };
192
193 /*******************************************************************************
194 * API
195 ******************************************************************************/
196
197 #if defined(__cplusplus)
198 extern "C" {
199 #endif /*_cplusplus*/
200
201 /*!
202 * @name FlexIO MCULCD Configuration
203 * @{
204 */
205
206 /*!
207 * @brief Ungates the FlexIO clock, resets the FlexIO module, configures the
208 * FlexIO MCULCD hardware, and configures the FlexIO MCULCD with FlexIO MCULCD
209 * configuration.
210 * The configuration structure can be filled by the user, or be set with default
211 * values
212 * by the @ref FLEXIO_MCULCD_GetDefaultConfig.
213 *
214 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
215 * @param config Pointer to the flexio_mculcd_config_t structure.
216 * @param srcClock_Hz FlexIO source clock in Hz.
217 * @retval kStatus_Success Initialization success.
218 * @retval kStatus_InvalidArgument Initialization failed because of invalid
219 * argument.
220 */
221 status_t FLEXIO_MCULCD_Init(FLEXIO_MCULCD_Type *base, flexio_mculcd_config_t *config, uint32_t srcClock_Hz);
222
223 /*!
224 * @brief Resets the FLEXIO_MCULCD timer and shifter configuration.
225 *
226 * @param base Pointer to the FLEXIO_MCULCD_Type.
227 */
228 void FLEXIO_MCULCD_Deinit(FLEXIO_MCULCD_Type *base);
229
230 /*!
231 * @brief Gets the default configuration to configure the FlexIO MCULCD.
232 *
233 * The default configuration value is:
234 * @code
235 * config->enable = true;
236 * config->enableInDoze = false;
237 * config->enableInDebug = true;
238 * config->enableFastAccess = true;
239 * config->baudRate_Bps = 96000000U;
240 * @endcode
241 * @param config Pointer to the flexio_mculcd_config_t structure.
242 */
243 void FLEXIO_MCULCD_GetDefaultConfig(flexio_mculcd_config_t *config);
244
245 /*! @} */
246
247 /*!
248 * @name Status
249 * @{
250 */
251
252 /*!
253 * @brief Gets FlexIO MCULCD status flags.
254 *
255 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
256 * @return status flag; OR'ed value or the @ref _flexio_mculcd_status_flags.
257 *
258 * @note Don't use this function with DMA APIs.
259 */
260 uint32_t FLEXIO_MCULCD_GetStatusFlags(FLEXIO_MCULCD_Type *base);
261
262 /*!
263 * @brief Clears FlexIO MCULCD status flags.
264 *
265 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
266 * @param mask Status to clear, it is the OR'ed value of @ref
267 * _flexio_mculcd_status_flags.
268 *
269 * @note Don't use this function with DMA APIs.
270 */
271 void FLEXIO_MCULCD_ClearStatusFlags(FLEXIO_MCULCD_Type *base, uint32_t mask);
272
273 /*! @} */
274
275 /*!
276 * @name Interrupts
277 * @{
278 */
279
280 /*!
281 * @brief Enables the FlexIO MCULCD interrupt.
282 *
283 * This function enables the FlexIO MCULCD interrupt.
284 *
285 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
286 * @param mask Interrupts to enable, it is the OR'ed value of @ref
287 * _flexio_mculcd_interrupt_enable.
288 */
289 void FLEXIO_MCULCD_EnableInterrupts(FLEXIO_MCULCD_Type *base, uint32_t mask);
290
291 /*!
292 * @brief Disables the FlexIO MCULCD interrupt.
293 *
294 * This function disables the FlexIO MCULCD interrupt.
295 *
296 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
297 * @param mask Interrupts to disable, it is the OR'ed value of @ref
298 * _flexio_mculcd_interrupt_enable.
299 */
300 void FLEXIO_MCULCD_DisableInterrupts(FLEXIO_MCULCD_Type *base, uint32_t mask);
301
302 /*! @} */
303
304 /*!
305 * @name DMA Control
306 * @{
307 */
308
309 /*!
310 * @brief Enables/disables the FlexIO MCULCD transmit DMA.
311 *
312 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
313 * @param enable True means enable DMA, false means disable DMA.
314 */
FLEXIO_MCULCD_EnableTxDMA(FLEXIO_MCULCD_Type * base,bool enable)315 static inline void FLEXIO_MCULCD_EnableTxDMA(FLEXIO_MCULCD_Type *base, bool enable)
316 {
317 FLEXIO_EnableShifterStatusDMA(base->flexioBase, (1UL << base->txShifterStartIndex), enable);
318 }
319
320 /*!
321 * @brief Enables/disables the FlexIO MCULCD receive DMA.
322 *
323 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
324 * @param enable True means enable DMA, false means disable DMA.
325 */
FLEXIO_MCULCD_EnableRxDMA(FLEXIO_MCULCD_Type * base,bool enable)326 static inline void FLEXIO_MCULCD_EnableRxDMA(FLEXIO_MCULCD_Type *base, bool enable)
327 {
328 FLEXIO_EnableShifterStatusDMA(base->flexioBase, (1UL << base->rxShifterEndIndex), enable);
329 }
330
331 /*!
332 * @brief Gets the FlexIO MCULCD transmit data register address.
333 *
334 * This function returns the MCULCD data register address, which is mainly used
335 * by DMA/eDMA.
336 *
337 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
338 * @return FlexIO MCULCD transmit data register address.
339 */
FLEXIO_MCULCD_GetTxDataRegisterAddress(FLEXIO_MCULCD_Type * base)340 static inline uint32_t FLEXIO_MCULCD_GetTxDataRegisterAddress(FLEXIO_MCULCD_Type *base)
341 {
342 return (uint32_t) & (base->flexioBase->SHIFTBUF[base->txShifterStartIndex]);
343 }
344
345 /*!
346 * @brief Gets the FlexIO MCULCD receive data register address.
347 *
348 * This function returns the MCULCD data register address, which is mainly used
349 * by DMA/eDMA.
350 *
351 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
352 * @return FlexIO MCULCD receive data register address.
353 */
FLEXIO_MCULCD_GetRxDataRegisterAddress(FLEXIO_MCULCD_Type * base)354 static inline uint32_t FLEXIO_MCULCD_GetRxDataRegisterAddress(FLEXIO_MCULCD_Type *base)
355 {
356 return (uint32_t) & (base->flexioBase->SHIFTBUF[base->rxShifterStartIndex]);
357 }
358
359 /*! @} */
360
361 /*!
362 * @name Bus Operations
363 * @{
364 */
365
366 /*!
367 * @brief Set desired baud rate.
368 *
369 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
370 * @param baudRate_Bps Desired baud rate in bit-per-second for all data lines combined.
371 * @param srcClock_Hz FLEXIO clock frequency in Hz.
372 * @retval kStatus_Success Set successfully.
373 * @retval kStatus_InvalidArgument Could not set the baud rate.
374 */
375 status_t FLEXIO_MCULCD_SetBaudRate(FLEXIO_MCULCD_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz);
376
377 /*!
378 * @brief Configures the FLEXIO MCULCD to multiple beats write mode.
379 *
380 * At the begining multiple beats write operation, the FLEXIO MCULCD is configured to
381 * multiple beats write mode using this function. After write operation, the configuration
382 * is cleared by @ref FLEXIO_MCULCD_ClearSingleBeatWriteConfig.
383 *
384 * @param base Pointer to the FLEXIO_MCULCD_Type.
385 *
386 * @note This is an internal used function, upper layer should not use.
387 */
388 void FLEXIO_MCULCD_SetSingleBeatWriteConfig(FLEXIO_MCULCD_Type *base);
389
390 /*!
391 * @brief Clear the FLEXIO MCULCD multiple beats write mode configuration.
392 *
393 * Clear the write configuration set by @ref FLEXIO_MCULCD_SetSingleBeatWriteConfig.
394 *
395 * @param base Pointer to the FLEXIO_MCULCD_Type.
396 *
397 * @note This is an internal used function, upper layer should not use.
398 */
399 void FLEXIO_MCULCD_ClearSingleBeatWriteConfig(FLEXIO_MCULCD_Type *base);
400
401 /*!
402 * @brief Configures the FLEXIO MCULCD to multiple beats read mode.
403 *
404 * At the begining or multiple beats read operation, the FLEXIO MCULCD is configured
405 * to multiple beats read mode using this function. After read operation, the configuration
406 * is cleared by @ref FLEXIO_MCULCD_ClearSingleBeatReadConfig.
407 *
408 * @param base Pointer to the FLEXIO_MCULCD_Type.
409 *
410 * @note This is an internal used function, upper layer should not use.
411 */
412 void FLEXIO_MCULCD_SetSingleBeatReadConfig(FLEXIO_MCULCD_Type *base);
413
414 /*!
415 * @brief Clear the FLEXIO MCULCD multiple beats read mode configuration.
416 *
417 * Clear the read configuration set by @ref FLEXIO_MCULCD_SetSingleBeatReadConfig.
418 *
419 * @param base Pointer to the FLEXIO_MCULCD_Type.
420 *
421 * @note This is an internal used function, upper layer should not use.
422 */
423 void FLEXIO_MCULCD_ClearSingleBeatReadConfig(FLEXIO_MCULCD_Type *base);
424
425 /*!
426 * @brief Configures the FLEXIO MCULCD to multiple beats write mode.
427 *
428 * At the begining multiple beats write operation, the FLEXIO MCULCD is configured to
429 * multiple beats write mode using this function. After write operation, the configuration
430 * is cleared by FLEXIO_MCULCD_ClearMultBeatsWriteConfig.
431 *
432 * @param base Pointer to the FLEXIO_MCULCD_Type.
433 *
434 * @note This is an internal used function, upper layer should not use.
435 */
436 void FLEXIO_MCULCD_SetMultiBeatsWriteConfig(FLEXIO_MCULCD_Type *base);
437
438 /*!
439 * @brief Clear the FLEXIO MCULCD multiple beats write mode configuration.
440 *
441 * Clear the write configuration set by FLEXIO_MCULCD_SetMultBeatsWriteConfig.
442 *
443 * @param base Pointer to the FLEXIO_MCULCD_Type.
444 *
445 * @note This is an internal used function, upper layer should not use.
446 */
447 void FLEXIO_MCULCD_ClearMultiBeatsWriteConfig(FLEXIO_MCULCD_Type *base);
448
449 /*!
450 * @brief Configures the FLEXIO MCULCD to multiple beats read mode.
451 *
452 * At the begining or multiple beats read operation, the FLEXIO MCULCD is configured
453 * to multiple beats read mode using this function. After read operation, the configuration
454 * is cleared by FLEXIO_MCULCD_ClearMultBeatsReadConfig.
455 *
456 * @param base Pointer to the FLEXIO_MCULCD_Type.
457 *
458 * @note This is an internal used function, upper layer should not use.
459 */
460 void FLEXIO_MCULCD_SetMultiBeatsReadConfig(FLEXIO_MCULCD_Type *base);
461
462 /*!
463 * @brief Clear the FLEXIO MCULCD multiple beats read mode configuration.
464 *
465 * Clear the read configuration set by FLEXIO_MCULCD_SetMultBeatsReadConfig.
466 *
467 * @param base Pointer to the FLEXIO_MCULCD_Type.
468 *
469 * @note This is an internal used function, upper layer should not use.
470 */
471 void FLEXIO_MCULCD_ClearMultiBeatsReadConfig(FLEXIO_MCULCD_Type *base);
472
473 /*!
474 * @brief Enables/disables the FlexIO MCULCD module operation.
475 *
476 * @param base Pointer to the FLEXIO_MCULCD_Type.
477 * @param enable True to enable, false does not have any effect.
478 */
FLEXIO_MCULCD_Enable(FLEXIO_MCULCD_Type * base,bool enable)479 static inline void FLEXIO_MCULCD_Enable(FLEXIO_MCULCD_Type *base, bool enable)
480 {
481 if (enable)
482 {
483 FLEXIO_Enable(base->flexioBase, enable);
484 }
485 }
486
487 /*!
488 * @brief Read data from the FLEXIO MCULCD RX shifter buffer.
489 *
490 * Read data from the RX shift buffer directly, it does no check whether the
491 * buffer is empty or not.
492 *
493 * If the data bus width is 8-bit:
494 * @code
495 * uint8_t value;
496 * value = (uint8_t)FLEXIO_MCULCD_ReadData(base);
497 * @endcode
498 *
499 * If the data bus width is 16-bit:
500 * @code
501 * uint16_t value;
502 * value = (uint16_t)FLEXIO_MCULCD_ReadData(base);
503 * @endcode
504 *
505 * @note This function returns the RX shifter buffer value (32-bit) directly.
506 * The return value should be converted according to data bus width.
507 *
508 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
509 * @return The data read out.
510 *
511 * @note Don't use this function with DMA APIs.
512 */
513 uint32_t FLEXIO_MCULCD_ReadData(FLEXIO_MCULCD_Type *base);
514
515 /*!
516 * @brief Write data into the FLEXIO MCULCD TX shifter buffer.
517 *
518 * Write data into the TX shift buffer directly, it does no check whether the
519 * buffer is full or not.
520 *
521 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
522 * @param data The data to write.
523 *
524 * @note Don't use this function with DMA APIs.
525 */
FLEXIO_MCULCD_WriteData(FLEXIO_MCULCD_Type * base,uint32_t data)526 static inline void FLEXIO_MCULCD_WriteData(FLEXIO_MCULCD_Type *base, uint32_t data)
527 {
528 base->flexioBase->SHIFTBUF[base->txShifterStartIndex] = data;
529 }
530
531 /*!
532 * @brief Assert the nCS to start transfer.
533 *
534 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
535 */
FLEXIO_MCULCD_StartTransfer(FLEXIO_MCULCD_Type * base)536 static inline void FLEXIO_MCULCD_StartTransfer(FLEXIO_MCULCD_Type *base)
537 {
538 #if FLEXIO_MCULCD_LEGACY_GPIO_FUNC
539 base->setCSPin(false);
540 #else
541 base->setCSPin(false, base->userData);
542 #endif
543 }
544
545 /*!
546 * @brief De-assert the nCS to stop transfer.
547 *
548 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
549 */
FLEXIO_MCULCD_StopTransfer(FLEXIO_MCULCD_Type * base)550 static inline void FLEXIO_MCULCD_StopTransfer(FLEXIO_MCULCD_Type *base)
551 {
552 #if FLEXIO_MCULCD_LEGACY_GPIO_FUNC
553 base->setCSPin(true);
554 #else
555 base->setCSPin(true, base->userData);
556 #endif
557 }
558
559 /*!
560 * @brief Wait for transmit data send out finished.
561 *
562 * Currently there is no effective method to wait for the data send out
563 * from the shiter, so here use a while loop to wait.
564 *
565 * @note This is an internal used function.
566 */
567 void FLEXIO_MCULCD_WaitTransmitComplete(void);
568
569 /*!
570 * @brief Send command in blocking way.
571 *
572 * This function sends the command and returns when the command has been sent
573 * out.
574 *
575 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
576 * @param command The command to send.
577 */
578 void FLEXIO_MCULCD_WriteCommandBlocking(FLEXIO_MCULCD_Type *base, uint32_t command);
579
580 /*!
581 * @brief Send data array in blocking way.
582 *
583 * This function sends the data array and returns when the data sent out.
584 *
585 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
586 * @param data The data array to send.
587 * @param size How many bytes to write.
588 */
589 void FLEXIO_MCULCD_WriteDataArrayBlocking(FLEXIO_MCULCD_Type *base, const void *data, size_t size);
590
591 /*!
592 * @brief Read data into array in blocking way.
593 *
594 * This function reads the data into array and returns when the data read
595 * finished.
596 *
597 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
598 * @param data The array to save the data.
599 * @param size How many bytes to read.
600 */
601 void FLEXIO_MCULCD_ReadDataArrayBlocking(FLEXIO_MCULCD_Type *base, void *data, size_t size);
602
603 /*!
604 * @brief Send the same value many times in blocking way.
605 *
606 * This function sends the same value many times. It could be used to clear the
607 * LCD screen. If the data bus width is 8, this function will send LSB 8 bits of
608 * @p sameValue for @p size times. If the data bus is 16, this function will send
609 * LSB 16 bits of @p sameValue for @p size / 2 times.
610 *
611 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
612 * @param sameValue The same value to send.
613 * @param size How many bytes to send.
614 */
615 void FLEXIO_MCULCD_WriteSameValueBlocking(FLEXIO_MCULCD_Type *base, uint32_t sameValue, size_t size);
616
617 /*!
618 * @brief Performs a polling transfer.
619 *
620 * @note The API does not return until the transfer finished.
621 *
622 * @param base pointer to FLEXIO_MCULCD_Type structure.
623 * @param xfer pointer to flexio_mculcd_transfer_t structure.
624 */
625 void FLEXIO_MCULCD_TransferBlocking(FLEXIO_MCULCD_Type *base, flexio_mculcd_transfer_t *xfer);
626 /*! @} */
627
628 /*!
629 * @name Transactional
630 * @{
631 */
632
633 /*!
634 * @brief Initializes the FlexIO MCULCD handle, which is used in transactional
635 * functions.
636 *
637 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
638 * @param handle Pointer to the flexio_mculcd_handle_t structure to store the
639 * transfer state.
640 * @param callback The callback function.
641 * @param userData The parameter of the callback function.
642 * @retval kStatus_Success Successfully create the handle.
643 * @retval kStatus_OutOfRange The FlexIO type/handle/ISR table out of range.
644 */
645 status_t FLEXIO_MCULCD_TransferCreateHandle(FLEXIO_MCULCD_Type *base,
646 flexio_mculcd_handle_t *handle,
647 flexio_mculcd_transfer_callback_t callback,
648 void *userData);
649
650 /*!
651 * @brief Transfer data using IRQ.
652 *
653 * This function sends data using IRQ. This is a non-blocking function, which
654 * returns right away. When all data is sent out/received, the callback
655 * function is called.
656 *
657 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
658 * @param handle Pointer to the flexio_mculcd_handle_t structure to store the
659 * transfer state.
660 * @param xfer FlexIO MCULCD transfer structure. See #flexio_mculcd_transfer_t.
661 * @retval kStatus_Success Successfully start a transfer.
662 * @retval kStatus_InvalidArgument Input argument is invalid.
663 * @retval kStatus_FLEXIO_MCULCD_Busy MCULCD is busy with another transfer.
664 */
665 status_t FLEXIO_MCULCD_TransferNonBlocking(FLEXIO_MCULCD_Type *base,
666 flexio_mculcd_handle_t *handle,
667 flexio_mculcd_transfer_t *xfer);
668
669 /*!
670 * @brief Aborts the data transfer, which used IRQ.
671 *
672 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
673 * @param handle Pointer to the flexio_mculcd_handle_t structure to store the
674 * transfer state.
675 */
676 void FLEXIO_MCULCD_TransferAbort(FLEXIO_MCULCD_Type *base, flexio_mculcd_handle_t *handle);
677
678 /*!
679 * @brief Gets the data transfer status which used IRQ.
680 *
681 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
682 * @param handle Pointer to the flexio_mculcd_handle_t structure to store the
683 * transfer state.
684 * @param count How many bytes transferred so far by the non-blocking transaction.
685 * @retval kStatus_Success Get the transferred count Successfully.
686 * @retval kStatus_NoTransferInProgress No transfer in process.
687 */
688 status_t FLEXIO_MCULCD_TransferGetCount(FLEXIO_MCULCD_Type *base, flexio_mculcd_handle_t *handle, size_t *count);
689
690 /*!
691 * @brief FlexIO MCULCD IRQ handler function.
692 *
693 * @param base Pointer to the FLEXIO_MCULCD_Type structure.
694 * @param handle Pointer to the flexio_mculcd_handle_t structure to store the
695 * transfer state.
696 */
697 void FLEXIO_MCULCD_TransferHandleIRQ(void *base, void *handle);
698
699 /*! @} */
700
701 #if defined(__cplusplus)
702 }
703 #endif /*_cplusplus*/
704 /*! @} */
705
706 #endif /*FSL_FLEXIO_MCULCD_H_*/
707