This section describes the programming interface of the FlexIO Camera with eDMA Peripheral driver.
FlexIO Camera with eDMA provides a use case that shows how to map the image data from the camera's sensor matrix to the indicated memory area. In this module, a DMA channel inside the driver syncs the data from the camera to memory automatically in the background. The DMA channel is triggered after the FlexIO Camera's buffer is filled and updates the data for every trigger. In this instance, the the internal DMA and camera's data stream are not relevant to the application. The application reads the mapped image data as soon as possible with no blocking. Reading the memory corresponds to reading the camera's sensor matrix directly.
Note that, when using DMA to transfer data, because of the cache for memory, the data mist be consistent. This means that, when reading data from memory, the application must ensure that data from or to the memory device is not cached.
#include "fsl_edma_driver.h"
#include "fsl_flexio_camera_edma_driver.h"
#include "fsl_flexio_driver.h"
static volatile uint16_t u16CameraFrameBuffer[OV7670_FRAME_PIXELS];
#define eDMA_LCD_CONFIG \
{ \
.srcAddr = (uint32_t)u16CameraFrameBuffer, \
.destAddr = (uint32_t)FLEX_BASE_ADDRESS, \
.srcTransferSize = kEDMATransferSize_2Bytes, \
.destTransferSize = kEDMATransferSize_2Bytes, \
.srcOffset = 2, \
.destOffset = 0, \
.srcLastAddrAdjust = -((sizeof(u16CameraFrameBuffer))), \
.destLastAddrAdjust = 0, \
.srcModulo = kEDMAModuloDisable, \
.destModulo = kEDMAModuloDisable, \
.minorLoopCount = 32, \
.majorLoopCount = ((sizeof(u16CameraFrameBuffer)>>5)), \
}
volatile flexio_camera_edma_handler_t gFlexioCameraHandlerStruct;
static void port_vsync_callback(uint32_t pin);
int main(void)
{
ov7670_status_t ov7670_status;
uint32_t ret;
flexio_user_config_t flexioUserConfig =
{
.useInt = false,
.onDozeEnable = true,
.onDebugEnable = true,
.fastAccessEnable = true
};
{
.notHaltOnError = false
};
flexio_camera_user_config_t UserFlexioCameraConfigStruct =
{
.flexioInstance = 0U,
.datPinStartIdx = 24U,
.pclkPinIdx = 1U,
.hrefPinIdx = 18U,
.shifterStartIdx = 0U,
.timerIdx = 0U
};
camera_edma_user_config_t UserCameraEdmaConfigStruct =
{
.userEdmaChn = APP_EDMA_CHN_FOR_CAMERA,
.userBufAddr = (uint32_t)(u16CameraFrameBuffer),
.userBufLenByte = (uint32_t)(sizeof(u16CameraFrameBuffer))
};
FLEXIO_DRV_Init(0U, &flexioUserConfig);
ret = FLEXIO_Camera_DRV_InitEdmaRx(
(flexio_camera_edma_handler_t *)&gFlexioCameraHandlerStruct,
&UserFlexioCameraConfigStruct,
&UserCameraEdmaConfigStruct );
if (ret != kStatus_FlexIO_Camera_Success)
{
while (1);
}
FLEXIO_Camera_DRV_SetBufferTriggerForExtEdma(
(flexio_camera_edma_handler_t *)&gFlexioCameraHandlerStruct,
0x03, true);
APP_EDMA_CHN_FOR_LCD,
(
dma_request_source_t)(kDmaRequestMux0Group1FlexIO0Channel0 + UserFlexioCameraConfigStruct.shifterStartIdx + 1U),
&lcdEdmaChnState);
{
while (1);
}
&lcdEdmaChnState,
lcdEdmaChnStcd,
&lcdEdmeConfigStruct,
false,
false
);
{
while (1);
}
{
while (1);
}
{
while (1);
}
FLEXIO_Camera_DRV_StartEdmaRx(
(flexio_camera_edma_handler_t *)&gFlexioCameraHandlerStruct);
FLEXIO_DRV_Start(0U);
PORTA_InstallCallback(1, port_vsync_callback);
configure_app_gpio_pins();
while(1) {}
}
static void port_vsync_callback(uint32_t pin)
{
if (pin == (1<<13))
{
FLEXIO_Camera_DRV_ResetEdmaRx(
(flexio_camera_edma_handler_t *)&gFlexioCameraHandlerStruct);
}
}