summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-06-13 02:12:01 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-06-13 02:25:15 +0200
commitf9cb5de58020936812653c578c79c79a13bc626c (patch)
treed1d6c29207472bea4daa68d2fffd7e8dbfac998b /utils
parentc5357940ab0108b4102442d07825c44d5be0d22f (diff)
downloadrockbox-f9cb5de58020936812653c578c79c79a13bc626c.tar.gz
rockbox-f9cb5de58020936812653c578c79c79a13bc626c.zip
hwstub: introduce lua code for the STMP and Creative ZEN V/Mozaic
Change-Id: Ice5f509a2e0d2114436d4760f338b9203ef96691
Diffstat (limited to 'utils')
-rw-r--r--utils/hwstub/tools/lua/load.lua3
-rw-r--r--utils/hwstub/tools/lua/stmp.lua78
-rw-r--r--utils/hwstub/tools/lua/stmp/digctl.lua38
-rw-r--r--utils/hwstub/tools/lua/stmp/lcdif.lua100
-rw-r--r--utils/hwstub/tools/lua/stmp/pinctrl.lua253
-rw-r--r--utils/hwstub/tools/lua/stmp/pwm.lua35
-rw-r--r--utils/hwstub/tools/lua/zenmozaic.lua98
-rw-r--r--utils/hwstub/tools/lua/zenv.lua56
8 files changed, 661 insertions, 0 deletions
diff --git a/utils/hwstub/tools/lua/load.lua b/utils/hwstub/tools/lua/load.lua
new file mode 100644
index 0000000000..a6f453d667
--- /dev/null
+++ b/utils/hwstub/tools/lua/load.lua
@@ -0,0 +1,3 @@
1package.path = string.sub(string.gsub(debug.getinfo(1).source, "load.lua", "?.lua"),2) .. ";" .. package.path
2
3require "stmp"
diff --git a/utils/hwstub/tools/lua/stmp.lua b/utils/hwstub/tools/lua/stmp.lua
new file mode 100644
index 0000000000..8f93b86c46
--- /dev/null
+++ b/utils/hwstub/tools/lua/stmp.lua
@@ -0,0 +1,78 @@
1---
2--- Chip Identification
3---
4
5STMP = { info = {} }
6
7local h = HELP:create_topic("STMP")
8h:add("This table contains the abstraction of the different device blocks for the STMP.")
9h:add("It allows one to use higher-level primitives rather than poking at register directly.")
10h:add("Furthermore, it tries as much as possible to hide the differences between the different STMP families.")
11
12local function identify(name, family, desc)
13 STMP.chipid = hwstub.dev.stmp.chipid
14 STMP.info.chip = name
15 STMP.info.revision = "TA" .. tostring(hwstub.dev.stmp.rev+1)
16 STMP.desc = desc
17 STMP.family = family
18 print("Chip identified as " .. name ..", ROM " .. STMP.info.revision)
19 if not hwstub.soc:select(desc) then
20 print("Looking for soc " .. desc .. ": not found. Please load a soc by hand.")
21 end
22end
23
24local hh = h:create_topic("is_imx233")
25hh:add("STMP.is_imx233() returns true if the chip ID reports a i.MX233")
26
27function STMP.is_imx233()
28 return hwstub.dev.stmp.chipid == 0x3780
29end
30
31hh = h:create_topic("is_stmp3700")
32hh:add("STMP.is_stmp3700() returns true if the chip ID reports a STMP3700")
33
34function STMP.is_stmp3700()
35 return hwstub.dev.stmp.chipid == 0x3700
36end
37
38hh = h:create_topic("is_stmp3770")
39hh:add("STMP.is_stmp3770() returns true if the chip ID reports a STMP3770")
40
41function STMP.is_stmp3770()
42 return hwstub.dev.stmp.chipid == 0x37b0
43end
44
45hh = h:create_topic("is_stmp3600")
46hh:add("STMP.is_stmp3600() returns true if the chip ID reports a STMP36xx")
47
48function STMP.is_stmp3600()
49 return hwstub.dev.stmp.chipid >= 0x3600 and hwstub.dev.stmp.chipid < 0x3700
50end
51
52if STMP.is_imx233() then
53 identify("STMP3780 (aka i.MX233)", "imx233", "imx233")
54elseif STMP.is_stmp3700() then
55 identify("STMP3700", "stmp3700", "stmp3700")
56elseif STMP.is_stmp3770() then
57 identify("STMP3770", "stmp3770", "stmp3700")
58elseif STMP.is_stmp3600() then
59 identify("STMP3600", "stmp3600", "stmp3600")
60else
61 print(string.format("Unable to identify this chip as a STMP: chipid=0x%x", hwstub.dev.stmp.chipid));
62end
63
64hh = h:create_topic("debug")
65hh:add("STMP.debug(...) prints some debug output if STMP.debug_on is true and does nothing otherwise.")
66
67STMP.debug_on = false
68
69function STMP.debug(...)
70 if STMP.debug_on then print(...) end
71end
72
73if STMP.info.chip ~= nil then
74 require "stmp/digctl"
75 require "stmp/pinctrl"
76 require "stmp/lcdif"
77 require "stmp/pwm"
78end \ No newline at end of file
diff --git a/utils/hwstub/tools/lua/stmp/digctl.lua b/utils/hwstub/tools/lua/stmp/digctl.lua
new file mode 100644
index 0000000000..8dfc13b7f2
--- /dev/null
+++ b/utils/hwstub/tools/lua/stmp/digctl.lua
@@ -0,0 +1,38 @@
1---
2--- DIGCTL
3---
4STMP.digctl = {}
5
6local h = HELP:get_topic("STMP"):create_topic("digctl")
7h:add("The STMP.digctl table handles the digctl device for all STMPs.")
8
9local hh = h:create_topic("package")
10hh:add("The STMP.digctl.package() function returns the name of the package.")
11hh:add("The following packages can be returned:")
12hh:add("* bga100")
13hh:add("* bga169")
14hh:add("* tqfp100")
15hh:add("* lqfp100")
16hh:add("* lqfp128")
17
18function STMP.digctl.package()
19 local pack = nil
20 if STMP.is_stmp3600() then
21 HW.DIGCTL.CTRL.PACKAGE_SENSE_ENABLE.set()
22 if HW.DIGCTL.STATUS.PACKAGE_TYPE.read() == 1 then
23 pack = "lqfp100"
24 else
25 pack = "bga169"
26 end
27 HW.DIGCTL.CTRL.PACKAGE_SENSE_ENABLE.clr()
28 elseif STMP.is_stmp3700() or STMP.is_stmp3770() or STMP.is_imx233() then
29 local t = HW.DIGCTL.STATUS.PACKAGE_TYPE.read()
30 if t == 0 then pack = "bga169"
31 elseif t == 1 then pack = "bga100"
32 elseif t == 2 then pack = "tqfp100"
33 elseif t == 3 then pack = "tqfp128"
34 end
35 end
36
37 return pack
38end \ No newline at end of file
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
5STMP.lcdif = {}
6
7function STMP.lcdif.init()
8 HW.LCDIF.CTRL.SFTRST.set()
9 HW.LCDIF.CTRL.SFTRST.clr()
10 HW.LCDIF.CTRL.CLKGATE.clr()
11end
12
13function 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)
18end
19
20function STMP.lcdif.set_byte_packing_format(val)
21 HW.LCDIF.CTRL1.BYTE_PACKING_FORMAT.write(val)
22end
23
24function 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
30end
31
32function 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
42end
43
44function 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
54end
55
56function 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)
66end
67
68function 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
74end
75
76function 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
100end \ No newline at end of file
diff --git a/utils/hwstub/tools/lua/stmp/pinctrl.lua b/utils/hwstub/tools/lua/stmp/pinctrl.lua
new file mode 100644
index 0000000000..2676f6476b
--- /dev/null
+++ b/utils/hwstub/tools/lua/stmp/pinctrl.lua
@@ -0,0 +1,253 @@
1---
2--- PINCTRL
3---
4STMP.pinctrl = {}
5
6local h = HELP:get_topic("STMP"):create_topic("pinctrl")
7h:add("The STMP.pinctrl table handles the pinctrl device for all STMPs.")
8h:add("It provides a simple abstraction to set individual pins.")
9
10local hh = h:create_topic("pin")
11hh:add("The STMP.pinctrl.pin(x,yy) function returns a table for the pin BxPyy.")
12hh:add("Depending on the STMP family, the following function might be available.")
13hh:add("* read() returns the value of the pin (the pin does not need to be configured as GPIO)")
14hh:add("* write(x) sets the value of the pin (provided it is a GPIO with output enabled)")
15hh:add("* set() is equivalent to write(1)")
16hh:add("* clr() is equivalent to write(0)")
17hh:add("* enable() enables the gpio output (provided it is configured as GPIO).")
18hh:add("* disable() disables the gpio output (provided it is configured as GPIO)")
19hh:add("* muxsel(x) set pin function to x, which can be an integer or one of: MAIN, ALT1, ALT2, GPIO")
20
21function STMP.pinctrl.pin(bank,pin)
22 local t = {
23 read = function()
24 return bit32.extract(HW.PINCTRL.DINn[bank].read(), pin)
25 end,
26
27 write = function(val)
28 if val then t.set() else t.clr() end
29 end,
30
31 set = function()
32 HW.PINCTRL.DOUTn[bank].set(bit32.lshift(1, pin))
33 end,
34
35 clr = function()
36 HW.PINCTRL.DOUTn[bank].clr(bit32.lshift(1, pin))
37 end,
38
39 enable = function()
40 HW.PINCTRL.DOEn[bank].set(bit32.lshift(1, pin))
41 end,
42
43 disable = function()
44 HW.PINCTRL.DOEn[bank].clr(bit32.lshift(1, pin))
45 end,
46
47 muxsel = function(x)
48 if type(x) == "string" then
49 if x == "MAIN" then x = 0
50 elseif x == "ALT1" then x = 1
51 elseif x == "ALT2" then x = 2
52 elseif x == "GPIO" then x = 3
53 else error("Invalid muxsel string " .. x) end
54 end
55 local v = nil
56 if STMP.is_stmp3600() then
57 if pin < 16 then
58 v = HW.PINCTRL.MUXSELLn[bank]
59 else
60 v = HW.PINCTRL.MUXSELHn[bank]
61 end
62 else
63 v = HW.PINCTRL.MUXSELn[2 * bank + math.floor(pin / 16)]
64 end
65 v.write(bit32.replace(v.read(), x, (pin % 16) * 2, 2))
66 end
67 }
68 return t
69end
70
71hh = h:create_topic("configure")
72hh:add("The STMP.pinctrl.configure(tbl) function configures pins according to a table.")
73hh:add("The table must contain a list of subtable, each corresponding to a pin.")
74hh:add("Each subtable can configure one or more aspects of a specific pin.")
75hh:add("The following characteristics are understood:")
76hh:add("* bank: pin bank (mandatory)")
77hh:add("* pin: pin number (mandatory) ")
78hh:add("* muxsel: same values as STMP.pinctrl.pin().muxsel (optional)")
79hh:add("* enable: enable/disable output (optional)")
80hh:add("* output: set/clear output (optional)")
81hh:add("All non-subtable entries are ignored")
82hh:add("All unknown parameters in subtablkes are ignored")
83hh:add("")
84hh:add("Example:")
85hh:add("STMP.pinctrl.configure({{bank=0,pin=1,muxsel=\"GPIO\",enable=false},{bank=0,pin=2,muxsel=\"MAIN\"}})")
86
87function STMP.pinctrl.configure(tbl)
88 if type(tbl) ~= "table" then error("Parameter must be a table") end
89 for i,v in pairs(tbl) do
90 if type(v) == "table" then
91 if v.bank ~= nil and v.pin ~= nil then
92 local pin = STMP.pinctrl.pin(v.bank,v.pin)
93 if v.muxsel ~= nil then
94 STMP.debug(string.format("cfg B%dP%02d muxsel %s", v.bank, v.pin, v.muxsel))
95 pin.muxsel(v.muxsel)
96 end
97 if v.enable ~= nil then
98 STMP.debug(string.format("cfg B%dP%02d enable %s", v.bank, v.pin, v.enable))
99 if v.enable then pin.enable()
100 else pin.disable() end
101 end
102 if v.output ~= nil then
103 STMP.debug(string.format("cfg B%dP%02d output %s", v.bank, v.pin, v.output))
104 if v.output then pin.set()
105 else pin.clr() end
106 end
107 end
108 end
109 end
110end
111
112hh = h:create_topic("configure_ex")
113hh:add("The STMP.pinctrl.configure_ex(tbl) function configures pins according to a table.")
114hh:add("It is an enhanced version of configure which handles the different families and packages.")
115hh:add("The argument must be a table with one entry per STMP family.")
116hh:add("Each entry must a subtable with one subentry per package.")
117hh:add("Each subentry must be a valid argument to STMP.pinctrl.configure().")
118hh:add("The family names are the one returned by STMP.family.")
119hh:add("The table can also contain an entry \"all\" which apply to all families")
120hh:add("The package names are the one returned by STMP.digctl.package().")
121hh:add("The table can also contain an entry \"all\" which apply to all packages.")
122
123function STMP.pinctrl.configure_ex(tbl)
124 if type(tbl) ~= "table" then error("Parameter must be a table") end
125 local pack = STMP.digctl.package()
126 if tbl[STMP.family] ~= nil then
127 if tbl[STMP.family][pack] ~= nil then STMP.pinctrl.configure(tbl[STMP.family][pack]) end
128 if tbl[STMP.family]["all"] ~= nil then STMP.pinctrl.configure(tbl[STMP.family]["all"]) end
129 end
130 if tbl["all"] ~= nil then
131 if tbl["all"][pack] ~= nil then STMP.pinctrl.configure(tbl["all"][pack]) end
132 if tbl["all"]["all"] ~= nil then STMP.pinctrl.configure(tbl["all"]["all"]) end
133 end
134end
135
136hh = h:create_topic("lcdif")
137hh:add("The STMP.pinctrl.lcdif tables provides some high level routines to configure the pins.")
138hh:add("It is specialised to configure the LCDIF pins correctly.")
139hh:add("Some of the modes may not be available on all STMP families.")
140
141STMP.pinctrl.lcdif = {}
142
143local hhh = hh:create_topic("setup_system")
144hhh:add("The STMP.pinctrl.lcdif.setup_system(bus_width,busy) functions configure the LCDIF pins.")
145hhh:add("It only take cares of the pins used in system mode and for a specified bus width.")
146hhh:add("The handled bus widths are 8, 16 and 18")
147hhh:add("The busy pin is configured only if busy is true")
148
149function STMP.pinctrl.lcdif.setup_system(bus_width, busy)
150 local common =
151 {
152 stmp3600 =
153 {
154 all =
155 {
156 lcd_reset = { bank = 1, pin = 16, muxsel = "MAIN"},
157 lcd_rs = { bank = 1, pin = 17, muxsel = "MAIN"},
158 lcd_wr = { bank = 1, pin = 18, muxsel = "MAIN"},
159 lcd_cs = { bank = 1, pin = 19, muxsel = "MAIN"},
160 lcd_d0 = {bank = 1, pin = 0, muxsel = "MAIN"},
161 lcd_d1 = {bank = 1, pin = 1, muxsel = "MAIN"},
162 lcd_d2 = {bank = 1, pin = 2, muxsel = "MAIN"},
163 lcd_d3 = {bank = 1, pin = 3, muxsel = "MAIN"},
164 lcd_d4 = {bank = 1, pin = 4, muxsel = "MAIN"},
165 lcd_d5 = {bank = 1, pin = 5, muxsel = "MAIN"},
166 lcd_d6 = {bank = 1, pin = 6, muxsel = "MAIN"},
167 lcd_d7 = {bank = 1, pin = 7, muxsel = "MAIN"}
168 }
169 },
170 stmp3700 =
171 {
172 all =
173 {
174 lcd_reset = { bank = 1, pin = 16, muxsel = "MAIN"},
175 lcd_rs = { bank = 1, pin = 17, muxsel = "MAIN"},
176 lcd_wr = { bank = 1, pin = 18, muxsel = "MAIN"},
177 lcd_rd = { bank = 1, pin = 19, muxsel = "MAIN"},
178 lcd_cs = { bank = 1, pin = 20, muxsel = "MAIN"},
179 lcd_d0 = {bank = 1, pin = 0, muxsel = "MAIN"},
180 lcd_d1 = {bank = 1, pin = 1, muxsel = "MAIN"},
181 lcd_d2 = {bank = 1, pin = 2, muxsel = "MAIN"},
182 lcd_d3 = {bank = 1, pin = 3, muxsel = "MAIN"},
183 lcd_d4 = {bank = 1, pin = 4, muxsel = "MAIN"},
184 lcd_d5 = {bank = 1, pin = 5, muxsel = "MAIN"},
185 lcd_d6 = {bank = 1, pin = 6, muxsel = "MAIN"},
186 lcd_d7 = {bank = 1, pin = 7, muxsel = "MAIN"}
187 }
188 }
189 }
190 local bus8_15 =
191 {
192 stmp3600 =
193 {
194 all =
195 {
196 lcd_d8 = {bank = 1, pin = 8, muxsel = "MAIN"},
197 lcd_d9 = {bank = 1, pin = 9, muxsel = "MAIN"},
198 lcd_d10 = {bank = 1, pin = 10, muxsel = "MAIN"},
199 lcd_d11 = {bank = 1, pin = 11, muxsel = "MAIN"},
200 lcd_d12 = {bank = 1, pin = 12, muxsel = "MAIN"},
201 lcd_d13 = {bank = 1, pin = 13, muxsel = "MAIN"},
202 lcd_d14 = {bank = 1, pin = 14, muxsel = "MAIN"},
203 lcd_d15 = {bank = 1, pin = 15, muxsel = "MAIN"}
204 }
205 },
206 stmp3700 =
207 {
208 all =
209 {
210 lcd_d8 = {bank = 1, pin = 8, muxsel = "MAIN"},
211 lcd_d9 = {bank = 1, pin = 9, muxsel = "MAIN"},
212 lcd_d10 = {bank = 1, pin = 10, muxsel = "MAIN"},
213 lcd_d11 = {bank = 1, pin = 11, muxsel = "MAIN"},
214 lcd_d12 = {bank = 1, pin = 12, muxsel = "MAIN"},
215 lcd_d13 = {bank = 1, pin = 13, muxsel = "MAIN"},
216 lcd_d14 = {bank = 1, pin = 14, muxsel = "MAIN"},
217 lcd_d15 = {bank = 1, pin = 15, muxsel = "MAIN"}
218 }
219 }
220 }
221 local bus16_17 =
222 {
223
224 }
225 local busy_pin =
226 {
227 stmp3600 =
228 {
229 all =
230 {
231 lcd_busy = { bank = 1, pin = 21, muxsel = "MAIN"},
232 }
233 },
234 stmp3700 =
235 {
236 all =
237 {
238 lcd_busy = { bank = 1, pin = 21, muxsel = "MAIN"},
239 }
240 },
241 }
242
243 STMP.pinctrl.configure_ex(common)
244 if bus_width > 8 then
245 STMP.pinctrl.configure_ex(bus8_15)
246 end
247 if bus_width > 16 then
248 STMP.pinctrl.configure_ex(bus16_17)
249 end
250 if busy then
251 STMP.pinctrl.configure_ex(busy_pin)
252 end
253end
diff --git a/utils/hwstub/tools/lua/stmp/pwm.lua b/utils/hwstub/tools/lua/stmp/pwm.lua
new file mode 100644
index 0000000000..8b078af5a7
--- /dev/null
+++ b/utils/hwstub/tools/lua/stmp/pwm.lua
@@ -0,0 +1,35 @@
1--
2-- LCDIF
3--
4
5STMP.pwm = {}
6
7function STMP.pwm.init()
8 HW.LCDIF.CTRL.SFTRST.clr()
9 HW.LCDIF.CTRL.CLKGATE.clr()
10end
11
12function STMP.pwm.enable(chan, en)
13 if en then
14 HW.PWM.CTRL.set(bit32.lshift(1, chan))
15 else
16 HW.PWM.CTRL.clr(bit32.lshift(1, chan))
17 end
18end
19
20function STMP.pwm.setup(channel, period, cdiv, active, active_state, inactive, inactive_state)
21 -- stop
22 STMP.pwm.enable(channel, false)
23 -- setup pin
24 --FIXME
25 -- watch the order ! active THEN period
26 -- NOTE: the register value is period-1
27 HW.PWM.ACTIVEn[channel].ACTIVE.write(active)
28 HW.PWM.ACTIVEn[channel].INACTIVE.write(inactive)
29 HW.PWM.PERIODn[channel].PERIOD.write(period - 1)
30 HW.PWM.PERIODn[channel].ACTIVE_STATE.write(active_state)
31 HW.PWM.PERIODn[channel].INACTIVE_STATE.write(inactive_state)
32 HW.PWM.PERIODn[channel].CDIV.write(cdiv)
33 -- restore
34 STMP.pwm.enable(channel, true)
35end \ No newline at end of file
diff --git a/utils/hwstub/tools/lua/zenmozaic.lua b/utils/hwstub/tools/lua/zenmozaic.lua
new file mode 100644
index 0000000000..a4135c25c5
--- /dev/null
+++ b/utils/hwstub/tools/lua/zenmozaic.lua
@@ -0,0 +1,98 @@
1--
2-- ZEN MOZAIC
3--
4ZENMOZAIC = {}
5
6function ZENMOZAIC.lcd_send(cmd, data)
7 STMP.lcdif.set_data_swizzle(3)
8 STMP.lcdif.send_pio(false, {bit32.band(cmd, 0xff), bit32.rshift(cmd, 8)})
9 if cmd ~= 0x22 then
10 STMP.lcdif.send_pio(true, {bit32.band(data, 0xff), bit32.rshift(data, 8)})
11 end
12end
13
14function ZENMOZAIC.lcd_init()
15 STMP.pinctrl.lcdif.setup_system(8, false)
16 STMP.lcdif.init()
17 STMP.lcdif.set_word_length(8)
18 STMP.lcdif.set_system_timing(2, 2, 2, 2)
19 STMP.lcdif.set_reset(1)
20 STMP.lcdif.set_reset(0)
21 STMP.lcdif.set_reset(1)
22 STMP.lcdif.set_byte_packing_format(0xf)
23
24 ZENMOZAIC.lcd_send(0, 1)
25 ZENMOZAIC.lcd_send(3, 0)
26
27 ZENMOZAIC.lcd_send(3, 0x510)
28 ZENMOZAIC.lcd_send(9, 8)
29 ZENMOZAIC.lcd_send(0xc, 0)
30 ZENMOZAIC.lcd_send(0xd, 0)
31 ZENMOZAIC.lcd_send(0xe, 0)
32 ZENMOZAIC.lcd_send(0x5b, 4)
33 ZENMOZAIC.lcd_send(0xd, 0x10)
34 ZENMOZAIC.lcd_send(9, 0)
35 ZENMOZAIC.lcd_send(3, 0x10)
36 ZENMOZAIC.lcd_send(0xd, 0x14)
37 ZENMOZAIC.lcd_send(0xe, 0x2b12)
38 ZENMOZAIC.lcd_send(1, 0x21f)
39 ZENMOZAIC.lcd_send(2, 0x700)
40 ZENMOZAIC.lcd_send(5, 0x30)
41 ZENMOZAIC.lcd_send(6, 0)
42 ZENMOZAIC.lcd_send(8, 0x202)
43 ZENMOZAIC.lcd_send(0xa, 0xc003)
44 ZENMOZAIC.lcd_send(0xb, 0)
45 ZENMOZAIC.lcd_send(0xf, 0)
46 ZENMOZAIC.lcd_send(0x10, 0)
47 ZENMOZAIC.lcd_send(0x11, 0)
48 ZENMOZAIC.lcd_send(0x14, 0x9f00)
49 ZENMOZAIC.lcd_send(0x15, 0x9f00)
50 ZENMOZAIC.lcd_send(0x16, 0x7f00)
51 ZENMOZAIC.lcd_send(0x17, 0x9f00)
52 ZENMOZAIC.lcd_send(0x20, 0)
53 ZENMOZAIC.lcd_send(0x21, 0)
54 ZENMOZAIC.lcd_send(0x23, 0)
55 ZENMOZAIC.lcd_send(0x24, 0)
56 ZENMOZAIC.lcd_send(0x25, 0)
57 ZENMOZAIC.lcd_send(0x26, 0)
58 ZENMOZAIC.lcd_send(0x30, 0x707)
59 ZENMOZAIC.lcd_send(0x31, 0x504)
60 ZENMOZAIC.lcd_send(0x32, 7)
61 ZENMOZAIC.lcd_send(0x33, 0x307)
62 ZENMOZAIC.lcd_send(0x34, 7)
63 ZENMOZAIC.lcd_send(0x35, 0x400)
64 ZENMOZAIC.lcd_send(0x36, 0x607)
65 ZENMOZAIC.lcd_send(0x37, 0x703)
66 ZENMOZAIC.lcd_send(0x3a, 0x1a0d)
67 ZENMOZAIC.lcd_send(0x3b, 0x1309)
68
69 ZENMOZAIC.lcd_send(9, 4)
70 ZENMOZAIC.lcd_send(7, 5)
71 ZENMOZAIC.lcd_send(7, 0x25)
72 ZENMOZAIC.lcd_send(7, 0x27)
73 ZENMOZAIC.lcd_send(0x5b, 0)
74 ZENMOZAIC.lcd_send(7, 0x37)
75
76 ZENMOZAIC.lcd_send(0x22, 0)
77 for i=0,128 do
78 STMP.lcdif.send_pio(true, {0xff, 0})
79 end
80end
81
82function ZENMOZAIC.set_backlight(val)
83 local v = math.floor((val + 200) * val / 1000)
84 for i=4,0,-1 do
85 if bit32.btest(v,bit32.lshift(1,i)) then
86 HW.UARTDBG.DR.write(0xff)
87 else
88 HW.UARTDBG.DR.write(0xf8)
89 end
90 while HW.UARTDBG.FR.TXFF.read() == 1 do end
91 end
92 HW.UARTDBG.DR.write(0)
93end
94
95function ZENMOZAIC.init()
96 ZENMOZAIC.lcd_init()
97end
98
diff --git a/utils/hwstub/tools/lua/zenv.lua b/utils/hwstub/tools/lua/zenv.lua
new file mode 100644
index 0000000000..5a6779c876
--- /dev/null
+++ b/utils/hwstub/tools/lua/zenv.lua
@@ -0,0 +1,56 @@
1--
2-- ZEN V
3--
4ZENV = {}
5
6function ZENV.lcd_send(cmd, data)
7 if #cmd == 1 and cmd[1] == 0x5c then
8 STMP.lcdif.set_word_length(16)
9 STMP.lcdif.set_data_swizzle("NONE")
10 else
11 STMP.lcdif.set_word_length(8)
12 STMP.lcdif.set_data_swizzle("NONE")
13 end
14 STMP.lcdif.send_pio(false, cmd)
15 STMP.lcdif.send_pio(true, data)
16end
17
18function ZENV.lcd_init()
19 STMP.pinctrl.lcdif.setup_system(16, false)
20 STMP.pinctrl.pin(3, 16).muxsel("GPIO")
21 STMP.pinctrl.pin(3, 16).disable()
22 if STMP.pinctrl.pin(3, 16).read() == 0 then
23 STMP.debug("ZENV: need lcd power init")
24 STMP.pinctrl.pin(0, 27).muxsel("GPIO")
25 STMP.pinctrl.pin(0, 27).enable()
26 STMP.pinctrl.pin(0, 27).set()
27 end
28
29 STMP.lcdif.init()
30 STMP.lcdif.set_system_timing(2, 2, 2, 2)
31 STMP.lcdif.set_reset(1)
32 STMP.lcdif.set_reset(0)
33 STMP.lcdif.set_reset(1)
34
35 ZENV.lcd_send({0xca}, {0x7f})
36 ZENV.lcd_send({0xa0}, {0x75})
37 ZENV.lcd_send({0xc7}, {0x08})
38 ZENV.lcd_send({0xbe}, {0x18})
39 ZENV.lcd_send({0xc1}, {0x7b, 0x69, 0x9f})
40 ZENV.lcd_send({0xb1}, {0x1f})
41 ZENV.lcd_send({0xb3}, {0x80})
42 ZENV.lcd_send({0xbb}, {0x00, 0x00, 0x00})
43 ZENV.lcd_send({0xad}, {0x8a})
44 ZENV.lcd_send({0xb0}, {0x00})
45 ZENV.lcd_send({0xd1}, {0x02})
46 ZENV.lcd_send({0xb9}, {})
47 ZENV.lcd_send({0x92}, {0x01})
48 ZENV.lcd_send({0xa2}, {0x80})
49 ZENV.lcd_send({0x9e}, {})
50 ZENV.lcd_send({0xa6}, {})
51 ZENV.lcd_send({0xaf}, {})
52end
53
54function ZENV.init()
55 ZENV.lcd_init()
56end