From 6b5ed89f2db1434da57cdd65f98e5bc014ce8039 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Fri, 10 Apr 2020 19:44:31 -0700 Subject: [PATCH] cirPy's i2c read/write funcs already handle address's read/write flags --- circuitpython_cirque_pinnacle/glidepoint.py | 7 ++----- circuitpython_cirque_pinnacle/glidepoint_lite.py | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/circuitpython_cirque_pinnacle/glidepoint.py b/circuitpython_cirque_pinnacle/glidepoint.py index 902b1ba..76c79fb 100644 --- a/circuitpython_cirque_pinnacle/glidepoint.py +++ b/circuitpython_cirque_pinnacle/glidepoint.py @@ -376,23 +376,21 @@ def _era_write_bytes(self, reg, value, numb_bytes): self.clear_flags() self.feed_enable = prev_feed_state # resume previous feed state -# pylint: disable=no-member,too-few-public-methods +# pylint: disable=no-member class PinnacleTouchI2C(PinnacleTouch): """Parent class for interfacing with the Pinnacle ASIC via the I2C protocol.""" def __init__(self, i2c, address=0x2A, dr_pin=None): - self._i2c = I2CDevice(i2c, (address << 1)) # per datasheet + self._i2c = I2CDevice(i2c, address) super(PinnacleTouchI2C, self).__init__(dr_pin=dr_pin) def _rap_read(self, reg): return self._rap_read_bytes(reg) def _rap_read_bytes(self, reg, numb_bytes=1): - self._i2c.device_address &= 0xFE # set write flag buf = bytearray([reg | 0xA0]) # per datasheet with self._i2c as i2c: i2c.write(buf) # includes a STOP condition - self._i2c.device_address |= 1 # set read flag buf = bytearray(numb_bytes) # for accumulating response(s) with self._i2c as i2c: # auto-increments register for each byte read @@ -403,7 +401,6 @@ def _rap_write(self, reg, value): self._rap_write_bytes(reg, [value]) def _rap_write_bytes(self, reg, values): - self._i2c.device_address &= 0xFE # set write flag buf = b'' for index, byte in enumerate(values): # for bytearrays/lists/tuples # Pinnacle doesn't auto-increment register addresses for diff --git a/circuitpython_cirque_pinnacle/glidepoint_lite.py b/circuitpython_cirque_pinnacle/glidepoint_lite.py index 1f89c66..a7251ae 100644 --- a/circuitpython_cirque_pinnacle/glidepoint_lite.py +++ b/circuitpython_cirque_pinnacle/glidepoint_lite.py @@ -177,18 +177,16 @@ def _era_write(self, reg, value): # pylint: disable=no-member class PinnacleTouchI2C(PinnacleTouch): def __init__(self, i2c, address=0x2A, dr_pin=None): - self._i2c = I2CDevice(i2c, (address << 1)) + self._i2c = I2CDevice(i2c, address) super(PinnacleTouchI2C, self).__init__(dr_pin=dr_pin) def _rap_read(self, reg): return self._rap_read_bytes(reg) def _rap_read_bytes(self, reg, numb_bytes=1): - self._i2c.device_address &= 0xFE buf = bytearray([reg | 0xA0]) with self._i2c as i2c: i2c.write(buf) - self._i2c.device_address |= 1 buf = bytearray(numb_bytes) with self._i2c as i2c: i2c.readinto(buf) @@ -198,7 +196,6 @@ def _rap_write(self, reg, value): self._rap_write_bytes(reg, [value]) def _rap_write_bytes(self, reg, values): - self._i2c.device_address &= 0xFE buf = b'' for index, byte in enumerate(values): buf += bytearray([(reg + index) | 0x80, byte & 0xFF])