/*
Autor: Miroslav Hancar
Header k ILI9341.c
Obsahuje definicie riadiacich pinov a prototypy funkcii
Obsahuje makra instrukcii pre displej (skratky z datasheetu)
*/
//------------------------------------------------------------
//prototypy funkcii

//inicializacia displeja
void ILI9341_init (void);
//life-sign
unsigned char ILI9341_check (void);
//pixel
void ILI9341_pixel (unsigned int color, unsigned int x, unsigned int y);
//vyplni cely displej 
void ILI9341_fill (unsigned int color);
//"vymaluje" plochu
void ILI9341_fillrect (unsigned int xs, unsigned int ys, unsigned int xe, unsigned int ye, unsigned int color);
//nakresli ASCII znak
void ILI9341_char (uint8_t character, uint16_t x, uint16_t y, uint16_t col, uint16_t bg_col, const uint8_t *fonts, const uint16_t font_descriptor[][2]);
//vypise retazec
void ILI9341_string (uint8_t str[], uint16_t x, uint16_t y, uint16_t col, uint16_t bg_col, const uint8_t *fonts, const uint16_t font_descriptor[][2]);
//vypise retazec okolo stredu suradnic
void ILI9341_center_string (uint8_t str[], uint16_t x, uint16_t y, uint16_t color, uint16_t bg_color, const uint8_t *fonts, const uint16_t font_descriptor[][2]);
//nakresli horizontalnu ciaru
void ILI9341_Hline (unsigned int xs, unsigned int ys, unsigned int lenght, unsigned int color);
//nakresli vertikalnu ciaru
void ILI9341_Vline (unsigned int xs, unsigned int ys, unsigned int lenght, unsigned int color);
//nakresli ciaru
void ILI9341_line (unsigned int xs, unsigned int ys, unsigned int xe, unsigned int ye, unsigned color);
//bitmapa
void ILI9341_bitmap (unsigned int x, unsigned int y, unsigned int s, unsigned int v, unsigned int bmp[]);
//nakresli kruznicu
void ILI9341_circle (unsigned int x0, unsigned int y0, unsigned int r, unsigned int color);
//zapis dat do displeja (DC = 1)
void ILI9341_write_DATA (unsigned char data);
//zapis instrukcie (DC = 0)
void ILI9341_write_COM (unsigned char data);
//precita 8-bitove data
unsigned char ILI9341_read_COM (unsigned char data);
//nastavenie Frame
void ILI9341_frameset (unsigned int xs, unsigned int ys, unsigned int xe, unsigned int ye);
//madctl
void ILI9341_madctl (uint8_t data);
//-------------------------------------------------------------
//deklaracia znakovej sady vo Flash pamati
extern const uint8_t droidSansMono_24ptBitmaps[];
extern const uint16_t droidSansMono_24ptDescriptors[][2];

extern const uint8_t droidSansMono_8ptBitmaps[];
extern const uint16_t droidSansMono_8ptDescriptors[][2];

extern const uint8_t droidSansMono_22ptBitmaps[];
extern const uint16_t droidSansMono_22ptDescriptors[][2];
//------------------------------------------------------------
//makra, symbolicke konstanty
//MADCTL nastavuje pociatocnu poziciu, smer zapisu a vykreslovania, vymenu riadkov a stlpcov...
#define MADCTL_DATA 0xA0	
// pre RGB zobrazenie dat musi byt bit BRG 1 - opacne (asi chyba v datasheete) 
//------------------------------------------------------------
//ZAKLADNE FARBY (16b)
#define WHITE		0xFFFF
#define BLACK		0x0000
#define RED			0xF800
#define GREEN		0x07E0
#define BLUE		0x001F
#define YELLOW		0xFFE0
#define PINK		0xF81F
#define CYAN		0x07FF
#define ORANGE      0xFC00
#define LIGHTGREY   0xC618


//------------------------------------------------------------
//makra pre instrukcie - skratky a poradie z datasheetu 
//ak instrukcia pre citanie (RD) vracia viac paramterov prvy je don't care pretoze sa instrukcia este len zapisuje (dummy), pre citanie treba len zaistit CLK signal a posielat nuly (dummy)
#define NOP			0x00	//NOP (No Operation) - bez parametrov
#define SWRESET		0x01	//Software Reset - bez parametrov 
#define RDDIDIF 	0x04	//Read Display Identification Information - vracia 4 parametre
#define RDDST		0x09	//Read Display Status - vracia 5 parametrov
#define RDDPM		0x0A	//Read Display Power Mode - vracia 2 parametre
#define RDDMADCTL	0x0B	//Read Display MADCTL - Memory Access Control - vracia 2 parametre
#define RDDCOLMOD	0x0C	//Read Display Pixel Format - vracia 2 parametre
#define RDDIM		0x0D	//Read Display Image Format - vracia 2 parametre
#define RDDSM		0x0E	//Read Display Signal Mode - vracia 2 parametre
#define RDDSDR		0x0F	//Read Display Self-Diagnostic Result - vracia 2 parametre
#define SPLIN		0x10	//Enter Sleep Mode - bez parametrov
#define SLPOUT		0x11	//Sleep Out - bez parametrov, medzi tymito dvoma prikazmi musi byt pauza min. 120ms
#define PTLON		0x12	//Partial Mode ON - bez parametrov
#define	NORON		0x13	//Normal Display Mode ON - bez parametrov
#define DINVOFF		0x20	//Display Inversion OFF - bez parametrov
#define DINVON		0x21	//Display Inversion ON - bez parametrov
#define GAMSET		0x26	//Gamma Set - 1 parameter (GC)
#define DISPOFF		0x28	//Display OFF - bez parametrov
#define DISPON		0x29	//Display ON - bez parametrov
#define CASET		0x2A	//Column Address Set - 4 parametre (SC<15:8>, SC<7:0>, EC<15:8>, EC<7:0> - Start/End Column)
#define PASET		0x2B 	//Page Address Set - 4 parametre (SP<15:8>, SP<7:0>, EP<15:8>, EP<7:0> - Start/End Page)
#define	RAMWR		0x2C	//Memory Write - N paramtrov (Display Data) SC a SP su resetovane
#define RGBSET		0x2D	//Color Set - 128 parametrov - This command is used to define the LUT for 16-bit to 18-bit color depth conversion. 128 bytes must be written to the LUT regardless of the color mode.
#define RAMRD		0x2E	//Memory Read - vracia N+1 parametrov  - cita data z pamate do konca alebo do dalsej instrukcie
#define	PLTAR		0x30	//Partial Areal - 4 parametre (SR<15:8>, SR<7:0>, ER<15:8>, ER<7:0>)
#define	VSCRDEF		0x33	//Vertical Scrolling Definition - 6 parametrov (TFA<15:8>, TFA<7:0>, VSA<15:8>, VSA<7:0>, BFA<15:8>, BFA<7:0>)
#define TEOFF		0x34	//Tearing Effect Line OFF - bez parametrov
#define TEON		0x35	//Tearing Effect Line ON - 1 parameter (1-bitovy M)
#define MADCTL		0x36	//Memory Access Control - 1 parameter
#define VSCRSADD	0x37	//Vertical Scrolling Start Address - 2 parametre (VSP<15:8>, VSP<7:0>)
#define IDMOFF		0x38	//Idle Mode OFF - bez parametrov
#define IDMON		0x39	//Idle Mode ON - bez parametrov
#define	PIXSET		0x3A	//Pixel Format Set - 1 parameter (2x3 bity - DPI<2:0>, DBI<2:0>)
#define	RAMWRCONT	0x3C	//Write_Memory_Continue - N parametrov - ZMENENA SKRATKA
#define	RAMRDCONT	0x3E	//Read_Memory_Continue - vracia N parametrov - ZMENENA SKRATKA
#define STSCAN		0x44	//Set_Tear_Scanline - 2 paramtere - ZMENENA SKRATKA
#define	GETSCAN		0x45	//Get_Scanline - vracia 3 parametre - ZMENENA SKRATKA
#define WRDISBV		0x51	//Write Display Brightness - 1 parameter
#define	RDDISBV		0x52	//Read Display Brightness - vracia 2 parametre
#define WRCTRLD		0x53	//Write CTRL Display - 1 parameter
#define RDCTRLD		0x54	//Read CTRL Display - vracia 2 parametre
#define WRCABC		0x55	//Write Content Adaptive Brightness Control - 1 parameter
#define RDCABC		0x56	//Read Content Adaptive Brightness Control - vracia 2 parametre
#define BACKLCTW1	0x5E	//Write CABC Minimum Brightness - 1 parameter - ZMENENA SKRATKA
#define BACKLCTR1	0x5F	//Read CABC Minimum Brightness - vracia 2 parametre - ZMENENA SKRATKA
#define RDID1		0xDA	//Read ID1 - vracia 2 parametre
#define RDID2		0xDB	//Read ID2 - vracia 2 parametre
#define RDID3		0xDC	//Read ID3 - vracia 2 parametre
//Extended Command
#define IFMODE		0xB0	//RGB Interface Signal Control - 1 parameter
#define FRMCTR1		0xB1	//Frame Rate Control (In Normal Mode/Full Colors) - 2 parametre 
#define FRMCTR2		0xB2	//Frame Rate Control (In Idle Mode/8 colors) - 2 parametre
#define FRMCTR3		0xB3	//Frame Rate control (In Partial Mode/Full Colors) - 2 parametre
#define INVTR		0xB4	//Display Inversion Control - 1 parameter
#define PRCTR		0xB5	//Blanking Porch Control - 4 parametre
#define DISCTRL		0xB6	//Display Function Control - 4 parametre
#define ETMOD		0xB7	//Entry Mode Set - 1 parameter
#define BACKLCONT1	0xB8	//Backlight Control 1 - 1 parameter - ZMENENA SKRATKA
#define BACKLCONT2 	0xB9 	//Backlight Control 2 - 1 parameter - ZMENENA SKRATKA
#define BACKLCONT3 	0xBA	//Backlight Control 3 - 1 parameter - ZMENENA SKRATKA
#define BACKLCONT4 	0xBB	//Backlight Control 4 - 1 parameter - ZMENENA SKRATKA
#define BACKLCONT5 	0xBC	//Backlight Control 5 - 1 parameter - ZMENENA SKRATKA
#define BACKLCONT7 	0xBE	//Backlight Control 7 - 1 parameter - ZMENENA SKRATKA
#define BACKLCONT8 	0xBF	//Backlight Control 8 - 1 parameter - ZMENENA SKRATKA
#define PWCTRL1		0xC0	//Power Control 1 - 1 parameter
#define PWCTRL2		0xC1	//Power Control 2 - 1 parameter
#define VMCTRL1		0xC5	//VCOM Control 1 - 2 parametre
#define VMCTRL2		0xC7	//VCOM Control 2 - 1 parameter
#define NVMWR		0xD0	//NV Memory Write - 2 parametre (adresa a data)
#define NVMPKEY		0xD1	//NV Memory Protection Key - 3 parametre (KEY<23:0> = 0x55AA66)
#define RDNVM		0xD2	//NV Memory Status Read - vracia 3 parametre
#define RDID4		0xD3	//Read ID4 - vracia 4 parametre
#define PGAMCTRL	0xE0	//Positive Gamma Correction - 15 parametrov
#define NGAMCTRL	0xE1	//Negative Gamma Correction - 15 parametrov
#define DGAMCTRL1	0xE2	//Digital Gamma Control 1 - 16 parametrov
#define DGAMCTRL2	0xE3	//Digital Gamma Control 2 - 64 parametrov
#define IFCTL		0xF6	//Interface Control - 3 parametre
#define PWCTRLA		0xCB	//Power control A - 5 parametrov - ZMENENA SKRATKA
#define PWCTRLB		0xCF	//Power control B - 3 parametre - ZMENENA SKRATKA
#define	DRTCA		0xE8	//Driver timing control A - 3 parametre - ZMENENA SKRATKA
#define DRTCA2		0xE9	//Driver timing control A - 3 parametre - ZMENENA SKRATKA
#define DRTCB		0xEA	//Driver timing control B - 2 parametre - ZMENENA SKRATKA
#define PWRONSEQ	0xED	//Power on sequence control - 4 parametre - ZMENENA SKRATKA
#define EN3G		0xF2	//Enable_3G - 1 parameter - ZMENENA SKRATKA
#define PRC			0xF7	//Pump Ratio Control - 1 parameter - ZMENENA SKRATKA

#define DUMMY       0	


