1 /*
2  * Copyright 2019, 2021 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef _FSL_FLEXIO_MCULCD_SMARTDMA_H_
9 #define _FSL_FLEXIO_MCULCD_SMARTDMA_H_
10 
11 #include "fsl_smartdma.h"
12 #include "fsl_flexio_mculcd.h"
13 
14 /*!
15  * @addtogroup flexio_smartdma_mculcd
16  * @{
17  */
18 
19 /*******************************************************************************
20  * Definitions
21  ******************************************************************************/
22 
23 /*@{*/
24 /*! @brief FlexIO MCULCD SMARTDMA driver version. */
25 #define FSL_FLEXIO_MCULCD_SMARTDMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
26 /*@}*/
27 
28 /*! @brief SMARTDMA transfer size should be multiple of 64 bytes. */
29 #define FLEXIO_MCULCD_SMARTDMA_TX_LEN_ALIGN 64U
30 
31 /*! @brief SMARTDMA transfer memory address should be 4 byte aligned. */
32 #define FLEXIO_MCULCD_SMARTDMA_TX_ADDR_ALIGN 4U
33 
34 /*! @brief  typedef for flexio_mculcd_smartdma_handle_t in advance. */
35 typedef struct _flexio_mculcd_smartdma_handle flexio_mculcd_smartdma_handle_t;
36 
37 /*! @brief FlexIO MCULCD master callback for transfer complete.
38  *
39  * When transfer finished, the callback function is called and returns the
40  * @p status as kStatus_FLEXIO_MCULCD_Idle.
41  */
42 typedef void (*flexio_mculcd_smartdma_transfer_callback_t)(FLEXIO_MCULCD_Type *base,
43                                                            flexio_mculcd_smartdma_handle_t *handle,
44                                                            status_t status,
45                                                            void *userData);
46 
47 /*! @brief FlexIO MCULCD SMARTDMA transfer handle, users should not touch the
48  * content of the handle.*/
49 struct _flexio_mculcd_smartdma_handle
50 {
51     FLEXIO_MCULCD_Type *base;       /*!< Pointer to the FLEXIO_MCULCD_Type. */
52     size_t dataCount;               /*!< Total count to be transferred. */
53     uint32_t dataAddrOrSameValue;   /*!< When sending the same value for many times,
54                                        this is the value to send. When writing or reading array,
55                                        this is the address of the data array. */
56     size_t dataCountUsingEzh;       /*!< Data transfered using SMARTDMA. */
57     volatile size_t remainingCount; /*!< Remaining count to transfer. */
58     volatile uint32_t state;        /*!< FlexIO MCULCD driver internal state. */
59     uint8_t smartdmaApi;            /*!< The SMARTDMA API used during transfer. */
60     bool needColorConvert;          /*!< Need color convert or not. */
61     uint8_t blockingXferBuffer[FLEXIO_MCULCD_SMARTDMA_TX_LEN_ALIGN * 3 /
62                                2];                                 /*!< Used for blocking method color space convet. */
63     flexio_mculcd_smartdma_transfer_callback_t completionCallback; /*!< Callback for MCULCD SMARTDMA transfer */
64     void *userData;                                                /*!< User Data for MCULCD SMARTDMA callback */
65     smartdma_flexio_mculcd_param_t smartdmaParam;                  /*!< SMARTDMA function parameters. */
66     uint32_t smartdmaStack[1];                                     /*!< SMARTDMA function stack. */
67 };
68 
69 /*! @brief FlexIO MCULCD SMARTDMA configuration. */
70 typedef struct _flexio_mculcd_smartdma_config
71 {
72     flexio_mculcd_pixel_format_t inputPixelFormat;  /*!< The pixel format in the frame buffer. */
73     flexio_mculcd_pixel_format_t outputPixelFormat; /*!< The pixel format on the 8080/68k bus. */
74 } flexio_mculcd_smartdma_config_t;
75 
76 /*******************************************************************************
77  * APIs
78  ******************************************************************************/
79 #if defined(__cplusplus)
80 extern "C" {
81 #endif
82 
83 /*!
84  * @name SMARTDMA Transactional
85  * @{
86  */
87 
88 /*!
89  * @brief Initializes the FLEXO MCULCD master SMARTDMA handle.
90  *
91  * This function initializes the FLEXO MCULCD master SMARTDMA handle which can be
92  * used for other FLEXO MCULCD transactional APIs. For a specified FLEXO MCULCD
93  * instance, call this API once to get the initialized handle.
94  *
95  * @param base Pointer to FLEXIO_MCULCD_Type structure.
96  * @param handle Pointer to flexio_mculcd_smartdma_handle_t structure to store the
97  * transfer state.
98  * @param config Pointer to the configuration.
99  * @param callback MCULCD transfer complete callback, NULL means no callback.
100  * @param userData callback function parameter.
101  * @retval kStatus_Success Successfully create the handle.
102  */
103 status_t FLEXIO_MCULCD_TransferCreateHandleSMARTDMA(FLEXIO_MCULCD_Type *base,
104                                                     flexio_mculcd_smartdma_handle_t *handle,
105                                                     const flexio_mculcd_smartdma_config_t *config,
106                                                     flexio_mculcd_smartdma_transfer_callback_t callback,
107                                                     void *userData);
108 
109 /*!
110  * @brief Performs a non-blocking FlexIO MCULCD transfer using SMARTDMA.
111  *
112  * This function returns immediately after transfer initiates. Use the callback
113  * function to check whether the transfer is completed.
114  *
115  * @param base pointer to FLEXIO_MCULCD_Type structure.
116  * @param handle pointer to flexio_mculcd_smartdma_handle_t structure to store the
117  * transfer state.
118  * @param xfer Pointer to FlexIO MCULCD transfer structure.
119  * @retval kStatus_Success Successfully start a transfer.
120  * @retval kStatus_InvalidArgument Input argument is invalid.
121  * @retval kStatus_FLEXIO_MCULCD_Busy FlexIO MCULCD is not idle, it is running another
122  * transfer.
123  */
124 status_t FLEXIO_MCULCD_TransferSMARTDMA(FLEXIO_MCULCD_Type *base,
125                                         flexio_mculcd_smartdma_handle_t *handle,
126                                         flexio_mculcd_transfer_t *xfer);
127 
128 /*!
129  * @brief Aborts a FlexIO MCULCD transfer using SMARTDMA.
130  *
131  * @param base pointer to FLEXIO_MCULCD_Type structure.
132  * @param handle FlexIO MCULCD SMARTDMA handle pointer.
133  */
134 void FLEXIO_MCULCD_TransferAbortSMARTDMA(FLEXIO_MCULCD_Type *base, flexio_mculcd_smartdma_handle_t *handle);
135 
136 /*!
137  * @brief Gets the remaining bytes for FlexIO MCULCD SMARTDMA transfer.
138  *
139  * @param base pointer to FLEXIO_MCULCD_Type structure.
140  * @param handle FlexIO MCULCD SMARTDMA handle pointer.
141  * @param count Number of count transferred so far by the SMARTDMA transaction.
142  * @retval kStatus_Success Get the transferred count Successfully.
143  * @retval kStatus_NoTransferInProgress No transfer in process.
144  */
145 status_t FLEXIO_MCULCD_TransferGetCountSMARTDMA(FLEXIO_MCULCD_Type *base,
146                                                 flexio_mculcd_smartdma_handle_t *handle,
147                                                 size_t *count);
148 
149 /*! @} */
150 
151 #if defined(__cplusplus)
152 }
153 #endif
154 
155 /*!
156  * @}
157  */
158 #endif /* _FSL_FLEXIO_MCULCD_SMARTDMA_H_ */
159