-
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
Conversation
tannewt
left a comment
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.
Thanks for the draft PR. This is definitely the right direction.
…e addresses. add some type annotations.
…for multibyte address. Update docstrings.
… fix. Implement signed argument for RWBits
…buffer inside Bit(s) classes.
|
I found that the OV5640 camera module has I2C interface with 2 byte register addresses. I was able to successfully test the current version from this PR branch with this code. import board
import busio
import digitalio
from adafruit_bus_device.i2c_device import I2CDevice
from adafruit_register.register_accessor import I2CRegisterAccessor
from adafruit_register.register_bits import ROBits, RWBits
I2C_ADDRESS = 0x3C
REG_CHIP_ID_HIGH = 0x300A
class OV5640Tester():
chip_id = ROBits(16, REG_CHIP_ID_HIGH, 0, register_width=2, lsb_first=False)
def __init__(self, i2c):
try:
i2c_device = I2CDevice(i2c, I2C_ADDRESS)
self.register_accessor = I2CRegisterAccessor(i2c_device, address_width=2, lsb_first=False)
except ValueError:
raise ValueError(f"No I2C device found.")
if __name__ == '__main__':
print("construct bus")
i2c = busio.I2C(board.GP5, board.GP4)
print("construct camera")
reset = digitalio.DigitalInOut(board.GP14)
ov5640 = OV5640Tester(i2c)
print(hex(ov5640.chip_id)) |
…d of concat. Add multibyte address test.
|
Thank you. I got honed in on The latest commit removes the buffer concatenation and only uses I tested the latest version successfully with I2C & SPI on BMP5x & SPA06-003, and I2C / multi-byte address with OV5640. I submitted the latter as a new example to this repo as well. |
tannewt
left a comment
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.
Thanks for iterating on this! I'm glad multibyte is working too.
| """ | ||
| RegisterAccessor class for I2C bus transport. Provides interface to read/write | ||
| registers over I2C | ||
|
|
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.
Same here, explain the protocol over I2C that this supports.
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.
Also talk about the relationship between address and data.
…h comment. use slices instead loop. set end for i2c.write().
|
@tannewt All of those changes are made in the latest commit. |
tannewt
left a comment
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.
One more minor doc thing. Do you want to undraft this PR?
| """ | ||
| RegisterAccessor class for I2C bus transport. Provides interface to read/write | ||
| registers over I2C | ||
|
|
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.
Also talk about the relationship between address and data.
|
Added more detail about the order of the addresses and data in the latest commit, and I've marked this ready now. Thank you |
tannewt
left a comment
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.
Ok, this will work. Thanks!
Updating https://github.com/adafruit/Adafruit_CircuitPython_BNO08X to 1.3.0 from 1.2.10: > Merge pull request adafruit/Adafruit_CircuitPython_BNO08x#58 from RenMurakami/main Updating https://github.com/adafruit/Adafruit_CircuitPython_CST8XX to 1.1.0 from 1.0.5: > Merge pull request adafruit/Adafruit_CircuitPython_CST8XX#1 from arturo182/patch-1 Updating https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display to 3.14.2 from 3.14.1: > Merge pull request adafruit/Adafruit_CircuitPython_RGB_Display#134 from adafruit/tannewt-patch-1 Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_MIDI to 1.0.21 from 1.0.20: > Merge pull request adafruit/Adafruit_CircuitPython_BLE_MIDI#16 from spridget/patch-3 Updating https://github.com/adafruit/Adafruit_CircuitPython_Register to 1.11.0 from 1.10.4: > Merge pull request adafruit/Adafruit_CircuitPython_Register#59 from FoamyGuy/accessor_layer
Only SPI is implemented right now, I'll work on I2C next.
Adds new RegisterAccessor classes which RWBits and RWBit use so that they are agnostic to bus type.
I have successfully tested with a development version of the bmp5xx driver. I'll submit a PR over in that repo soon with the driver that relies on this new functionality.
Marking this draft until I2C is implemented, but wanted to get it opened now for any feedback.