machine: make machine.I2C0 and similar objects pointers

This makes it possible to assign I2C objects (machine.I2C0,
machine.I2C1, etc.) without needing to take a pointer.

This is important especially in the future when I2C may be driven using
DMA and the machine.I2C type needs to store some state.
This commit is contained in:
Ayke van Laethem
2021-02-06 12:37:15 +01:00
committed by Ron Evans
parent 71bbe93ab2
commit 90b42799a2
41 changed files with 129 additions and 136 deletions
+3 -3
View File
@@ -6,7 +6,7 @@ package machine
var (
SPI0 = SPI{0}
I2C0 = I2C{0}
I2C0 = &I2C{0}
UART0 = UART{0}
)
@@ -115,13 +115,13 @@ type I2CConfig struct {
}
// Configure is intended to setup the I2C interface.
func (i2c I2C) Configure(config I2CConfig) error {
func (i2c *I2C) Configure(config I2CConfig) error {
i2cConfigure(i2c.Bus, config.SCL, config.SDA)
return nil
}
// Tx does a single I2C transaction at the specified address.
func (i2c I2C) Tx(addr uint16, w, r []byte) error {
func (i2c *I2C) Tx(addr uint16, w, r []byte) error {
i2cTransfer(i2c.Bus, &w[0], len(w), &r[0], len(r))
// TODO: do something with the returned error code.
return nil