1 /** 2 * @file csi2.h 3 * @brief Camera Serial Interface 2 (CSI-2) function prototypes and data types. 4 */ 5 6 /****************************************************************************** 7 * 8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 9 * Analog Devices, Inc.), 10 * Copyright (C) 2023-2024 Analog Devices, Inc. 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 ******************************************************************************/ 25 26 /* Define to prevent redundant inclusion */ 27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_CSI2_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_CSI2_H_ 29 30 /* **** Includes **** */ 31 #include <stdbool.h> 32 #include "csi2_regs.h" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /** 39 * @defgroup csi2 Camera Serial Interface 2 (CSI-2) 40 * @ingroup periphlibs 41 * @{ 42 */ 43 44 /* **** Definitions **** */ 45 46 typedef struct _mxc_csi2_req_t mxc_csi2_req_t; 47 48 /** 49 * @brief Enumeration type for the CSI-2 PPI Clock Inversion. 50 */ 51 typedef enum { 52 MXC_CSI2_PPI_NO_INVERT, ///< No inversion of PPI input clock 53 MXC_CSI2_PPI_INVERT, ///< Invert PPI input clock 54 } mxc_csi2_ppi_clk_t; 55 56 /** 57 * @brief Enumeration type for the CSI-2 Payload 0 data types. 58 */ 59 typedef enum { 60 MXC_CSI2_PL0_DISABLE_ALL = 0xFFFFFFFF, ///< Disable payload0 data 61 MXC_CSI2_PL0_NULL = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_NULL, ///< NULL payload data 62 MXC_CSI2_PL0_BLANK = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_BLANK, ///< BLANK payload data 63 MXC_CSI2_PL0_EMBEDDED = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_EMBEDDED, ///< EMBEDDED payload data 64 MXC_CSI2_PL0_YUV420_8BIT = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_YUV420_8BIT, ///< YUV420 8-bit data 65 MXC_CSI2_PL0_YUV420_10BIT = 66 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_YUV420_10BIT, ///< YUV420 10-bit data 67 MXC_CSI2_PL0_LEG_YUV420_8BIT = 68 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_YUV420_8BIT_LEG, ///< Legacy YUV420 8-bit data 69 MXC_CSI2_PL0_YUV422_8BIT_CSP = 70 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_YUV420_8BIT_CSP, ///< YUV422 8-bit CSP data 71 MXC_CSI2_PL0_YUV422_10BIT_CSP = 72 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_YUV420_10BIT_CSP, ///< YUV422 10-bit CSP data 73 MXC_CSI2_PL0_YUV422_8BIT = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_YUV422_8BIT, ///< YUV422 8-bit data 74 MXC_CSI2_PL0_YUV422_10BIT = 75 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_YUV422_10BIT, ///< YUV422 10-bit data 76 MXC_CSI2_PL0_RGB444 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RGB444, ///< RGB444 data 77 MXC_CSI2_PL0_RGB555 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RGB555, ///< RGB555 data 78 MXC_CSI2_PL0_RGB565 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RGB565, ///< RGB565 data 79 MXC_CSI2_PL0_RGB666 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RGB666, ///< RGB666 data 80 MXC_CSI2_PL0_RGB888 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RGB888, ///< RGB888 data 81 MXC_CSI2_PL0_RAW6 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RAW6, ///< RAW6 data 82 MXC_CSI2_PL0_RAW7 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RAW7, ///< RAW7 data 83 MXC_CSI2_PL0_RAW8 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RAW8, ///< RAW8 data 84 MXC_CSI2_PL0_RAW10 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RAW10, ///< RAW10 data 85 MXC_CSI2_PL0_RAW12 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RAW12, ///< RAW12 data 86 MXC_CSI2_PL0_RAW14 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RAW14, ///< RAW14 data 87 MXC_CSI2_PL0_RAW16 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RAW16, ///< RAW16 data 88 MXC_CSI2_PL0_RAW20 = ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_0_RAW20, ///< RAW20 data 89 } mxc_csi2_payload0_t; 90 91 /** 92 * @brief Enumeration type for the CSI-2 Payload 1 Datatypes. 93 */ 94 typedef enum { 95 MXC_CSI2_PL1_DISABLE_ALL = 0x0001FFFF, ///< Disable payload1 data 96 MXC_CSI2_PL1_UD_0x30 = 97 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_1_USR_DEF_TYPE30, ///< User defined type 0x30 data 98 MXC_CSI2_PL1_UD_0x31 = 99 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_1_USR_DEF_TYPE31, ///< User defined type 0x31 data 100 MXC_CSI2_PL1_UD_0x32 = 101 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_1_USR_DEF_TYPE32, ///< User defined type 0x32 data 102 MXC_CSI2_PL1_UD_0x33 = 103 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_1_USR_DEF_TYPE33, ///< User defined type 0x33 data 104 MXC_CSI2_PL1_UD_0x34 = 105 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_1_USR_DEF_TYPE34, ///< User defined type 0x34 data 106 MXC_CSI2_PL1_UD_0x35 = 107 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_1_USR_DEF_TYPE35, ///< User defined type 0x35 data 108 MXC_CSI2_PL1_UD_0x36 = 109 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_1_USR_DEF_TYPE36, ///< User defined type 0x36 data 110 MXC_CSI2_PL1_UD_0x37 = 111 ~MXC_F_CSI2_CFG_DISABLE_PAYLOAD_1_USR_DEF_TYPE37, ///< User defined type 0x37 data 112 } mxc_csi2_payload1_t; 113 114 /** 115 * @brief Enumeration type for the CSI-2 Lane Control Source Selections. 116 */ 117 typedef enum { 118 MXC_CSI2_PAD_CDRX_PN_L0, ///< Connected to PAD_CDRX_L0P/N 119 MXC_CSI2_PAD_CDRX_PN_L1, ///< Connected to PAD_CDRX_L1P/N 120 MXC_CSI2_PAD_CDRX_PN_L2, ///< Connected to PAD_CDRX_L2P/N 121 MXC_CSI2_PAD_CDRX_PN_L3, ///< Connected to PAD_CDRX_L3P/N 122 MXC_CSI2_PAD_CDRX_PN_L4, ///< Connected to PAD_CDRX_L4P/N 123 } mxc_csi2_swap_sel_t; 124 125 /** 126 * @brief Enumeration type for CSI-2 VFIFO DMA Mode. 127 */ 128 typedef enum { 129 MXC_CSI2_DMA_NO_DMA = MXC_S_CSI2_VFIFO_CFG0_DMAMODE_NO_DMA, ///< No DMA Mode 130 MXC_CSI2_DMA_SEND_REQUEST = MXC_S_CSI2_VFIFO_CFG0_DMAMODE_DMA_REQ, ///< DMA Request Mode 131 MXC_CSI2_DMA_FIFO_ABV_THD = 132 MXC_S_CSI2_VFIFO_CFG0_DMAMODE_FIFO_THD, ///< Above FIFO Threshold Mode 133 MXC_CSI2_DMA_FIFO_FULL = MXC_S_CSI2_VFIFO_CFG0_DMAMODE_FIFO_FULL, ///< FIFO Full Mode 134 } mxc_csi2_dma_mode_t; 135 136 /** 137 * @brief Enumeration type for CSI-2 VFIFO Read Mode. 138 */ 139 typedef enum { 140 MXC_CSI2_READ_ONE_BY_ONE, ///< One by One FIFO Read Mode 141 MXC_CSI2_READ_DIRECT_ADDR, ///< Direct Addressing FIFO Read Mode 142 } mxc_csi2_fiform_t; 143 144 /** 145 * @brief Enumeration type for CSI-2 VIFO Error Detection. 146 */ 147 typedef enum { 148 MXC_CSI2_ERR_DETECT_DISABLE, ///< Disable Error Detection 149 MXC_CSI2_ERR_DETECT_ENABLE, ///< Enable Error Detection 150 } mxc_csi2_err_det_t; 151 152 /** 153 * @brief Enumeration type for the CSI-2 VFIFO Bandwidth. 154 */ 155 typedef enum { 156 MXC_CSI2_NORMAL_BW, ///< Normal Bandwidth Mode 157 MXC_CSI2_FULL_BW, ///< Full Bandwidth Mode 158 } mxc_csi2_fbwm_t; 159 160 /** 161 * @brief Enumeration type for the CSI-2 RGB Type. 162 */ 163 typedef enum { 164 MXC_CSI2_TYPE_RGB444 = MXC_S_CSI2_VFIFO_RAW_CTRL_RGB_TYP_RGB444, ///< RGB444 Type 165 MXC_CSI2_TYPE_RGB555 = MXC_S_CSI2_VFIFO_RAW_CTRL_RGB_TYP_RGB555, ///< RGB555 Type 166 MXC_CSI2_TYPE_RGB565 = MXC_S_CSI2_VFIFO_RAW_CTRL_RGB_TYP_RGB565, ///< RGB565 Type 167 MXC_CSI2_TYPE_RGB666 = MXC_S_CSI2_VFIFO_RAW_CTRL_RGB_TYP_RGB666, ///< RGB666 Type 168 MXC_CSI2_TYPE_RGB888 = MXC_S_CSI2_VFIFO_RAW_CTRL_RGB_TYP_RGG888, ///< RGB888 Type 169 } mxc_csi2_rgb_type_t; 170 171 /** 172 * @brief Enumeration type for the CSI-2 RAW Format. 173 */ 174 typedef enum { 175 MXC_CSI2_FORMAT_RGRG_GBGB = 176 (0x0 << MXC_F_CSI2_VFIFO_RAW_CTRL_RAW_FMT_POS), ///< RGRG_GBGB Format 177 MXC_CSI2_FORMAT_GRGR_BGBG = 178 (0x1 << MXC_F_CSI2_VFIFO_RAW_CTRL_RAW_FMT_POS), ///< GRGR_BGBG Format 179 MXC_CSI2_FORMAT_GBGB_RGRG = 180 (0x2 << MXC_F_CSI2_VFIFO_RAW_CTRL_RAW_FMT_POS), ///< GBGB_RGRG Format 181 MXC_CSI2_FORMAT_BGBG_GRGR = 182 (0x3 << MXC_F_CSI2_VFIFO_RAW_CTRL_RAW_FMT_POS), ///M BGBG_GRGR Format 183 } mxc_csi2_raw_format_t; 184 185 /** 186 * @brief Enumeration type for the CSI-2 Autoflush. 187 */ 188 typedef enum { 189 MXC_CSI2_AUTOFLUSH_DISABLE = 0, ///< Disable FIFO Automatic Flush-Out 190 MXC_CSI2_AUTOFLUSH_ENABLE, ///< Enable FIFO Automatic Flush-Out 191 } mxc_csi2_raw_autoflush_t; 192 193 /** 194 * @brief Enumeration type for the CSI-2 AHB Wait option. 195 */ 196 typedef enum { 197 MXC_CSI2_AHBWAIT_DISABLE = 0, ///< Disable AHB Wait 198 MXC_CSI2_AHBWAIT_ENABLE, ///< Enable AHB Wait 199 } mxc_csi2_ahbwait_t; 200 201 /** 202 * @brief Enumeration type for the CSI-2 DMA Frame option. 203 */ 204 typedef enum { 205 MXC_CSI2_DMA_WHOLE_FRAME = 0, ///< DMA entire frames at a time 206 MXC_CSI2_DMA_LINE_BY_LINE, ///< DMA line by line per frame 207 } mxc_csi2_dma_frame_t; 208 209 typedef struct _mxc_csi2_capture_stats_t { 210 bool success; 211 uint32_t ctrl_err; 212 uint32_t ppi_err; 213 uint32_t vfifo_err; 214 size_t frame_size; 215 size_t bytes_captured; 216 } mxc_csi2_capture_stats_t; 217 218 /** 219 * @brief The callback routine used to indicate to indicate transaction has terminated. This is currently unused until multi-frame exposures are implemented. 220 * @param req The details of the image capture. 221 * @param result See \ref MXC_Error_Codes for the list of error codes. 222 */ 223 typedef void (*mxc_csi2_frame_handler_cb_t)(mxc_csi2_req_t *req, int result); 224 225 /** 226 * @brief The callback routine used to handle incoming image data from the camera sensor. 227 * It is triggered once per row. Application code should implement this 228 * and ensure that the callback is fast enough to keep up with the incoming data. 229 * @param[in] data Pointer to the received bytes in memory. 230 * @param[in] len The number of bytes received. 231 * 232 * @return This function should return 0 on success. If non-zero, the CSI-2 controller will end the frame capture 233 */ 234 typedef int (*mxc_csi2_line_handler_cb_t)(uint8_t *data, unsigned int len); 235 236 /** 237 * @brief Selects control source signals for data and clock lanes. 238 */ 239 typedef struct { 240 mxc_csi2_swap_sel_t d0_swap_sel; ///< Data Lane 0 Control Source Select 241 mxc_csi2_swap_sel_t d1_swap_sel; ///< Data Lane 1 Control Source Select 242 mxc_csi2_swap_sel_t d2_swap_sel; ///< Data Lane 2 Control Source Select 243 mxc_csi2_swap_sel_t d3_swap_sel; ///< Data Lane 3 Control Source Select 244 mxc_csi2_swap_sel_t c0_swap_sel; ///< Clock Lane Control Source Select 245 } mxc_csi2_lane_src_t; 246 247 /** 248 * @brief Struct containing RX Controller and D-PHY configuration details. 249 */ 250 typedef struct { 251 mxc_csi2_ppi_clk_t invert_ppi_clk; ///< Invert the PPI input clock 252 uint32_t num_lanes; ///< Configure number of lanes 253 uint32_t flush_cnt; ///< Flush Count 254 mxc_csi2_payload0_t payload0; ///< Payload 0 data select 255 mxc_csi2_payload1_t payload1; ///< Payload 1 data select 256 mxc_csi2_lane_src_t lane_src; ///< Data and Clock lane sources 257 } mxc_csi2_ctrl_cfg_t; 258 259 /** 260 * @brief Struct containing parameters for the VFIFO. 261 */ 262 typedef struct { 263 uint32_t virtual_channel; ///< Virtual Channel (0-3) 264 uint32_t flow_ctrl; ///< Flow control selection 265 uint32_t wait_en; ///< AHB Wait Enable 266 uint32_t wait_cyc; ///< AHB Maximal Wait Cycles 267 268 mxc_csi2_dma_frame_t dma_whole_frame; ///< DMA whole frame or line by line 269 mxc_csi2_dma_mode_t dma_mode; ///< DMA Mode 270 mxc_csi2_fiform_t fifo_rd_mode; ///< FIFO Read Mode 271 mxc_csi2_err_det_t err_det_en; ///< Error Detection Enable 272 uint32_t rx_thd; ///< FIFO Threshold 273 mxc_csi2_fbwm_t bandwidth_mode; ///< Full Band Width Mode Enable 274 } mxc_csi2_vfifo_cfg_t; 275 276 /** 277 * @brief The information required to capture images. 278 */ 279 struct _mxc_csi2_req_t { 280 uint32_t pixels_per_line; ///< Image Width 281 uint32_t lines_per_frame; ///< Image Height 282 uint32_t bits_per_pixel_odd; ///< Bits Per Pixel Odd 283 uint32_t bits_per_pixel_even; ///< Bits Per Pixel Even 284 uint32_t frame_num; ///< Number of frames to capture 285 mxc_csi2_line_handler_cb_t 286 line_handler; ///< Callback triggered for each image row. Application code must implement this to offload data. 287 288 uint8_t process_raw_to_rgb; ///< Select if processing RAW data to RGB type 289 mxc_csi2_rgb_type_t rgb_type; ///< Select final processed RGB type 290 mxc_csi2_raw_format_t raw_format; ///< Select RAW format 291 mxc_csi2_raw_autoflush_t autoflush; ///< FIFO Automatic Flush-Out enable 292 uint32_t raw_buf0_addr; ///< RAW Buffer 0 Address (line by line) 293 uint32_t raw_buf1_addr; ///< RAW Buffer 1 Address (line by line) 294 }; 295 296 /* **** Function Prototypes **** */ 297 298 /******************************************/ 299 /* Global Control/Configuration Functions */ 300 /******************************************/ 301 302 /** 303 * @brief Initialize CSI-2. 304 * @param req The details of the image for capture. 305 * @param ctrl_cfg Configuration details for RX Controller. 306 * @param vfifo_cfg Configuration details for VFIFO. 307 * @return #E_NO_ERROR if everything is successful. 308 */ 309 int MXC_CSI2_Init(mxc_csi2_req_t *req, mxc_csi2_ctrl_cfg_t *ctrl_cfg, 310 mxc_csi2_vfifo_cfg_t *vfifo_cfg); 311 312 /** 313 * @brief Shutdown CSI-2. 314 * @return #E_NO_ERROR if everything is successful. 315 */ 316 int MXC_CSI2_Shutdown(void); 317 318 /** 319 * @brief Enable the blocks and start the CSI-2. 320 * @param num_data_lanes Number of data lanes used. 321 * @return #E_NO_ERROR if everything is successful. 322 */ 323 int MXC_CSI2_Start(int num_data_lanes); 324 325 /** 326 * @brief Disable the blocks and stop the CSI-2. 327 * @return #E_NO_ERROR if everything is successful. 328 */ 329 int MXC_CSI2_Stop(void); 330 331 /** 332 * @brief Capture an image frame using DMA. Same as MXC_CSI2_CaptureFrameDMA. 333 * @param num_data_lanes Number of data lanes used. 334 * @return #E_NO_ERROR if everything is successful. 335 */ 336 int MXC_CSI2_CaptureFrame(int num_data_lanes); 337 338 /** 339 * @brief Capture an image frame using DMA. 340 * @param num_data_lanes Number of data lanes used. 341 * @return #E_NO_ERROR if everything is successful. 342 */ 343 int MXC_CSI2_CaptureFrameDMA(); 344 345 /** 346 * @brief Select Lane Control Source for D0-D4 and C0. 347 * @param src The lane control source signal assignments. 348 * @return #E_NO_ERROR if everything is successful. 349 */ 350 int MXC_CSI2_SetLaneCtrlSource(mxc_csi2_lane_src_t *src); 351 352 /** 353 * @brief Get Lane Control Source for D0-D4 and C0. 354 * @param src Pointer to hold lane control source signal assignments. 355 * @return #E_NO_ERROR if everything is successful. 356 */ 357 int MXC_CSI2_GetLaneCtrlSource(mxc_csi2_lane_src_t *src); 358 359 /** 360 * @brief Grab the configured image details. 361 * @param[out] imgLen Pointer to the total length of the image (in bytes). 362 * @param[out] w Pointer to image width (in pixels). 363 * @param[out] h Pointer to image height (in pixels). 364 */ 365 void MXC_CSI2_GetImageDetails(uint32_t *imgLen, uint32_t *w, uint32_t *h); 366 367 /********************************/ 368 /* CSI2 RX Controller Functions */ 369 /********************************/ 370 371 /** 372 * @brief Configure the RX Controller. 373 * @param cfg Struct containing RX Controller config parameters. 374 * @return #E_NO_ERROR if everything is successful. 375 */ 376 int MXC_CSI2_CTRL_Config(mxc_csi2_ctrl_cfg_t *cfg); 377 378 /** 379 * @brief Enable RX Controller Interrupts. 380 * @param mask The interrupt to be enabled. 381 */ 382 void MXC_CSI2_CTRL_EnableInt(uint32_t mask); 383 384 /** 385 * @brief Disable RX Controller Interrupts. 386 * @param mask The interrupt to be disable. 387 */ 388 void MXC_CSI2_CTRL_DisableInt(uint32_t mask); 389 390 /** 391 * @brief Gets the interrupt flags that are currently set. 392 * @return The interrupt flags. 393 */ 394 int MXC_CSI2_CTRL_GetFlags(void); 395 396 /** 397 * @brief Clears the interrupt flags. 398 * @param flags mask of flags to be cleared. 399 */ 400 void MXC_CSI2_CTRL_ClearFlags(uint32_t flags); 401 402 /************************/ 403 /* CSI2 VFIFO Functions */ 404 /************************/ 405 406 /** 407 * @brief Clears the interrupt flags. 408 * @param flags mask of flags to be cleared. 409 * @return #E_NO_ERROR if everything is successful. 410 */ 411 int MXC_CSI2_VFIFO_Config(mxc_csi2_vfifo_cfg_t *cfg); 412 413 /** 414 * @brief Set Next FIFO Trigger Mode: FIFO Not Empty, Above Threshold, Full. 415 * @param ff_not_empty Set trigger when FIFO not empty. 416 * @param ff_abv_thd Set trigger when FIFO above threshold. 417 * @param ff_full Set trigger when FIFO Full. 418 * @return #E_NO_ERROR if everything is successful. 419 */ 420 int MXC_CSI2_VFIFO_NextFIFOTrigMode(uint8_t ff_not_empty, uint8_t ff_abv_thd, uint8_t ff_full); 421 422 /** 423 * @brief Enable VFIFO Interrupts. 424 * @param mask The interrupt to be enabled. 425 * @param edge Edge triggered or level triggered FIFO detection. 426 */ 427 void MXC_CSI2_VFIFO_EnableInt(uint32_t mask, uint32_t edge); 428 429 /** 430 * @brief Change FIFO detection mode for FIFO-specific VFIFO interrupts. 431 * @param mask The interrupt to be enabled. 432 * @param edge Edge triggered (true) or level triggered (false) FIFO detection. 433 */ 434 void MXC_CSI2_VFIFO_ChangeIntMode(uint32_t mask, uint32_t edge); 435 436 /** 437 * @brief Disable VFIFO Interrupts. 438 * @param mask The interrupt to be disable. 439 */ 440 void MXC_CSI2_VFIFO_DisableInt(uint32_t mask); 441 442 /** 443 * @brief Gets the interrupt flags that are currently set for VFIFO. 444 * @return The interrupt flags. 445 */ 446 int MXC_CSI2_VFIFO_GetFlags(void); 447 448 /** 449 * @brief Clears the interrupt flags for VFIFO. 450 * @param flags mask of flags to be cleared. 451 */ 452 void MXC_CSI2_VFIFO_ClearFlags(uint32_t flags); 453 454 /** 455 * @brief Only enables the VFIFO. 456 * @return #E_NO_ERROR if everything is successful. 457 */ 458 int MXC_CSI2_VFIFO_Enable(void); 459 460 /** 461 * @brief Only disables the VFIFO. 462 * @return #E_NO_ERROR if everything is successful. 463 */ 464 int MXC_CSI2_VFIFO_Disable(void); 465 466 /** 467 * @brief Set parameters for processing RAW image data to RGB type data. 468 * @note Payload data type from Init function should be set to RAW. 469 * @param req Struct containing parameters for RAW to RGB. 470 * @return #E_NO_ERROR if everything is successful. 471 */ 472 int MXC_CSI2_VFIFO_ProcessRAWtoRGB(mxc_csi2_req_t *req); 473 474 /** 475 * @brief Sets the Payload data type. 476 * @note Parameters negative logic. 0 - enabled, 1 disabled. Passing set value disables data type. 477 * @param payload0 Select payload data type from mxc_csi2_payload0_t. 478 * @param payload1 Select payload data type from mxc_csi2_payload1_t. 479 * @return #E_NO_ERROR if everything is successful. 480 */ 481 int MXC_CSI2_VFIFO_SetPayloadType(mxc_csi2_payload0_t payload0, mxc_csi2_payload1_t payload1); 482 483 /** 484 * @brief Get the Payload data type. 485 * @note Value of registers are negative logic. 0 - enabled, 1 disabled. Compare 486 * with mxc_csi2_payloadn_t enum types or check user guide for specific value. 487 * @param payload0 Pointer to save the value of DISABLE_PAYLOAD_0 register. 488 * @param payload1 Pointer to save the value DISABLE_PAYLOAD_1 register. 489 * @return #E_NO_ERROR if everything is successful. 490 */ 491 int MXC_CSI2_VFIFO_GetPayloadType(uint32_t *payload0, uint32_t *payload1); 492 493 /** 494 * @brief Sets the DMA Mode for VFIFO. 495 * @param dma_mode Select DMA mode (condition to trigger) from mxc_csi2_dma_mode_t. 496 * @return #E_NO_ERROR if everything is successful. 497 */ 498 int MXC_CSI2_VFIFO_SetDMAMode(mxc_csi2_dma_mode_t dma_mode); 499 500 /** 501 * @brief Get the currently set DMA Mode for VFIFO. 502 * @return The currently set DMA mode. 503 */ 504 mxc_csi2_dma_mode_t MXC_CSI2_VFIFO_GetDMAMode(void); 505 506 /** 507 * @brief Sets the RGB Type when reading CSI2 FIFO. 508 * @param rgb_type Select RGB type from mxc_csi2_rgb_type_t. 509 * @return #E_NO_ERROR if everything is successful. 510 */ 511 int MXC_CSI2_VFIFO_SetRGBType(mxc_csi2_rgb_type_t rgb_type); 512 513 /** 514 * @brief Get the currently set RGB type. 515 * @return The currently set RGB Type. 516 */ 517 mxc_csi2_rgb_type_t MXC_CSI2_VFIFO_GetRGBType(void); 518 519 /** 520 * @brief Sets the RAW format type. 521 * @param raw_format Select Bayer Filter Pattern format type from mxc_csi2_raw_format_t. 522 * @return #E_NO_ERROR if everything is successful. 523 */ 524 int MXC_CSI2_VFIFO_SetRAWFormat(mxc_csi2_raw_format_t raw_format); 525 526 /** 527 * @brief Gets the currently set Bayer Filter pattern RAW format type. 528 * @return The currently set RAW format. 529 */ 530 mxc_csi2_raw_format_t MXC_CSI2_VFIFO_GetRAWFormat(void); 531 532 /** 533 * @brief Get the remaining current FIFO count in VFIFO. 534 * @note RGB Type can vary entity width. 535 * @return Number of entities currently in the FIFO. 536 */ 537 int MXC_CSI2_VFIFO_GetFIFOEntityCount(void); 538 539 /** 540 * @brief Set the AHB Wait (enable/disable) 541 * @param wait_en The setting to set AHBWAIT using type mxc_csi2_ahbwait_t. 542 */ 543 void MXC_CSI2_VFIFO_SetAHBWait(mxc_csi2_ahbwait_t wait_en); 544 545 /** 546 * @brief Retrieves whether AHB Wait is enabled or disabled. 547 * @return State of AHB Wait 548 */ 549 mxc_csi2_ahbwait_t MXC_CSI2_VFIFO_GetAHBWait(void); 550 551 /***********************************************/ 552 /* CSI2 PHY Protocol Interface (PPI) Functions */ 553 /***********************************************/ 554 555 /** 556 * @brief Enable PHY Protocol interface (PPI) Interrupts. 557 * @param mask The interrupt to be enabled. 558 */ 559 void MXC_CSI2_PPI_EnableInt(uint32_t mask); 560 561 /** 562 * @brief Disable PHY Protocol interface (PPI) Interrupts. 563 * @param mask The interrupt to be disable. 564 */ 565 void MXC_CSI2_PPI_DisableInt(uint32_t mask); 566 567 /** 568 * @brief Gets the interrupt flags that are currently set for PPI. 569 * @return The interrupt flags. 570 */ 571 int MXC_CSI2_PPI_GetFlags(void); 572 573 /** 574 * @brief Clears the interrupt flags for PPI. 575 * @param flags mask of flags to be cleared. 576 */ 577 void MXC_CSI2_PPI_ClearFlags(uint32_t flags); 578 579 /** 580 * @brief Stops the PPI by disabling interrupts. 581 * @return #E_NO_ERROR if everything is successful. 582 */ 583 int MXC_CSI2_PPI_Stop(void); 584 585 /************************************/ 586 /* CSI2 DMA - Used for all features */ 587 /************************************/ 588 589 bool MXC_CSI2_DMA_Frame_Complete(void); 590 591 mxc_csi2_capture_stats_t MXC_CSI2_GetCaptureStats(); 592 593 /** 594 * @brief Clears the interrupt flags for PPI. 595 * @param flags mask of flags to be cleared. 596 * @return #E_NO_ERROR if everything is successful. 597 */ 598 int MXC_CSI2_DMA_Config(uint8_t *dst_addr, uint32_t byte_cnt, uint32_t burst_size); 599 600 /** 601 * @brief Gets the acquired DMA channel used for CSI-2 operations. 602 * @return The channel currently used for CSI-2 operations. 603 */ 604 int MXC_CSI2_DMA_GetChannel(void); 605 606 /** 607 * @brief Gets the current DMA line count when using line by line DMA requests. 608 * @note In other words, gets the number of lines the DMA interrupt was triggered. 609 * @return The current number of lines processed using DMA. 610 */ 611 int MXC_CSI2_DMA_GetCurrentLineCnt(void); 612 613 /** 614 * @brief Gets the current DMA Frame End Count when using whole frame DMA requests. 615 * @note In other words, gets the number of frames the DMA interrupt was triggered. 616 * @return The current number of frames processed using DMA. 617 */ 618 int MXC_CSI2_DMA_GetCurrentFrameEndCnt(void); 619 620 /** 621 * @brief The processing function for DMA and the CSI-2. 622 * @note When using the DMA functions, the application must call this function 623 * periodically. This can be done within the DMA Interrupt Handler. 624 * @param a Required input parameter for calling this function but unused. 625 * @param b Required input parameter for calling this function but unused. 626 */ 627 void MXC_CSI2_DMA_Callback(int a, int b); 628 629 /**@} end of group csi2 */ 630 631 #ifdef __cplusplus 632 } 633 #endif 634 635 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_CSI2_H_ 636