tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/lis2mdl/lis2mdl_test.go (about) 1 package lis2mdl 2 3 import ( 4 "testing" 5 6 qt "github.com/frankban/quicktest" 7 "tinygo.org/x/drivers/tester" 8 ) 9 10 func TestDefaultI2CAddress(t *testing.T) { 11 c := qt.New(t) 12 bus := tester.NewI2CBus(c) 13 dev := New(bus) 14 c.Assert(dev.Address, qt.Equals, uint8(ADDRESS)) 15 } 16 17 func TestWhoAmI(t *testing.T) { 18 c := qt.New(t) 19 bus := tester.NewI2CBus(c) 20 fake := tester.NewI2CDevice(c, ADDRESS) 21 copy(fake.Registers[:], defaultRegisters()) 22 bus.AddDevice(fake) 23 24 dev := New(bus) 25 c.Assert(dev.Connected(), qt.Equals, true) 26 27 fake.Registers[WHO_AM_I] = 0x99 28 c.Assert(dev.Connected(), qt.Equals, false) 29 } 30 31 // defaultRegisters returns the default values for all of the device's registers. 32 // see table 22 on page 27 of the datasheet. 33 func defaultRegisters() []uint8 { 34 return []uint8{ 35 OFFSET_X_REG_L: 0, 36 OFFSET_X_REG_H: 0, 37 OFFSET_Y_REG_L: 0, 38 OFFSET_Y_REG_H: 0, 39 OFFSET_Z_REG_L: 0, 40 OFFSET_Z_REG_H: 0, 41 WHO_AM_I: 0x40, 42 CFG_REG_A: 0x03, 43 CFG_REG_B: 0, 44 CFG_REG_C: 0, 45 INT_CRTL_REG: 0xE0, 46 INT_SOURCE_REG: 0, 47 INT_THS_L_REG: 0, 48 INT_THS_H_REG: 0, 49 STATUS_REG: 0, 50 OUTX_L_REG: 0, 51 OUTX_H_REG: 0, 52 OUTY_L_REG: 0, 53 OUTY_H_REG: 0, 54 OUTZ_L_REG: 0, 55 OUTZ_H_REG: 0, 56 TEMP_OUT_L_REG: 0, 57 TEMP_OUT_H_REG: 0, 58 } 59 }