diff options
Diffstat (limited to 'utils/hwstub/tools/lua/stmp/lcdif.lua')
-rw-r--r-- | utils/hwstub/tools/lua/stmp/lcdif.lua | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/utils/hwstub/tools/lua/stmp/lcdif.lua b/utils/hwstub/tools/lua/stmp/lcdif.lua new file mode 100644 index 0000000000..0878cb1139 --- /dev/null +++ b/utils/hwstub/tools/lua/stmp/lcdif.lua | |||
@@ -0,0 +1,100 @@ | |||
1 | -- | ||
2 | -- LCDIF | ||
3 | -- | ||
4 | |||
5 | STMP.lcdif = {} | ||
6 | |||
7 | function STMP.lcdif.init() | ||
8 | HW.LCDIF.CTRL.SFTRST.set() | ||
9 | HW.LCDIF.CTRL.SFTRST.clr() | ||
10 | HW.LCDIF.CTRL.CLKGATE.clr() | ||
11 | end | ||
12 | |||
13 | function STMP.lcdif.set_system_timing(data_setup, data_hold, cmd_setup, cmd_hold) | ||
14 | HW.LCDIF.TIMING.CMD_HOLD.write(cmd_hold) | ||
15 | HW.LCDIF.TIMING.CMD_SETUP.write(cmd_setup) | ||
16 | HW.LCDIF.TIMING.DATA_HOLD.write(data_hold) | ||
17 | HW.LCDIF.TIMING.DATA_SETUP.write(data_setup) | ||
18 | end | ||
19 | |||
20 | function STMP.lcdif.set_byte_packing_format(val) | ||
21 | HW.LCDIF.CTRL1.BYTE_PACKING_FORMAT.write(val) | ||
22 | end | ||
23 | |||
24 | function STMP.lcdif.set_reset(val) | ||
25 | if STMP.is_stmp3600() then | ||
26 | HW.LCDIF.CTRL.RESET.write(val) | ||
27 | else | ||
28 | HW.LCDIF.CTRL1.RESET.write(val) | ||
29 | end | ||
30 | end | ||
31 | |||
32 | function STMP.lcdif.set_word_length(bus_width) | ||
33 | if STMP.is_stmp3600() or STMP.is_stmp3700() then | ||
34 | if bus_width == 8 then | ||
35 | HW.LCDIF.CTRL.WORD_LENGTH.set() | ||
36 | else | ||
37 | HW.LCDIF.CTRL.WORD_LENGTH.clr() | ||
38 | end | ||
39 | else | ||
40 | error("STMP.lcdif.set_word_length: unimplemented") | ||
41 | end | ||
42 | end | ||
43 | |||
44 | function STMP.lcdif.get_word_length() | ||
45 | if STMP.is_stmp3600() or STMP.is_stmp3700() then | ||
46 | if HW.LCDIF.CTRL.WORD_LENGTH.read() == 1 then | ||
47 | return 8 | ||
48 | else | ||
49 | return 16 | ||
50 | end | ||
51 | else | ||
52 | error("STMP.lcdif.get_word_length: unimplemented") | ||
53 | end | ||
54 | end | ||
55 | |||
56 | function STMP.lcdif.set_data_swizzle(swizzle) | ||
57 | local v = swizzle | ||
58 | if type(swizzle) == "string" then | ||
59 | if swizzle == "NONE" then | ||
60 | v = 0 | ||
61 | else | ||
62 | error("unimplemented") | ||
63 | end | ||
64 | end | ||
65 | HW.LCDIF.CTRL.DATA_SWIZZLE.write(v) | ||
66 | end | ||
67 | |||
68 | function STMP.lcdif.is_busy() | ||
69 | if STMP.is_stmp3600() then | ||
70 | return HW.LCDIF.CTRL.FIFO_STATUS.read() == 0 | ||
71 | else | ||
72 | return HW.LCDIF.STAT.TXFIFO_FULL.read() == 1 | ||
73 | end | ||
74 | end | ||
75 | |||
76 | function STMP.lcdif.send_pio(data_mode, data) | ||
77 | local wl = STMP.lcdif.get_word_length() | ||
78 | if data_mode then | ||
79 | HW.LCDIF.CTRL.DATA_SELECT.set() | ||
80 | else | ||
81 | HW.LCDIF.CTRL.DATA_SELECT.clr() | ||
82 | end | ||
83 | STMP.debug(string.format("lcdif: count = %d", #data)) | ||
84 | HW.LCDIF.CTRL.RUN.clr() | ||
85 | HW.LCDIF.CTRL.COUNT.write(#data) | ||
86 | HW.LCDIF.CTRL.RUN.set() | ||
87 | local i = 1 | ||
88 | while i <= #data do | ||
89 | local v = 0 | ||
90 | local v_size = 0 | ||
91 | while i <= #data and v_size + wl <= 32 do | ||
92 | v = bit32.bor(v, bit32.lshift(data[i], v_size)) | ||
93 | v_size = v_size + wl | ||
94 | i = i + 1 | ||
95 | end | ||
96 | STMP.debug(string.format("lcdif: i=%d send 0x%x", i, v)) | ||
97 | while STMP.lcdif.is_busy() do STMP.debug("lcdif: fifo full") end | ||
98 | HW.LCDIF.DATA.write(v) | ||
99 | end | ||
100 | end \ No newline at end of file | ||