fsl_flexio_mculcd.h 24 KB

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