Closed
Conversation
tannewt
requested changes
Sep 12, 2025
Member
tannewt
left a comment
There was a problem hiding this comment.
I'd prefer to make Register more flexible than make this driver more complicated.
What I'm picturing is one BMP5XX class that takes an I2CDevice or a SPIDevice and adapts internally to the transport. I think it'll need to create a "RegisterAccessor" or something that reads and writes registers and then the data descriptors will not be from i2c_ and instead look for a register_accessor on the given obj. This new accessor layer will allow the register fields to focus on packing and unpacking instead of the transport itself.
(Data descriptor reference: https://docs.python.org/3/howto/descriptor.html)
Contributor
Author
|
Closing this PR, I started a new branch for the refactored version |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change proposes a version of the driver that supports both I2C and SPI for communication. @tannewt I'm interested to get feedback from you on this refactor when you have time.
This code goes along with the changes in: adafruit/Adafruit_CircuitPython_Register_SPI#8 it will not work without those.
The main API change with this as compared to a "plain" I2C driver using adafruit_register is having a function that creates the class using dynamic arguments for RWBits, ROBits etc... classes instead of using a class constructor to make an instance.
This means that user code must call the create function like this:
instead of using a class constructor like this:
But the resulting object returned is essentially the same, an instance of BMP5XX that is ready to take readings by accessing properties like
bmp.temperatureetc. And happily it allows us to have unified definitions for the descriptors that don't get duplicated and work with either type of bus.I tested this version successfully with both the SPI and I2C example scripts using different breakouts connected to each bus. On this device: