12#include "fsl_common.h"
25#define FSL_CSI_DRIVER_VERSION (MAKE_VERSION(2, 1, 5))
28#define CSI_REG_CR1(base) (base)->CR1
29#define CSI_REG_CR2(base) (base)->CR2
30#define CSI_REG_CR3(base) (base)->CR3
31#define CSI_REG_CR18(base) (base)->CR18
32#define CSI_REG_SR(base) (base)->SR
33#define CSI_REG_DMASA_FB1(base) (base)->DMASA_FB1
34#define CSI_REG_DMASA_FB2(base) (base)->DMASA_FB2
35#define CSI_REG_IMAG_PARA(base) (base)->IMAG_PARA
36#define CSI_REG_FBUF_PARA(base) (base)->FBUF_PARA
39#ifndef CSI_DRIVER_QUEUE_SIZE
40#define CSI_DRIVER_QUEUE_SIZE 4U
44#ifndef CSI_DRIVER_FRAG_MODE
45#define CSI_DRIVER_FRAG_MODE 0U
53#define CSI_DRIVER_ACTUAL_QUEUE_SIZE (CSI_DRIVER_QUEUE_SIZE + 1U)
58#if (CSI_DRIVER_ACTUAL_QUEUE_SIZE > 254)
59#error Required queue size is too large
67#define CSI_CR1_INT_EN_MASK 0xFFFF0000U
68#define CSI_CR3_INT_EN_MASK 0x000000FFU
69#define CSI_CR18_INT_EN_MASK 0x0000FF00U
71#if ((~CSI_CR1_INT_EN_MASK) & \
72 (CSI_CR1_EOF_INT_EN_MASK | CSI_CR1_COF_INT_EN_MASK | CSI_CR1_SF_OR_INTEN_MASK | CSI_CR1_RF_OR_INTEN_MASK | \
73 CSI_CR1_SFF_DMA_DONE_INTEN_MASK | CSI_CR1_STATFF_INTEN_MASK | CSI_CR1_FB2_DMA_DONE_INTEN_MASK | \
74 CSI_CR1_FB1_DMA_DONE_INTEN_MASK | CSI_CR1_RXFF_INTEN_MASK | CSI_CR1_SOF_INTEN_MASK))
75#error CSI_CR1_INT_EN_MASK could not cover all interrupt bits in CSICR1.
78#if ((~CSI_CR3_INT_EN_MASK) & (CSI_CR3_ECC_INT_EN_MASK | CSI_CR3_HRESP_ERR_EN_MASK))
79#error CSI_CR3_INT_EN_MASK could not cover all interrupt bits in CSICR3.
82#if ((~CSI_CR18_INT_EN_MASK) & \
83 ((CSI_CR18_FIELD0_DONE_IE_MASK | CSI_CR18_DMA_FIELD1_DONE_IE_MASK | CSI_CR18_BASEADDR_CHANGE_ERROR_IE_MASK) \
85#error CSI_CR18_INT_EN_MASK could not cover all interrupt bits in CSICR18.
253#if CSI_DRIVER_FRAG_MODE
256typedef enum _csi_frag_input_pixel_format
258 kCSI_FragInputRGB565 = 0,
261} csi_frag_input_pixel_format_t;
264typedef struct _csi_frag_config
268 uint32_t polarityFlags;
273 csi_frag_input_pixel_format_t inputFormat;
275 uint32_t dmaBufferAddr0;
276 uint32_t dmaBufferAddr1;
277 uint16_t dmaBufferLine;
280 bool isDmaBufferCachable;
284typedef struct _csi_frag_handle csi_frag_handle_t;
292typedef void (*csi_frag_transfer_callback_t)(
CSI_Type *base,
293 csi_frag_handle_t *handle,
300typedef void (*csi_frag_copy_func_t)(
void *pDest,
const void *pSrc,
size_t cnt);
303struct _csi_frag_handle
307 uint16_t maxLinePerFrag;
308 uint16_t linePerFrag;
309 uint16_t dmaBytePerLine;
310 uint16_t datBytePerLine;
316 uint32_t outputBuffer;
317 uint32_t datCurWriteAddr;
318 csi_frag_input_pixel_format_t inputFormat;
320 csi_frag_transfer_callback_t callback;
322 csi_frag_copy_func_t copyFunc;
323 bool isDmaBufferCachable;
327typedef struct _csi_frag_window
336typedef struct _csi_frag_capture_config
338 bool outputGrayScale;
340 csi_frag_window_t *window;
342} csi_frag_capture_config_t;
350#if defined(__cplusplus)
456static inline void CSI_Start(
CSI_Type *base)
459 CSI_REG_CR18(base) |= CSI_CR18_CSI_ENABLE_MASK;
467static inline void CSI_Stop(
CSI_Type *base)
469 CSI_REG_CR18(base) &= ~CSI_CR18_CSI_ENABLE_MASK;
517static inline uint32_t CSI_GetStatusFlags(
CSI_Type *base)
519 return CSI_REG_SR(base);
537static inline void CSI_ClearStatusFlags(
CSI_Type *base, uint32_t statusMask)
539 CSI_REG_SR(base) = statusMask;
543#if !CSI_DRIVER_FRAG_MODE
656void CSI_FragModeInit(
CSI_Type *base);
665void CSI_FragModeDeinit(
CSI_Type *base);
680 csi_frag_handle_t *handle,
681 const csi_frag_config_t *
config,
682 csi_frag_transfer_callback_t callback,
696 csi_frag_handle_t *handle,
697 const csi_frag_capture_config_t *
config);
707void CSI_FragModeTransferAbortCaptureImage(
CSI_Type *base, csi_frag_handle_t *handle);
718void CSI_FragModeTransferHandleIRQ(
CSI_Type *base, csi_frag_handle_t *handle);
724#if defined(__cplusplus)
#define CSI_CR1_CCIR_EN(x)
Definition: MIMXRT1052.h:10642
#define CSI_CR1_GCLK_MODE(x)
Definition: MIMXRT1052.h:10608
volatile uint8_t queueWriteIdx
Definition: fsl_csi.h:240
void CSI_SetRxBufferAddr(CSI_Type *base, uint8_t index, uint32_t addr)
Set the RX frame buffer address.
Definition: fsl_csi.c:478
_csi_data_bus
CSI data bus witdh.
Definition: fsl_csi.h:113
void CSI_EnableFifoDmaRequest(CSI_Type *base, csi_fifo_t fifo, bool enable)
Enable or disable the CSI FIFO DMA request.
Definition: fsl_csi.c:572
void CSI_Deinit(CSI_Type *base)
De-initialize the CSI.
Definition: fsl_csi.c:380
status_t CSI_TransferGetFullBuffer(CSI_Type *base, csi_handle_t *handle, uint32_t *frameBuffer)
Get one full frame buffer from queue.
Definition: fsl_csi.c:805
volatile uint8_t queueReadIdx
Definition: fsl_csi.h:241
void CSI_EnableInterrupts(CSI_Type *base, uint32_t mask)
Enables CSI interrupt requests.
Definition: fsl_csi.c:602
_csi_interrupt_enable
CSI feature interrupt source.
Definition: fsl_csi.h:157
void CSI_GetDefaultConfig(csi_config_t *config)
Get the default configuration for to initialize the CSI.
Definition: fsl_csi.c:454
void * userData
Definition: fsl_csi.h:250
enum _csi_data_bus csi_data_bus_t
CSI data bus witdh.
uint8_t bytesPerPixel
Definition: fsl_csi.h:136
volatile bool transferStarted
Definition: fsl_csi.h:247
_csi_work_mode
CSI work mode.
Definition: fsl_csi.h:103
bool useExtVsync
Definition: fsl_csi.h:143
status_t CSI_TransferStart(CSI_Type *base, csi_handle_t *handle)
Start the transfer using transactional functions.
Definition: fsl_csi.c:678
status_t CSI_Init(CSI_Type *base, const csi_config_t *config)
Initialize the CSI.
Definition: fsl_csi.c:279
csi_transfer_callback_t callback
Definition: fsl_csi.h:249
void *volatile emptyBuffer
Definition: fsl_csi.h:242
struct _csi_config csi_config_t
Configuration to initialize the CSI module.
status_t CSI_TransferSubmitEmptyBuffer(CSI_Type *base, csi_handle_t *handle, uint32_t frameBuffer)
Submit empty frame buffer to queue.
Definition: fsl_csi.c:773
enum _csi_fifo csi_fifo_t
The CSI FIFO, used for FIFO operation.
uint16_t linePitch_Bytes
Definition: fsl_csi.h:140
void CSI_TransferHandleIRQ(CSI_Type *base, csi_handle_t *handle)
CSI IRQ handle function.
Definition: fsl_csi.c:848
uint16_t width
Definition: fsl_csi.h:133
uint32_t polarityFlags
Definition: fsl_csi.h:135
void CSI_ClearFifo(CSI_Type *base, csi_fifo_t fifo)
Clear the CSI FIFO.
Definition: fsl_csi.c:500
volatile uint8_t activeBufferNum
Definition: fsl_csi.h:245
void CSI_DisableInterrupts(CSI_Type *base, uint32_t mask)
Disable CSI interrupt requests.
Definition: fsl_csi.c:615
void CSI_Reset(CSI_Type *base)
Reset the CSI.
Definition: fsl_csi.c:397
void CSI_ReflashFifoDma(CSI_Type *base, csi_fifo_t fifo)
Reflash the CSI FIFO DMA.
Definition: fsl_csi.c:543
status_t CSI_TransferStop(CSI_Type *base, csi_handle_t *handle)
Stop the transfer using transactional functions.
Definition: fsl_csi.c:730
_csi_fifo
The CSI FIFO, used for FIFO operation.
Definition: fsl_csi.h:149
void(* csi_transfer_callback_t)(CSI_Type *base, csi_handle_t *handle, status_t status, void *userData)
CSI transfer callback function.
Definition: fsl_csi.h:229
_csi_flags
CSI status flags.
Definition: fsl_csi.h:198
uint16_t height
Definition: fsl_csi.h:134
csi_data_bus_t dataBus
Definition: fsl_csi.h:142
volatile uint8_t emptyBufferCnt
Definition: fsl_csi.h:243
csi_work_mode_t workMode
Definition: fsl_csi.h:141
uint32_t frameBufferQueue[CSI_DRIVER_ACTUAL_QUEUE_SIZE]
Definition: fsl_csi.h:238
enum _csi_work_mode csi_work_mode_t
CSI work mode.
_csi_polarity_flags
CSI signal polarity.
Definition: fsl_csi.h:121
status_t CSI_TransferCreateHandle(CSI_Type *base, csi_handle_t *handle, csi_transfer_callback_t callback, void *userData)
Initializes the CSI handle.
Definition: fsl_csi.c:636
@ kCSI_DataBus16Bit
Definition: fsl_csi.h:115
@ kCSI_DataBus24Bit
Definition: fsl_csi.h:116
@ kCSI_DataBus8Bit
Definition: fsl_csi.h:114
@ kCSI_StartOfFrameInterruptEnable
Definition: fsl_csi.h:167
@ kCSI_StatFifoFullInterruptEnable
Definition: fsl_csi.h:163
@ kCSI_RxFifoFullInterruptEnable
Definition: fsl_csi.h:166
@ kCSI_EccErrorInterruptEnable
Definition: fsl_csi.h:169
@ kCSI_BaseAddrChangeErrorInterruptEnable
Definition: fsl_csi.h:173
@ kCSI_Field1DoneInterruptEnable
Definition: fsl_csi.h:176
@ kCSI_Field0DoneInterruptEnable
Definition: fsl_csi.h:175
@ kCSI_EndOfFrameInterruptEnable
Definition: fsl_csi.h:158
@ kCSI_StatFifoDmaDoneInterruptEnable
Definition: fsl_csi.h:162
@ kCSI_RxBuffer0DmaDoneInterruptEnable
Definition: fsl_csi.h:165
@ kCSI_RxBuffer1DmaDoneInterruptEnable
Definition: fsl_csi.h:164
@ kCSI_RxFifoOverrunInterruptEnable
Definition: fsl_csi.h:161
@ kCSI_ChangeOfFieldInterruptEnable
Definition: fsl_csi.h:159
@ kCSI_StatFifoOverrunInterruptEnable
Definition: fsl_csi.h:160
@ kCSI_AhbResErrorInterruptEnable
Definition: fsl_csi.h:170
@ kCSI_GatedClockMode
Definition: fsl_csi.h:104
@ kCSI_CCIR656ProgressiveMode
Definition: fsl_csi.h:106
@ kCSI_NonGatedClockMode
Definition: fsl_csi.h:105
@ kStatus_CSI_NoEmptyBuffer
Definition: fsl_csi.h:91
@ kStatus_CSI_NoFullBuffer
Definition: fsl_csi.h:92
@ kStatus_CSI_QueueFull
Definition: fsl_csi.h:93
@ kStatus_CSI_FrameDone
Definition: fsl_csi.h:94
@ kCSI_RxFifo
Definition: fsl_csi.h:150
@ kCSI_StatFifo
Definition: fsl_csi.h:151
@ kCSI_AllFifo
Definition: fsl_csi.h:152
@ kCSI_StatFifoOverrunFlag
Definition: fsl_csi.h:212
@ kCSI_StartOfFrameFlag
Definition: fsl_csi.h:205
@ kCSI_Field1PresentFlag
Definition: fsl_csi.h:204
@ kCSI_BaseAddrChangeErrorFlag
Definition: fsl_csi.h:216
@ kCSI_Field0DoneFlag
Definition: fsl_csi.h:214
@ kCSI_RxBuffer1DmaDoneFlag
Definition: fsl_csi.h:208
@ kCSI_RxBuffer0DmaDoneFlag
Definition: fsl_csi.h:209
@ kCSI_RxFifoDataReadyFlag
Definition: fsl_csi.h:199
@ kCSI_EccErrorFlag
Definition: fsl_csi.h:200
@ kCSI_Field1DoneFlag
Definition: fsl_csi.h:215
@ kCSI_StatFifoFullFlag
Definition: fsl_csi.h:210
@ kCSI_StatFifoDmaDoneFlag
Definition: fsl_csi.h:211
@ kCSI_AhbResErrorFlag
Definition: fsl_csi.h:201
@ kCSI_RxFifoOverrunFlag
Definition: fsl_csi.h:213
@ kCSI_Field0PresentFlag
Definition: fsl_csi.h:203
@ kCSI_RxFifoFullFlag
Definition: fsl_csi.h:207
@ kCSI_ChangeOfFieldFlag
Definition: fsl_csi.h:202
@ kCSI_EndOfFrameFlag
Definition: fsl_csi.h:206
@ kCSI_VsyncActiveHigh
Definition: fsl_csi.h:126
@ kCSI_DataLatchOnFallingEdge
Definition: fsl_csi.h:125
@ kCSI_VsyncActiveLow
Definition: fsl_csi.h:127
@ kCSI_HsyncActiveLow
Definition: fsl_csi.h:122
@ kCSI_DataLatchOnRisingEdge
Definition: fsl_csi.h:124
@ kCSI_HsyncActiveHigh
Definition: fsl_csi.h:123
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:225
#define MAKE_STATUS(group, code)
Construct a status code value from a group and code number.
Definition: fsl_common.h:47
@ kStatusGroup_CSI
Definition: fsl_common.h:112
Definition: MIMXRT1052.h:10538
Configuration to initialize the CSI module.
Definition: fsl_csi.h:132
CSI handle structure.
Definition: fsl_csi.h:237
Definition: deflate.c:114