tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/tester/device16_test.go (about) 1 package tester 2 3 import ( 4 "testing" 5 6 qt "github.com/frankban/quicktest" 7 ) 8 9 func TestCreate16(t *testing.T) { 10 c := qt.New(t) 11 bus := NewI2CBus(c) 12 d := NewI2CDevice16(c, 8) 13 bus.AddDevice(d) 14 } 15 16 func TestRead16(t *testing.T) { 17 c := qt.New(t) 18 bus := NewI2CBus(c) 19 d := NewI2CDevice16(c, 8) 20 bus.AddDevice(d) 21 22 // Setup a random register 23 d.Registers[3] = 0x1234 24 25 buf := []byte{0, 0} 26 err := bus.ReadRegister(8, 3, buf) 27 c.Assert(err, qt.IsNil) 28 c.Assert(buf[0], qt.Equals, byte(0x12)) 29 c.Assert(buf[1], qt.Equals, byte(0x34)) 30 } 31 32 func TestWrite16(t *testing.T) { 33 c := qt.New(t) 34 bus := NewI2CBus(c) 35 d := NewI2CDevice16(c, 8) 36 bus.AddDevice(d) 37 38 d.Registers[9] = 0x0 39 err := bus.WriteRegister(8, 9, []byte{0xbe, 0xad}) 40 c.Assert(err, qt.IsNil) 41 c.Assert(d.Registers[9], qt.Equals, uint16(0xbead)) 42 }