Skip to content

Conversation

@soypat
Copy link
Contributor

@soypat soypat commented Nov 9, 2025

Adds Device8Txer to the regmap package, providing transaction-based register access for I2C and SPI devices using pre-allocated buffers. This enables heapless multi-byte register writes by reusing fixed buffers across transactions, eliminating heap allocations during bus operations. The Device8Txer wraps Device8 and manages write/read buffer state through a transaction API:

  • Tx() initiates a transaction with a register address
  • AddWriteByte()/AddWriteData() stage bytes into the write buffer
  • DoTxI2C()/DoTxSPI() execute the transaction over the respective bus
// Initialization.
var dtx Device8Txer
dtx.SetTxBuffers(make([]byte, 256), make([]byte, 256))

// Usage.
const (
	defaultAddr = 65
	REG_WRITE   = 0x1f
	IOCTL_CALL  = 0xc0
)
tx, err := dtx.Tx(REG_WRITE)
if err != nil {
	panic(err)
}
err = tx.AddWriteData(IOCTL_CALL, 0x80, 0x80)
if err != nil {
	panic(err)
}
var bus drivers.I2C
readData, err := tx.DoTxI2C(bus, defaultAddr, 20)
if err != nil {
	panic(err)
}
fmt.Println(readData)

@soypat soypat changed the base branch from release to dev November 9, 2025 15:22
@soypat soypat changed the title Regmap tx Regmap Tx8 - heapless buffer writing for SPI and I2C Nov 9, 2025
@soypat
Copy link
Contributor Author

soypat commented Nov 10, 2025

@ysoldak @deadprogram check this out! Saw the pains in latest si5351 driver and came up with this!

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