/*
*************************************************************************************************
*	  			SSD1928 262k color Graphical LCD Display Driver in Landscape mode
*										All Rights Reserved
* File name		: SSD1928L_8BIT.h
* Programmer 	: John Leung, TechToys Co. Hong Kong
* Web presence  : www.TechToys.com.hk
* Note			: 
* Language		: RealView Compiler Demo version from Keil
* Hardware		: LPC2103
* Date			: 16th March 2009
*************************************************************************************************
*										DESCRIPTION
*
* This module provides an interface to LVC75Z779 Eval Board (Version 1E) graphical LCD module of 240*320dots
* Image Processor is Solomon SSD1928
* 8-bit data bus mode 8080
*
* --------- LCD			MCU -----------------
* pin 40	n.c.		- NOT connected
* pin 38 	n.c. 		- NOT connected
* pin 36	SLEEP		- P0.3
* pin 34:22	DB[7:0]		- P0.[15:8]
* pin 18	/RES		- RST of the system (MAX811)
* pin 16	RS			- P0.20
* pin 14	CS			- P0.19
* pin 12	RD			- P0.17
* pin 10	WR			- P0.18
* pin 8		n.c.		- NOT used
* pin 6		Vdd			- 3.3V
* pin 4		GND			- GND
* pin 2		EN			- P0.21
*
***********************************************************************************************
*/

#ifndef _SSD1928L_8BIT_H
#define _SSD1928L_8BIT_H

#include <LPC2103.H>
#include "SSD1928_REG.h"

typedef unsigned char 		INT8U;
typedef unsigned short		INT16U;
typedef unsigned long		INT32U;
typedef unsigned char		BOOLEAN;

#define TRUE				1
#define FALSE				0

typedef union _SHORT_VAL
{
    INT16U Val;
    INT8U v[2];
    struct
    {
        INT8U LB;
        INT8U HB;
    } byte;
    struct
    {
        unsigned char b0:1;
        unsigned char b1:1;
        unsigned char b2:1;
        unsigned char b3:1;
        unsigned char b4:1;
        unsigned char b5:1;
        unsigned char b6:1;
        unsigned char b7:1;
        unsigned char b8:1;
        unsigned char b9:1;
        unsigned char b10:1;
        unsigned char b11:1;
        unsigned char b12:1;
        unsigned char b13:1;
        unsigned char b14:1;
        unsigned char b15:1;
    } bits;
} SHORT_VAL;


typedef union _DWORD_VAL
{
	INT32U Val;
	INT16U w[2];
	INT8U  v[4];
	struct
	{
		INT16U LW;
		INT16U HW;
	} word;
	struct
    {
        INT8U LB;
        INT8U HB;
        INT8U UB;
        INT8U MB;
    } byte;
    struct
    {
        unsigned char b0:1;
        unsigned char b1:1;
        unsigned char b2:1;
        unsigned char b3:1;
        unsigned char b4:1;
        unsigned char b5:1;
        unsigned char b6:1;
        unsigned char b7:1;
        unsigned char b8:1;
        unsigned char b9:1;
        unsigned char b10:1;
        unsigned char b11:1;
        unsigned char b12:1;
        unsigned char b13:1;
        unsigned char b14:1;
        unsigned char b15:1;
        unsigned char b16:1;
        unsigned char b17:1;
        unsigned char b18:1;
        unsigned char b19:1;
        unsigned char b20:1;
        unsigned char b21:1;
        unsigned char b22:1;
        unsigned char b23:1;
        unsigned char b24:1;
        unsigned char b25:1;
        unsigned char b26:1;
        unsigned char b27:1;
        unsigned char b28:1;
        unsigned char b29:1;
        unsigned char b30:1;
        unsigned char b31:1;
    } bits;	
} DWORD_VAL;

// Horizontal and vertical screen size
#define SCREEN_HOR_SIZE    320
#define SCREEN_VER_SIZE    240

// Definition for SPI interface for HIMAX 8238-A relevant to hardware layout
// SSD1928 specific 
#define GPIO3 3
#define GPIO2 2
#define GPIO1 1
#define GPIO0 0
#define LCD_RESET (1<<GPIO3)		//wiring for LCD Reset signal
#define LCD_SPENA (1<<GPIO2)		//wiring for LCD EN signal
#define LCD_SPCLK (1<<GPIO1)		//LCD SPI CLK
#define LCD_SPDAT (1<<GPIO0)		//LCD SPI DATA

/*
***********************************************************************************************
*								Pin definition, RealView specific
*					Hardware: LPC2103, with color LCD pinout mapped to GPIO
***********************************************************************************************
*/
typedef struct {
	unsigned long 	    :3;
	unsigned long SLEEP	:1;	//P0.3=SLEEP pin of SSD1928
	unsigned long 		:4;
 	unsigned long DAT	:8; //Data = P0.[15:8]
	unsigned long 		:1;	//P0.16 not used for LCD
	unsigned long RD	:1;	//P0.17=RD
	unsigned long WR	:1; //P0.18=WR
	unsigned long CS	:1; //P0.19=CS
	unsigned long RS	:1; //P0.20=RS
	unsigned long LED	:1; //P0.21=EN for LED backlight
	unsigned long 		:10;
}__cDisp_bits;

#define cDispPIN_bit          (*((volatile __cDisp_bits *) 0xE0028000))
#define cDispSET_bit          (*((volatile __cDisp_bits *) 0xE0028004))
#define cDispDIR_bit          (*((volatile __cDisp_bits *) 0xE0028008))
#define cDispCLR_bit          (*((volatile __cDisp_bits *) 0xE002800C))


/*
***********************************************************************************************
*								 		COLOR CODES

		 

***********************************************************************************************
*/
                                  	//RRRRRGGGGGGBBBBB 
#define BLACK              0x0000	//0000000000000000
#define BRIGHTBLUE         0x001F	//0000000000011111
#define BRIGHTGREEN        0x07E0	//0000011111100000
#define BRIGHTCYAN         0x07FF	//0000011111111111
#define BRIGHTRED          0xF800	//1111100000000000
#define BRIGHTMAGENTA      0xF81F	//1111100000011111
#define BRIGHTYELLOW       0xFFE0	//1111111111100000
#define BLUE               0x0010	//0000000000010000
#define GREEN              0x0400	//0000010000000000
#define CYAN               0x0410	//0000010000010000
#define RED                0x8000	//100000000000000
/*
#define MAGENTA            (INT16U)1000000000010000Y
#define BROWN              (INT16U)1111110000000000Y
#define LIGHTGRAY          (INT16U)1000010000010000Y
#define DARKGRAY           (INT16U)0100001000001000Y
#define LIGHTBLUE          (INT16U)1000010000011111Y
#define LIGHTGREEN         (INT16U)1000011111110000Y
#define LIGHTCYAN          (INT16U)1000011111111111Y
#define LIGHTRED           (INT16U)1111110000010000Y
#define LIGHTMAGENTA       (INT16U)1111110000011111Y
#define YELLOW             (INT16U)1111111111110000Y
*/
#define WHITE              0xFFFF	//1111111111111111Y



/*
***********************************************************************************************
*									FUNCTION PROTOTYPES
***********************************************************************************************
*/
void cDispInit(void);
void cDispPutPixel(INT16U x, INT16U y, INT16U color);

/*
***********************************************************************************************
*									FUNCTION PROTOTYPES
*									 HARDWARE SPECIFIC
***********************************************************************************************
*/

void cDispClearDevice(INT16U color);
void cDispInitPort(void);
//void cDispSetAddress(INT8U addr2, INT8U addr1, INT8U addr0);
void cDispSetAddress(INT32U address);
void cDispWrReg(INT16U reg, INT8U value);
void cDispWrDat(INT8U byte1, INT8U byte0);

#endif // _SSD1928L_8BIT_H
