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 
9 #ifndef _FSL_FLEXIO_CAMERA_H_
10 #define _FSL_FLEXIO_CAMERA_H_
11 
12 #include "fsl_common.h"
13 #include "fsl_flexio.h"
14 /*!
15  * @addtogroup flexio_camera
16  * @{
17  */
18 
19 /*******************************************************************************
20  * Definitions
21  ******************************************************************************/
22 
23 /*! @name Driver version */
24 /*@{*/
25 /*! @brief FlexIO Camera driver version 2.1.3. */
26 #define FSL_FLEXIO_CAMERA_DRIVER_VERSION (MAKE_VERSION(2, 1, 3))
27 /*@}*/
28 
29 /*! @brief Define the Camera CPI interface is constantly 8-bit width. */
30 #define FLEXIO_CAMERA_PARALLEL_DATA_WIDTH (8U)
31 
32 /*! @brief Error codes for the Camera driver. */
33 enum
34 {
35     kStatus_FLEXIO_CAMERA_RxBusy = MAKE_STATUS(kStatusGroup_FLEXIO_CAMERA, 0), /*!< Receiver is busy. */
36     kStatus_FLEXIO_CAMERA_RxIdle = MAKE_STATUS(kStatusGroup_FLEXIO_CAMERA, 1), /*!< Camera receiver is idle. */
37 };
38 
39 /*! @brief Define FlexIO Camera status mask. */
40 enum _flexio_camera_status_flags
41 {
42     kFLEXIO_CAMERA_RxDataRegFullFlag = 0x1U, /*!< Receive buffer full flag. */
43     kFLEXIO_CAMERA_RxErrorFlag       = 0x2U, /*!< Receive buffer error flag. */
44 };
45 
46 /*!
47  * @brief Define structure of configuring the FlexIO Camera device.
48  */
49 typedef struct _flexio_camera_type
50 {
51     FLEXIO_Type *flexioBase; /*!< FlexIO module base address. */
52     uint32_t datPinStartIdx; /*!< First data pin (D0) index for flexio_camera.
53                                   Then the successive following FLEXIO_CAMERA_DATA_WIDTH-1 pins
54                                   are used as D1-D7.*/
55     uint32_t pclkPinIdx;     /*!< Pixel clock pin (PCLK) index for flexio_camera. */
56     uint32_t hrefPinIdx;     /*!< Horizontal sync pin (HREF) index for flexio_camera. */
57 
58     uint32_t shifterStartIdx; /*!< First shifter index used for flexio_camera data FIFO. */
59     uint32_t shifterCount;    /*!< The count of shifters that are used as flexio_camera data FIFO. */
60     uint32_t timerIdx;        /*!< Timer index used for flexio_camera in FlexIO. */
61 } FLEXIO_CAMERA_Type;
62 
63 /*! @brief Define FlexIO Camera user configuration structure. */
64 typedef struct _flexio_camera_config
65 {
66     bool enablecamera;     /*!< Enable/disable FlexIO Camera TX & RX. */
67     bool enableInDoze;     /*!< Enable/disable FlexIO operation in doze mode*/
68     bool enableInDebug;    /*!< Enable/disable FlexIO operation in debug mode*/
69     bool enableFastAccess; /*!< Enable/disable fast access to FlexIO registers,
70                             fast access requires the FlexIO clock to be at least
71                             twice the frequency of the bus clock. */
72 } flexio_camera_config_t;
73 
74 /*! @brief Define FlexIO Camera transfer structure. */
75 typedef struct _flexio_camera_transfer
76 {
77     uint32_t dataAddress; /*!< Transfer buffer*/
78     uint32_t dataNum;     /*!< Transfer num*/
79 } flexio_camera_transfer_t;
80 
81 /*******************************************************************************
82  * API
83  ******************************************************************************/
84 
85 #if defined(__cplusplus)
86 extern "C" {
87 #endif /*_cplusplus*/
88 
89 /*!
90  * @name Initialization and configuration
91  * @{
92  */
93 
94 /*!
95  * @brief Ungates the FlexIO clock, resets the FlexIO module, and configures the FlexIO Camera.
96  *
97  * @param base Pointer to FLEXIO_CAMERA_Type structure
98  * @param config Pointer to flexio_camera_config_t structure
99  */
100 void FLEXIO_CAMERA_Init(FLEXIO_CAMERA_Type *base, const flexio_camera_config_t *config);
101 
102 /*!
103  * @brief Resets the FLEXIO_CAMERA shifer and timer config.
104  *
105  * @note After calling this API, call FLEXO_CAMERA_Init to use the FlexIO Camera module.
106  *
107  * @param base Pointer to FLEXIO_CAMERA_Type structure
108  */
109 void FLEXIO_CAMERA_Deinit(FLEXIO_CAMERA_Type *base);
110 
111 /*!
112  * @brief Gets the default configuration to configure the FlexIO Camera. The configuration
113  * can be used directly for calling the FLEXIO_CAMERA_Init().
114  * Example:
115    @code
116    flexio_camera_config_t config;
117    FLEXIO_CAMERA_GetDefaultConfig(&userConfig);
118    @endcode
119  * @param config Pointer to the flexio_camera_config_t structure
120 */
121 void FLEXIO_CAMERA_GetDefaultConfig(flexio_camera_config_t *config);
122 
123 /*!
124  * @brief Enables/disables the FlexIO Camera module operation.
125  *
126  * @param base Pointer to the FLEXIO_CAMERA_Type
127  * @param enable True to enable, false does not have any effect.
128  */
FLEXIO_CAMERA_Enable(FLEXIO_CAMERA_Type * base,bool enable)129 static inline void FLEXIO_CAMERA_Enable(FLEXIO_CAMERA_Type *base, bool enable)
130 {
131     if (enable)
132     {
133         base->flexioBase->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;
134     }
135 }
136 
137 /*! @} */
138 
139 /*!
140  * @name Status
141  * @{
142  */
143 
144 /*!
145  * @brief Gets the FlexIO Camera status flags.
146  *
147  * @param base Pointer to FLEXIO_CAMERA_Type structure
148  * @return FlexIO shifter status flags
149  *          @arg FLEXIO_SHIFTSTAT_SSF_MASK
150  *          @arg 0
151  */
152 uint32_t FLEXIO_CAMERA_GetStatusFlags(FLEXIO_CAMERA_Type *base);
153 
154 /*!
155  * @brief Clears the receive buffer full flag manually.
156  *
157  * @param base Pointer to the device.
158  * @param mask status flag
159  *      The parameter can be any combination of the following values:
160  *          @arg kFLEXIO_CAMERA_RxDataRegFullFlag
161  *          @arg kFLEXIO_CAMERA_RxErrorFlag
162  */
163 void FLEXIO_CAMERA_ClearStatusFlags(FLEXIO_CAMERA_Type *base, uint32_t mask);
164 
165 /* @} */
166 
167 /*!
168  * @name Interrupts
169  * @{
170  */
171 
172 /*!
173  * @brief Switches on the interrupt for receive buffer full event.
174  *
175  * @param base Pointer to the device.
176  */
177 void FLEXIO_CAMERA_EnableInterrupt(FLEXIO_CAMERA_Type *base);
178 
179 /*!
180  * @brief Switches off the interrupt for receive buffer full event.
181  *
182  * @param base Pointer to the device.
183  *
184  */
185 void FLEXIO_CAMERA_DisableInterrupt(FLEXIO_CAMERA_Type *base);
186 
187 /*! @} */
188 
189 /*!
190  * @name DMA support
191  * @{
192  */
193 
194 /*!
195  * @brief Enables/disables the FlexIO Camera receive DMA.
196  *
197  * @param base Pointer to FLEXIO_CAMERA_Type structure
198  * @param enable True to enable, false to disable.
199  *
200  *    The FlexIO Camera mode can't work without the DMA or eDMA support,
201  *    Usually, it needs at least two DMA or eDMA channels, one for transferring data from
202  *    Camera, such as 0V7670 to FlexIO buffer, another is for transferring data from FlexIO
203  *    buffer to LCD.
204  *
205  */
FLEXIO_CAMERA_EnableRxDMA(FLEXIO_CAMERA_Type * base,bool enable)206 static inline void FLEXIO_CAMERA_EnableRxDMA(FLEXIO_CAMERA_Type *base, bool enable)
207 {
208     FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1UL << base->shifterStartIdx, enable);
209 }
210 
211 /*!
212  * @brief Gets the data from the receive buffer.
213  *
214  * @param base Pointer to the device.
215  * @return data Pointer to the buffer that keeps the data with count of base->shifterCount .
216  */
FLEXIO_CAMERA_GetRxBufferAddress(FLEXIO_CAMERA_Type * base)217 static inline uint32_t FLEXIO_CAMERA_GetRxBufferAddress(FLEXIO_CAMERA_Type *base)
218 {
219     return FLEXIO_GetShifterBufferAddress(base->flexioBase, kFLEXIO_ShifterBuffer, (uint8_t)base->shifterStartIdx);
220 }
221 
222 /*! @} */
223 
224 #if defined(__cplusplus)
225 }
226 #endif /*_cplusplus*/
227 
228 /*@}*/
229 
230 #endif /*_FSL_FLEXIO_CAMERA_H_*/
231