hwstub: improve lcdif, digtctl, add sony nwz-e370

Change-Id: I5316cc9fd9addfca8a674628695fed1c1bf9269f
This commit is contained in:
Amaury Pouly 2013-09-05 23:14:07 +02:00
parent f13cad4c8e
commit f40b15d0cb
4 changed files with 176 additions and 4 deletions

View file

@ -0,0 +1,98 @@
--
-- Sony NWZ-E370
--
NWZE370 = {}
function NWZE370.lcd_send(cmd, data)
STMP.lcdif.set_data_swizzle(0)
STMP.lcdif.set_byte_packing_format(0xf)
STMP.lcdif.send_pio(false, {cmd})
if #data ~= 0 then
STMP.lcdif.send_pio(true, data)
end
end
function NWZE370.lcd_set_update_rect(x, y, w, h)
NWZE370.lcd_send(0x2a, {0, x, 0, x + w - 1})
NWZE370.lcd_send(0x2b, {0, y, 0, y + h - 1})
NWZE370.lcd_send(0x2c, {})
end
function NWZE370.lcd_init()
STMP.pinctrl.lcdif.setup_system(8, false)
STMP.lcdif.init()
STMP.lcdif.set_databus_width(8)
STMP.lcdif.set_word_length(8)
STMP.lcdif.set_system_timing(2, 2, 2, 2)
STMP.lcdif.set_byte_packing_format(0xf)
STMP.lcdif.set_reset(1)
STMP.lcdif.set_reset(0)
STMP.lcdif.set_reset(1)
STMP.digctl.mdelay(150)
NWZE370.lcd_send(1, {}) -- software reset
NWZE370.lcd_send(0x11, {}) -- slee out
STMP.digctl.mdelay(150)
NWZE370.lcd_send(0x26, {4}) -- gamma set (curve 3)
NWZE370.lcd_send(0xb1, {9, 0xd}) -- frame rate (DIVA=9, VPA=13) => 88.9 Hz ?
NWZE370.lcd_send(0xc0, {8, 0}) -- power control 1 (GVDD=4.4 V, VCI1=2.75 V)
NWZE370.lcd_send(0xc1, {5}) -- power control 2 (setting 5)
NWZE370.lcd_send(0xc5, {0x31, 0x40}) -- VCOM control 1 (0x31, 0x40)
NWZE370.lcd_send(0xc7, {0xc8}) -- VCOM offset control (0xc8)
NWZE370.lcd_send(0xec, {0xc}) --
NWZE370.lcd_send(0x3a, {5}) -- interface pixel format (16 bit/pixel)
NWZE370.lcd_send(0x2a, {0, 0, 0, 0x7f}) -- column address (0, 127)
NWZE370.lcd_send(0x2b, {0, 0, 0, 0x9f}) -- page address set (0, 159)
NWZE370.lcd_send(0x35, {0}) -- tear effect line on (M=0)
NWZE370.lcd_send(0x36, {0xc8}) -- memory access control (MH=0, BGR, ML=MV=0, MX=MY=1)
NWZE370.lcd_send(0xb4, {0}) -- display inversion (NLA=NLB=NLC=0)
NWZE370.lcd_send(0xb7, {0}) -- source driver direction control (CRL=0)
NWZE370.lcd_send(0xb8, {0}) -- gate driver direction control (CTB=0)
NWZE370.lcd_send(0xf2, {1}) -- gamma adjustment (enable)
NWZE370.lcd_send(0xe0, {0x3f, 0x20, 0x1d, 0x2d, 0x26, 0xc, 0x4b, 0xb7,
0x39, 0x17, 0x1d, 0x16, 0x16, 0x10, 0}) -- positive gamma
NWZE370.lcd_send(0xe1, {0, 0x1f, 0x21, 0x12, 0x18, 0x13, 0x34, 0x48,
0x46, 8, 0x21, 0x29, 0x28, 0x2f, 0x3f}) --negative gamma
NWZE370.lcd_send(0x29, {}) -- display on
NWZE370.lcd_set_update_rect(10, 10, 20, 20)
for i = 0, 19 do
for j = 0, 19 do
pix = 0xf800
STMP.lcdif.send_pio(true, {bit32.band(pix, 0xff), bit32.rshift(pix, 8)})
end
end
end
function NWZE370.set_backlight(val)
end
function NWZE370.init()
NWZE370.lcd_init()
--[[
HW.LRADC.CTRL0.SFTRST.clr()
HW.LRADC.CTRL0.CLKGATE.clr()
HW.LRADC.CHn[0].ACCUMULATE.clr()
HW.LRADC.CHn[0].NUM_SAMPLES.write(0)
HW.LRADC.CHn[0].VALUE.write(0)
local t = {}
for i = 1,1000,1 do
HW.LRADC.CTRL0.SCHEDULE.write(1)
--local time = HW.DIGCTL.MICROSECONDS.read()
local time = i * 1000
local val = HW.LRADC.CHn[0].VALUE.read()
t[#t + 1] = {time, val}
end
local file = io.open("data.txt", "w")
for i,v in ipairs(t) do
file:write(string.format("%d %d\n", v[1] / 1000, v[2]))
end
file:close()
print("Display curve using:")
print("gnuplot -persist");
print("> plot \"data.txt\" using 1:2")
]]--
end

View file

@ -36,3 +36,14 @@ function STMP.digctl.package()
return pack
end
function STMP.digctl.udelay(us)
local tend = HW.DIGCTL.MICROSECONDS.read() + us
while HW.DIGCTL.MICROSECONDS.read() < tend do
end
end
function STMP.digctl.mdelay(ms)
STMP.digctl.udelay(ms * 1000)
end

View file

@ -29,6 +29,18 @@ function STMP.lcdif.set_reset(val)
end
end
function STMP.lcdif.set_databus_width(bus_width)
local v = 0
if bus_width == 8 then
v = 1
elseif bus_width == 18 then
v = 2
elseif bus_width == 24 then
v = 3
end
HW.LCDIF.CTRL.LCD_DATABUS_WIDTH.write(v)
end
function STMP.lcdif.set_word_length(bus_width)
if STMP.is_stmp3600() or STMP.is_stmp3700() then
if bus_width == 8 then
@ -37,7 +49,15 @@ function STMP.lcdif.set_word_length(bus_width)
HW.LCDIF.CTRL.WORD_LENGTH.clr()
end
else
error("STMP.lcdif.set_word_length: unimplemented")
local v = 0
if bus_width == 8 then
v = 1
elseif bus_width == 18 then
v = 2
elseif bus_width == 24 then
v = 3
end
HW.LCDIF.CTRL.WORD_LENGTH.write(v)
end
end
@ -49,7 +69,11 @@ function STMP.lcdif.get_word_length()
return 16
end
else
error("STMP.lcdif.get_word_length: unimplemented")
local v = HW.LCDIF.CTRL.WORD_LENGTH.read()
if v == 0 then return 16
elseif v == 1 then return 8
elseif v == 2 then return 18
else return 24 end
end
end
@ -62,7 +86,11 @@ function STMP.lcdif.set_data_swizzle(swizzle)
error("unimplemented")
end
end
HW.LCDIF.CTRL.DATA_SWIZZLE.write(v)
if STMP.is_stmp3600() or STMP.is_stmp3700() then
HW.LCDIF.CTRL.DATA_SWIZZLE.write(v)
else
HW.LCDIF.CTRL.INPUT_DATA_SWIZZLE.write(v)
end
end
function STMP.lcdif.is_busy()
@ -73,6 +101,11 @@ function STMP.lcdif.is_busy()
end
end
function STMP.lcdif.wait_ready()
while HW.LCDIF.CTRL.RUN.read() == 1 do
end
end
function STMP.lcdif.send_pio(data_mode, data)
local wl = STMP.lcdif.get_word_length()
if data_mode then
@ -81,8 +114,16 @@ function STMP.lcdif.send_pio(data_mode, data)
HW.LCDIF.CTRL.DATA_SELECT.clr()
end
STMP.debug(string.format("lcdif: count = %d", #data))
if STMP.is_imx233() then
HW.LCDIF.CTRL.LCDIF_MASTER.clr()
end
HW.LCDIF.CTRL.RUN.clr()
HW.LCDIF.CTRL.COUNT.write(#data)
if STMP.is_stmp3600() or STMP.is_stmp3700() then
HW.LCDIF.CTRL.COUNT.write(#data)
else
HW.LCDIF.TRANSFER_COUNT.V_COUNT.write(1)
HW.LCDIF.TRANSFER_COUNT.H_COUNT.write(#data)
end
HW.LCDIF.CTRL.RUN.set()
local i = 1
while i <= #data do
@ -97,4 +138,5 @@ function STMP.lcdif.send_pio(data_mode, data)
while STMP.lcdif.is_busy() do STMP.debug("lcdif: fifo full") end
HW.LCDIF.DATA.write(v)
end
STMP.lcdif.wait_ready()
end

View file

@ -94,5 +94,26 @@ end
function ZENMOZAIC.init()
ZENMOZAIC.lcd_init()
HW.LRADC.CTRL0.SFTRST.clr()
HW.LRADC.CTRL0.CLKGATE.clr()
HW.LRADC.CHn[0].ACCUMULATE.clr()
HW.LRADC.CHn[0].NUM_SAMPLES.write(0)
HW.LRADC.CHn[0].VALUE.write(0)
local t = {}
for i = 1,1000,1 do
HW.LRADC.CTRL0.SCHEDULE.write(1)
--local time = HW.DIGCTL.MICROSECONDS.read()
local time = i * 1000
local val = HW.LRADC.CHn[0].VALUE.read()
t[#t + 1] = {time, val}
end
local file = io.open("data.txt", "w")
for i,v in ipairs(t) do
file:write(string.format("%d %d\n", v[1] / 1000, v[2]))
end
file:close()
print("Display curve using:")
print("gnuplot -persist");
print("> plot \"data.txt\" using 1:2")
end