summaryrefslogtreecommitdiff
path: root/utils/hwstub/tools/lua/i2c_scan.lua
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-12-06 01:56:04 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2013-12-06 01:56:04 +0100
commit58bb4b9b4cc7d0e5eee9d2c5b0cb16237d889e4c (patch)
treedc0df1f9c812f484159e440cd93ec6ae6074a270 /utils/hwstub/tools/lua/i2c_scan.lua
parentc945fb6e94252faa9c6cdf5a5e73a60ededda8a8 (diff)
downloadrockbox-58bb4b9b4cc7d0e5eee9d2c5b0cb16237d889e4c.tar.gz
rockbox-58bb4b9b4cc7d0e5eee9d2c5b0cb16237d889e4c.zip
hwstub: implement i2c and i2c eeprom dump
Change-Id: Iff1b4f40affb88c104e7322e25cdbe34f8886476
Diffstat (limited to 'utils/hwstub/tools/lua/i2c_scan.lua')
-rw-r--r--utils/hwstub/tools/lua/i2c_scan.lua39
1 files changed, 38 insertions, 1 deletions
diff --git a/utils/hwstub/tools/lua/i2c_scan.lua b/utils/hwstub/tools/lua/i2c_scan.lua
index def7b5d84c..55066b0bf2 100644
--- a/utils/hwstub/tools/lua/i2c_scan.lua
+++ b/utils/hwstub/tools/lua/i2c_scan.lua
@@ -8,4 +8,41 @@ function I2CSCAN.scan()
8 print(string.format("%#x OK", i)) 8 print(string.format("%#x OK", i))
9 end 9 end
10 end 10 end
11 end \ No newline at end of file 11end
12
13-- if file is nil, return array
14-- if size is nil, dump the whole EEPROM
15function I2CSCAN.dump_rom(file, size)
16 STMP.i2c.init()
17 STMP.i2c.set_speed(true)
18 if not STMP.i2c.transmit(0xa0, {0, 0}, false) then
19 error("Cannot send address")
20 end
21 local res = {}
22 if size == nil then
23 size = 0xffff
24 end
25 for i = 0, size do
26 local l = STMP.i2c.receive(0xa0, 1)
27 if l == nil then
28 error("error during transfer")
29 end
30 for i = 1, #l do
31 table.insert(res, l[i])
32 end
33 end
34 if file == nil then
35 return res
36 end
37 local f = file
38 if type(file) == "string" then
39 f = io.open(file, "w")
40 end
41 if f == nil then error("Cannot open file or write to nil") end
42 for i = 1, #res do
43 f:write(string.char(res[i]))
44 end
45 if type(file) == "string" then
46 io.close(f)
47 end
48end \ No newline at end of file