/**
  ******************************************************************************
  * @file    dcmi_drv.h
  * @author  Product application department
  * @version V1.0
  * @date    2020.02.13
  * @brief   Header file of DCMI DRV module.
  *
  ******************************************************************************
  */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DCMI_DRV_H
#define __DCMI_DRV_H

#ifdef __cplusplus
extern "C"
{
#endif

/* Includes ------------------------------------------------------------------*/
#include "drv_reg.h"
#include "drv_gpio_def.h"


#ifdef FILE_OUT
/**@defgroup DRV 3 HAL driver
  *
  *@{
  */

/** @defgroup DRV_DCMI DCMI
  *
  *@{
  */
#endif
/*** 宏定义 *******************************************************************/
#ifdef FILE_OUT
/** @defgroup DRV_DCMI_Exported_Macros Exported Macros
  *
  * @{
  */
#endif

/**
  * @brief  DCMI 常用宏常量
  *
  */
#define DCMI_ENABLE             (1<<14)	
#define CAPTURE                 (1<<0)	

#define EDMA_ENABLE             (1<<31)	
#define IDMA_ENABLE             (1<<0)		

#define RGB_BGR_1               (1<<12)
#define DVP_1                   (1<<11)
#define RAW_PROC_EN             (1<<3)
#define RGB_PROC_EN             (1<<2)	
#define YUV_PROC_EN             (1<<1)
#define Y2EXTDMA_EN             (1<<0)	


#define IDMA_FIXED_ADDR         (1<<30)

//#define SNSR_DATA_FORMAT_YUV422     (5<<4)	
//#define SNSR_DATA_FORMAT_YUV420     (7<<4)	
//#define SNSR_DATA_FORMAT_RGB565     (2<<4)	
//#define SNSR_DATA_FORMAT_RGB888     (4<<4)	

//#define DISP_DATA_FORMAT_RGB565 (0<<9)	
//#define DISP_DATA_FORMAT_OTHER  (7<<9)	

#define SNSR_DATA_FORMAT_YUV422 (5<<4)
#define SNSR_DATA_FORMAT_YUV420 (7<<4)
#define SNSR_DATA_FORMAT_RGB565 (2<<4)
#define SNSR_DATA_FORMAT_RGB888 (4<<4)
#define SNSR_DATA_FORMAT_OTHER  (0x10<<4)

#define DISP_DATA_FORMAT_YUV422 (3<<9)
#define DISP_DATA_FORMAT_YUV420 (4<<9)
#define DISP_DATA_FORMAT_RGB565 (0<<9)
#define DISP_DATA_FORMAT_RGB565 (0<<9)
#define DISP_DATA_FORMAT_RGB888 (2<<9)
#define DISP_DATA_FORMAT_OTHER  (7<<9)


 
#define CM_SNAP                 (1<<1)	
	/**
  * @brief DCMI状态定义
  */
typedef enum
{
  DRV_DCMI_OK       = 0x00,
  DRV_DCMI_ERROR    = 0x01,
  DRV_DCMI_BUSY     = 0x02,
  DRV_DCMI_TIMEOUT  = 0x03,
}DRV_DCMI_StatusTypeDef;
/**
  * @brief DCMI输入格式定义
  */
typedef enum
{
	INPUT_FORMAT_RGB565,//0
	INPUT_FORMAT_RGB666,
	INPUT_FORMAT_RGB888,
	INPUT_FORMAT_YUV422,
	INPUT_FORMAT_YUV420,
	INPUT_FORMAT_MO1NO,
	INPUT_FORMAT_RAWBAYER,
	INPUT_FORMAT_JPEG,
}DCMI_InputModeTypeDef;	


/**
  * @brief DCMI输出格式定义
  */
typedef enum
{
	OUTPUT_FORMAT_RGB444,
	OUTPUT_FORMAT_RGB555,
	OUTPUT_FORMAT_RGB565,
	OUTPUT_FORMAT_YUV444,
	OUTPUT_FORMAT_RGB888,
	OUTPUT_FORMAT_YUV422,
	OUTPUT_FORMAT_420LEGACY,
	OUTPUT_FORMAT_YUV420,
	OUTPUT_FORMAT_RAW6,
	OUTPUT_FORMAT_RAW7,
	OUTPUT_FORMAT_RAW8,
	OUTPUT_FORMAT_RAW10,
	OUTPUT_FORMAT_RAW12,
	OUTPUT_FORMAT_RAW14,
	OUTPUT_FORMAT_MONO,
	
}DCMI_OutputModeTypeDef;	
	/**
  * @}
  */
/**
  * @brief dcmi初始定义
  */
typedef struct
{
    uint8_t InputMode;          /**<输入图像格式*/
	  uint8_t OutputMode;          /**<输出图像格式*/
	
		uint8_t  isCaptureMode;      /**<0:single  1:continuous*/
	  uint8_t  isRgbiDmaMode;      /**<0:dma->lcd  1:idma->lcd*/
	  
	  //uint8_t iDmaMode;           /**<图像传输是否采用内部DMA*/
	
	  uint32_t iDmaDst;           /**<内部DMA传输的目的地址*/
	  uint32_t eDmaDst;           /**<外部DMA传输的目的地址*/
    
	  uint16_t Input_width;       /**<输入图像宽度*/
	  uint16_t Input_height;      /**<输入图像高度*/

	  uint8_t   EnableIE;
	  uint8_t   IEMask;

	  uint8_t   Rgb2Bgr;
    				 
}DCMI_InitTypeDef;

/**
  *@}
  */

/**
  *@}
  */
extern DRV_DCMI_StatusTypeDef DRV_DCMI_Getgray(DCMI_TypeDef *pdcmi ,DCMI_InitTypeDef *pinit);
extern DRV_DCMI_StatusTypeDef DRV_DCMI_Init(DCMI_TypeDef *pdcmi, DCMI_InitTypeDef *pinit);

extern DRV_DCMI_StatusTypeDef DRV_DCMI_Getgray_Idma(DCMI_TypeDef *pdcmi,DCMI_InitTypeDef *pinit);
extern DRV_DCMI_StatusTypeDef DRV_DCMI_Getgray_Edma(DCMI_TypeDef *pdcmi,DCMI_InitTypeDef *pinit);
#ifdef __cplusplus
}

#endif

#endif /* __DCMI_DRV_H */
