/****************************************************************************/
/* Copyright 2008, © Bendor Research Pty. Ltd. All rights reserved.			*/
/* Permission is granted to use this software for any purpose whatsoever	*/
/* as long as this copyright notice is preserved. The code is provided		*/
/* "as is", with no explicit, implicit or implied warranty or guarantee		*/
/* of any kind and Bendor Research Pty. Ltd. can not be held liable for		*/
/* any loss or damages arising out of the use of this software.				*/
/****************************************************************************/
/*																			*/
/*	Include file describing the Epson S1D15G00 LCD controller chip			*/
/*	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~			*/
/*																			*/
/*	2008 Aug	ZK		Original											*/
/*																			*/
/****************************************************************************/

#ifndef	__S1D15G00_H__
#define	__S1D15G00_H__

/*
*	Commands are indicated by S1D15G00_CD_??? while parameters that
*	belong to a command are indicated S1D15G00_Pn_cname_??? where
*	cname is the command they belong to and n is their sequence number.
*	All parameters belonging to a command must be transferred otherwise
*	the entire command sequence is ignored.
*
*	It should be noted that some non-authentical copies of the controller
*	do not implement all commands and even if they do, some parameter and
*	configuration settings are ignored (e.g. the display on the Olimex
*	LPC2378 dev board ignores half the settings...).
*	In particular, only the 24 bit mode (i.e. 12 bit per pixel but you
*	must write two pixels at a time) works, neither the 8-bit per pixel
*	nor the 12-bit per pixel but single pixel access are available.
*
*	No detailed explanations of the commands is given here, you must read
*	the manual anyway. This header does not contain anything that is not
*	available through the serial interface (i.e. no commands that read
*	from the chip are documented).
*/

#define	S1D15G00_CD_NOP			0x025				// No operation

#define	S1D15G00_CD_DON			0x0af				// Display on

#define	S1D15G00_CD_DOFF		0x0ae				// Display off

#define	S1D15G00_CD_NORM		0x0a6				// Normal display

#define	S1D15G00_CD_INV			0x0a7				// Inverted display

#define	S1D15G00_CD_SCAN		0x0bb				// Scan direction
#define	S1D15G00_P0_SCAN_LL		0x100				// Scan left, left
#define	S1D15G00_P0_SCAN_LR		0x101				// Scan left, right
#define	S1D15G00_P0_SCAN_RL		0x102				// Scan right, left
#define	S1D15G00_P0_SCAN_RR		0x103				// Scan right, right

#define	S1D15G00_CD_CTRL		0x0ca				// Timing control
#define	S1D15G00_P0_CTRL_DIV1	0x10c				// Division ratio is 1
#define	S1D15G00_P0_CTRL_DIV2	0x108				// Division ratio is 2
#define	S1D15G00_P0_CTRL_DIV4	0x104				// Division ratio is 4
#define	S1D15G00_P0_CTRL_DIV8	0x100				// Division ratio is 8
#define	S1D15G00_P0_CTRL_8H		0x100				// Switching period 8H
#define	S1D15G00_P0_CTRL_4H		0x101				// Switching period 4H
#define	S1D15G00_P0_CTRL_16H	0x102				// Switching period 16H
#define	S1D15G00_P0_CTRL_FLD	0x103				// Switching period field
#define	S1D15G00_P1_CTRL_NL(l)	(0x100|((l)/4-1))	// Number of display lines
#define	S1D15G00_P2_CTRL_NI(i)	(0x100|((i)-1))		// Number of inverted lines
#define	S1D15G00_P2_CTRL_ALLFR	0x110				// Inversion in every frame
#define	S1D15G00_P2_CTRL_INDEP	0x100				// Inversion independent
#define	S1D15G00_P3_CTRL_DENA	0x100				// Dispersion enabled
#define	S1D15G00_P3_CTRL_DDIS	0x101				// Dispersion disabled

#define	S1D15G00_CD_SLEEP		0x095				// Go to sleep

#define	S1D15G00_CD_WAKE		0x094				// Wake up

#define	S1D15G00_CD_PAGE		0x075				// Page address
#define	S1D15G00_P0_PAGE_BEG(n)	(0x100|(n))			// Page address start
#define	S1D15G00_P1_PAGE_END(n)	(0x100|(n))			// Page address end

#define	S1D15G00_CD_COLA		0x015				// Column address
#define	S1D15G00_P0_COLA_BEG(n)	(0x100|(n))			// Column address start
#define	S1D15G00_P1_COLA_END(n)	(0x100|(n))			// Column address end

#define	S1D15G00_CD_MODE		0x0bc				// Memory mode control
#define	S1D15G00_P0_MODE_N		0x100				// Normal mode
#define	S1D15G00_P0_MODE_I		0x101				// Inverted mode
#define	S1D15G00_P0_MODE_LR		0x100				// Scan left to rightt
#define	S1D15G00_P0_MODE_RL		0x102				// Scan right to left
#define	S1D15G00_P0_MODE_ROW	0x100				// Write rows
#define	S1D15G00_P0_MODE_COL	0x104				// Write columns
#define	S1D15G00_P1_MODE_RRRR	0x100				// Memory organisation modes
#define	S1D15G00_P1_MODE_BBBB	0x101				// for which you need to
#define	S1D15G00_P1_MODE_RBRB	0x102				// read the manual.
#define	S1D15G00_P1_MODE_BRBR	0x103
#define	S1D15G00_P1_MODE_RRBB	0x104
#define	S1D15G00_P1_MODE_BBRR	0x105
#define	S1D15G00_P1_MODE_RBBR	0x106
#define	S1D15G00_P1_MODE_BRRB	0x107
#define	S1D15G00_P2_MODE_8BIT	0x101				// 8-bit per pixel
#define	S1D15G00_P2_MODE_24BIT	0x102				// 12-bit 2 pixels at a time
#define	S1D15G00_P2_MODE_12BIT	0x104				// 12-bit single pixel

#define	S1D15G00_CD_CMAP		0x0ce				// Set 8-bit colour map
#define	S1D15G00_Pn_CMAP(x)		(0x100|(x))			// Mapping:8R, 8G, 4B

#define	S1D15G00_CD_WRITE		0x05c				// Write display data
#define	S1D15G00_Pn_WRITE(n)	(0x100|((n)&255))	// Data to be written

#define	S1D15G00_CD_PART		0x0a8				// Enable partial display
#define	S1D15G00_P0_PART_BEG(n)	(0x100|(n)/4)		// Partial display begin
#define	S1D15G00_P1_PART_END(n)	(0x100|(n)/4)		// Partial display finish

#define	S1D15G00_CD_FULL		0x0a9				// Full display mode

#define	S1D15G00_CD_OSCON		0x0d1				// Turn oscillator on

#define	S1D15G00_CD_OSCOFF		0x0d0				// Turn oscillator off

#define	S1D15G00_CD_POW			0x020				// Power control
#define	S1D15G00_P0_POW_REF		0x101				// Reference on
#define	S1D15G00_P0_POW_REG		0x102				// Voltage regulator on
#define	S1D15G00_P0_POW_BST		0x10c				// Boosters on

#define	S1D15G00_CD_INT			0x081				// Intensity control
#define	S1D15G00_P0_INT_LEV(l)	(0x100|(l))			// Intensity level (0-63)
#define	S1D15G00_P1_INT_CON(c)	(0x100|(c))			// Contrast level (0-7)

#define	S1D15G00_CD_INCLEV		0x0d6				// Increment intensity

#define	S1D15G00_CD_DECLEV		0x0d7				// Decrement intensity

/*
*	The memory readback command is not available in SPI mode!
*/

#define	S1D15G00_CD_READ		0x05d				// Read display data
#define	S1D15G00_Pn_READ		0x100				// Dummy data to send

// FIXME: SCROLL commands
// FIXME: Read-modify-write command
// FIXME: EEPROM commands

#endif

