diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-09-12 15:45:45 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-09-17 09:50:41 +0200 |
commit | de6d3aeec9a590c4eb53a953c8758f183ffeba1e (patch) | |
tree | 89c4df0d7bcfdcd157d80a5b759037b7db052ef8 /scripts/remote/controller.py | |
parent | 2d2daa3c65a08c201cbbbad772a93b1855709eb3 (diff) | |
download | barebox-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/controller.py')
-rw-r--r-- | scripts/remote/controller.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/scripts/remote/controller.py b/scripts/remote/controller.py index 1a83909042..10037b8903 100644 --- a/scripts/remote/controller.py +++ b/scripts/remote/controller.py @@ -61,6 +61,18 @@ def unpack(data): elif p_type == BBType.reset: logging.debug("received: reset") return BBPacketReset(raw=data) + elif p_type == BBType.i2c_read: + logging.debug("received: i2c_read") + return BBPacketI2cRead(raw=data) + elif p_type == BBType.i2c_read_return: + logging.debug("received: i2c_read_return") + return BBPacketI2cReadReturn(raw=data) + elif p_type == BBType.i2c_write: + logging.debug("received: i2c_write") + return BBPacketI2cWrite(raw=data) + elif p_type == BBType.i2c_write_return: + logging.debug("received: i2c_write_return") + return BBPacketI2cWriteReturn(raw=data) else: logging.debug("received: UNKNOWN") return BBPacket(raw=data) @@ -139,6 +151,18 @@ class Controller(Thread): logging.info("Mw return: %r", r) return (r.exit_code,r.written) + def i2c_read(self, bus, addr, reg, flags, size): + self._send(BBPacketI2cRead(bus=bus, addr=addr, reg=reg, flags=flags, size=size)) + r = self._expect(BBPacketI2cReadReturn) + logging.info("i2c read return: %r", r) + return (r.exit_code,r.data) + + def i2c_write(self, bus, addr, reg, flags, data): + self._send(BBPacketI2cWrite(bus=bus, addr=addr, reg=reg, flags=flags, data=data)) + r = self._expect(BBPacketI2cWriteReturn) + logging.info("i2c write return: %r", r) + return (r.exit_code,r.written) + def reset(self, force): self._send(BBPacketReset(force=force)) |