2004-10-26 06:54:03 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2004-10-26 06:54:03 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "system.h"
|
2006-11-10 00:02:28 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
#include "lcd.h"
|
2004-10-26 06:54:03 +00:00
|
|
|
|
|
|
|
/*** definitions ***/
|
|
|
|
|
|
|
|
/* LCD command codes */
|
2005-06-23 16:53:54 +00:00
|
|
|
#define LCD_CNTL_POWER_CONTROL 0x25
|
|
|
|
#define LCD_CNTL_VOLTAGE_SELECT 0x2b
|
|
|
|
#define LCD_CNTL_LINE_INVERT_DRIVE 0x36
|
|
|
|
#define LCD_CNTL_GRAY_SCALE_PATTERN 0x39
|
|
|
|
#define LCD_CNTL_TEMP_GRADIENT_SELECT 0x4e
|
|
|
|
#define LCD_CNTL_OSC_FREQUENCY 0x5f
|
|
|
|
#define LCD_CNTL_ON_OFF 0xae
|
2005-06-27 19:28:55 +00:00
|
|
|
#define LCD_CNTL_OSC_ON_OFF 0xaa
|
2005-06-23 16:53:54 +00:00
|
|
|
#define LCD_CNTL_OFF_MODE 0xbe
|
|
|
|
#define LCD_CNTL_REVERSE 0xa6
|
|
|
|
#define LCD_CNTL_ALL_LIGHTING 0xa4
|
|
|
|
#define LCD_CNTL_COMMON_OUTPUT_STATUS 0xc4
|
|
|
|
#define LCD_CNTL_COLUMN_ADDRESS_DIR 0xa0
|
|
|
|
#define LCD_CNTL_NLINE_ON_OFF 0xe4
|
|
|
|
#define LCD_CNTL_DISPLAY_MODE 0x66
|
|
|
|
#define LCD_CNTL_DUTY_SET 0x6d
|
|
|
|
#define LCD_CNTL_ELECTRONIC_VOLUME 0x81
|
|
|
|
#define LCD_CNTL_DATA_INPUT_DIR 0x84
|
|
|
|
#define LCD_CNTL_DISPLAY_START_LINE 0x8a
|
2006-03-08 08:09:52 +00:00
|
|
|
#define LCD_CNTL_AREA_SCROLL 0x10
|
2005-06-23 16:53:54 +00:00
|
|
|
|
|
|
|
#define LCD_CNTL_PAGE 0xb1
|
|
|
|
#define LCD_CNTL_COLUMN 0x13
|
|
|
|
#define LCD_CNTL_DATA_WRITE 0x1d
|
2004-10-26 06:54:03 +00:00
|
|
|
|
2006-11-10 00:02:28 +00:00
|
|
|
/*** shared semi-private declarations ***/
|
|
|
|
extern const unsigned char lcd_dibits[16] ICONST_ATTR;
|
2005-06-23 16:53:54 +00:00
|
|
|
|
|
|
|
/*** hardware configuration ***/
|
2004-10-26 06:54:03 +00:00
|
|
|
int lcd_default_contrast(void)
|
|
|
|
{
|
2006-11-10 00:02:28 +00:00
|
|
|
return DEFAULT_CONTRAST_SETTING;
|
2004-10-26 06:54:03 +00:00
|
|
|
}
|
|
|
|
|
2005-06-23 16:53:54 +00:00
|
|
|
void lcd_set_contrast(int val)
|
|
|
|
{
|
2006-11-10 00:02:28 +00:00
|
|
|
/* Keep val in acceptable hw range */
|
|
|
|
if (val < 0)
|
|
|
|
val = 0;
|
|
|
|
else if (val > 127)
|
|
|
|
val = 127;
|
|
|
|
|
2005-06-23 16:53:54 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_ELECTRONIC_VOLUME, val, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_set_invert_display(bool yesno)
|
|
|
|
{
|
|
|
|
lcd_write_command(LCD_CNTL_REVERSE | (yesno?1:0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* turn the display upside down (call lcd_update() afterwards) */
|
|
|
|
void lcd_set_flip(bool yesno)
|
|
|
|
{
|
|
|
|
if (yesno)
|
|
|
|
{
|
|
|
|
lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 1);
|
|
|
|
lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 0);
|
|
|
|
lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 0);
|
|
|
|
}
|
2005-06-24 22:33:21 +00:00
|
|
|
else
|
2005-06-23 16:53:54 +00:00
|
|
|
{
|
|
|
|
lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 0);
|
|
|
|
lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 1);
|
|
|
|
lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-10 00:02:28 +00:00
|
|
|
void lcd_init_device(void)
|
2004-10-26 06:54:03 +00:00
|
|
|
{
|
2005-01-27 00:00:55 +00:00
|
|
|
/* GPO35 is the LCD A0 pin
|
|
|
|
GPO46 is LCD RESET */
|
2005-07-06 22:58:02 +00:00
|
|
|
or_l(0x00004008, &GPIO1_OUT);
|
|
|
|
or_l(0x00004008, &GPIO1_ENABLE);
|
|
|
|
or_l(0x00004008, &GPIO1_FUNCTION);
|
2005-01-27 00:00:55 +00:00
|
|
|
|
|
|
|
/* Reset LCD */
|
|
|
|
sleep(1);
|
2005-07-06 22:58:02 +00:00
|
|
|
and_l(~0x00004000, &GPIO1_OUT);
|
2005-01-27 00:00:55 +00:00
|
|
|
sleep(1);
|
2005-07-06 22:58:02 +00:00
|
|
|
or_l(0x00004000, &GPIO1_OUT);
|
2005-01-27 00:00:55 +00:00
|
|
|
sleep(1);
|
2005-06-27 19:28:55 +00:00
|
|
|
|
2004-10-26 06:54:03 +00:00
|
|
|
lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 0); /* Normal */
|
|
|
|
lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 1); /* Reverse dir */
|
|
|
|
lcd_write_command(LCD_CNTL_REVERSE | 0); /* Reverse OFF */
|
|
|
|
lcd_write_command(LCD_CNTL_ALL_LIGHTING | 0); /* Normal */
|
2005-01-27 00:00:55 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1);
|
2005-06-27 19:28:55 +00:00
|
|
|
lcd_write_command(LCD_CNTL_OFF_MODE | 1); /* OFF -> VCC on drivers */
|
2005-01-27 00:00:55 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_VOLTAGE_SELECT, 3, -1);
|
|
|
|
lcd_write_command_ex(LCD_CNTL_ELECTRONIC_VOLUME, 0x1c, -1);
|
|
|
|
lcd_write_command_ex(LCD_CNTL_TEMP_GRADIENT_SELECT, 0, -1);
|
2005-06-27 19:28:55 +00:00
|
|
|
|
2005-01-27 00:00:55 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_LINE_INVERT_DRIVE, 0x10, -1);
|
2005-06-27 19:28:55 +00:00
|
|
|
lcd_write_command(LCD_CNTL_NLINE_ON_OFF | 1); /* N-line ON */
|
|
|
|
|
2005-01-27 00:00:55 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_OSC_FREQUENCY, 3, -1);
|
|
|
|
lcd_write_command(LCD_CNTL_OSC_ON_OFF | 1); /* Oscillator ON */
|
|
|
|
|
2005-06-27 19:28:55 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_POWER_CONTROL, 0x16, -1);
|
|
|
|
sleep(HZ/10); /* 100 ms pause */
|
|
|
|
lcd_write_command_ex(LCD_CNTL_POWER_CONTROL, 0x17, -1);
|
2005-01-27 00:00:55 +00:00
|
|
|
|
|
|
|
lcd_write_command_ex(LCD_CNTL_DISPLAY_START_LINE, 0, -1);
|
2006-11-21 17:14:07 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_GRAY_SCALE_PATTERN, 0x43, -1);
|
2005-07-06 22:58:02 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_DISPLAY_MODE, 0, -1); /* Greyscale mode */
|
2005-01-27 00:00:55 +00:00
|
|
|
lcd_write_command(LCD_CNTL_DATA_INPUT_DIR | 0); /* Column mode */
|
|
|
|
|
2004-10-26 06:54:03 +00:00
|
|
|
lcd_update();
|
2005-06-27 19:28:55 +00:00
|
|
|
lcd_write_command(LCD_CNTL_ON_OFF | 1); /* LCD ON */
|
2004-10-26 06:54:03 +00:00
|
|
|
}
|
|
|
|
|
2005-06-23 16:53:54 +00:00
|
|
|
/*** update functions ***/
|
2004-10-26 06:54:03 +00:00
|
|
|
|
|
|
|
/* Performance function that works with an external buffer
|
2005-09-30 20:11:31 +00:00
|
|
|
note that by and bheight are in 8-pixel units! */
|
2008-03-24 00:35:53 +00:00
|
|
|
void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
|
|
|
|
int bheight, int stride)
|
2004-10-26 06:54:03 +00:00
|
|
|
{
|
2005-09-30 20:10:27 +00:00
|
|
|
const unsigned char *src, *src_end;
|
|
|
|
unsigned char *dst_u, *dst_l;
|
2005-11-09 23:24:33 +00:00
|
|
|
static unsigned char upper[LCD_WIDTH] IBSS_ATTR;
|
|
|
|
static unsigned char lower[LCD_WIDTH] IBSS_ATTR;
|
2005-09-30 20:10:27 +00:00
|
|
|
unsigned int byte;
|
|
|
|
|
|
|
|
by *= 2;
|
|
|
|
|
2005-06-28 23:15:47 +00:00
|
|
|
while (bheight--)
|
2004-10-26 06:54:03 +00:00
|
|
|
{
|
2005-09-30 20:10:27 +00:00
|
|
|
src = data;
|
|
|
|
src_end = data + width;
|
|
|
|
dst_u = upper;
|
|
|
|
dst_l = lower;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
byte = *src++;
|
2006-11-10 00:02:28 +00:00
|
|
|
*dst_u++ = lcd_dibits[byte & 0x0F];
|
2005-09-30 20:10:27 +00:00
|
|
|
byte >>= 4;
|
2006-11-10 00:02:28 +00:00
|
|
|
*dst_l++ = lcd_dibits[byte & 0x0F];
|
2005-09-30 20:10:27 +00:00
|
|
|
}
|
|
|
|
while (src < src_end);
|
|
|
|
|
2005-07-16 02:09:22 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
|
2005-06-24 22:33:21 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
|
2005-09-30 20:10:27 +00:00
|
|
|
lcd_write_command(LCD_CNTL_DATA_WRITE);
|
|
|
|
lcd_write_data(upper, width);
|
2004-10-26 06:54:03 +00:00
|
|
|
|
2005-09-30 20:10:27 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
|
|
|
|
lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
|
2004-10-26 06:54:03 +00:00
|
|
|
lcd_write_command(LCD_CNTL_DATA_WRITE);
|
2005-09-30 20:10:27 +00:00
|
|
|
lcd_write_data(lower, width);
|
|
|
|
|
2005-06-28 23:15:47 +00:00
|
|
|
data += stride;
|
2005-09-30 20:10:27 +00:00
|
|
|
}
|
2004-10-26 06:54:03 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 23:48:26 +00:00
|
|
|
/* Helper function for lcd_grey_phase_blit(). */
|
|
|
|
void lcd_grey_data(unsigned char *values, unsigned char *phases, int count);
|
|
|
|
|
2008-01-04 23:42:38 +00:00
|
|
|
/* Performance function that works with an external buffer
|
|
|
|
note that by and bheight are in 4-pixel units! */
|
2008-03-24 00:35:53 +00:00
|
|
|
void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
|
2008-01-09 23:48:26 +00:00
|
|
|
int x, int by, int width, int bheight, int stride)
|
2008-01-04 23:42:38 +00:00
|
|
|
{
|
|
|
|
stride <<= 2; /* 4 pixels per block */
|
|
|
|
while (bheight--)
|
|
|
|
{
|
|
|
|
lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
|
|
|
|
lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
|
|
|
|
lcd_write_command(LCD_CNTL_DATA_WRITE);
|
2008-01-09 23:48:26 +00:00
|
|
|
lcd_grey_data(values, phases, width);
|
|
|
|
values += stride;
|
|
|
|
phases += stride;
|
2008-01-04 23:42:38 +00:00
|
|
|
}
|
|
|
|
}
|
2004-10-26 06:54:03 +00:00
|
|
|
|
2005-06-23 16:53:54 +00:00
|
|
|
/* Update the display.
|
|
|
|
This must be called after all other LCD functions that change the display. */
|
2005-07-06 22:58:02 +00:00
|
|
|
void lcd_update(void) ICODE_ATTR;
|
2005-06-23 16:53:54 +00:00
|
|
|
void lcd_update(void)
|
2004-10-26 06:54:03 +00:00
|
|
|
{
|
|
|
|
int y;
|
|
|
|
|
|
|
|
/* Copy display bitmap to hardware */
|
2007-02-20 19:31:34 +00:00
|
|
|
for (y = 0; y < LCD_FBHEIGHT; y++)
|
2004-10-26 06:54:03 +00:00
|
|
|
{
|
2005-01-27 00:00:55 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_PAGE, y, -1);
|
|
|
|
lcd_write_command_ex(LCD_CNTL_COLUMN, 0, -1);
|
2004-10-26 06:54:03 +00:00
|
|
|
|
|
|
|
lcd_write_command(LCD_CNTL_DATA_WRITE);
|
2012-02-22 10:18:05 +00:00
|
|
|
lcd_write_data (FBADDR(0, y), LCD_WIDTH);
|
2004-10-26 06:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-23 16:53:54 +00:00
|
|
|
/* Update a fraction of the display. */
|
2005-07-06 22:58:02 +00:00
|
|
|
void lcd_update_rect(int, int, int, int) ICODE_ATTR;
|
2005-06-28 23:15:47 +00:00
|
|
|
void lcd_update_rect(int x, int y, int width, int height)
|
2004-10-26 06:54:03 +00:00
|
|
|
{
|
|
|
|
int ymax;
|
|
|
|
|
|
|
|
/* The Y coordinates have to work on even 8 pixel rows */
|
2005-07-06 22:58:02 +00:00
|
|
|
ymax = (y + height-1) >> 2;
|
|
|
|
y >>= 2;
|
2004-10-26 06:54:03 +00:00
|
|
|
|
2005-06-28 23:15:47 +00:00
|
|
|
if(x + width > LCD_WIDTH)
|
|
|
|
width = LCD_WIDTH - x;
|
2004-10-26 06:54:03 +00:00
|
|
|
if (width <= 0)
|
|
|
|
return; /* nothing left to do, 0 is harmful to lcd_write_data() */
|
2007-02-20 19:31:34 +00:00
|
|
|
if(ymax >= LCD_FBHEIGHT)
|
|
|
|
ymax = LCD_FBHEIGHT-1;
|
2004-10-26 06:54:03 +00:00
|
|
|
|
|
|
|
/* Copy specified rectange bitmap to hardware */
|
|
|
|
for (; y <= ymax; y++)
|
|
|
|
{
|
2005-01-27 00:00:55 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_PAGE, y, -1);
|
2005-06-28 23:15:47 +00:00
|
|
|
lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
|
2004-10-26 06:54:03 +00:00
|
|
|
|
|
|
|
lcd_write_command(LCD_CNTL_DATA_WRITE);
|
2012-02-22 10:18:05 +00:00
|
|
|
lcd_write_data (FBADDR(x,y), width);
|
2004-10-26 06:54:03 +00:00
|
|
|
}
|
|
|
|
}
|