/******************************************************************************

Copyright (c) 2005 Analog Devices.  All Rights Reserved.

This software is proprietary and confidential.  By using this software you agree
to the terms of the associated Analog Devices License Agreement.  

******************************************************************************/



/******************************************************************************

$File:		device.c $
$Revision: 1.3 $
$Date: 2008/03/24 20:03:52 $


Description:
	Generic device control functions.
	

Modification History:
====================
Revision 1.0 - BJ 2006/07/02
	Created file
	
******************************************************************************/



/******************************************************************************

Include files

******************************************************************************/

#include <SensorCommon/device.h>
#include <SensorCommon/encoder.h>
#include <SensorCommon/lcd.h>
#include <SensorCommon/micron.h>
#include <SensorCommon/omnivision.h>




/******************************************************************************

Data

******************************************************************************/

ADI_DEV_MANAGER_HANDLE	DeviceManager=NULL;
ADI_DMA_MANAGER_HANDLE	DeviceDMA=NULL;
ADI_DCB_HANDLE			DeviceDCB=NULL;




/******************************************************************************

Function definitions

******************************************************************************/

//static void device_callback(void *, u32, void *);




/******************************************************************************

	Function: device_init
	
	Description: Initialise the device interface

******************************************************************************/

u32 device_init(
	ADI_DEV_MANAGER_HANDLE	Manager,
	ADI_DEV_MANAGER_HANDLE	DMA,
	ADI_DCB_HANDLE			DCB)
{
	// save the service handles for later use
	DeviceManager=Manager;
	DeviceDMA=DMA;
	DeviceDCB=DCB;
	
	return ADI_DEV_RESULT_SUCCESS;
}




/******************************************************************************

	Function: device_detect
	
	Description: Detect the presence of the a device

******************************************************************************/

u32 device_detect(DEVICE_TYPE Device)
{
    switch (Device)
    {
		case DEVICE_ADV7179: return ADI_DEV_RESULT_SUCCESS;
		case DEVICE_NL6448BC33: return ADI_DEV_RESULT_SUCCESS;
		case DEVICE_MT9V022M: return micron_detect_mt9v022m(DeviceManager);
		case DEVICE_OV7648: return omnivision_detect_ov7648(DeviceManager);
    }
	return ADI_DEV_RESULT_FAILED;
}




/******************************************************************************

	Function: device_open
	
	Description: Open a device

******************************************************************************/

ADI_DEV_DEVICE_HANDLE device_open(
	DEVICE_TYPE Device, 
	u32 PPI, 
	u16 *Data, u8 DataSize, 
	ADI_DCB_CALLBACK_FN Callback,
	ADI_DEV_CMD_VALUE_PAIR *Args)
{
	switch (Device)
	{
		case DEVICE_ADV7179: return encoder_open_adv7179(DeviceManager,DeviceDMA,DeviceDCB,PPI,Data,DataSize,Callback,Args);
		case DEVICE_NL6448BC33: return lcd_open_nl6448bc33(DeviceManager,DeviceDMA,DeviceDCB,PPI,Data,DataSize,Callback,Args);
		case DEVICE_MT9V022M: return micron_open_mt9v022m(DeviceManager,DeviceDMA,DeviceDCB,PPI,Data,DataSize,Callback,Args);
		case DEVICE_OV7648: return omnivision_open_ov7648(DeviceManager,DeviceDMA,DeviceDCB,PPI,Data,DataSize,Callback,Args);
	}
	
	// Return null if no device opened
	return NULL;
}




/******************************************************************************

	Function: device_close
	
	Description: Close a device

******************************************************************************/

u32 device_close(ADI_DEV_DEVICE_HANDLE Handle)
{
	// now close device and reset device pointer
	if (!Handle) return ADI_DEV_RESULT_SUCCESS;
	
	
	// Return result from close
	return adi_dev_Close(Handle);
}

/*****************************************************************************/
