summaryrefslogtreecommitdiff
path: root/utils/hwstub/tools/lua
diff options
context:
space:
mode:
Diffstat (limited to 'utils/hwstub/tools/lua')
-rw-r--r--utils/hwstub/tools/lua/sonynwze370.lua98
-rw-r--r--utils/hwstub/tools/lua/stmp/digctl.lua11
-rw-r--r--utils/hwstub/tools/lua/stmp/lcdif.lua50
-rw-r--r--utils/hwstub/tools/lua/zenmozaic.lua21
4 files changed, 176 insertions, 4 deletions
diff --git a/utils/hwstub/tools/lua/sonynwze370.lua b/utils/hwstub/tools/lua/sonynwze370.lua
new file mode 100644
index 0000000000..969a440a08
--- /dev/null
+++ b/utils/hwstub/tools/lua/sonynwze370.lua
@@ -0,0 +1,98 @@
1--
2-- Sony NWZ-E370
3--
4NWZE370 = {}
5
6function NWZE370.lcd_send(cmd, data)
7 STMP.lcdif.set_data_swizzle(0)
8 STMP.lcdif.set_byte_packing_format(0xf)
9 STMP.lcdif.send_pio(false, {cmd})
10 if #data ~= 0 then
11 STMP.lcdif.send_pio(true, data)
12 end
13end
14
15function NWZE370.lcd_set_update_rect(x, y, w, h)
16 NWZE370.lcd_send(0x2a, {0, x, 0, x + w - 1})
17 NWZE370.lcd_send(0x2b, {0, y, 0, y + h - 1})
18 NWZE370.lcd_send(0x2c, {})
19end
20
21function NWZE370.lcd_init()
22 STMP.pinctrl.lcdif.setup_system(8, false)
23 STMP.lcdif.init()
24 STMP.lcdif.set_databus_width(8)
25 STMP.lcdif.set_word_length(8)
26 STMP.lcdif.set_system_timing(2, 2, 2, 2)
27 STMP.lcdif.set_byte_packing_format(0xf)
28 STMP.lcdif.set_reset(1)
29 STMP.lcdif.set_reset(0)
30 STMP.lcdif.set_reset(1)
31
32 STMP.digctl.mdelay(150)
33 NWZE370.lcd_send(1, {}) -- software reset
34 NWZE370.lcd_send(0x11, {}) -- slee out
35 STMP.digctl.mdelay(150)
36 NWZE370.lcd_send(0x26, {4}) -- gamma set (curve 3)
37 NWZE370.lcd_send(0xb1, {9, 0xd}) -- frame rate (DIVA=9, VPA=13) => 88.9 Hz ?
38 NWZE370.lcd_send(0xc0, {8, 0}) -- power control 1 (GVDD=4.4 V, VCI1=2.75 V)
39 NWZE370.lcd_send(0xc1, {5}) -- power control 2 (setting 5)
40 NWZE370.lcd_send(0xc5, {0x31, 0x40}) -- VCOM control 1 (0x31, 0x40)
41 NWZE370.lcd_send(0xc7, {0xc8}) -- VCOM offset control (0xc8)
42 NWZE370.lcd_send(0xec, {0xc}) --
43 NWZE370.lcd_send(0x3a, {5}) -- interface pixel format (16 bit/pixel)
44 NWZE370.lcd_send(0x2a, {0, 0, 0, 0x7f}) -- column address (0, 127)
45 NWZE370.lcd_send(0x2b, {0, 0, 0, 0x9f}) -- page address set (0, 159)
46 NWZE370.lcd_send(0x35, {0}) -- tear effect line on (M=0)
47 NWZE370.lcd_send(0x36, {0xc8}) -- memory access control (MH=0, BGR, ML=MV=0, MX=MY=1)
48 NWZE370.lcd_send(0xb4, {0}) -- display inversion (NLA=NLB=NLC=0)
49 NWZE370.lcd_send(0xb7, {0}) -- source driver direction control (CRL=0)
50 NWZE370.lcd_send(0xb8, {0}) -- gate driver direction control (CTB=0)
51 NWZE370.lcd_send(0xf2, {1}) -- gamma adjustment (enable)
52 NWZE370.lcd_send(0xe0, {0x3f, 0x20, 0x1d, 0x2d, 0x26, 0xc, 0x4b, 0xb7,
53 0x39, 0x17, 0x1d, 0x16, 0x16, 0x10, 0}) -- positive gamma
54 NWZE370.lcd_send(0xe1, {0, 0x1f, 0x21, 0x12, 0x18, 0x13, 0x34, 0x48,
55 0x46, 8, 0x21, 0x29, 0x28, 0x2f, 0x3f}) --negative gamma
56 NWZE370.lcd_send(0x29, {}) -- display on
57
58 NWZE370.lcd_set_update_rect(10, 10, 20, 20)
59 for i = 0, 19 do
60 for j = 0, 19 do
61 pix = 0xf800
62 STMP.lcdif.send_pio(true, {bit32.band(pix, 0xff), bit32.rshift(pix, 8)})
63 end
64 end
65end
66
67function NWZE370.set_backlight(val)
68
69end
70
71function NWZE370.init()
72 NWZE370.lcd_init()
73 --[[
74 HW.LRADC.CTRL0.SFTRST.clr()
75 HW.LRADC.CTRL0.CLKGATE.clr()
76 HW.LRADC.CHn[0].ACCUMULATE.clr()
77 HW.LRADC.CHn[0].NUM_SAMPLES.write(0)
78 HW.LRADC.CHn[0].VALUE.write(0)
79 local t = {}
80 for i = 1,1000,1 do
81 HW.LRADC.CTRL0.SCHEDULE.write(1)
82 --local time = HW.DIGCTL.MICROSECONDS.read()
83 local time = i * 1000
84 local val = HW.LRADC.CHn[0].VALUE.read()
85 t[#t + 1] = {time, val}
86 end
87 local file = io.open("data.txt", "w")
88 for i,v in ipairs(t) do
89 file:write(string.format("%d %d\n", v[1] / 1000, v[2]))
90 end
91 file:close()
92 print("Display curve using:")
93 print("gnuplot -persist");
94 print("> plot \"data.txt\" using 1:2")
95 ]]--
96end
97
98
diff --git a/utils/hwstub/tools/lua/stmp/digctl.lua b/utils/hwstub/tools/lua/stmp/digctl.lua
index 8dfc13b7f2..2ef3551c77 100644
--- a/utils/hwstub/tools/lua/stmp/digctl.lua
+++ b/utils/hwstub/tools/lua/stmp/digctl.lua
@@ -35,4 +35,15 @@ function STMP.digctl.package()
35 end 35 end
36 36
37 return pack 37 return pack
38end
39
40function STMP.digctl.udelay(us)
41 local tend = HW.DIGCTL.MICROSECONDS.read() + us
42 while HW.DIGCTL.MICROSECONDS.read() < tend do
43
44 end
45end
46
47function STMP.digctl.mdelay(ms)
48 STMP.digctl.udelay(ms * 1000)
38end \ No newline at end of file 49end \ No newline at end of file
diff --git a/utils/hwstub/tools/lua/stmp/lcdif.lua b/utils/hwstub/tools/lua/stmp/lcdif.lua
index 0878cb1139..a2f085e166 100644
--- a/utils/hwstub/tools/lua/stmp/lcdif.lua
+++ b/utils/hwstub/tools/lua/stmp/lcdif.lua
@@ -29,6 +29,18 @@ function STMP.lcdif.set_reset(val)
29 end 29 end
30end 30end
31 31
32function STMP.lcdif.set_databus_width(bus_width)
33 local v = 0
34 if bus_width == 8 then
35 v = 1
36 elseif bus_width == 18 then
37 v = 2
38 elseif bus_width == 24 then
39 v = 3
40 end
41 HW.LCDIF.CTRL.LCD_DATABUS_WIDTH.write(v)
42end
43
32function STMP.lcdif.set_word_length(bus_width) 44function STMP.lcdif.set_word_length(bus_width)
33 if STMP.is_stmp3600() or STMP.is_stmp3700() then 45 if STMP.is_stmp3600() or STMP.is_stmp3700() then
34 if bus_width == 8 then 46 if bus_width == 8 then
@@ -37,7 +49,15 @@ function STMP.lcdif.set_word_length(bus_width)
37 HW.LCDIF.CTRL.WORD_LENGTH.clr() 49 HW.LCDIF.CTRL.WORD_LENGTH.clr()
38 end 50 end
39 else 51 else
40 error("STMP.lcdif.set_word_length: unimplemented") 52 local v = 0
53 if bus_width == 8 then
54 v = 1
55 elseif bus_width == 18 then
56 v = 2
57 elseif bus_width == 24 then
58 v = 3
59 end
60 HW.LCDIF.CTRL.WORD_LENGTH.write(v)
41 end 61 end
42end 62end
43 63
@@ -49,7 +69,11 @@ function STMP.lcdif.get_word_length()
49 return 16 69 return 16
50 end 70 end
51 else 71 else
52 error("STMP.lcdif.get_word_length: unimplemented") 72 local v = HW.LCDIF.CTRL.WORD_LENGTH.read()
73 if v == 0 then return 16
74 elseif v == 1 then return 8
75 elseif v == 2 then return 18
76 else return 24 end
53 end 77 end
54end 78end
55 79
@@ -62,7 +86,11 @@ function STMP.lcdif.set_data_swizzle(swizzle)
62 error("unimplemented") 86 error("unimplemented")
63 end 87 end
64 end 88 end
65 HW.LCDIF.CTRL.DATA_SWIZZLE.write(v) 89 if STMP.is_stmp3600() or STMP.is_stmp3700() then
90 HW.LCDIF.CTRL.DATA_SWIZZLE.write(v)
91 else
92 HW.LCDIF.CTRL.INPUT_DATA_SWIZZLE.write(v)
93 end
66end 94end
67 95
68function STMP.lcdif.is_busy() 96function STMP.lcdif.is_busy()
@@ -73,6 +101,11 @@ function STMP.lcdif.is_busy()
73 end 101 end
74end 102end
75 103
104function STMP.lcdif.wait_ready()
105 while HW.LCDIF.CTRL.RUN.read() == 1 do
106 end
107end
108
76function STMP.lcdif.send_pio(data_mode, data) 109function STMP.lcdif.send_pio(data_mode, data)
77 local wl = STMP.lcdif.get_word_length() 110 local wl = STMP.lcdif.get_word_length()
78 if data_mode then 111 if data_mode then
@@ -81,8 +114,16 @@ function STMP.lcdif.send_pio(data_mode, data)
81 HW.LCDIF.CTRL.DATA_SELECT.clr() 114 HW.LCDIF.CTRL.DATA_SELECT.clr()
82 end 115 end
83 STMP.debug(string.format("lcdif: count = %d", #data)) 116 STMP.debug(string.format("lcdif: count = %d", #data))
117 if STMP.is_imx233() then
118 HW.LCDIF.CTRL.LCDIF_MASTER.clr()
119 end
84 HW.LCDIF.CTRL.RUN.clr() 120 HW.LCDIF.CTRL.RUN.clr()
85 HW.LCDIF.CTRL.COUNT.write(#data) 121 if STMP.is_stmp3600() or STMP.is_stmp3700() then
122 HW.LCDIF.CTRL.COUNT.write(#data)
123 else
124 HW.LCDIF.TRANSFER_COUNT.V_COUNT.write(1)
125 HW.LCDIF.TRANSFER_COUNT.H_COUNT.write(#data)
126 end
86 HW.LCDIF.CTRL.RUN.set() 127 HW.LCDIF.CTRL.RUN.set()
87 local i = 1 128 local i = 1
88 while i <= #data do 129 while i <= #data do
@@ -97,4 +138,5 @@ function STMP.lcdif.send_pio(data_mode, data)
97 while STMP.lcdif.is_busy() do STMP.debug("lcdif: fifo full") end 138 while STMP.lcdif.is_busy() do STMP.debug("lcdif: fifo full") end
98 HW.LCDIF.DATA.write(v) 139 HW.LCDIF.DATA.write(v)
99 end 140 end
141 STMP.lcdif.wait_ready()
100end \ No newline at end of file 142end \ No newline at end of file
diff --git a/utils/hwstub/tools/lua/zenmozaic.lua b/utils/hwstub/tools/lua/zenmozaic.lua
index a4135c25c5..b2a899ab5d 100644
--- a/utils/hwstub/tools/lua/zenmozaic.lua
+++ b/utils/hwstub/tools/lua/zenmozaic.lua
@@ -94,5 +94,26 @@ end
94 94
95function ZENMOZAIC.init() 95function ZENMOZAIC.init()
96 ZENMOZAIC.lcd_init() 96 ZENMOZAIC.lcd_init()
97 HW.LRADC.CTRL0.SFTRST.clr()
98 HW.LRADC.CTRL0.CLKGATE.clr()
99 HW.LRADC.CHn[0].ACCUMULATE.clr()
100 HW.LRADC.CHn[0].NUM_SAMPLES.write(0)
101 HW.LRADC.CHn[0].VALUE.write(0)
102 local t = {}
103 for i = 1,1000,1 do
104 HW.LRADC.CTRL0.SCHEDULE.write(1)
105 --local time = HW.DIGCTL.MICROSECONDS.read()
106 local time = i * 1000
107 local val = HW.LRADC.CHn[0].VALUE.read()
108 t[#t + 1] = {time, val}
109 end
110 local file = io.open("data.txt", "w")
111 for i,v in ipairs(t) do
112 file:write(string.format("%d %d\n", v[1] / 1000, v[2]))
113 end
114 file:close()
115 print("Display curve using:")
116 print("gnuplot -persist");
117 print("> plot \"data.txt\" using 1:2")
97end 118end
98 119