| Kinetis SDK v.2.0 API Reference Manual Rev. 0 Freescale Semiconductor, Inc.

- Main Page
- Related Pages
- API Reference

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Modules | Files | Data Structures | Macros | Enumerations
FlexIO Camera Driver
FlexIO: FlexIO Driver

## Overview

The KSDK provides driver for the camera function using Flexible I/O.

# Overview

FlexIO CAMERA driver includes 2 parts: functional APIs and EDMA transactional APIs. Functional APIs are feature/property target low level APIs. User can use functional APIs for FLEXIO CAMERA initialization/configuration/operation purpose. Using the functional API require user get knowledge of the FLEXIO CAMERA peripheral and know how to organize functional APIs to meet the requirement of application. All functional API use the FLEXIO_CAMERA_Type * as the first parameter. FLEXIO CAMERA functional operation groups provide the functional APIs set.

EDMA transactional APIs are transaction target high level APIs. User can use the transactional API to enable the peripheral quickly and can also use in the application if the code size and performance of transactional APIs can satisfy requirement. If the code size and performance are critical requirement, user can refer to the transactional API implementation and write their own code. All transactional APIs use the flexio_camera_edma_handle_t as the second parameter and user need to initialize the handle by calling FLEXIO_CAMERA_TransferCreateHandleEDMA() API.

EDMA transactional APIs support asynchronized receive. It means, the functions FLEXIO_CAMERA_TransferReceiveEDMA() setup interrupt for data receive, when the receive complete, upper layer is notified through callback function with status kStatus_FLEXIO_CAMERA_RxIdle.

# Typical use case

## FLEXIO CAMERA Receive in EDMA way

volatile uint32_t isEDMAGetOnePictureFinish = false;
edma_handle_t g_edmaHandle;
flexio_camera_edma_handle_t g_cameraEdmaHandle;
edma_config_t edmaConfig;
FLEXIO_CAMERA_Type g_FlexioCameraDevice = {.flexioBase = FLEXIO0,
.datPinStartIdx = 24U, /* fxio_pin 24 -31 are used.
.pclkPinIdx = 1U, /* fxio_pin 1 is used as pclk pin.
.hrefPinIdx = 18U, /* flexio_pin 18 is used as href pin.
.shifterStartIdx = 0U, /* Shifter 0 = 7 are used.
.shifterCount = 8U,
.timerIdx = 0U};
flexio_camera_config_t cameraConfig;
/* Configure DMAMUX
DMAMUX_Init(DMAMUX0);
/* Configure DMA
EDMA_GetDefaultConfig(&edmaConfig);
EDMA_Init(DMA0, &edmaConfig);
DMAMUX_SetSource(DMAMUX0, DMA_CHN_FLEXIO_TO_FRAMEBUFF, (g_FlexioCameraDevice.shifterStartIdx + 1U));
DMAMUX_EnableChannel(DMAMUX0, DMA_CHN_FLEXIO_TO_FRAMEBUFF);
EDMA_CreateHandle(&g_edmaHandle, DMA0, DMA_CHN_FLEXIO_TO_FRAMEBUFF);
FLEXIO_CAMERA_GetDefaultConfig(&cameraConfig);
FLEXIO_CAMERA_Init(&g_FlexioCameraDevice, &cameraConfig);
/* Clear all the flag.
FLEXIO_CAMERA_ClearStatusFlags(&g_FlexioCameraDevice,
kFLEXIO_CAMERA_RxDataRegFullFlag | kFLEXIO_CAMERA_RxErrorFlag);
FLEXIO_ClearTimerStatusFlags(FLEXIO0, 0xFF);
FLEXIO_CAMERA_TransferCreateHandleEDMA(&g_FlexioCameraDevice, &g_cameraEdmaHandle, FLEXIO_CAMERA_UserCallback, NULL,
&g_edmaHandle);
cameraTransfer.dataAddress = (uint32_t)u16CameraFrameBuffer;
cameraTransfer.dataNum = sizeof(u16CameraFrameBuffer);
FLEXIO_CAMERA_TransferReceiveEDMA(&g_FlexioCameraDevice, &g_cameraEdmaHandle, &cameraTransfer);
while (!(isEDMAGetOnePictureFinish))
{
;
}
/* A callback function is also needed
void FLEXIO_CAMERA_UserCallback(FLEXIO_CAMERA_Type *base,
flexio_camera_edma_handle_t *handle,
status_t status,
void *userData)
{
userData = userData;
/* EDMA Transfer finished
if (kStatus_FLEXIO_CAMERA_RxIdle == status)
{
isEDMAGetOnePictureFinish = true;
}
}

## Modules
| FlexIO eDMA Camera Driver

## Files
file | fsl_flexio_camera.h

## Data Structures
struct | FLEXIO_CAMERA_Type
| Define structure of configuring the FlexIO camera device. More...
struct | flexio_camera_config_t
| Define FLEXIO camera user configuration structure. More...
struct | flexio_camera_transfer_t
| Define FLEXIO CAMERA transfer structure. More...

## Macros
#define | FLEXIO_CAMERA_PARALLEL_DATA_WIDTH (8U)
| Define the camera CPI interface is constantly 8-bit width. More...

## Enumerations
enum | _flexio_camera_status { kStatus_FLEXIO_CAMERA_RxBusy = MAKE_STATUS(kStatusGroup_FLEXIO_CAMERA, 0), kStatus_FLEXIO_CAMERA_RxIdle = MAKE_STATUS(kStatusGroup_FLEXIO_CAMERA, 1) }
| Error codes for the CAMERA driver. More...
enum | _flexio_camera_status_flags { kFLEXIO_CAMERA_RxDataRegFullFlag = 0x1U, kFLEXIO_CAMERA_RxErrorFlag = 0x2U }
| Define FlexIO CAMERA status mask. More...

## Driver version
#define | FSL_FLEXIO_CAMERA_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
| FlexIO camera driver version 2.1.0. More...

## Initialize and configuration
void | FLEXIO_CAMERA_Init (FLEXIO_CAMERA_Type *base, const flexio_camera_config_t *config)
| Ungates the FlexIO clock, reset the FlexIO module and do FlexIO CAMERA hardware configuration. More...
void | FLEXIO_CAMERA_Deinit (FLEXIO_CAMERA_Type *base)
| Disables the FlexIO CAMERA and gate the FlexIO clock. More...
void | FLEXIO_CAMERA_GetDefaultConfig (flexio_camera_config_t *config)
| Get the default configuration to configure FLEXIO CAMERA. More...
static void | FLEXIO_CAMERA_Enable (FLEXIO_CAMERA_Type *base, bool enable)
| Enables/disables the FlexIO CAMERA module operation. More...

## Status
uint32_t | FLEXIO_CAMERA_GetStatusFlags (FLEXIO_CAMERA_Type *base)
| Gets the FlexIO CAMERA status flags. More...
void | FLEXIO_CAMERA_ClearStatusFlags (FLEXIO_CAMERA_Type *base, uint32_t mask)
| Clears the receive buffer full flag manually. More...

## Interrupts
void | FLEXIO_CAMERA_EnableInterrupt (FLEXIO_CAMERA_Type *base)
| Switches on the interrupt for receive buffer full event. More...
void | FLEXIO_CAMERA_DisableInterrupt (FLEXIO_CAMERA_Type *base)
| Switches off the interrupt for receive buffer full event. More...

## DMA support
static void | FLEXIO_CAMERA_EnableRxDMA (FLEXIO_CAMERA_Type *base, bool enable)
| Enables/disables the FlexIO CAMERA receive DMA. More...
static uint32_t | FLEXIO_CAMERA_GetRxBufferAddress (FLEXIO_CAMERA_Type *base)
| Gets the data from the receive buffer. More...

## Data Structure Documentation

struct FLEXIO_CAMERA_Type

### Data Fields
FLEXIO_Type * | flexioBase
| FlexIO module base address. More...
uint32_t | datPinStartIdx
| First data pin (D0) index for flexio_camera. More...
uint32_t | pclkPinIdx
| Pixel clock pin (PCLK) index for flexio_camera. More...
uint32_t | hrefPinIdx
| Horizontal sync pin (HREF) index for flexio_camera. More...
uint32_t | shifterStartIdx
| First shifter index used for flexio_camera data FIFO. More...
uint32_t | shifterCount
| The count of shifters that are used as flexio_camera data FIFO. More...
uint32_t | timerIdx
| Timer index used for flexio_camera in FlexIO. More...

#### Field Documentation

FLEXIO_Type* FLEXIO_CAMERA_Type::flexioBase

uint32_t FLEXIO_CAMERA_Type::datPinStartIdx

Then the successive following FLEXIO_CAMERA_DATA_WIDTH-1 pins would be used as D1-D7.

uint32_t FLEXIO_CAMERA_Type::pclkPinIdx

uint32_t FLEXIO_CAMERA_Type::hrefPinIdx

uint32_t FLEXIO_CAMERA_Type::shifterStartIdx

uint32_t FLEXIO_CAMERA_Type::shifterCount

uint32_t FLEXIO_CAMERA_Type::timerIdx

struct flexio_camera_config_t

### Data Fields
bool | enablecamera
| Enable/disable FLEXIO camera TX & RX. More...
bool | enableInDoze
| Enable/disable FLEXIO operation in doze mode.
bool | enableInDebug
| Enable/disable FLEXIO operation in debug mode.
bool | enableFastAccess
| Enable/disable fast access to FLEXIO registers, fast access requires the FLEXIO clock to be at least twice the frequency of the bus clock. More...

#### Field Documentation

bool flexio_camera_config_t::enablecamera

bool flexio_camera_config_t::enableFastAccess

struct flexio_camera_transfer_t

### Data Fields
uint32_t | dataAddress
| Transfer buffer.
uint32_t | dataNum
| Transfer num.

## Macro Definition Documentation

#define FSL_FLEXIO_CAMERA_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))

#define FLEXIO_CAMERA_PARALLEL_DATA_WIDTH (8U)

## Enumeration Type Documentation

enum _flexio_camera_status

Enumerator
kStatus_FLEXIO_CAMERA_RxBusy | Receiver is busy.
kStatus_FLEXIO_CAMERA_RxIdle | CAMERA receiver is idle.

enum _flexio_camera_status_flags

Enumerator
kFLEXIO_CAMERA_RxDataRegFullFlag | Receive buffer full flag.
kFLEXIO_CAMERA_RxErrorFlag | Receive buffer error flag.

## Function Documentation

void FLEXIO_CAMERA_Init | ( | FLEXIO_CAMERA_Type * | base,
|  | const flexio_camera_config_t * | config
| ) |  |

Parameters

  base | pointer to FLEXIO_CAMERA_Type structure
  config | pointer to flexio_camera_config_t structure

void FLEXIO_CAMERA_Deinit | ( | FLEXIO_CAMERA_Type * | base | ) |

Note
  After calling this API, user need to call FLEXO_CAMERA_Init to use the FlexIO CAMERA module.

Parameters

  base | pointer to FLEXIO_CAMERA_Type structure

void FLEXIO_CAMERA_GetDefaultConfig | ( | flexio_camera_config_t * | config | ) |

The configuration could be used directly for calling FLEXIO_CAMERA_Init(). Example:

flexio_camera_config_t config;
FLEXIO_CAMERA_GetDefaultConfig(&userConfig);

Parameters

  config | pointer to flexio_camera_config_t structure

static void FLEXIO_CAMERA_Enable | ( | FLEXIO_CAMERA_Type * | base,
|  | bool | enable
| ) |  |
| inline static

Parameters

  base | pointer to FLEXIO_CAMERA_Type
  enable | True to enable, false to disable.

uint32_t FLEXIO_CAMERA_GetStatusFlags | ( | FLEXIO_CAMERA_Type * | base | ) |

Parameters

  base | pointer to FLEXIO_CAMERA_Type structure

Returns
  FlexIO shifter status flags
  - FLEXIO_SHIFTSTAT_SSF_MASK
  - 0

void FLEXIO_CAMERA_ClearStatusFlags | ( | FLEXIO_CAMERA_Type * | base,
|  | uint32_t | mask
| ) |  |

Parameters

  base | pointer to the device.
  mask | status flag The parameter could be any combination of the following values: kFLEXIO_CAMERA_RxDataRegFullFlag kFLEXIO_CAMERA_RxErrorFlag

void FLEXIO_CAMERA_EnableInterrupt | ( | FLEXIO_CAMERA_Type * | base | ) |

Parameters

  base | pointer to the device.

void FLEXIO_CAMERA_DisableInterrupt | ( | FLEXIO_CAMERA_Type * | base | ) |

Parameters

  base | pointer to the device.

static void FLEXIO_CAMERA_EnableRxDMA | ( | FLEXIO_CAMERA_Type * | base,
|  | bool | enable
| ) |  |
| inline static

Parameters

  base | pointer to FLEXIO_CAMERA_Type structure
  enable | True to enable, false to disable.

The FlexIO camera mode can't work without the DMA or EDMA support, Usually, it needs at least two DMA or EDMA channel, one for transferring data from camera, such as 0V7670 to FlexIO buffer, another is for transferring data from FlexIO buffer to LCD.

static uint32_t FLEXIO_CAMERA_GetRxBufferAddress | ( | FLEXIO_CAMERA_Type * | base | ) |
| inline static

Parameters

  base | pointer to the device.

Returns
  data pointer to the buffer that would keep the data with count of base->shifterCount .