
#include "type.h"

#include "sys.h"
#include "misc.h"
#include "font.h"
#include "lcd_func.h"


static UINT8 DigitToHexAscii(char data)
{
	data&=0x0f;
	if (data>=10) data+=7;
	data+=0x30;
	return(data);
}

static void ByteToHexAscii(UINT8 data,char *temp)
{
	*temp=DigitToHexAscii((data&0xF0)>>4);
	*(temp+1)=DigitToHexAscii(data&0x0f);
}

void Display_8BitHex(UINT16 x,UINT16 y,UINT8 data,UINT16 fgColor,UINT16 bgColor)
{
	char temp[3];
	temp[2]=0;
	
	ByteToHexAscii((UINT8)(data),temp);
	Display_Text(x*8,y*16,FONT_8x16,OPAQUE,fgColor,bgColor,temp);
}

void Display_16BitHex(UINT16 x,UINT16 y,UINT16 data,UINT16 fgColor,UINT16 bgColor)
{
	char temp[3];
	temp[2]=0;
	
	ByteToHexAscii((char)(data>>8),temp);
	Display_Text(x*8,y*16,FONT_8x16,OPAQUE,fgColor,bgColor,temp);
	
	ByteToHexAscii((char)data,temp);
	Display_Text((x+2)*8,y*16,FONT_8x16,OPAQUE,fgColor,bgColor,temp);
}

void Display_32BitHex(UINT16 x,UINT16 y,UINT32 data,UINT16 fgColor,UINT16 bgColor)
{
	char temp[3];
	temp[2]=0;
	
	ByteToHexAscii((char)(data>>24),temp);
	Display_Text(x*8,y*16,FONT_8x16,OPAQUE,fgColor,bgColor,temp);
	ByteToHexAscii((char)(data>>16),temp);
	Display_Text((x+2)*8,y*16,FONT_8x16,OPAQUE,fgColor,bgColor,temp);

	ByteToHexAscii((char)(data>>8),temp);
	Display_Text((x+4)*8,y*16,FONT_8x16,OPAQUE,fgColor,bgColor,temp);
	ByteToHexAscii((char)data,temp);
	Display_Text((x+6)*8,y*16,FONT_8x16,OPAQUE,fgColor,bgColor,temp);
}

void Display_8BitDec(UINT16 x,UINT16 y,u8 data,UINT16 fgColor,UINT16 bgColor)
{
	UINT16 value,tmpValue=10,i;
	char temp[2];
	temp[1]=0;
	
	for (i=0;i<2;i++)
	{
		value=data/tmpValue;
		data=data%tmpValue;
		temp[0]=DigitToHexAscii((char)(value));
		Display_Text((x+i)*8,y*16,FONT_8x16,OPAQUE,fgColor,bgColor,temp);		
		tmpValue/=10;
	}
}

void Display_16BitDec(UINT16 x,UINT16 y,UINT16 data,UINT16 fgColor,UINT16 bgColor)
{
	UINT16 value,tmpValue=1000,i;
	char temp[2];
	temp[1]=0;
	
	for (i=0;i<4;i++)
	{
		value=data/tmpValue;
		data=data%tmpValue;
		temp[0]=DigitToHexAscii((char)(value));
		Display_Text((x+i)*8,y*16,FONT_8x16,OPAQUE,fgColor,bgColor,temp);		
		tmpValue/=10;
	}
}

void Display_32BitDec(UINT16 x,UINT16 y,UINT32 data,UINT16 fgColor,UINT16 bgColor)
{
	UINT16 i;
	UINT32 value,tmpValue=10000000;
	char temp[2];
	temp[1]=0;
	
	for (i=0;i<8;i++)
	{
		value=data/tmpValue;
		data=data%tmpValue;
		temp[0]=DigitToHexAscii((char)(value));
		Display_Text((x+i)*8,y*16,FONT_8x16,OPAQUE,fgColor,bgColor,temp);		
		tmpValue/=10;
	}
}


#include "pwm_drv.h"
#include "spi_drv.h"
#include "gpio_drv.h"
void SPI_Switch(void)
{
	PWM_ConfigGpio(PWM_PORT0,GPIO_OUTPUT,1); //CS  1: PWM_PULLUP
	PWM_WriteGpioData(PWM_PORT0,Bit_SET);	
	
	//EPORT_ConfigGpio(EPORT_PIN7, GPIO_OUTPUT);  			//RS
	//EPORT_WriteGpioData(EPORT_PIN7, Bit_SET);
	
	GPIOPin_Init(GPIO_PIN7,OUTPUT,PULL_UP);
	GPIOPin_Write(GPIO_PIN7,HIGH);
	
	SPI_ConfigGpio(SPI3,SPI_MOSI, GPIO_OUTPUT);				//RD
	SPI_WriteGpioData(SPI3,SPI_MOSI, Bit_SET);
	
	SPI_ConfigGpio(SPI3,SPI_SCK, GPIO_OUTPUT);				//WR
	SPI_WriteGpioData(SPI3,SPI_SCK, Bit_SET);
}




