summaryrefslogtreecommitdiffstats
path: root/utils/hwstub/tools/lua/irivere150.lua
blob: e5a0d26686c56adf565586b6392f4c42f8252be5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
E150 = {}

function E150.lcd_reg_write(reg, val)
    ATJ.lcm.rs_command()
    HW.YUV2RGB.FIFODATA.write(reg)
    ATJ.lcm.rs_data()
    HW.YUV2RGB.FIFODATA.write(val)
end

function E150.lcd_init()
    ATJ.lcm.init()

    ATJ.gpio.outen("PORTA", 16, 1)
    ATJ.gpio.set("PORTA", 16 , 1)
    hwstub.mdelay(10)
    ATJ.gpio.set("PORTA", 16, 0)
    hwstub.mdelay(10)
    ATJ.gpio.set("PORTA", 16, 1)
    hwstub.mdelay(10)

    -- lcd controller init sequence matching HX8347-D
    E150.lcd_reg_write(0xea, 0x00)
    E150.lcd_reg_write(0xeb, 0x20)
    E150.lcd_reg_write(0xec, 0x0f)
    E150.lcd_reg_write(0xed, 0xc4)
    E150.lcd_reg_write(0xe8, 0xc4)
    E150.lcd_reg_write(0xe9, 0xc4)
    E150.lcd_reg_write(0xf1, 0xc4)
    E150.lcd_reg_write(0xf2, 0xc4)
    E150.lcd_reg_write(0x27, 0xc4)
    E150.lcd_reg_write(0x40, 0x00) -- gamma block start
    E150.lcd_reg_write(0x41, 0x00)
    E150.lcd_reg_write(0x42, 0x01)
    E150.lcd_reg_write(0x43, 0x13)
    E150.lcd_reg_write(0x44, 0x10)
    E150.lcd_reg_write(0x45, 0x26)
    E150.lcd_reg_write(0x46, 0x08)
    E150.lcd_reg_write(0x47, 0x51)
    E150.lcd_reg_write(0x48, 0x02)
    E150.lcd_reg_write(0x49, 0x12)
    E150.lcd_reg_write(0x4a, 0x18)
    E150.lcd_reg_write(0x4b, 0x19)
    E150.lcd_reg_write(0x4c, 0x14)
    E150.lcd_reg_write(0x50, 0x19)
    E150.lcd_reg_write(0x51, 0x2f)
    E150.lcd_reg_write(0x52, 0x2c)
    E150.lcd_reg_write(0x53, 0x3e)
    E150.lcd_reg_write(0x54, 0x3f)
    E150.lcd_reg_write(0x55, 0x3f)
    E150.lcd_reg_write(0x56, 0x2e)
    E150.lcd_reg_write(0x57, 0x77)
    E150.lcd_reg_write(0x58, 0x0b)
    E150.lcd_reg_write(0x59, 0x06)
    E150.lcd_reg_write(0x5a, 0x07)
    E150.lcd_reg_write(0x5b, 0x0d)
    E150.lcd_reg_write(0x5c, 0x1d)
    E150.lcd_reg_write(0x5d, 0xcc) -- gamma block end
    E150.lcd_reg_write(0x1b, 0x1b)
    E150.lcd_reg_write(0x1a, 0x01)
    E150.lcd_reg_write(0x24, 0x2f)
    E150.lcd_reg_write(0x25, 0x57)
    E150.lcd_reg_write(0x23, 0x86)
    E150.lcd_reg_write(0x18, 0x36) -- 70Hz framerate
    E150.lcd_reg_write(0x19, 0x01) -- osc enable
    E150.lcd_reg_write(0x01, 0x00)
    E150.lcd_reg_write(0x1f, 0x88)
    hwstub.mdelay(5)
    E150.lcd_reg_write(0x1f, 0x80)
    hwstub.mdelay(5)
    E150.lcd_reg_write(0x1f, 0x90)
    hwstub.mdelay(5)
    E150.lcd_reg_write(0x1f, 0xd0)
    hwstub.mdelay(5)
    E150.lcd_reg_write(0x17, 0x05) -- 16bpp
    E150.lcd_reg_write(0x36, 0x00)
    E150.lcd_reg_write(0x28, 0x38)
    hwstub.mdelay(40)
    E150.lcd_reg_write(0x28, 0x3c)

    E150.lcd_reg_write(0x02, 0x00) -- column start MSB
    E150.lcd_reg_write(0x03, 0x00) -- column start LSB
    E150.lcd_reg_write(0x04, 0x00) -- column end MSB
    E150.lcd_reg_write(0x05, 0xef) -- column end LSB
    E150.lcd_reg_write(0x06, 0x00) -- row start MSB
    E150.lcd_reg_write(0x07, 0x00) -- row start LSB
    E150.lcd_reg_write(0x08, 0x01) -- row end MSB
    E150.lcd_reg_write(0x09, 0x3f) -- row end LSB

    ATJ.lcm.fb_data() -- prepare for write to fifo

    -- clear lcd gram
    for y=0, 319 do
        for x=0, 239/2 do
            HW.YUV2RGB.FIFODATA.write(0)
        end
    end

end

function E150.set_backlight(val)
    local fmclk = HW.CMU.FMCLK.read()
    fmclk = bit32.band(fmclk, bit32.bnot(0x1c))
    fmclk = bit32.bor(fmclk, 0x22)
    HW.CMU.FMCLK.write(fmclk)

    HW.PMU.CTL.write(bit32.bor(HW.PMU.CTL.read(), 0x8000))
    local chg = HW.PMU.CHG.read()
    chg = bit32.band(chg, bit32.bnot(0x1f00))
    chg = bit32.bor(chg, bit32.bor(0xc000, bit32.lshift(val, 8)))
    HW.PMU.CHG.write(chg)
end

function E150.init()
    E150.lcd_init()
    E150.set_backlight(24);
end