#ifndef _VS1003B_H
	#define _VS1003B_H

	#include "Graphics\Graphics.h"

/*
****************************************************************************
* COMMANDS AND OPCODE
****************************************************************************
*/
#define VS1003_READ		0x03
#define VS1003_WRITE	0x02

#define SCI_MODE		0x00	//Mode control, rw
#define SCI_STATUS		0x01	//Status of VS1003B
#define SCI_BASS		0x02	//Built-in bass/treble enhancer
#define SCI_CLOCKF		0x03	//Clock freq + multiplier
#define SCI_DECODE_TIME	0x04	//Decode time in seconds
#define SCI_AUDATA		0x05	//Misc audio data
#define SCI_WRAM		0x06
#define SCI_WRAMADDR	0x07
#define SCI_HDAT0		0x08
#define SCI_HDAT1		0x09
#define SCI_AIADDR		0x0A
#define SCI_VOL			0x0B	//volume control
#define SCI_AICTRL0		0x0C
#define SCI_AICTRL1		0x0D
#define SCI_AICTRL2		0x0E
#define SCI_AICTRL3		0x0F

#define vs1003CSLow()   	VS1003_CS_LAT = 0;
#define vs1003CSHigh()		VS1003_CS_LAT = 1;

#define vs1003xDCSLow()		VS1003_xDCS_LAT = 0;
#define vs1003xDCSHigh()	VS1003_xDCS_LAT = 1;

/*
*****************************************************************************************************
* Description: 	vs1003LLInit(void)
*				Low level SPI initialization. This can be the spi configuration 
*				initialization if SPI bus is to be shared between various SPI slaves
* Dependency:	none
* Arguments:	none
*
* Remarks:		This function is hardware specific.
* The sampling freq is a function of Fpb, which can be as high as 80MHz for a PIC32MX device
* SPI clock rate for vs1003b max. at 2CLKI cycles. Although the timing is derived from internal
* clock CLKI, the system always starts up in 1.0x mode, therefore CLKI=XTALI=12.288MHz on
* PIC32_SSD1963_STK hardware prior to CLOCKF register updated. 
* This is equivalent to a high pulse timing of 163ns leading to 
* a max. SCK1 rate of merely 6MHz something. Thus, a "high" SPI1BRG divider has been chosen to 
* make sure SCK1 clock with a period of 440ns is there to match vs1003b prior to internal clock init
*****************************************************************************************************
*/
void 	vs1003LLInit(void);

/*
******************************************************************************************
* Description: 	vs1003HWReset(void)
*				Hardware reset fot VS1003 by bringing xRESET pin low and then high for
*				normal operation
* Dependency:	Software delay DelayMs()
* Arguments:	none
* Remarks:		vs1003 runs at XTALI since no PLL enabled yet.
******************************************************************************************
*/
void	vs1003HWReset(void);
void	vs1003SWReset(void);
void	vs1003PowerOn(BOOL state);

/*
******************************************************************************************
* Description: 	vs1003SineTest(BOOL sw, WORD freq)
*				
* Dependency:	Sine Test in compliance with section 9.8.1 of 
*				vs1003's datasheet(Version 1.04 2009-02-03).
*				
* Arguments:	BOOL sw		1 to enable sine test
*							0 to disable sine test. "WORD freq" doesn't matter here
*				WORD freq	frequency of the sine wave output.
*				The frequency does not span a continuous spectrum due to the fact that,
*				the output is obtained by the formula Fs x S/128 with Fs = 22050Hz
*				which has been hard-coded in this function with S being a 5-bit number.
*				Please refer to section 9.8.1 on datasheet for details 
*				Therefore the max freq to use in this function = 22050Hz * 31/128 = 5,340Hz;
*				wherease, the min. freq = 22050Hz * 1/128 = 172Hz
*
*				When BOOL sw = 0, the sine test exit.
*
* Remarks:		vs1003HWReset(void) executed in this function. Therefore all control
*				registers and internal states are set to the initial values.
*				vs1003 runs at XTALI since no PLL enabled yet.
******************************************************************************************
*/
void	vs1003SineTest(BOOL sw, WORD freq);
/*
******************************************************************************************
* Description: 	vs1003MemoryTest(void)
*				This test complies with the Memory Test procedure as stipulated in 9.8.3
*				on vs1003b datasheet (Version 1.04 2009-02-03).
* Arguments:	(none)
* Return:		If "all ok", the return value should be 0x807f with msb first	
*				Memory test overwrite the current contents of the RAM memories
*				vs1003HWReset(void) executed in this function. Therefore all control
*				registers and internal states are set to the initial values.
*				vs1003 runs at XTALI since no PLL enabled yet.
******************************************************************************************
*/
WORD	vs1003MemoryTest(void);

#endif
