-
Notifications
You must be signed in to change notification settings - Fork 25
register accessor layer and SPI support #59
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dc6d647
register accessor layer and SPI support
FoamyGuy 4532b05
repo and version meta vars
FoamyGuy 77983d4
I2C accessor implementation, repo and version meta vars
FoamyGuy a5e9569
Merge remote-tracking branch 'foamyguy/accessor_layer' into accessor_…
FoamyGuy 9bdc1f8
docstrings. implement bool vs int logic in i2c write
FoamyGuy 5196696
move read current value out of accessor into Bit(s). Support multibyt…
FoamyGuy c850754
pass address to read/write Accessor functions. Fix start/end indexes …
FoamyGuy 5039f29
SPI start/end fix for multibyte address. big endian multibyte address…
FoamyGuy b42f50e
split address and data buffers. Address buffer inside Accessor, data …
FoamyGuy 262e989
only use full_buffer for i2c.write(). Split SPI write into two instea…
FoamyGuy f4861a7
add protocol details to both Accessor docstrings. Remove buffer lengt…
FoamyGuy 4b553b4
add i2c comms details
FoamyGuy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add protocol details to both Accessor docstrings. Remove buffer lengt…
…h comment. use slices instead loop. set end for i2c.write().
- Loading branch information
commit f4861a758a638b125a1312fa2577e7805c399326
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,10 @@ def _pack_address_into_buffer(self, address): | |
| class SPIRegisterAccessor(RegisterAccessor): | ||
| """ | ||
| RegisterAccessor class for SPI bus transport. Provides interface to read/write | ||
| registers over SPI. | ||
| registers over SPI. This class automatically handles the R/W bit by setting the | ||
| highest bit of the address to 1 when reading and 0 when writing. For multi-byte | ||
| addresses the R/W bit will be set as the highest bit in the first byte of the | ||
| address. | ||
|
|
||
| :param SPIDevice spi_device: The SPI bus device to communicate over. | ||
| :param int address_width: The number of bytes in the address | ||
|
|
@@ -80,7 +83,6 @@ def read_register(self, address: int, buffer: bytearray): | |
|
|
||
| :param int address: The register address to read. | ||
| :param bytearray buffer: Buffer that will be used to read register data into. | ||
| Buffer must be long enough to be read all data sent by the device. | ||
| :return: None | ||
| """ | ||
|
|
||
|
|
@@ -112,7 +114,9 @@ def write_register( | |
| class I2CRegisterAccessor(RegisterAccessor): | ||
| """ | ||
| RegisterAccessor class for I2C bus transport. Provides interface to read/write | ||
| registers over I2C | ||
| registers over I2C. This class uses `adafruit_bus_device.I2CDevice` for | ||
| communication. I2CDevice automatically handles the R/W bit by setting | ||
| the lowest bit of the device address to 1 for reading and 0 for writing. | ||
|
|
||
|
Member
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. Same here, explain the protocol over I2C that this supports.
Member
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. Also talk about the relationship between address and data. |
||
| :param I2CDevice i2c_device: I2C device to communicate over | ||
| :param int address_width: The number of bytes in the address | ||
|
|
@@ -131,7 +135,6 @@ def read_register(self, address: int, buffer: bytearray): | |
|
|
||
| :param int address: The register address to read. | ||
| :param bytearray buffer: Buffer that will be used to read register data into. | ||
| Buffer must be long enough to be read all data sent by the device. | ||
| :return: None | ||
| """ | ||
|
|
||
|
|
@@ -145,7 +148,6 @@ def write_register(self, address: int, buffer: bytearray): | |
|
|
||
| :param int address: The register address to read. | ||
| :param bytearray buffer: Buffer of data that will be written to the register. | ||
|
|
||
| :return: None | ||
| """ | ||
| # grow full buffer if needed | ||
|
|
@@ -154,12 +156,10 @@ def write_register(self, address: int, buffer: bytearray): | |
|
|
||
| # put address into full buffer | ||
| self._pack_address_into_buffer(address) | ||
| for i in range(self.address_width): | ||
| self._full_buffer[i] = self.address_buffer[i] | ||
| self._full_buffer[: self.address_width] = self.address_buffer | ||
|
|
||
| # put data into full buffer | ||
| for i, b in enumerate(buffer): | ||
| self._full_buffer[i + self.address_width] = b | ||
| self._full_buffer[self.address_width : self.address_width + len(buffer)] = buffer | ||
|
|
||
| with self.i2c_device as i2c: | ||
| i2c.write(self._full_buffer) | ||
| i2c.write(self._full_buffer, end=self.address_width + len(buffer)) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.