-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/add no addr reads #22
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,19 +117,29 @@ def __setattr__(self, name, value): | |
|
||
# read commands ---------------------------------------------------------- | ||
def readWord(self, address, commandCode): | ||
buffer = self._i2cbus.readfrom_mem(address, commandCode, 2) | ||
if (commandCode == None): | ||
buffer = self._i2cbus.readfrom(address, 2) | ||
else: | ||
buffer = self._i2cbus.readfrom_mem(address, commandCode, 2) | ||
|
||
return (buffer[1] << 8 ) | buffer[0] | ||
|
||
def read_word(self, address, commandCode): | ||
return self.readWord(address, commandCode) | ||
|
||
def readByte(self, address, commandCode): | ||
def readByte(self, address, commandCode = None): | ||
if (commandCode == None): | ||
return self._i2cbus.readfrom(address, 1)[0] | ||
|
||
return self._i2cbus.readfrom_mem(address, commandCode, 1)[0] | ||
|
||
def read_byte(self, address, commandCode = None): | ||
return self.readByte(address, commandCode) | ||
|
||
def readBlock(self, address, commandCode, nBytes): | ||
if (commandCode == None): | ||
return self._i2cbus.readfrom(address, nBytes) | ||
|
||
return self._i2cbus.readfrom_mem(address, commandCode, nBytes) | ||
|
||
def read_block(self, address, commandCode, nBytes): | ||
|
@@ -182,3 +192,24 @@ def ping(self, devAddress): | |
def scan(self): | ||
""" Returns a list of addresses for the devices connected to the I2C bus.""" | ||
return self._i2cbus.scan() | ||
|
||
#----------------------------------------------------------------------- | ||
# Custom method for reading +8-bit register using `i2c_msg` from `smbus2` | ||
# | ||
# Designed to have same operation as the __i2c_rdwr method in linux_i2c.py | ||
def __i2c_rdwr__(self, address, write_message, read_nbytes): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method should be changed. I know this is what was used elsewhere, but it's not a great name. Should match the conventions of the other methods in this driver, and get added to i2c_driver.py and linux_i2c.py. Then any device drivers that use it (I think just the VL53?) should be changed to use this new method. Does that make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The naming convention was based off the original
When we added this method, I included the double underscores ( Note Starting with v0.2, the smbus2 library also has support for combined read and write transactions.
Each operation is represented by a As a recommendation... I'd keep the
|
||
""" | ||
Custom method used for 16-bit (or greater) register reads | ||
:param address: 7-bit address | ||
:param write_message: list with register(s) to read | ||
:param read_nbytes: number of bytes to be read | ||
|
||
:return: response of read transaction | ||
:rtype: list | ||
""" | ||
|
||
# micropython I2C doesn't have a corresponding "i2c_rdwr" function like smbus2, so we will make our own by passing stop=False to not send stop bits between repeated transfers | ||
self._i2cbus.writeto(address, bytes(write_message), False) | ||
return self._i2cbus.readfrom(address, read_nbytes) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work in CircuitPython