/*****************************************************************************
 *  Solomon Systech. SSD1963 LCD controller driver
 *****************************************************************************
 * FileName:        SSD1963.h
 * Dependencies:    plib.h, SSD1963_CMD.h, TimeDelay.h, TFT.h, & system.h
 * Processor:       Microchip PIC32MX360F512L
 * Compiler:       	MPLAB C32 version 1.10 or higher
 * Linker:          MPLAB LINK32
 * Company:			TechToys Company
 *
 * Author               Date        Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * John Leung		    17/06/2011
 *****************************************************************************/
#ifndef _SSD1963_H
#define _SSD1963_H
#include "cabecera.h"

#include "system.h"				//Define the hardware platform, system clock speed etc.
#include "SSD1963_CMD.h"		//include the command table for SSD1963
//#include "TimeDelay.h"			//required for DelayMs(xx) software delay
#include "TFT.h"				//configuration for individual TFT panels
#include "GenericTypeDefs.h"
#include "Primitive.h"            

extern WORD	_color;

/*
*****************************************************************************
* IO port definitions for Microchip PIC32MX series.
* Two development platforms available from us as the MCU host:
* (1) Multimedia Evaluation Kit Rev 1A (MMEVK R1A)
* (2) PIC24/32 EVK RD4 with PIC32MX360F512L as the MCU.
*
* Function		mcu pins				LCD pins
* ==========	========				========
* TE			AN4/RB4 or RG15			TE
* DATA LINES	PMD[15:0]				D[15:0] in 16-bit addressing
* RESET			RD1 or RA7				/RESET
* CHIP SELECT	AN15/RB15 or RD11		/CS
* COMMAND/DATA	RD3 or RA6				RS 
* WR STROBE		RD4/PMPWR				/WR
* RD STROBE		RD5/PMPRD				/RD
*
*****************************************************************************
*/

	//Definitions for TE pin of SSD1963
	#define TE_TRIS_BIT	   	_TRISA1
	#define TE_PORT_BIT	   	_PORTA1
		
	// Definitions for reset pin
	#define RST_TRIS_BIT       _TRISC13
	#define RST_LAT_BIT        _LATC13
		
	//Definition for RS pin
	#define RS_TRIS_BIT			_TRISF1
	#define RS_LAT_BIT			_LATF1
		
	// Definitions for CS pin
	#define CS_TRIS_BIT        _TRISC14
	#define CS_LAT_BIT         _LATC14
		
	// Definition for WR pin
	#define WR_TRIS_BIT		   _TRISF0
	#define WR_LAT_BIT		   _LATF0
		
	// Definition for RD pin
	#define RD_TRIS_BIT		   _TRISA0
	#define RD_LAT_BIT		   _LATA0



#define RGB565CONVERT(red, green, blue) (WORD) (((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3))
/*********************************************************************
* Overview: Some basic colors definitions.
*********************************************************************/
#define BLACK               RGB565CONVERT(0,    0,      0)
#define BRIGHTBLUE          RGB565CONVERT(0,    0,      255)
#define BRIGHTGREEN         RGB565CONVERT(0,    255,    0)
#define BRIGHTCYAN          RGB565CONVERT(0,    255,    255)
#define BRIGHTRED           RGB565CONVERT(255,  0,      0)
#define BRIGHTMAGENTA       RGB565CONVERT(255,  0,      255)
#define BRIGHTYELLOW        RGB565CONVERT(255,  255,    0)
#define BLUE                RGB565CONVERT(0,    0,      128)
#define GREEN               RGB565CONVERT(0,    128,    0)
#define CYAN                RGB565CONVERT(0,    128,    128)
#define RED                 RGB565CONVERT(128,  0,      0)
#define MAGENTA             RGB565CONVERT(128,  0,      128)
#define BROWN               RGB565CONVERT(255,  128,    0)
#define LIGHTGRAY           RGB565CONVERT(128,  128,    128)
#define DARKGRAY            RGB565CONVERT(64,   64,     64)
#define LIGHTBLUE           RGB565CONVERT(128,  128,    235)
#define LIGHTGREEN          RGB565CONVERT(128,  255,    128)
#define LIGHTCYAN           RGB565CONVERT(128,  255,    255)
#define LIGHTRED            RGB565CONVERT(235,  128,    128)
#define LIGHTMAGENTA        RGB565CONVERT(235,  128,    235)
#define YELLOW              RGB565CONVERT(235,  235,    128)
#define WHITE               RGB565CONVERT(200,  200,    200)
                            
#define GRAY0       	    RGB565CONVERT(224,  224,    224)
#define GRAY1         	    RGB565CONVERT(192,  192,    192)   
#define GRAY2               RGB565CONVERT(160,  160,    160)   
#define GRAY3               RGB565CONVERT(128,  128,    128)
#define GRAY4               RGB565CONVERT(96,   96,     96)
#define GRAY5               RGB565CONVERT(64,   64,     64)
#define GRAY6	            RGB565CONVERT(32,   32,     32)
#define GRAY7	            RGB565CONVERT(240,  240,    240)

#define	CMD_90_GRADOS		0b00000011
#define	CMD_180_GRADOS		0b00000000
#define	CMD_270_GRADOS		0b11000100




void ResetDevice(void);
void PutPixel(SHORT x, SHORT y, SHORT color__);
void ClearDevice(SHORT color);
void SetScrollArea(SHORT top, SHORT scroll, SHORT bottom);
void SetScrollStart(SHORT line);
void EnterSleepMode (void);
void ExitSleepMode (void);
void DisplayOff(void);
void DisplayOn(void);
void EnterDeepSleep(void);
void SetBacklight(BYTE intensity);
void SetTearingCfg(BOOL state, BOOL mode);

void modifica(unsigned char contraste,unsigned char brillo, unsigned char saturacion);

void glcd_line(short x1, short y1, short x2, short y2, unsigned short color);
void glcd_rect(short x1, short y1, short x2, short y2, unsigned char fill, unsigned short color);
void glcd_circle(short x, short y, short radius, short fill, unsigned short color);
void glcd_text57(short x, short y, char* textptr, unsigned short size, unsigned short color);
void glcd_text57B(short x, short y, char* textptr, unsigned short size, unsigned short color, unsigned short color_fondo);
void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch);
void test_display(void);



#endif // _SSD1963_H
