1
0
Fork 0
forked from len0rd/rockbox
foxbox/utils/hwstub/tools/lua/jz/gpio.lua
Amaury Pouly 4fd9400458 hwstub/tools/shell: add JZ4760B and Fiio X1 code
The jz code can do several useful things like dumping the IPL and SPL.
The Fiio code can play with backlight and has code do dump the IPL
and SPL with the correct parameters (extracted by reverse engineering).

Change-Id: I317b3174f5db8d38c9a56670c1d45565142ec208
2017-01-24 15:17:46 +01:00

82 lines
No EOL
1.7 KiB
Lua

---
--- GPIO
---
JZ.gpio = {}
function JZ.gpio.pinmask(bank, mask)
local t = {}
t.read = function()
return bit32.band(HW.GPIO.IN[bank].read(), mask)
end
t.write = function(val)
if val then t.set() else t.clr() end
end
t.set = function()
HW.GPIO.OUT[bank].SET.write(mask)
end
t.clr = function()
HW.GPIO.OUT[bank].CLR.write(mask)
end
t.gpio = function()
HW.GPIO.FUN[bank].CLR.write(mask)
HW.GPIO.SEL[bank].CLR.write(mask)
end
t.dir = function(out)
if out then
HW.GPIO.DIR[bank].SET.write(mask)
else
HW.GPIO.DIR[bank].CLR.write(mask)
end
end
t.pull = function(val)
if val then
HW.GPIO.PULL[bank].CLR.write(mask)
else
HW.GPIO.PULL[bank].SET.write(mask)
end
end
t.std_gpio_out = function(data)
t.gpio()
t.dir(true)
t.pull(false)
t.write(data)
end
t.gpio_in = function(data)
t.gpio()
t.dir(false)
end
t.std_function = function(fun_nr)
HW.GPIO.FUN[bank].SET.write(mask)
if fun_nr >= 2 then
HW.GPIO.TRG[bank].SET.write(mask)
fun_nr = fun_nr - 2
else
HW.GPIO.TRG[bank].CLR.write(mask)
end
if fun_nr >= 2 then
HW.GPIO.SEL[bank].SET.write(mask)
else
HW.GPIO.SEL[bank].CLR.write(mask)
end
end
return t
end
function JZ.gpio.pin(bank,pin)
local mask = bit32.lshift(1, pin)
local t = JZ.gpio.pinmask(bank,mask)
t.read = function()
return bit32.extract(HW.GPIO.IN[bank].read(), pin)
end
return t
end