1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2025-04-21 12:27:27 +03:00

make lcd almost work

This commit is contained in:
Bas Wijnen
2009-07-05 10:52:44 +02:00
parent eb141d7901
commit 4b47df85e3
11 changed files with 194 additions and 174 deletions

View File

@@ -37,97 +37,53 @@ static void set_backlight (bool state):
PWM_CTR (0) = 0x3f
GPIO_GPDR (2) &= ~PWM_ENABLE
// Write to a register. Value must be in range [0, 0xff].
static void write_reg (unsigned reg, unsigned value):
unsigned data = (reg << 0xa) | 0x200 | value
GPIO_GPDR (2) |= SPEN
GPIO_GPDR (2) = (GPIO_GPDR (2) & ~SPDA) | SPCK
GPIO_GPDR (2) &= ~SPEN
udelay(25)
for unsigned i = 0; i < 16; ++i:
GPIO_GPDR (2) &= ~SPCK
if data & 0x8000:
GPIO_GPDR (2) |= SPDA
else:
GPIO_GPDR (2) &= ~SPDA
udelay (25)
GPIO_GPDR (2) |= SPCK
udelay (25)
data <<= 1
GPIO_GPDR (2) |= SPEN
udelay(200)
static void lcd_enable ():
udelay (50)
GPIO_GPDR (2) &= ~LCD_RET
udelay(150000)
GPIO_GPDR (2) |= LCD_RET
udelay(10000)
// These values have been copied from the linux source.
// I have no idea what they do.
write_reg (0x00, 0x03)
write_reg (0x01, 0x40)
write_reg (0x02, 0x11)
write_reg (0x03, 0xcd)
write_reg (0x04, 0x32)
write_reg (0x05, 0x0e)
write_reg (0x07, 0x03)
write_reg (0x08, 0x08)
write_reg (0x09, 0x32)
write_reg (0x0A, 0x88)
write_reg (0x0B, 0xc6)
write_reg (0x0C, 0x20)
write_reg (0x0D, 0x20)
set_backlight (true)
static void lcd_disable ():
write_reg (0x00, 0x03)
set_backlight (false)
static void reset ():
gpio_as_pwm ()
gpio_as_lcd_master ()
GPIO_GPDR (2) &= ~PWM_ENABLE
PWM_CTR (0) = 0x3f
PWM_PER (0) = 300
pwm_set_duty (0, 300)
pwm_set_full_duty (0)
set_backlight (false)
// initialize things.
GPIO_GPIER (2) &= ~(PWM_ENABLE | LCD_RET | SPEN | SPCK | SPDA)
GPIO_GPDIR (2) |= PWM_ENABLE | LCD_RET | SPEN | SPCK | SPDA
udelay (50)
GPIO_GPDR (2) &= ~LCD_RET
udelay (150000)
ddelay (2)
GPIO_GPDR (2) |= LCD_RET
udelay (10000)
lcd_enable ()
ddelay (1)
// For now, support only 16 bpp.
// Screen is 800x480 tft.
unsigned h = 800, v = 480, hs = 80, vs = 20, fps = 60, Bpp = 2
LCD_CTRL = LCD_CTRL_BPP_16 | LCD_CTRL_BST_16
LCD_VSYNC = 20
LCD_HSYNC = 80
LCD_DAV = (20 << 16) | 500
LCD_DAH = (80 << 16) | 880
LCD_VAT = (880 << 16) | 500
//LCD_CFG = MODE_TFT_GEN | PCLK_N | VSYNC_N
LCD_VSYNC = vs
LCD_HSYNC = hs
LCD_DAV = (vs << 16) | (vs + v)
LCD_DAH = (hs << 16) | (hs + h)
LCD_VAT = ((hs + h) << 16) | (vs + v)
#define MODE_TFT_GEN 0
#define PCLK_N (1 << 10)
#define VSYNC_N (1 << 8)
LCD_CFG = MODE_TFT_GEN | PCLK_N | VSYNC_N
// Stop lcd.
CPM_MSCR |= 1 << 7
cpm_stop_lcd ()
unsigned pclk = 60 * (800 * 3 + 80) * 500
unsigned pllout = cpm_get_pllout ()
CPM_CFCR2 = pllout / pclk - 1
unsigned v = pllout / (pclk * 4) - 1
while v < 0xf && pllout / (v + 1) > 150000000:
++v
CPM_CFCR = (CPM_CFCR & ~CPM_CFCR_LFR_MASK) | (v << CPM_CFCR_LFR_BIT) | CPM_CFCR_UPE
unsigned pixclock = fps * (hs + h) * (vs + v)
CPM_CFCR2 = pllout / pixclock - 1
unsigned val = pllout / (pixclock * 4) - 1
while val < 0xf && pllout / (val + 1) > 150000000:
++val
cpm_set_lcdclk_div (val)
CPM_CFCR |= CPM_CFCR_UPE
cpm_start_lcd ()
// Start lcd.
CPM_MSCR &= ~(1 << 7)
udelay (1000)
//LCD_DA0 = framebuffer
unsigned frame_size = v * h * Bpp
LCD_CMD0 = LCD_CMD_SOFINT | LCD_CMD_EOFINT | (frame_size << LCD_CMD_LEN_BIT)
lcd_set_ena ()
lcd_enable_eof_intr ()
int main ():
map_gpio ()
@@ -136,19 +92,20 @@ int main ():
map_cpm ()
reset ()
while true:
set_backlight (false)
kdebug (0)
set_backlight (true)
kdebug (0)
schedule ()
register_interrupt (IRQ_LCD)
set_backlight (true)
while true:
Message msg
if !wait (&msg):
continue
switch msg.protected_data:
case IRQ_LCD:
kdebug (0)
LCD_STATE &= ~LCD_STATE_EOF
register_interrupt (IRQ_LCD)
// TODO: allow callback
break
case LCD_BACKLIGHT:
set_backlight (msg.data[0])
break