/*****************************************************************************\

  File Name: devicecontrol.c

  Description: 	This module contains functions that controls, opens, closes 
  				the various	device drivers for the media player

  Copyright(c) 2007 Analog Devices Incorporated. All Rights Reserved.

  Revision History:


\*****************************************************************************/

/*****************************************************************************\

  Includes:

\*****************************************************************************/

#include "devicecontrol.h"
#include "mediaplayer.h"

#define _ADI_CONSOLEIO_DEFAULT_DEF_
#include <adi_uart_consoleIO.h>


/*****************************************************************************\

  Defines:

\*****************************************************************************/



/*****************************************************************************\

  Declarations:

\*****************************************************************************/


/*****************************************************************************\

  Externs:

\*****************************************************************************/

/* CRT Device Driver definitions for Console I/0 */
extern DevEntry adi_console_entry;

/*****************************************************************************\

  Function Prototypes:

\*****************************************************************************/

int init_devicecontrol(void);
int init_lcd(void);
int init_codec(void);
int init_keypad(void);

int close_lcd(void);
int close_keypad(void);
int close_codec(void);




/*********************************************************************

    Function:       init_devicecontrol

    Description:    This routine controls, opens, closes the various
    				device drivers for the media player
*********************************************************************/
int init_devicecontrol(void){
    
    u32 Result= ADI_DEV_RESULT_SUCCESS;    

	/* And add the UART console for debug output */
    //add_devtab_entry( &adi_console_entry );
    
    	/* initialize the file system */
    if (Result == ADI_DEV_RESULT_SUCCESS)
	   	Result = init_fss();

	   	
	/* initialize the LCD */ 
    if (Result == ADI_DEV_RESULT_SUCCESS)
		Result = init_lcd();
		
			   	
	    /* initialize the Keypad */ 
    if (Result == ADI_DEV_RESULT_SUCCESS)
	    Result = init_keypad();
	   		    


    /* initialize the Thumbwheel */
	if (Result == ADI_DEV_RESULT_SUCCESS)
		Result = init_thumbwheel();
		
		/* And add the UART console for debug output */
    add_devtab_entry( &adi_console_entry );
	

    return Result;		

}    


/*********************************************************************

    Function:       init_lcd

    Description:    This routine initialises the LCD device driver 
                    for the media player
*********************************************************************/


int init_lcd(void){
    
    u32 Result= ADI_DEV_RESULT_SUCCESS;     
    
#if defined(__ADSP_MOAB__)
    if (Result == ADI_DEV_RESULT_SUCCESS)
	    Result = init_lcd_LQ043T1DG01();
#endif        

#if defined(__ADSP_KOOKABURRA__)  
    if (Result == ADI_DEV_RESULT_SUCCESS)
        Result = init_lcd_T350MCQB01();
#endif

    return Result;
}

/*********************************************************************

    Function:       close_lcd

    Description:    This routine closes the LCD	device driver for 
                    the media player
*********************************************************************/


int close_lcd(void){
    
    u32 Result= ADI_DEV_RESULT_SUCCESS;     
    
#if defined(__ADSP_MOAB__) 
    if (Result == ADI_DEV_RESULT_SUCCESS)
	    Result = close_lcd_LQ043T1DG01();
#endif        

#if defined(__ADSP_KOOKABURRA__)  
    if (Result == ADI_DEV_RESULT_SUCCESS)
        Result = close_lcd_T350MCQB01();
#endif

    return Result;
}

/*********************************************************************

    Function:       init_keypad

    Description:    This routine initialises the keypad device driver 
                    for the media player
*********************************************************************/


int init_keypad(void){
    
    u32 Result= ADI_DEV_RESULT_SUCCESS;     
    
#if defined(__ADSP_MOAB__) 
    if (Result == ADI_DEV_RESULT_SUCCESS)
	    Result = init_keypad_548();
#endif        

#if defined(__ADSP_KOOKABURRA__) 
    if (Result == ADI_DEV_RESULT_SUCCESS)
        Result = init_keypad_MAX1233();
#endif

    return Result;
}

/*********************************************************************

    Function:       close_keypad

    Description:    This routine closes the keypaddevice driver for 
                    the media player
*********************************************************************/


int close_keypad(void){
    
    u32 Result= ADI_DEV_RESULT_SUCCESS;     
    
#if defined(__ADSP_MOAB__) 
    if (Result == ADI_DEV_RESULT_SUCCESS)
	    Result = close_keypad_548();
#endif        

#if defined(__ADSP_KOOKABURRA__) 
    if (Result == ADI_DEV_RESULT_SUCCESS)
        Result = close_keypad_MAX1233();
#endif

    return Result;
}

/*********************************************************************

    Function:       init_codec

    Description:    This routine initialises the codec device driver 
                    for the media player
*********************************************************************/


int init_codec(void){
    
    u32 Result= ADI_DEV_RESULT_SUCCESS;     
    
#if defined(__ADSP_MOAB__)
    if (Result == ADI_DEV_RESULT_SUCCESS)
	    Result = init_codec_1980();
#endif        

#if defined(__ADSP_KOOKABURRA__)  
    if (Result == ADI_DEV_RESULT_SUCCESS)
        Result = init_codec_52xc1();
#endif

    return Result;
}

/*********************************************************************

    Function:       close_codec

    Description:    This routine closes the codec driver for 
                    the media player
*********************************************************************/


int close_codec(void){
    
    u32 Result= ADI_DEV_RESULT_SUCCESS;     
    
#if defined(__ADSP_MOAB__)
    if (Result == ADI_DEV_RESULT_SUCCESS)
	    Result = close_codec_1980();
#endif        

#if defined(__ADSP_KOOKABURRA__)  
    if (Result == ADI_DEV_RESULT_SUCCESS)
        Result = close_codec_52xc1();
#endif

    return Result;
}
