Skip to content

Commit 31538f1

Browse files
soypatdeadprogram
authored andcommitted
fix requested changes by @aykevl
1 parent 6402961 commit 31538f1

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

i2c.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ package drivers
33
// I2C represents an I2C bus. It is notably implemented by the
44
// machine.I2C type.
55
type I2C interface {
6-
// ReadRegister(addr uint8, r uint8, buf []byte) error
7-
// WriteRegister(addr uint8, r uint8, buf []byte) error
6+
// Tx performs a [I²C] transaction with address addr.
7+
// Most I2C peripherals have some sort of register mapping scheme to allow
8+
// users to interact with them:
9+
//
10+
// bus.Tx(addr, []byte{reg}, buf) // Reads register reg into buf.
11+
// bus.Tx(addr, append([]byte{reg}, buf...), nil) // Writes buf into register reg.
12+
//
13+
// The semantics of most I2C transactions require that the w write buffer be non-empty.
14+
//
15+
// [I²C]: https://en.wikipedia.org/wiki/I%C2%B2C
816
Tx(addr uint16, w, r []byte) error
917
}

tester/device.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const MaxRegisters = 255
55

66
type I2CDevice interface {
77
// ReadRegister implements I2C.ReadRegister.
8-
ReadRegister(r uint8, buf []byte) error
8+
readRegister(r uint8, buf []byte) error
99

1010
// WriteRegister implements I2C.WriteRegister.
11-
WriteRegister(r uint8, buf []byte) error
11+
writeRegister(r uint8, buf []byte) error
1212

1313
// Tx implements I2C.Tx
1414
Tx(w, r []byte) error

tester/device16.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (d *I2CDevice16) Addr() uint8 {
3333
}
3434

3535
// ReadRegister implements I2C.ReadRegister.
36-
func (d *I2CDevice16) ReadRegister(r uint8, buf []byte) error {
36+
func (d *I2CDevice16) readRegister(r uint8, buf []byte) error {
3737
if d.Err != nil {
3838
return d.Err
3939
}
@@ -54,7 +54,7 @@ func (d *I2CDevice16) ReadRegister(r uint8, buf []byte) error {
5454
}
5555

5656
// WriteRegister implements I2C.WriteRegister.
57-
func (d *I2CDevice16) WriteRegister(r uint8, buf []byte) error {
57+
func (d *I2CDevice16) writeRegister(r uint8, buf []byte) error {
5858
if d.Err != nil {
5959
return d.Err
6060
}
@@ -80,11 +80,11 @@ func (bus *I2CDevice16) Tx(w, r []byte) error {
8080
bus.c.Fatalf("i2c mock: need a write byte")
8181
return nil
8282
case 1:
83-
return bus.ReadRegister(w[0], r)
83+
return bus.readRegister(w[0], r)
8484
default:
8585
if len(r) > 0 || len(w) == 1 {
8686
bus.c.Fatalf("i2c mock: unsupported lengths in Tx(%d, %d)", len(w), len(r))
8787
}
88-
return bus.WriteRegister(w[0], w[1:])
88+
return bus.writeRegister(w[0], w[1:])
8989
}
9090
}

tester/device8.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (d *I2CDevice8) Addr() uint8 {
3434
}
3535

3636
// ReadRegister implements I2C.ReadRegister.
37-
func (d *I2CDevice8) ReadRegister(r uint8, buf []byte) error {
37+
func (d *I2CDevice8) readRegister(r uint8, buf []byte) error {
3838
if d.Err != nil {
3939
return d.Err
4040
}
@@ -47,7 +47,7 @@ func (d *I2CDevice8) ReadRegister(r uint8, buf []byte) error {
4747
}
4848

4949
// WriteRegister implements I2C.WriteRegister.
50-
func (d *I2CDevice8) WriteRegister(r uint8, buf []byte) error {
50+
func (d *I2CDevice8) writeRegister(r uint8, buf []byte) error {
5151
if d.Err != nil {
5252
return d.Err
5353
}
@@ -63,12 +63,12 @@ func (bus *I2CDevice8) Tx(w, r []byte) error {
6363
bus.c.Fatalf("i2c mock: need a write byte")
6464
return nil
6565
case 1:
66-
return bus.ReadRegister(w[0], r)
66+
return bus.readRegister(w[0], r)
6767
default:
6868
if len(r) > 0 || len(w) == 1 {
6969
bus.c.Fatalf("i2c mock: unsupported lengths in Tx(%d, %d)", len(w), len(r))
7070
}
71-
return bus.WriteRegister(w[0], w[1:])
71+
return bus.writeRegister(w[0], w[1:])
7272
}
7373
}
7474

tester/devicecmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (d *I2CDeviceCmd) Addr() uint8 {
5050
}
5151

5252
// ReadRegister implements I2C.ReadRegister.
53-
func (d *I2CDeviceCmd) ReadRegister(r uint8, buf []byte) error {
53+
func (d *I2CDeviceCmd) readRegister(r uint8, buf []byte) error {
5454
if d.Err != nil {
5555
return d.Err
5656
}
@@ -59,7 +59,7 @@ func (d *I2CDeviceCmd) ReadRegister(r uint8, buf []byte) error {
5959
}
6060

6161
// WriteRegister implements I2C.WriteRegister.
62-
func (d *I2CDeviceCmd) WriteRegister(r uint8, buf []byte) error {
62+
func (d *I2CDeviceCmd) writeRegister(r uint8, buf []byte) error {
6363
if d.Err != nil {
6464
return d.Err
6565
}

tester/i2c.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ func (bus *I2CBus) NewDevice(addr uint8) *I2CDevice8 {
3838

3939
// ReadRegister implements I2C.ReadRegister.
4040
func (bus *I2CBus) ReadRegister(addr uint8, r uint8, buf []byte) error {
41-
return bus.FindDevice(addr).ReadRegister(r, buf)
41+
return bus.FindDevice(addr).readRegister(r, buf)
4242
}
4343

4444
// WriteRegister implements I2C.WriteRegister.
4545
func (bus *I2CBus) WriteRegister(addr uint8, r uint8, buf []byte) error {
46-
return bus.FindDevice(addr).WriteRegister(r, buf)
46+
return bus.FindDevice(addr).writeRegister(r, buf)
4747
}
4848

4949
// Tx implements I2C.Tx.

0 commit comments

Comments
 (0)