diff options
Diffstat (limited to 'utils/hwstub')
-rw-r--r-- | utils/hwstub/tools/lua/load.lua | 3 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/stmp.lua | 78 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/stmp/digctl.lua | 38 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/stmp/lcdif.lua | 100 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/stmp/pinctrl.lua | 253 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/stmp/pwm.lua | 35 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/zenmozaic.lua | 98 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/zenv.lua | 56 |
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 @@ | |||
1 | package.path = string.sub(string.gsub(debug.getinfo(1).source, "load.lua", "?.lua"),2) .. ";" .. package.path | ||
2 | |||
3 | require "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 | |||
5 | STMP = { info = {} } | ||
6 | |||
7 | local h = HELP:create_topic("STMP") | ||
8 | h:add("This table contains the abstraction of the different device blocks for the STMP.") | ||
9 | h:add("It allows one to use higher-level primitives rather than poking at register directly.") | ||
10 | h:add("Furthermore, it tries as much as possible to hide the differences between the different STMP families.") | ||
11 | |||
12 | local 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 | ||
22 | end | ||
23 | |||
24 | local hh = h:create_topic("is_imx233") | ||
25 | hh:add("STMP.is_imx233() returns true if the chip ID reports a i.MX233") | ||
26 | |||
27 | function STMP.is_imx233() | ||
28 | return hwstub.dev.stmp.chipid == 0x3780 | ||
29 | end | ||
30 | |||
31 | hh = h:create_topic("is_stmp3700") | ||
32 | hh:add("STMP.is_stmp3700() returns true if the chip ID reports a STMP3700") | ||
33 | |||
34 | function STMP.is_stmp3700() | ||
35 | return hwstub.dev.stmp.chipid == 0x3700 | ||
36 | end | ||
37 | |||
38 | hh = h:create_topic("is_stmp3770") | ||
39 | hh:add("STMP.is_stmp3770() returns true if the chip ID reports a STMP3770") | ||
40 | |||
41 | function STMP.is_stmp3770() | ||
42 | return hwstub.dev.stmp.chipid == 0x37b0 | ||
43 | end | ||
44 | |||
45 | hh = h:create_topic("is_stmp3600") | ||
46 | hh:add("STMP.is_stmp3600() returns true if the chip ID reports a STMP36xx") | ||
47 | |||
48 | function STMP.is_stmp3600() | ||
49 | return hwstub.dev.stmp.chipid >= 0x3600 and hwstub.dev.stmp.chipid < 0x3700 | ||
50 | end | ||
51 | |||
52 | if STMP.is_imx233() then | ||
53 | identify("STMP3780 (aka i.MX233)", "imx233", "imx233") | ||
54 | elseif STMP.is_stmp3700() then | ||
55 | identify("STMP3700", "stmp3700", "stmp3700") | ||
56 | elseif STMP.is_stmp3770() then | ||
57 | identify("STMP3770", "stmp3770", "stmp3700") | ||
58 | elseif STMP.is_stmp3600() then | ||
59 | identify("STMP3600", "stmp3600", "stmp3600") | ||
60 | else | ||
61 | print(string.format("Unable to identify this chip as a STMP: chipid=0x%x", hwstub.dev.stmp.chipid)); | ||
62 | end | ||
63 | |||
64 | hh = h:create_topic("debug") | ||
65 | hh:add("STMP.debug(...) prints some debug output if STMP.debug_on is true and does nothing otherwise.") | ||
66 | |||
67 | STMP.debug_on = false | ||
68 | |||
69 | function STMP.debug(...) | ||
70 | if STMP.debug_on then print(...) end | ||
71 | end | ||
72 | |||
73 | if STMP.info.chip ~= nil then | ||
74 | require "stmp/digctl" | ||
75 | require "stmp/pinctrl" | ||
76 | require "stmp/lcdif" | ||
77 | require "stmp/pwm" | ||
78 | end \ 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 | --- | ||
4 | STMP.digctl = {} | ||
5 | |||
6 | local h = HELP:get_topic("STMP"):create_topic("digctl") | ||
7 | h:add("The STMP.digctl table handles the digctl device for all STMPs.") | ||
8 | |||
9 | local hh = h:create_topic("package") | ||
10 | hh:add("The STMP.digctl.package() function returns the name of the package.") | ||
11 | hh:add("The following packages can be returned:") | ||
12 | hh:add("* bga100") | ||
13 | hh:add("* bga169") | ||
14 | hh:add("* tqfp100") | ||
15 | hh:add("* lqfp100") | ||
16 | hh:add("* lqfp128") | ||
17 | |||
18 | function 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 | ||
38 | end \ 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 | |||
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 | ||
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 | --- | ||
4 | STMP.pinctrl = {} | ||
5 | |||
6 | local h = HELP:get_topic("STMP"):create_topic("pinctrl") | ||
7 | h:add("The STMP.pinctrl table handles the pinctrl device for all STMPs.") | ||
8 | h:add("It provides a simple abstraction to set individual pins.") | ||
9 | |||
10 | local hh = h:create_topic("pin") | ||
11 | hh:add("The STMP.pinctrl.pin(x,yy) function returns a table for the pin BxPyy.") | ||
12 | hh:add("Depending on the STMP family, the following function might be available.") | ||
13 | hh:add("* read() returns the value of the pin (the pin does not need to be configured as GPIO)") | ||
14 | hh:add("* write(x) sets the value of the pin (provided it is a GPIO with output enabled)") | ||
15 | hh:add("* set() is equivalent to write(1)") | ||
16 | hh:add("* clr() is equivalent to write(0)") | ||
17 | hh:add("* enable() enables the gpio output (provided it is configured as GPIO).") | ||
18 | hh:add("* disable() disables the gpio output (provided it is configured as GPIO)") | ||
19 | hh:add("* muxsel(x) set pin function to x, which can be an integer or one of: MAIN, ALT1, ALT2, GPIO") | ||
20 | |||
21 | function 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 | ||
69 | end | ||
70 | |||
71 | hh = h:create_topic("configure") | ||
72 | hh:add("The STMP.pinctrl.configure(tbl) function configures pins according to a table.") | ||
73 | hh:add("The table must contain a list of subtable, each corresponding to a pin.") | ||
74 | hh:add("Each subtable can configure one or more aspects of a specific pin.") | ||
75 | hh:add("The following characteristics are understood:") | ||
76 | hh:add("* bank: pin bank (mandatory)") | ||
77 | hh:add("* pin: pin number (mandatory) ") | ||
78 | hh:add("* muxsel: same values as STMP.pinctrl.pin().muxsel (optional)") | ||
79 | hh:add("* enable: enable/disable output (optional)") | ||
80 | hh:add("* output: set/clear output (optional)") | ||
81 | hh:add("All non-subtable entries are ignored") | ||
82 | hh:add("All unknown parameters in subtablkes are ignored") | ||
83 | hh:add("") | ||
84 | hh:add("Example:") | ||
85 | hh:add("STMP.pinctrl.configure({{bank=0,pin=1,muxsel=\"GPIO\",enable=false},{bank=0,pin=2,muxsel=\"MAIN\"}})") | ||
86 | |||
87 | function 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 | ||
110 | end | ||
111 | |||
112 | hh = h:create_topic("configure_ex") | ||
113 | hh:add("The STMP.pinctrl.configure_ex(tbl) function configures pins according to a table.") | ||
114 | hh:add("It is an enhanced version of configure which handles the different families and packages.") | ||
115 | hh:add("The argument must be a table with one entry per STMP family.") | ||
116 | hh:add("Each entry must a subtable with one subentry per package.") | ||
117 | hh:add("Each subentry must be a valid argument to STMP.pinctrl.configure().") | ||
118 | hh:add("The family names are the one returned by STMP.family.") | ||
119 | hh:add("The table can also contain an entry \"all\" which apply to all families") | ||
120 | hh:add("The package names are the one returned by STMP.digctl.package().") | ||
121 | hh:add("The table can also contain an entry \"all\" which apply to all packages.") | ||
122 | |||
123 | function 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 | ||
134 | end | ||
135 | |||
136 | hh = h:create_topic("lcdif") | ||
137 | hh:add("The STMP.pinctrl.lcdif tables provides some high level routines to configure the pins.") | ||
138 | hh:add("It is specialised to configure the LCDIF pins correctly.") | ||
139 | hh:add("Some of the modes may not be available on all STMP families.") | ||
140 | |||
141 | STMP.pinctrl.lcdif = {} | ||
142 | |||
143 | local hhh = hh:create_topic("setup_system") | ||
144 | hhh:add("The STMP.pinctrl.lcdif.setup_system(bus_width,busy) functions configure the LCDIF pins.") | ||
145 | hhh:add("It only take cares of the pins used in system mode and for a specified bus width.") | ||
146 | hhh:add("The handled bus widths are 8, 16 and 18") | ||
147 | hhh:add("The busy pin is configured only if busy is true") | ||
148 | |||
149 | function 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 | ||
253 | end | ||
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 | |||
5 | STMP.pwm = {} | ||
6 | |||
7 | function STMP.pwm.init() | ||
8 | HW.LCDIF.CTRL.SFTRST.clr() | ||
9 | HW.LCDIF.CTRL.CLKGATE.clr() | ||
10 | end | ||
11 | |||
12 | function 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 | ||
18 | end | ||
19 | |||
20 | function 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) | ||
35 | end \ 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 | -- | ||
4 | ZENMOZAIC = {} | ||
5 | |||
6 | function 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 | ||
12 | end | ||
13 | |||
14 | function 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 | ||
80 | end | ||
81 | |||
82 | function 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) | ||
93 | end | ||
94 | |||
95 | function ZENMOZAIC.init() | ||
96 | ZENMOZAIC.lcd_init() | ||
97 | end | ||
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 | -- | ||
4 | ZENV = {} | ||
5 | |||
6 | function 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) | ||
16 | end | ||
17 | |||
18 | function 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}, {}) | ||
52 | end | ||
53 | |||
54 | function ZENV.init() | ||
55 | ZENV.lcd_init() | ||
56 | end | ||