Accepted FS #5772 by Michael Sevakis

1. X5 lcd sleep
2. #define HAVE_LCD_ENABLE
3. add "backlight (on hold switch)" setting, adapted from FS #5735

Note that the while(1) yield ==> asm("halt") part is NOT commited here,
I prefer it would be discussed separately.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10489 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Rani Hod 2006-08-08 22:03:56 +00:00
parent f8866a3a9c
commit c9f59e6f75
17 changed files with 644 additions and 211 deletions

View file

@ -21,10 +21,13 @@
#include "system.h"
#include "backlight.h"
#include "pcf50606.h"
#include "lcd.h"
void __backlight_on(void)
{
int level = set_irq_level(HIGHEST_IRQ_LEVEL);
int level;
lcd_enable(true);
level = set_irq_level(HIGHEST_IRQ_LEVEL);
pcf50606_write(0x38, 0xb0); /* Backlight ON, GPO1INV=1, GPO1ACT=011 */
set_irq_level(level);
}
@ -34,6 +37,7 @@ void __backlight_off(void)
int level = set_irq_level(HIGHEST_IRQ_LEVEL);
pcf50606_write(0x38, 0x80); /* Backlight OFF, GPO1INV=1, GPO1ACT=000 */
set_irq_level(level);
lcd_enable(false);
}
void __remote_backlight_on(void)

View file

@ -50,18 +50,16 @@ int button_read_device(void)
int btn = BUTTON_NONE;
static bool hold_button = false;
static bool remote_hold_button = false;
/* backlight handling */
if (hold_button && !button_hold())
{
backlight_on();
}
/* TODO: add light handling for the remote */
hold_button = button_hold();
remote_hold_button = remote_button_hold();
bool hold_button_old;
/* normal buttons */
hold_button_old = hold_button;
hold_button = button_hold();
/* give BL notice if HB state chaged */
if (hold_button != hold_button_old)
backlight_hold_changed(hold_button);
if (!hold_button)
{
data = adc_scan(ADC_BUTTONS);
@ -90,6 +88,11 @@ int button_read_device(void)
}
/* remote buttons */
/* TODO: add light handling for the remote */
remote_hold_button = remote_button_hold();
data = adc_scan(ADC_REMOTE);
if(data < 0x17)
remote_hold_button = true;

View file

@ -30,14 +30,20 @@
#include "font.h"
#include "bidi.h"
/** Initialized in lcd_init_device() **/
/* Is the power turned on? */
static bool power_on;
/* Is the display turned on? */
static bool display_on = false;
/* Amount of vertical offset. Used for offset correction when flipped. */
static int y_offset = 0;
static bool display_on;
/* Amount of vertical offset. Used for flip offset correction/detection. */
static int y_offset;
/* Amount of roll offset (0-127). */
static int roll_offset = 0;
static int roll_offset;
/* Reverse flag. Must be remembered when display is turned off. */
static unsigned short disp_control_rev;
/* Forward declarations */
static void lcd_display_off(void);
/* A15(0x8000) && CS1->CS, A1(0x0002)->RS */
#define LCD_CMD *(volatile unsigned short *)0xf0008000
@ -79,16 +85,16 @@ static int roll_offset = 0;
#define R_GAMMA_AMP_ADJ_NEG 0x3b
/* called very frequently - inline! */
inline void lcd_write_reg(int reg, int val)
static inline void lcd_write_reg(int reg, int val)
{
LCD_CMD = 0x0000; /* MSB is ~always~ 0 */
LCD_CMD = reg << 1;
LCD_DATA = (val >> 8) << 1;
LCD_DATA = (val & 0xff) << 1;
LCD_DATA = val << 1;
}
/* called very frequently - inline! */
inline void lcd_begin_write_gram(void)
static inline void lcd_begin_write_gram(void)
{
LCD_CMD = 0x0000;
LCD_CMD = R_WRITE_DATA_2_GRAM << 1;
@ -112,7 +118,7 @@ static inline void lcd_write_two(unsigned long px2)
LCD_DATA = px2sr + (px2sr & 0x1F8);
LCD_DATA = px2 << 1;
}
/*** hardware configuration ***/
int lcd_default_contrast(void)
@ -135,29 +141,43 @@ void lcd_set_contrast(int val)
void lcd_set_invert_display(bool yesno)
{
if (yesno == (disp_control_rev == 0x0000))
return;
disp_control_rev = yesno ? 0x0000 : 0x0004;
if (!display_on)
return;
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=x, D1-0=11 */
lcd_write_reg(R_DISP_CONTROL, yesno ? 0x0033 : 0x0037);
lcd_write_reg(R_DISP_CONTROL, 0x0033 | disp_control_rev);
}
/* turn the display upside down (call lcd_update() afterwards) */
void lcd_set_flip(bool yesno)
{
if (yesno == (y_offset != 0))
return;
y_offset = yesno ? 4 : 0;
/* SCN4-0=000x0 (G160) */
if (!power_on)
return;
/* SCN4-0=000x0 (G1/G160) */
lcd_write_reg(R_GATE_SCAN_START_POS, yesno ? 0x0000 : 0x0002);
/* SM=0, GS=x, SS=x, NL4-0=10011 (G1-G160)*/
lcd_write_reg(R_DRV_OUTPUT_CONTROL, yesno ? 0x0013 : 0x0313);
/* Vertical stripe */
/* HEA7-0=0xxx, HSA7-0=0xxx */
lcd_write_reg(R_HORIZ_RAM_ADDR_POS, 0x7f00 + (y_offset << 8) + y_offset);
/* HEA7-0=0xxx, HSA7-0=0xxx */
lcd_write_reg(R_HORIZ_RAM_ADDR_POS, yesno ? 0x8304 : 0x7f00);
}
/* Rolls up the lcd display by the specified amount of lines.
* Lines that are rolled out over the top of the screen are
* rolled in from the bottom again. This is a hardware
* rolled in from the bottom again. This is a hardware
* remapping only and all operations on the lcd are affected.
* ->
* @param int lines - The number of lines that are rolled.
* ->
* @param int lines - The number of lines that are rolled.
* The value must be 0 <= pixels < LCD_HEIGHT.
* Call lcd_update() afterwards */
void lcd_roll(int lines)
@ -171,17 +191,11 @@ void lcd_roll(int lines)
roll_offset = lines;
}
/* LCD init */
void lcd_init_device(void)
static void lcd_power_on(void)
{
/* LCD Reset */
and_l(~0x00000010, &GPIO1_OUT);
or_l(0x00000010, &GPIO1_ENABLE);
or_l(0x00000010, &GPIO1_FUNCTION);
sleep(HZ/100);
or_l(0x00000010, &GPIO1_OUT);
sleep(HZ/100);
/* Be sure standby bit is clear. */
/* BT2-0=000, DC2-0=000, AP2-0=000, SLP=0, STB=0 */
lcd_write_reg(R_POWER_CONTROL1, 0x0000);
/** Power ON Sequence **/
/* Per datasheet Rev.1.10, Jun.21.2003, p. 99 */
@ -212,13 +226,13 @@ void lcd_init_device(void)
/* Instruction (4) for power setting; PON = "1" */
/* VRL3-0=0100, PON=1, VRH3-0=0001 */
lcd_write_reg(R_POWER_CONTROL4, 0x0411);
/* 40ms or more; time for step-up circuit 4 to stabilize */
sleep(HZ/25);
/* Instructions for other mode settings (in register order). */
/* SM=0, GS=1, SS=1, NL4-0=10011 (G1-G160)*/
lcd_write_reg(R_DRV_OUTPUT_CONTROL, 0x313);
/* Instructions for other mode settings (in register order). */
/* SM=0, GS=x, SS=x, NL4-0=10011 (G1-G160)*/
lcd_write_reg(R_DRV_OUTPUT_CONTROL, y_offset ? 0x0013 : 0x0313);
/* FLD1-0=01 (1 field), B/C=1, EOR=1 (C-pat), NW5-0=000000 (1 row) */
lcd_write_reg(R_DRV_AC_CONTROL, 0x0700);
/* DIT=1, BGR=1, HWM=0, I/D1-0=11, AM=1, LG2-0=000 */
@ -227,16 +241,16 @@ void lcd_init_device(void)
lcd_write_reg(R_COMPARE_REG, 0x0000);
/* NO1-0=01, SDT1-0=00, EQ1-0=00, DIV1-0=00, RTN3-00000 */
lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x4000);
/* SCN4-0=00010 (G160) */
lcd_write_reg(R_GATE_SCAN_START_POS, 0x0002);
/* SCN4-0=000x0 (G1/G160) */
lcd_write_reg(R_GATE_SCAN_START_POS, y_offset ? 0x0000 : 0x0002);
/* VL7-0=0x00 */
lcd_write_reg(R_VERT_SCROLL_CONTROL, 0x0000);
/* SE17-10(End)=0x9f (159), SS17-10(Start)=0x00 */
lcd_write_reg(R_1ST_SCR_DRV_POS, 0x9f00);
/* SE27-20(End)=0x5c (92), SS27-20(Start)=0x00 */
lcd_write_reg(R_2ND_SCR_DRV_POS, 0x5c00);
/* HEA7-0=0x7f, HSA7-0=0x00 */
lcd_write_reg(R_HORIZ_RAM_ADDR_POS, 0x7f00); /* Vertical stripe */
/* HEA7-0=0xxx, HSA7-0=0xxx */
lcd_write_reg(R_HORIZ_RAM_ADDR_POS, y_offset ? 0x8304 : 0x7f00);
/* PKP12-10=0x0, PKP02-00=0x0 */
lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x0003);
/* PKP32-30=0x4, PKP22-20=0x0 */
@ -261,32 +275,135 @@ void lcd_init_device(void)
/* 100ms or more; time for step-up circuits to stabilize */
sleep(HZ/10);
power_on = true;
}
static void lcd_power_off(void)
{
/* Display must be off first */
if (display_on)
lcd_display_off();
power_on = false;
/** Power OFF sequence **/
/* Per datasheet Rev.1.10, Jun.21.2003, p. 99 */
/* Step-up1 halt setting bit */
/* BT2-0=110, DC2-0=001, AP2-0=011, SLP=0, STB=0 */
lcd_write_reg(R_POWER_CONTROL1, 0x062c);
/* Step-up3,4 halt setting bit */
/* VRL3-0=0100, PON=0, VRH3-0=0001 */
lcd_write_reg(R_POWER_CONTROL4, 0x0401);
/* VCOMG=0, VDV4-0=10011, VCM4-0=11000 */
lcd_write_reg(R_POWER_CONTROL5, 0x1318);
/* Wait 100ms or more */
sleep(HZ/10);
/* Step-up2,amp halt setting bit */
/* BT2-0=000, DC2-0=000, AP2-0=000, SLP=0, STB=0 */
lcd_write_reg(R_POWER_CONTROL1, 0x0000);
}
static void lcd_display_on(void)
{
/* Be sure power is on first */
if (!power_on)
lcd_power_on();
/** Display ON Sequence **/
/* Per datasheet Rev.1.10, Jun.21.2003, p. 97 */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=0, DTE=0, REV=1, D1-0=01 */
lcd_write_reg(R_DISP_CONTROL, 0x0005);
/* PT1-0=00, VLE2-1=00, SPT=0, GON=0, DTE=0, REV=0, D1-0=01 */
lcd_write_reg(R_DISP_CONTROL, 0x0001);
sleep(HZ/25); /* Wait 2 frames or more */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=1, D1-0=01 */
lcd_write_reg(R_DISP_CONTROL, 0x0025);
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=1, D1-0=11 */
lcd_write_reg(R_DISP_CONTROL, 0x0027);
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=x, D1-0=01 */
lcd_write_reg(R_DISP_CONTROL, 0x0021 | disp_control_rev);
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=x, D1-0=11 */
lcd_write_reg(R_DISP_CONTROL, 0x0023 | disp_control_rev);
sleep(HZ/25); /* Wait 2 frames or more */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=1, D1-0=11 */
lcd_write_reg(R_DISP_CONTROL, 0x0037);
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=x, D1-0=11 */
lcd_write_reg(R_DISP_CONTROL, 0x0033 | disp_control_rev);
display_on = true;
}
static void lcd_display_off(void)
{
display_on = false;
/** Display OFF sequence **/
/* Per datasheet Rev.1.10, Jun.21.2003, p. 97 */
/* EQ1-0=00 already */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=x, D1-0=10 */
lcd_write_reg(R_DISP_CONTROL, 0x0032 | disp_control_rev);
sleep(HZ/25); /* Wait 2 frames or more */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=x, D1-0=10 */
lcd_write_reg(R_DISP_CONTROL, 0x0022 | disp_control_rev);
sleep(HZ/25); /* Wait 2 frames or more */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=0, DTE=0, REV=0, D1-0=00 */
lcd_write_reg(R_DISP_CONTROL, 0x0000);
}
/* LCD init */
void lcd_init_device(void)
{
/* Reset settings */
power_on = false;
display_on = false;
y_offset = 0;
roll_offset = 0;
disp_control_rev = 0x0004;
/* LCD Reset */
and_l(~0x00000010, &GPIO1_OUT);
or_l(0x00000010, &GPIO1_ENABLE);
or_l(0x00000010, &GPIO1_FUNCTION);
sleep(HZ/100);
or_l(0x00000010, &GPIO1_OUT);
sleep(HZ/100);
lcd_display_on();
}
void lcd_enable(bool on)
{
display_on = on;
if (on == display_on)
return;
if (on)
{
lcd_display_on();
/* Probably out of sync and we don't wanna pepper the code with
lcd_update() calls for this. */
lcd_update();
}
else
{
lcd_display_off();
}
}
void lcd_sleep(void)
{
if (power_on)
lcd_power_off();
/* Set standby mode */
/* BT2-0=000, DC2-0=000, AP2-0=000, SLP=0, STB=1 */
lcd_write_reg(R_POWER_CONTROL1, 0x0001);
}
/*** update functions ***/
@ -303,7 +420,7 @@ void lcd_blit(const fb_data* data, int x, int by, int width,
(void)width;
(void)bheight;
(void)stride;
/*if(display_on)*/
/*if(display_on)*/
}
@ -327,7 +444,7 @@ void lcd_update(void)
lcd_begin_write_gram();
ptr = (unsigned long *)lcd_framebuffer;
ptr_end = ptr + (LCD_WIDTH*LCD_HEIGHT >> 1);
ptr_end = ptr + LCD_WIDTH*LCD_HEIGHT/2;
do
{
@ -375,8 +492,6 @@ void lcd_update_rect(int x, int y, int width, int height)
if (y >= y_end)
return; /* nothing left to do */
ptr = (unsigned long *)&lcd_framebuffer[y][x];
/* Set start position and window */
lcd_write_reg(R_RAM_ADDR_SET, (x << 8) |
(((y + roll_offset) & 127) + y_offset));
@ -384,44 +499,28 @@ void lcd_update_rect(int x, int y, int width, int height)
lcd_begin_write_gram();
ptr = (unsigned long *)&lcd_framebuffer[y][x];
/* Aligning source reads to long boundaries helps 2% - 3% with IRAM
buffer. DK with DRAM. */
odd_lead = x & 1;
/* special case widths 1 and 2. */
switch (width)
if (odd_lead)
{
case 1:
odd_lead = 1; /* odd_lead case writes pixels */
odd_trail = 0;
duff = 0; /* Squelch compiler warning. */
duff_end = ptr;
break;
case 2: /* Just read as long */
odd_lead = 0;
odd_trail = 0;
duff = 1;
duff_end = ptr + 1;
break;
default:
odd_lead = x & 1;
duff = width - 1;
odd_trail = duff & 1;
duff >>= 1;
}
else
{
duff = width >> 1;
odd_trail = width & 1;
}
if (odd_lead)
{
duff = width - 1;
odd_trail = duff & 1;
duff >>= 1;
}
else
{
duff = width >> 1;
odd_trail = width & 1;
}
duff_end = ptr + duff;
#ifndef BOOTLOADER
duff &= 7;
duff_end = ptr + duff;
#ifndef BOOTLOADER
duff &= 7;
#endif
} /* end switch */
stride = LCD_WIDTH - width + odd_trail; /* See odd_trail below */
@ -440,7 +539,7 @@ void lcd_update_rect(int x, int y, int width, int height)
do
lcd_write_two(*ptr);
while (++ptr < duff_end);
#else
#else
switch (duff)
{
do