Skip to content

Paged i2c accessor - #64

Open
FoamyGuy wants to merge 2 commits into
adafruit:mainfrom
FoamyGuy:paged_i2c_accessor
Open

Paged i2c accessor#64
FoamyGuy wants to merge 2 commits into
adafruit:mainfrom
FoamyGuy:paged_i2c_accessor

Conversation

@FoamyGuy

Copy link
Copy Markdown
Contributor

Paged I2C accessor that supports chips like CS42L42 which use a page register to be able to re-use the same smaller address space across different pages.

@tannewt

tannewt commented Aug 20, 2026

Copy link
Copy Markdown
Member

Are there other chips that need this? Could it live with the CS42L42 for now until it is needed elsewhere?

@FoamyGuy

Copy link
Copy Markdown
Contributor Author

There are other chips that use the same paging mechanism. TLV320AIC3xxx, LSM6DSO/DSOX/DSV, LSM6DSR, LIS2DUX, other Cirrus codecs, even BNO055 which we have a driver for but it doesn't use adafruit_register.

So it is used more broadly, but I wouldn't say it's strictly needed anywhere else at this time. Can move it into the CS42L42 driver for now.

@FoamyGuy FoamyGuy closed this Aug 20, 2026
@tannewt

tannewt commented Aug 21, 2026

Copy link
Copy Markdown
Member

How do those other drivers do it? Should we refactor them all?

@FoamyGuy

Copy link
Copy Markdown
Contributor Author

@tannewt I think the only with an Adafruit driver is the BNO055. It doesn't use adafruit_register. It has it's on _write_register() function which it just calls "manually" to write the page ID before other transactions, like here: https://github.com/adafruit/Adafruit_CircuitPython_BNO055/blob/33fec1851ce0fd660e210a024365461b11ec0bf0/adafruit_bno055.py#L510. I do prefer the adafruit_register style drivers, so I'd be in favor of this getting refactored to use adafruit_register, and if that were to happen it would need some solution for the paged access.

The TLV320AIC3204 has a community bundle driver. That one uses adafruit_register with PagedRWBit/Bits classes that are in the driver itself https://github.com/relic-se/CircuitPython_TLV320AIC3204/blob/accbf7ae8f8a649aeb7dce07d62a1a291ef23e89/relic_tlv320aic3204.py#L398-L443

@tannewt tannewt reopened this Aug 24, 2026
@tannewt

tannewt commented Aug 24, 2026

Copy link
Copy Markdown
Member

Ok, I've reopened this so drivers can be migrated to it.

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion to make a new file for it. Otherwise it'll be good. I like packing the page number into the register address.

i2c.write(self._full_buffer, end=self.address_width + len(buffer))


class PagedI2CRegisterAccessor(I2CRegisterAccessor):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in a new file so it is imported separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants