summaryrefslogtreecommitdiff
path: root/utils/hwstub/tools/lua/jz/gpio.lua
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-03-19 21:57:58 +0000
committerAmaury Pouly <amaury.pouly@gmail.com>2017-01-24 15:17:46 +0100
commit4fd9400458f131e61a18142105c2d2d3a082a057 (patch)
tree8c2802574edb52423d94a71e6caad6610dd90186 /utils/hwstub/tools/lua/jz/gpio.lua
parent0b6cbd8e49eaf664cd005c6bb63a3111a4f4c308 (diff)
downloadrockbox-4fd9400458f131e61a18142105c2d2d3a082a057.tar.gz
rockbox-4fd9400458f131e61a18142105c2d2d3a082a057.zip
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
Diffstat (limited to 'utils/hwstub/tools/lua/jz/gpio.lua')
-rw-r--r--utils/hwstub/tools/lua/jz/gpio.lua82
1 files changed, 82 insertions, 0 deletions
diff --git a/utils/hwstub/tools/lua/jz/gpio.lua b/utils/hwstub/tools/lua/jz/gpio.lua
new file mode 100644
index 0000000000..d85529f9bb
--- /dev/null
+++ b/utils/hwstub/tools/lua/jz/gpio.lua
@@ -0,0 +1,82 @@
1---
2--- GPIO
3---
4JZ.gpio = {}
5
6
7function JZ.gpio.pinmask(bank, mask)
8 local t = {}
9 t.read = function()
10 return bit32.band(HW.GPIO.IN[bank].read(), mask)
11 end
12
13 t.write = function(val)
14 if val then t.set() else t.clr() end
15 end
16
17 t.set = function()
18 HW.GPIO.OUT[bank].SET.write(mask)
19 end
20
21 t.clr = function()
22 HW.GPIO.OUT[bank].CLR.write(mask)
23 end
24
25 t.gpio = function()
26 HW.GPIO.FUN[bank].CLR.write(mask)
27 HW.GPIO.SEL[bank].CLR.write(mask)
28 end
29
30 t.dir = function(out)
31 if out then
32 HW.GPIO.DIR[bank].SET.write(mask)
33 else
34 HW.GPIO.DIR[bank].CLR.write(mask)
35 end
36 end
37
38 t.pull = function(val)
39 if val then
40 HW.GPIO.PULL[bank].CLR.write(mask)
41 else
42 HW.GPIO.PULL[bank].SET.write(mask)
43 end
44 end
45
46 t.std_gpio_out = function(data)
47 t.gpio()
48 t.dir(true)
49 t.pull(false)
50 t.write(data)
51 end
52
53 t.gpio_in = function(data)
54 t.gpio()
55 t.dir(false)
56 end
57
58 t.std_function = function(fun_nr)
59 HW.GPIO.FUN[bank].SET.write(mask)
60 if fun_nr >= 2 then
61 HW.GPIO.TRG[bank].SET.write(mask)
62 fun_nr = fun_nr - 2
63 else
64 HW.GPIO.TRG[bank].CLR.write(mask)
65 end
66 if fun_nr >= 2 then
67 HW.GPIO.SEL[bank].SET.write(mask)
68 else
69 HW.GPIO.SEL[bank].CLR.write(mask)
70 end
71 end
72 return t
73end
74
75function JZ.gpio.pin(bank,pin)
76 local mask = bit32.lshift(1, pin)
77 local t = JZ.gpio.pinmask(bank,mask)
78 t.read = function()
79 return bit32.extract(HW.GPIO.IN[bank].read(), pin)
80 end
81 return t
82end \ No newline at end of file