/*
 * /WR    P4[29]
 * /RD    P4[28]
 * /CS    P4[30]
 * RS     P4[31]
 */
#define	PIO_nWR	(1<<29)
#define	PIO_nRD	(1<<28)
#define	PIO_nCS	(1<<30)
#define	PIO_RS	(1<<31)
#define	CTRL_MASK	(PIO_nWR|PIO_nRD|PIO_nCS|PIO_RS)

#define	Set_CS()	{ FIO4SET = PIO_nCS; }
#define	Clear_CS()	{ FIO4CLR = PIO_nCS; }
#define	LCD_DATA	FIO4PIN

/*
 * CLE    P3[0]
 * ALE    P3[1]
 * R/B    P3[2]
 * NANDCE P3[3]
 */
#define	PIO_CLE		(1<<0)
#define	PIO_ALE		(1<<1)
#define	PIO_RDYBUSY	(1<<2)
#define	PIO_NANDCE	(1<<3)

#define	Set_NANDCE	{ FIO3SET = PIO_NANDCE; }
#define	Clear_NANDCE	{ FIO3CLR = PIO_NANDCE; }
#define	NAND_BUSY	((FIO3PIN & PIO_RDYBUSY) == 0)

#define	PWM_MASK	0x02

#define	LCD_WIDTH	240
#define	LCD_HEIGHT	320

#define	LINE_THICK	1

#define	C_WHITE		0xffff
#define	C_RED		0xf800
#define	C_GREEN		0x07e0
#define	C_BLUE		0x001f
#define	C_BLACK		0x0000
#define	C_YELLOW	0xffe0
#define	C_PURPLE	0xf81f
#define	C_LBLUE		0x067f		/* Light blue */

#define	AIMAGE_X	2
#define	AIMAGE_Y	2
#define	PERFORMER_X	82
#define	PERFORMER_Y 	15
#define	ALBUM_X		82
#define	ALBUM_Y		50
#define	TITLE_Y		100
#define	SNUMBER_Y	120
#define	BAR_Y		160
#define	METER_Y		190
#define	ICON_Y		220
#define	VOL_Y		270

struct icon {
  UH bwidth;
  UH width, height;
  const UH *bitmap;
};

void lcd_fill_rect(int xpos, int ypos, int width, int height, int color);
void lcd_fill_root(int xpos, int ypos, int width, int height, const UH *p_image);
void lcd_load_icon(int xpos, int ypos, const struct icon *icon);
