summaryrefslogtreecommitdiffstats
path: root/utils/hwstub/tools/lua/stmp/lcdif.lua
blob: 0878cb1139527dc83ebf8ffad5204e04ec3290da (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
--
-- LCDIF
-- 

STMP.lcdif = {}

function STMP.lcdif.init()
    HW.LCDIF.CTRL.SFTRST.set()
    HW.LCDIF.CTRL.SFTRST.clr()
    HW.LCDIF.CTRL.CLKGATE.clr()
end

function STMP.lcdif.set_system_timing(data_setup, data_hold, cmd_setup, cmd_hold)
    HW.LCDIF.TIMING.CMD_HOLD.write(cmd_hold)
    HW.LCDIF.TIMING.CMD_SETUP.write(cmd_setup)
    HW.LCDIF.TIMING.DATA_HOLD.write(data_hold)
    HW.LCDIF.TIMING.DATA_SETUP.write(data_setup)
end

function STMP.lcdif.set_byte_packing_format(val)
    HW.LCDIF.CTRL1.BYTE_PACKING_FORMAT.write(val)
end

function STMP.lcdif.set_reset(val)
    if STMP.is_stmp3600() then
        HW.LCDIF.CTRL.RESET.write(val)
    else
        HW.LCDIF.CTRL1.RESET.write(val)
    end
end

function STMP.lcdif.set_word_length(bus_width)
    if STMP.is_stmp3600() or STMP.is_stmp3700() then
        if bus_width == 8 then
            HW.LCDIF.CTRL.WORD_LENGTH.set()
        else
            HW.LCDIF.CTRL.WORD_LENGTH.clr()
        end
    else
        error("STMP.lcdif.set_word_length: unimplemented")
    end
end

function STMP.lcdif.get_word_length()
    if STMP.is_stmp3600() or STMP.is_stmp3700() then
        if HW.LCDIF.CTRL.WORD_LENGTH.read() == 1 then
            return 8
        else
            return 16
        end
    else
        error("STMP.lcdif.get_word_length: unimplemented")
    end
end

function STMP.lcdif.set_data_swizzle(swizzle)
    local v = swizzle
    if type(swizzle) == "string" then
        if swizzle == "NONE" then
            v = 0
        else
            error("unimplemented")
        end
    end
    HW.LCDIF.CTRL.DATA_SWIZZLE.write(v)
end

function STMP.lcdif.is_busy()
    if STMP.is_stmp3600() then
        return HW.LCDIF.CTRL.FIFO_STATUS.read() == 0
    else
        return HW.LCDIF.STAT.TXFIFO_FULL.read() == 1
    end
end

function STMP.lcdif.send_pio(data_mode, data)
    local wl = STMP.lcdif.get_word_length()
    if data_mode then
        HW.LCDIF.CTRL.DATA_SELECT.set()
    else
        HW.LCDIF.CTRL.DATA_SELECT.clr()
    end
    STMP.debug(string.format("lcdif: count = %d", #data))
    HW.LCDIF.CTRL.RUN.clr()
    HW.LCDIF.CTRL.COUNT.write(#data)
    HW.LCDIF.CTRL.RUN.set()
    local i = 1
    while i <= #data do
        local v = 0
        local v_size = 0
        while i <= #data and v_size + wl <= 32 do
            v = bit32.bor(v, bit32.lshift(data[i], v_size))
            v_size = v_size + wl
            i = i + 1
        end
        STMP.debug(string.format("lcdif: i=%d send 0x%x", i, v))
        while STMP.lcdif.is_busy() do STMP.debug("lcdif: fifo full") end
        HW.LCDIF.DATA.write(v)
    end
end