//*****************************************************************************
// "$RCSfile: Analog_CPT2.h,v $"
//*****************************************************************************
// Information by CVS or VSS:
//     Last check in on: $Date: 2011-02-17 16:08:10 $
//     by                $Author: goebel $
//     Revision        : $Revision: 1.2 $
//
// CVS: $Source: /Daten/Projekte/CVS/Lib/Analog_Lib/src/Analog_CPT2.h,v $
// VSS: $Archive:$
//
// $NoKeywords: $ expanding by VSS -->
//
// CVS: $Revision: 1.2 $
//
//*****************************************************************************
//! \file Analog_CPT2.h
//! \brief Header for analog camera functions
//! \author (c) 2004 - 2013 IMAGO Technologies GmbH
//!
//! $Revision: 1.2 $
//! $Date: 2011-02-17 16:08:10 $
//! \addtogroup AnalogC2
//! \{
//******************************************************************************

#ifndef __ANALOG_H__
#define __ANALOG_H__

#include "vision_box.h"

/******************************************************************************\
* Defines                                                                      *
\******************************************************************************/

enum eACAM_MODE
{
	PAL_Y =				0x00000010, //!< PAL monochrome camera
	PAL_YUYV =			0x00000011, //!< PAL color camera
	PAL_Y_360 =			0x00000012, //!< PAL scaled 2 CIF monochrome camera
	PAL_YUYV_360 =		0x00000013, //!< PAL scaled 2 CIF color camera
	PAL_CIF_YUYV =		0x00000014,	//!< PAS scaled 2 CIF color camera
	PAL_CIF_Y =			0x00000015,	//!< PAL scaled 2 CIF monochrome camera
	NTSC_Y =			0x00000020, //!< NTSC monochrome camera
	NTSC_YUYV =			0x00000021, //!< NTSC color camera
	NTSC_CIF_Y =		0x00000022, //!< NTSC scaled 2 CIF monochrome camera
	NTSC_CIF_YUYV =		0x00000023  //!< NTSC scaled 2 CIF color camera
};

enum eACAM_PORT
{
	VIB_MPS_SA_P1 =		0x00100000, //!< VIB_MPS2 SAT_A Port1
	VIB_MPS_SA_P2 =		0x00110000, //!< VIB_MPS2 SAT_A Port2
	VIB_MPS_SB_P1 =		0x00200000, //!< VIB_MPS2 SAT_B Port1
	VIB_MPS_SB_P2 =		0x00210000, //!< VIB_MPS2 SAT_B Port2
	VIB_MPS_SC_P1 =		0x00300000, //!< VIB_MPS2 SAT_C Port1
	VIB_MPS_SC_P2 =		0x00310000, //!< VIB_MPS2 SAT_C Port2
	VIB_C2_P1 =			0x00400000, //!< VIB_CompactII2 Port1
	VIB_C2_P2 =			0x00410000, //!< VIB_CompactII2 Port2
	VIB_C2_P3 =			0x00420000, //!< VIB_CompactII2 Port3
	VIB_C2_P4 =			0x00430000  //!< VIB_CompactII2 Port4
};

//!@cond SHOWALL

enum eTVP_Command
{
	TVP_PAL_YUYV =	0,
	TVP_PAL_Y =		1,
	TVP_INPUT_1A =	2,
	TVP_INPUT_2A =	3,
	TVP_DEC_RE1 =	4,
	TVP_DEC_RE2 =	5,
	TVP_DEC_RE3 =	6,
	TVP_DEC_RE4 =	7,
	TVP_DEC_WE1 =	8,
	TVP_DEC_WE2 =	9,
	TVP_DEC_WE3 =	10,
	TVP_DEC_WE4 =	11,
	TVP_DEC_WEALL =	12,
	TVP_INPUT_A =	13,
	TVP_UNLOCK_DID =14,
	TVP_LOCK_DID =	15,
	TVP_PAL_YUYV_SCALED=16,
	TVP_PAL_Y_SCALED = 17
};

/******************************************************************************\
* Structures                                                                   *
\******************************************************************************/

typedef union sSatan_LR
{
	unsigned int Register;
	struct
	{
		unsigned int left	:12;
		unsigned int right	:12;
		unsigned int rsvd	:8;
	} Bits;
} SATAN_LR;

typedef union sSatan_TB
{
	unsigned int Register;
	struct
	{
		unsigned int top	:12;
		unsigned int bottom	:12;
		unsigned int rsvd	:8;
	} Bits;
} SATAN_TB;

typedef union sSatan_Mask
{
	unsigned int Register;
	struct
	{
		unsigned int scalmask1		:4;
		unsigned int scalmask2		:4;
		unsigned int enable_field	:2;
		unsigned int start_field	:3;
		unsigned int enable_counter	:1;
		unsigned int rsvd			:18;
	} Bits;
} SATAN_MASK;

typedef union sSatan_Mask8
{
	unsigned int Register;
	struct
	{
		unsigned int scalmask		:8;
		unsigned int enable_field	:2;
		unsigned int start_field	:3;
		unsigned int enable_counter	:1;
		unsigned int rsvd			:18;
	} Bits;
} SATAN_MASK8;

typedef union sSatan_FC
{
	unsigned int Register;
	struct
	{
		unsigned int fieldcount	:16;
		unsigned int rsvd	:16;
	} Bits;
} SATAN_FC;

typedef union sSatan_Sel
{
	unsigned int Register;
	struct
	{
		unsigned int wen		:2;
		unsigned int sync		:2;
		unsigned int extsync	:1;
		unsigned int rsvd		:27;
	} Bits;
} SATAN_SEL;

typedef union sSatan_Dpm
{
	unsigned int Register;
	struct
	{
		unsigned int datamode	:2;
		unsigned int rsvd		:30;
	} Bits;
} SATAN_DPM;	

typedef union sSatan_GenFld
{
	unsigned int Register;
	struct
	{
		unsigned int blank_lines	:11;
		unsigned int rsvd1			:1;
		unsigned int active_lines	:11;
		unsigned int rsvd2			:9;
	} Bits;
} SATAN_GENFLD;

typedef union sSatan_GenLin
{
	unsigned int Register;
	struct
	{
		unsigned int pixels			:12;
		unsigned int active_pixels	:12;
		unsigned int rsvd			:8;
	} Bits;
} SATAN_GENLIN;

typedef union sSatan_Trg
{
	unsigned int Register;
	struct
	{
		unsigned int position		:12;
		unsigned int shuttertime	:16; //!< 1=10 µs
		unsigned int mode			:2;
		unsigned int rsvd1			:2;
	} Bits;
} SATAN_TRG;

//!@endcond

//! Analog camera parameter structure
typedef struct sVIB_AnalogParameter
{
	unsigned int Header0;
	unsigned int Header1;
	unsigned char Port;				//!< Video Port
	unsigned int BaseAddress;		//
	unsigned int BaseAddressLength;	//
	int DmaChannel;					//
	int DmaChannelDI;				//!< DMA-Channel for De-interlacer
	int DIFrame;					//
	int IICAddress;					//!< ADC IIC-Address [0..1]
	int ADCInput;					//!< ADC-INPUT
	int ADCMode;					//!< PAL/NTSC, ...
	int PacketSize;					//!< Packet size for DMA/VIB_SunSystem
	int PacketCount;				//!< \brief Number of packets for one image or one line,
									//!< depending on grabbing mode
									//!<
									//!< (a. one DMA/image\n b. one DMA/line)
	int LineOffset;					//!< Offset between two lines
	int PSize;						//!< Number of bytes per pixel
	int XSize;						//!< Width of image
	int FrameHeight;				//!< Height of frame
	int ImageHeight;				//!< Height of image 
	int FrameCount;					//!< Number of frames to grab.
	int XOffset;					//!< Horizontal offset from HSync (2 * pixel clock-cycles)
	int YOffset;					//!< Vertical offset from VSync
	unsigned char *pDstDeInt;		//!< Memory destination for de-interlacing
	unsigned char *pSrcDeInt;		//!< Memory source for de-interlacing
	SATAN_LR lr;					//!< Crop image left/right
	SATAN_TB tb;					//!< Crop image top/bottom
	SATAN_SEL sel;					//!< Synchronization mode selection
	SATAN_MASK8 mask;				//!< Byte/word selection mask
	SATAN_FC fc;					//!< Number of fields to grab
} ANALOG_PARAMETER;

typedef struct sVIB_AnalogParameter *pACPARAM;
typedef struct sVIB_AnalogParameter ACPARAM;

//!@cond SHOWALL

/******************************************************************************\
* Globals                                                                      *
\******************************************************************************/

extern ANALOG_PARAMETER grParam[2];
extern unsigned char VIB_TVP5145mtable[];
extern int VIB_TVP5145mtable_size[];
extern unsigned int VIB_AnalogGrabTimestamp[];

/******************************************************************************\
* Prototypes                                                                   *
\******************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

int  TVP_SetMode(ACPARAM *pParam);
int  TVP_SendCommand(ACPARAM *pParam, int Command);
int  VIB_TVP_Read(ACPARAM *pParam, unsigned char MAdr, unsigned char *pData);
void VIB_ACSetReg(ACPARAM *pParam, unsigned int RegSubAddr, unsigned int RegVal);
unsigned int VIB_ACGetReg(ACPARAM *pParam, unsigned int RegSubAddr);
int  VIB_ACOpen(ACPARAM *pParam, unsigned int InputMode);
int  VIB_ACClose(ACPARAM *pParam);
void VIB_ACDeInterlace(ACPARAM *pParam, void *pSrc, void *pDst);
void VIB_ACDeInterlaceWait(ACPARAM *pParam);
void VIB_ACStartGrab(ACPARAM *pParam, unsigned char *pDestination);
int  VIB_ACWait4FrameEnd(ACPARAM *pParam, unsigned int usTimeout);

#ifdef __cplusplus
}
#endif
//!@endcond


#endif // __ANALOG_H__
//! \}
/******************************************************************************/
