Skip to content

Commit

Permalink
cirPy's i2c read/write funcs already handle address's read/write flags
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Apr 11, 2020
1 parent 1a0dba3 commit 6b5ed89
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
7 changes: 2 additions & 5 deletions circuitpython_cirque_pinnacle/glidepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions circuitpython_cirque_pinnacle/glidepoint_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand Down

0 comments on commit 6b5ed89

Please sign in to comment.