The MCUXpresso SDK provides a peripheral driver for LCD (8080 or 6800 interface) function using Flexible I/O module of MCUXpresso SDK devices.
The FlexIO LCD driver supports both 8-bit and 16-bit data bus, 8080 and 6800 interface. User could change the macro FLEXIO_MCULCD_DATA_BUS_WIDTH to choose 8-bit data bus or 16-bit data bus.
The FlexIO LCD driver supports three kinds of data transfer:
- Send a data array. For example, send the LCD image data to the LCD controller.
- Send a value many times. For example, send 0 many times to clean the LCD screen.
- Read data into a data array. For example, read image from LCD controller.
The FlexIO LCD driver includes functional APIs and transactional APIs.
Functional APIs are feature/property target low level APIs. Functional APIs can be used for FlexIO LCD initialization/configuration/operation for optimization/customization purpose. Using the functional API requires the knowledge of the FlexIO LCD peripheral and how to organize functional APIs to meet the application requirements. All functional API use the peripheral base address as the first parameter. FlexIO LCD functional operation groups provide the functional APIs set.
Transactional APIs are transaction target high level APIs. The transactional APIs can be used to enable the peripheral and also in the application if the code size and performance of transactional APIs can satisfy requirements. If the code size and performance are critical requirements, see the transactional API implementation and write custom code.
Transactional APIs support asynchronous transfer. This means that the function FLEXIO_MCULCD_TransferNonBlocking sets up an interrupt for data transfer. When the transfer completes, the upper layer is notified through a callback function with the kStatus_FLEXIO_MCULCD_Idle status.
Typical use case
FlexIO LCD send/receive using functional APIs
This example shows how to send command, or write and read data using the functional APIs. The data bus is 16-bit.
uint16_t dataToSend[] = { ... };
uint16_t dataToReceive[] = { ... };
flexio_MCULCD_transfer_t xfer;
flexio_MCULCD_config_t config;
xfer.command = command1;
xfer.dataCount = 0;
xfer.command = command2;
xfer.dataAddrOrSameValue = (uint32_t)dataToSend;
xfer.dataCount = sizeof(dataToSend);
xfer.command = command2;
xfer.dataAddrOrSameValue = value;
xfer.dataCount = 1000;
xfer.command = command3;
xfer.dataAddrOrSameValue = (uint32_t)dataToReceive;
xfer.dataCount = sizeof(dataToReceive);
FlexIO LCD send/receive using interrupt transactional APIs
flexio_MCULCD_handle_t handle;
volatile bool completeFlag = false;
{
{
completeFlag = true;
}
}
void main(void)
{
xfer.command = command1;
xfer.dataCount = 0;
completeFlag = false;
while (!completeFlag)
{
}
xfer.command = command2;
xfer.dataAddrOrSameValue = (uint32_t)dataToSend;
xfer.dataCount = sizeof(dataToSend);
completeFlag = false;
while (!completeFlag)
{
}
xfer.command = command2;
xfer.dataAddrOrSameValue = value;
xfer.dataCount = 1000;
completeFlag = false;
while (!completeFlag)
{
}
xfer.command = command3;
xfer.dataAddrOrSameValue = (uint32_t)dataToReceive;
xfer.dataCount = sizeof(dataToReceive);
completeFlag = false;
while (!completeFlag)
{
}
}
|
enum | {
kStatus_FLEXIO_MCULCD_Idle = MAKE_STATUS(kStatusGroup_FLEXIO_MCULCD, 0),
kStatus_FLEXIO_MCULCD_Busy = MAKE_STATUS(kStatusGroup_FLEXIO_MCULCD, 1),
kStatus_FLEXIO_MCULCD_Error = MAKE_STATUS(kStatusGroup_FLEXIO_MCULCD, 2)
} |
| FlexIO LCD transfer status. More...
|
|
enum | flexio_mculcd_pixel_format_t {
kFLEXIO_MCULCD_RGB565 = 0,
kFLEXIO_MCULCD_BGR565,
kFLEXIO_MCULCD_RGB888,
kFLEXIO_MCULCD_BGR888
} |
| Define FlexIO MCULCD pixel format. More...
|
|
enum | flexio_mculcd_bus_t {
kFLEXIO_MCULCD_8080,
kFLEXIO_MCULCD_6800
} |
| Define FlexIO MCULCD bus type. More...
|
|
enum | _flexio_mculcd_interrupt_enable {
kFLEXIO_MCULCD_TxEmptyInterruptEnable = (1U << 0U),
kFLEXIO_MCULCD_RxFullInterruptEnable = (1U << 1U)
} |
| Define FlexIO MCULCD interrupt mask. More...
|
|
enum | _flexio_mculcd_status_flags {
kFLEXIO_MCULCD_TxEmptyFlag = (1U << 0U),
kFLEXIO_MCULCD_RxFullFlag = (1U << 1U)
} |
| Define FlexIO MCULCD status mask. More...
|
|
enum | _flexio_mculcd_dma_enable {
kFLEXIO_MCULCD_TxDmaEnable = 0x1U,
kFLEXIO_MCULCD_RxDmaEnable = 0x2U
} |
| Define FlexIO MCULCD DMA mask. More...
|
|
enum | flexio_mculcd_transfer_mode_t {
kFLEXIO_MCULCD_ReadArray,
kFLEXIO_MCULCD_WriteArray,
kFLEXIO_MCULCD_WriteSameValue
} |
| Transfer mode. More...
|
|
|
status_t | FLEXIO_MCULCD_SetBaudRate (FLEXIO_MCULCD_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz) |
| Set desired baud rate. More...
|
|
void | FLEXIO_MCULCD_SetSingleBeatWriteConfig (FLEXIO_MCULCD_Type *base) |
| Configures the FLEXIO MCULCD to multiple beats write mode. More...
|
|
void | FLEXIO_MCULCD_ClearSingleBeatWriteConfig (FLEXIO_MCULCD_Type *base) |
| Clear the FLEXIO MCULCD multiple beats write mode configuration. More...
|
|
void | FLEXIO_MCULCD_SetSingleBeatReadConfig (FLEXIO_MCULCD_Type *base) |
| Configures the FLEXIO MCULCD to multiple beats read mode. More...
|
|
void | FLEXIO_MCULCD_ClearSingleBeatReadConfig (FLEXIO_MCULCD_Type *base) |
| Clear the FLEXIO MCULCD multiple beats read mode configuration. More...
|
|
void | FLEXIO_MCULCD_SetMultiBeatsWriteConfig (FLEXIO_MCULCD_Type *base) |
| Configures the FLEXIO MCULCD to multiple beats write mode. More...
|
|
void | FLEXIO_MCULCD_ClearMultiBeatsWriteConfig (FLEXIO_MCULCD_Type *base) |
| Clear the FLEXIO MCULCD multiple beats write mode configuration. More...
|
|
void | FLEXIO_MCULCD_SetMultiBeatsReadConfig (FLEXIO_MCULCD_Type *base) |
| Configures the FLEXIO MCULCD to multiple beats read mode. More...
|
|
void | FLEXIO_MCULCD_ClearMultiBeatsReadConfig (FLEXIO_MCULCD_Type *base) |
| Clear the FLEXIO MCULCD multiple beats read mode configuration. More...
|
|
static void | FLEXIO_MCULCD_Enable (FLEXIO_MCULCD_Type *base, bool enable) |
| Enables/disables the FlexIO MCULCD module operation. More...
|
|
uint32_t | FLEXIO_MCULCD_ReadData (FLEXIO_MCULCD_Type *base) |
| Read data from the FLEXIO MCULCD RX shifter buffer. More...
|
|
static void | FLEXIO_MCULCD_WriteData (FLEXIO_MCULCD_Type *base, uint32_t data) |
| Write data into the FLEXIO MCULCD TX shifter buffer. More...
|
|
static void | FLEXIO_MCULCD_StartTransfer (FLEXIO_MCULCD_Type *base) |
| Assert the nCS to start transfer. More...
|
|
static void | FLEXIO_MCULCD_StopTransfer (FLEXIO_MCULCD_Type *base) |
| De-assert the nCS to stop transfer. More...
|
|
void | FLEXIO_MCULCD_WaitTransmitComplete (void) |
| Wait for transmit data send out finished. More...
|
|
void | FLEXIO_MCULCD_WriteCommandBlocking (FLEXIO_MCULCD_Type *base, uint32_t command) |
| Send command in blocking way. More...
|
|
void | FLEXIO_MCULCD_WriteDataArrayBlocking (FLEXIO_MCULCD_Type *base, void *data, size_t size) |
| Send data array in blocking way. More...
|
|
void | FLEXIO_MCULCD_ReadDataArrayBlocking (FLEXIO_MCULCD_Type *base, void *data, size_t size) |
| Read data into array in blocking way. More...
|
|
void | FLEXIO_MCULCD_WriteSameValueBlocking (FLEXIO_MCULCD_Type *base, uint32_t sameValue, size_t size) |
| Send the same value many times in blocking way. More...
|
|
void | FLEXIO_MCULCD_TransferBlocking (FLEXIO_MCULCD_Type *base, flexio_mculcd_transfer_t *xfer) |
| Performs a polling transfer. More...
|
|
|
status_t | FLEXIO_MCULCD_TransferCreateHandle (FLEXIO_MCULCD_Type *base, flexio_mculcd_handle_t *handle, flexio_mculcd_transfer_callback_t callback, void *userData) |
| Initializes the FlexIO MCULCD handle, which is used in transactional functions. More...
|
|
status_t | FLEXIO_MCULCD_TransferNonBlocking (FLEXIO_MCULCD_Type *base, flexio_mculcd_handle_t *handle, flexio_mculcd_transfer_t *xfer) |
| Transfer data using IRQ. More...
|
|
void | FLEXIO_MCULCD_TransferAbort (FLEXIO_MCULCD_Type *base, flexio_mculcd_handle_t *handle) |
| Aborts the data transfer, which used IRQ. More...
|
|
status_t | FLEXIO_MCULCD_TransferGetCount (FLEXIO_MCULCD_Type *base, flexio_mculcd_handle_t *handle, size_t *count) |
| Gets the data transfer status which used IRQ. More...
|
|
void | FLEXIO_MCULCD_TransferHandleIRQ (void *base, void *handle) |
| FlexIO MCULCD IRQ handler function. More...
|
|
struct FLEXIO_MCULCD_Type |
FLEXIO_Type* FLEXIO_MCULCD_Type::flexioBase |
uint8_t FLEXIO_MCULCD_Type::dataPinStartIndex |
Only support data bus width 8 and 16.
uint8_t FLEXIO_MCULCD_Type::ENWRPinIndex |
uint8_t FLEXIO_MCULCD_Type::RDPinIndex |
uint8_t FLEXIO_MCULCD_Type::txShifterStartIndex |
uint8_t FLEXIO_MCULCD_Type::txShifterEndIndex |
uint8_t FLEXIO_MCULCD_Type::rxShifterStartIndex |
uint8_t FLEXIO_MCULCD_Type::rxShifterEndIndex |
uint8_t FLEXIO_MCULCD_Type::timerIndex |
struct flexio_mculcd_config_t |
bool flexio_mculcd_config_t::enable |
bool flexio_mculcd_config_t::enableInDoze |
bool flexio_mculcd_config_t::enableInDebug |
bool flexio_mculcd_config_t::enableFastAccess |
uint32_t flexio_mculcd_config_t::baudRate_Bps |
struct flexio_mculcd_transfer_t |
uint32_t flexio_mculcd_transfer_t::command |
uint32_t flexio_mculcd_transfer_t::dataAddrOrSameValue |
When writing or reading array, this is the address of the data array.
size_t flexio_mculcd_transfer_t::dataSize |
struct _flexio_mculcd_handle |
typedef for flexio_mculcd_handle_t in advance.
uint32_t flexio_mculcd_handle_t::dataAddrOrSameValue |
When writing or reading array, this is the address of the data array.
size_t flexio_mculcd_handle_t::dataCount |
volatile size_t flexio_mculcd_handle_t::remainingCount |
volatile uint32_t flexio_mculcd_handle_t::state |
void* flexio_mculcd_handle_t::userData |
#define FSL_FLEXIO_MCULCD_DRIVER_VERSION (MAKE_VERSION(2, 0, 4)) |
#define FLEXIO_MCULCD_WAIT_COMPLETE_TIME 512 |
Currently there is no method to detect whether the data has been sent out from the shifter, so the driver use a software delay for this. When the data is written to shifter buffer, the driver call the delay function to wait for the data shift out. If this value is too small, then the last few bytes might be lost when writing data using interrupt method or DMA method.
typedef void(* flexio_mculcd_pin_func_t)(bool set) |
typedef void(* flexio_mculcd_transfer_callback_t)(FLEXIO_MCULCD_Type *base, flexio_mculcd_handle_t *handle, status_t status, void *userData) |
When transfer finished, the callback function is called and returns the status
as kStatus_FLEXIO_MCULCD_Idle.
Enumerator |
---|
kStatus_FLEXIO_MCULCD_Idle |
FlexIO LCD is idle.
|
kStatus_FLEXIO_MCULCD_Busy |
FlexIO LCD is busy.
|
kStatus_FLEXIO_MCULCD_Error |
FlexIO LCD error occurred.
|
Enumerator |
---|
kFLEXIO_MCULCD_RGB565 |
RGB565, 16-bit.
|
kFLEXIO_MCULCD_BGR565 |
BGR565, 16-bit.
|
kFLEXIO_MCULCD_RGB888 |
RGB888, 24-bit.
|
kFLEXIO_MCULCD_BGR888 |
BGR888, 24-bit.
|
Enumerator |
---|
kFLEXIO_MCULCD_8080 |
Using Intel 8080 bus.
|
kFLEXIO_MCULCD_6800 |
Using Motorola 6800 bus.
|
Enumerator |
---|
kFLEXIO_MCULCD_TxEmptyInterruptEnable |
Transmit buffer empty interrupt enable.
|
kFLEXIO_MCULCD_RxFullInterruptEnable |
Receive buffer full interrupt enable.
|
Enumerator |
---|
kFLEXIO_MCULCD_TxEmptyFlag |
Transmit buffer empty flag.
|
kFLEXIO_MCULCD_RxFullFlag |
Receive buffer full flag.
|
Enumerator |
---|
kFLEXIO_MCULCD_TxDmaEnable |
Tx DMA request source.
|
kFLEXIO_MCULCD_RxDmaEnable |
Rx DMA request source.
|
Enumerator |
---|
kFLEXIO_MCULCD_ReadArray |
Read data into an array.
|
kFLEXIO_MCULCD_WriteArray |
Write data from an array.
|
kFLEXIO_MCULCD_WriteSameValue |
Write the same value many times.
|
The configuration structure can be filled by the user, or be set with default values by the FLEXIO_MCULCD_GetDefaultConfig.
- Parameters
-
- Return values
-
kStatus_Success | Initialization success. |
kStatus_InvalidArgument | Initialization failed because of invalid argument. |
The default configuration value is:
* config->enable = true;
* config->enableInDoze = false;
* config->enableInDebug = true;
* config->enableFastAccess = true;
* config->baudRate_Bps = 96000000U;
*
- Parameters
-
- Parameters
-
- Note
- Don't use this function with DMA APIs.
This function enables the FlexIO MCULCD interrupt.
- Parameters
-
This function disables the FlexIO MCULCD interrupt.
- Parameters
-
- Parameters
-
base | Pointer to the FLEXIO_MCULCD_Type structure. |
enable | True means enable DMA, false means disable DMA. |
- Parameters
-
base | Pointer to the FLEXIO_MCULCD_Type structure. |
enable | True means enable DMA, false means disable DMA. |
This function returns the MCULCD data register address, which is mainly used by DMA/eDMA.
- Parameters
-
- Returns
- FlexIO MCULCD transmit data register address.
This function returns the MCULCD data register address, which is mainly used by DMA/eDMA.
- Parameters
-
- Returns
- FlexIO MCULCD receive data register address.
- Parameters
-
base | Pointer to the FLEXIO_MCULCD_Type structure. |
baudRate_Bps | Desired baud rate. |
srcClock_Hz | FLEXIO clock frequency in Hz. |
- Return values
-
kStatus_Success | Set successfully. |
kStatus_InvalidArgument | Could not set the baud rate. |
At the begining multiple beats write operation, the FLEXIO MCULCD is configured to multiple beats write mode using this function. After write operation, the configuration is cleared by FLEXIO_MCULCD_ClearSingleBeatWriteConfig.
- Parameters
-
- Note
- This is an internal used function, upper layer should not use.
At the begining or multiple beats read operation, the FLEXIO MCULCD is configured to multiple beats read mode using this function. After read operation, the configuration is cleared by FLEXIO_MCULCD_ClearSingleBeatReadConfig.
- Parameters
-
- Note
- This is an internal used function, upper layer should not use.
At the begining multiple beats write operation, the FLEXIO MCULCD is configured to multiple beats write mode using this function. After write operation, the configuration is cleared by FLEXIO_MCULCD_ClearMultBeatsWriteConfig.
- Parameters
-
- Note
- This is an internal used function, upper layer should not use.
Clear the write configuration set by FLEXIO_MCULCD_SetMultBeatsWriteConfig.
- Parameters
-
- Note
- This is an internal used function, upper layer should not use.
At the begining or multiple beats read operation, the FLEXIO MCULCD is configured to multiple beats read mode using this function. After read operation, the configuration is cleared by FLEXIO_MCULCD_ClearMultBeatsReadConfig.
- Parameters
-
- Note
- This is an internal used function, upper layer should not use.
Clear the read configuration set by FLEXIO_MCULCD_SetMultBeatsReadConfig.
- Parameters
-
- Note
- This is an internal used function, upper layer should not use.
- Parameters
-
base | Pointer to the FLEXIO_MCULCD_Type. |
enable | True to enable, false does not have any effect. |
Read data from the RX shift buffer directly, it does no check whether the buffer is empty or not.
If the data bus width is 8-bit:
If the data bus width is 16-bit:
- Note
- This function returns the RX shifter buffer value (32-bit) directly. The return value should be converted according to data bus width.
- Parameters
-
- Returns
- The data read out.
- Note
- Don't use this function with DMA APIs.
Write data into the TX shift buffer directly, it does no check whether the buffer is full or not.
- Parameters
-
- Note
- Don't use this function with DMA APIs.
void FLEXIO_MCULCD_WaitTransmitComplete |
( |
void |
| ) |
|
Currently there is no effective method to wait for the data send out from the shiter, so here use a while loop to wait.
- Note
- This is an internal used function.
This function sends the command and returns when the command has been sent out.
- Parameters
-
void FLEXIO_MCULCD_WriteDataArrayBlocking |
( |
FLEXIO_MCULCD_Type * |
base, |
|
|
void * |
data, |
|
|
size_t |
size |
|
) |
| |
This function sends the data array and returns when the data sent out.
- Parameters
-
base | Pointer to the FLEXIO_MCULCD_Type structure. |
data | The data array to send. |
size | How many bytes to write. |
void FLEXIO_MCULCD_ReadDataArrayBlocking |
( |
FLEXIO_MCULCD_Type * |
base, |
|
|
void * |
data, |
|
|
size_t |
size |
|
) |
| |
This function reads the data into array and returns when the data read finished.
- Parameters
-
base | Pointer to the FLEXIO_MCULCD_Type structure. |
data | The array to save the data. |
size | How many bytes to read. |
void FLEXIO_MCULCD_WriteSameValueBlocking |
( |
FLEXIO_MCULCD_Type * |
base, |
|
|
uint32_t |
sameValue, |
|
|
size_t |
size |
|
) |
| |
This function sends the same value many times. It could be used to clear the LCD screen. If the data bus width is 8, this function will send LSB 8 bits of sameValue
for size
times. If the data bus is 16, this function will send LSB 16 bits of sameValue
for size
/ 2 times.
- Parameters
-
base | Pointer to the FLEXIO_MCULCD_Type structure. |
sameValue | The same value to send. |
size | How many bytes to send. |
- Note
- The API does not return until the transfer finished.
- Parameters
-
- Parameters
-
base | Pointer to the FLEXIO_MCULCD_Type structure. |
handle | Pointer to the flexio_mculcd_handle_t structure to store the transfer state. |
callback | The callback function. |
userData | The parameter of the callback function. |
- Return values
-
kStatus_Success | Successfully create the handle. |
kStatus_OutOfRange | The FlexIO type/handle/ISR table out of range. |
This function sends data using IRQ. This is a non-blocking function, which returns right away. When all data is sent out/received, the callback function is called.
- Parameters
-
- Return values
-
kStatus_Success | Successfully start a transfer. |
kStatus_InvalidArgument | Input argument is invalid. |
kStatus_FLEXIO_MCULCD_Busy | MCULCD is busy with another transfer. |
void FLEXIO_MCULCD_TransferAbort |
( |
FLEXIO_MCULCD_Type * |
base, |
|
|
flexio_mculcd_handle_t * |
handle |
|
) |
| |
- Parameters
-
base | Pointer to the FLEXIO_MCULCD_Type structure. |
handle | Pointer to the flexio_mculcd_handle_t structure to store the transfer state. |
- Parameters
-
base | Pointer to the FLEXIO_MCULCD_Type structure. |
handle | Pointer to the flexio_mculcd_handle_t structure to store the transfer state. |
count | How many bytes transferred so far by the non-blocking transaction. |
- Return values
-
kStatus_Success | Get the transferred count Successfully. |
kStatus_NoTransferInProgress | No transfer in process. |
void FLEXIO_MCULCD_TransferHandleIRQ |
( |
void * |
base, |
|
|
void * |
handle |
|
) |
| |
- Parameters
-
base | Pointer to the FLEXIO_MCULCD_Type structure. |
handle | Pointer to the flexio_mculcd_handle_t structure to store the transfer state. |