summaryrefslogtreecommitdiffstats
path: root/scripts/remote/main.py
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2018-09-12 15:45:45 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2018-09-17 09:50:41 +0200
commitde6d3aeec9a590c4eb53a953c8758f183ffeba1e (patch)
tree89c4df0d7bcfdcd157d80a5b759037b7db052ef8 /scripts/remote/main.py
parent2d2daa3c65a08c201cbbbad772a93b1855709eb3 (diff)
downloadbarebox-de6d3aeec9a590c4eb53a953c8758f183ffeba1e.tar.gz
barebox-de6d3aeec9a590c4eb53a953c8758f183ffeba1e.tar.xz
bbremote: implement i2c read/write support
Extend the bbremote script with operations to perform binary i2c read/write operations. E.g.: barebox:/ i2c_read -b 0 -a 0x68 -r 0x06A0 -c 4 -w 0x8f 0x30 0x00 0x00 barebox:/ i2c_write -b 0 -a 0x68 -r 0x06A0 -w 0x87 0x30 0x00 0x00 barebox:/ i2c_read -b 0 -a 0x68 -r 0x06A0 -c 4 -w 0x87 0x30 0x00 0x00 barebox:/ i2c_write -b 0 -a 0x68 -r 0x06A0 -w 0x8f 0x30 0x00 0x00 barebox:/ i2c_read -b 0 -a 0x68 -r 0x06A0 -c 4 -w 0x8f 0x30 0x00 0x00 =================================================================== $ ./scripts/bbremote --port /dev/ttyUSB2 i2c-read 0x00 0x68 0x06A0 0x01 4 8f300000 $ ./scripts/bbremote --port /dev/ttyUSB2 i2c-write 0x00 0x68 0x06A0 0x01 "87300000" 4 bytes written $ ./scripts/bbremote --port /dev/ttyUSB2 i2c-read 0x00 0x68 0x06A0 0x01 4 87300000 $ ./scripts/bbremote --port /dev/ttyUSB2 i2c-write 0x00 0x68 0x06A0 0x01 "8f300000" 4 bytes written $ ./scripts/bbremote --port /dev/ttyUSB2 i2c-read 0x00 0x68 0x06A0 0x01 4 8f300000 Signed-off-by: Aleksander Morgado <aleksander@aleksander.es> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts/remote/main.py')
-rw-r--r--scripts/remote/main.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/remote/main.py b/scripts/remote/main.py
index 38d280bfee..0f77839272 100644
--- a/scripts/remote/main.py
+++ b/scripts/remote/main.py
@@ -98,6 +98,27 @@ def handle_mw(args):
return res
+def handle_i2c_read(args):
+ ctrl = get_controller(args)
+ (res,data) = ctrl.i2c_read(args.bus, args.address, args.reg, args.flags, args.size)
+ if res == 0:
+ print(binascii.hexlify(data))
+ ctrl.close()
+ return res
+
+
+def handle_i2c_write(args):
+ ctrl = get_controller(args)
+ data=args.data
+ if ((len(data) % 2) != 0):
+ data="0"+data
+ (res,written) = ctrl.i2c_write(args.bus, args.address, args.reg, args.flags, binascii.unhexlify(data))
+ if res == 0:
+ print("%i bytes written" % written)
+ ctrl.close()
+ return res
+
+
def handle_reset(args):
ctrl = get_controller(args)
ctrl.reset(args.force)
@@ -188,6 +209,22 @@ parser_mw.add_argument('address', type=auto_int, help="address")
parser_mw.add_argument('data', help="data")
parser_mw.set_defaults(func=handle_mw)
+parser_i2c_read = subparsers.add_parser('i2c-read', help="run i2c read command")
+parser_i2c_read.add_argument('bus', type=auto_int, help="bus")
+parser_i2c_read.add_argument('address', type=auto_int, help="address")
+parser_i2c_read.add_argument('reg', type=auto_int, help="reg")
+parser_i2c_read.add_argument('flags', type=auto_int, help="flags")
+parser_i2c_read.add_argument('size', type=auto_int, help="size")
+parser_i2c_read.set_defaults(func=handle_i2c_read)
+
+parser_i2c_write = subparsers.add_parser('i2c-write', help="run i2c write command")
+parser_i2c_write.add_argument('bus', type=auto_int, help="bus")
+parser_i2c_write.add_argument('address', type=auto_int, help="address")
+parser_i2c_write.add_argument('reg', type=auto_int, help="reg")
+parser_i2c_write.add_argument('flags', type=auto_int, help="flags")
+parser_i2c_write.add_argument('data', help="data")
+parser_i2c_write.set_defaults(func=handle_i2c_write)
+
parser_reset = subparsers.add_parser('reset', help="run reset command")
parser_reset_force = parser_reset.add_mutually_exclusive_group(required=False)
parser_reset_force.add_argument('--force', dest='force', action='store_true')