For all IO, rename Write to W and Read to R

Fix Tx() for the Record objects (conntest, i2ctest, onewiretest and spitest) to
guard against write buffer corruption.
pull/1/head
Marc-Antoine Ruel 9 years ago
parent b61c90429c
commit 860d4aa457

@ -46,24 +46,24 @@ func TestSPISense_success(t *testing.T) {
Ops: []conntest.IO{ Ops: []conntest.IO{
// Chipd ID detection. // Chipd ID detection.
{ {
Write: []byte{0xD0, 0x00}, W: []byte{0xD0, 0x00},
Read: []byte{0x00, 0x60}, R: []byte{0x00, 0x60},
}, },
// Calibration data. // Calibration data.
{ {
Write: []byte{0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, W: []byte{0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
Read: []byte{0x00, 0xC9, 0x6C, 0x63, 0x65, 0x32, 0x00, 0x77, 0x93, 0x98, 0xD5, 0xD0, 0x0B, 0x67, 0x23, 0xBA, 0x00, 0xF9, 0xFF, 0xAC, 0x26, 0x0A, 0xD8, 0xBD, 0x10, 0x00, 0x4B}, R: []byte{0x00, 0xC9, 0x6C, 0x63, 0x65, 0x32, 0x00, 0x77, 0x93, 0x98, 0xD5, 0xD0, 0x0B, 0x67, 0x23, 0xBA, 0x00, 0xF9, 0xFF, 0xAC, 0x26, 0x0A, 0xD8, 0xBD, 0x10, 0x00, 0x4B},
}, },
// Calibration data. // Calibration data.
{ {
Write: []byte{0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, W: []byte{0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
Read: []byte{0x00, 0x5C, 0x01, 0x00, 0x15, 0x0F, 0x00, 0x1E}, R: []byte{0x00, 0x5C, 0x01, 0x00, 0x15, 0x0F, 0x00, 0x1E},
}, },
{Write: []byte{0x74, 0xB4, 0x72, 0x05, 0x75, 0xA0, 0x74, 0xB7}}, {W: []byte{0x74, 0xB4, 0x72, 0x05, 0x75, 0xA0, 0x74, 0xB7}},
// Read. // R.
{ {
Write: []byte{0xF7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, W: []byte{0xF7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
Read: []byte{0x00, 0x51, 0x9F, 0xC0, 0x9E, 0x3A, 0x50, 0x5E, 0x5B}, R: []byte{0x00, 0x51, 0x9F, 0xC0, 0x9E, 0x3A, 0x50, 0x5E, 0x5B},
}, },
}, },
}, },
@ -112,8 +112,8 @@ func TestNewSPI_fail_len(t *testing.T) {
Ops: []conntest.IO{ Ops: []conntest.IO{
{ {
// Chipd ID detection. // Chipd ID detection.
Write: []byte{0xD0, 0x00}, W: []byte{0xD0, 0x00},
Read: []byte{0x00}, R: []byte{0x00},
}, },
}, },
DontPanic: true, DontPanic: true,
@ -135,8 +135,8 @@ func TestNewSPI_fail_chipid(t *testing.T) {
Ops: []conntest.IO{ Ops: []conntest.IO{
{ {
// Chipd ID detection. // Chipd ID detection.
Write: []byte{0xD0, 0x00}, W: []byte{0xD0, 0x00},
Read: []byte{0x00, 0xFF}, R: []byte{0x00, 0xFF},
}, },
}, },
}, },
@ -153,7 +153,7 @@ func TestNewI2C_fail(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Chipd ID detection. // Chipd ID detection.
{Addr: 0x76, Write: []byte{0xd0}}, {Addr: 0x76, W: []byte{0xd0}},
}, },
DontPanic: true, DontPanic: true,
} }
@ -171,7 +171,7 @@ func TestNewI2C_chipid(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Chipd ID detection. // Chipd ID detection.
{Addr: 0x76, Write: []byte{0xd0}, Read: []byte{0x60}}, {Addr: 0x76, W: []byte{0xd0}, R: []byte{0x60}},
}, },
DontPanic: true, DontPanic: true,
} }
@ -187,12 +187,12 @@ func TestNewI2C_calib1(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Chipd ID detection. // Chipd ID detection.
{Addr: 0x76, Write: []byte{0xd0}, Read: []byte{0x60}}, {Addr: 0x76, W: []byte{0xd0}, R: []byte{0x60}},
// Calibration data. // Calibration data.
{ {
Addr: 0x76, Addr: 0x76,
Write: []byte{0x88}, W: []byte{0x88},
Read: []byte{0x10, 0x6e, 0x6c, 0x66, 0x32, 0x0, 0x5d, 0x95, 0xb8, 0xd5, 0xd0, 0xb, 0x77, 0x1e, 0x9d, 0xff, 0xf9, 0xff, 0xac, 0x26, 0xa, 0xd8, 0xbd, 0x10, 0x0, 0x4b}, R: []byte{0x10, 0x6e, 0x6c, 0x66, 0x32, 0x0, 0x5d, 0x95, 0xb8, 0xd5, 0xd0, 0xb, 0x77, 0x1e, 0x9d, 0xff, 0xf9, 0xff, 0xac, 0x26, 0xa, 0xd8, 0xbd, 0x10, 0x0, 0x4b},
}, },
}, },
DontPanic: true, DontPanic: true,
@ -210,15 +210,15 @@ func TestNewI2C_calib2(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Chipd ID detection. // Chipd ID detection.
{Addr: 0x76, Write: []byte{0xd0}, Read: []byte{0x60}}, {Addr: 0x76, W: []byte{0xd0}, R: []byte{0x60}},
// Calibration data. // Calibration data.
{ {
Addr: 0x76, Addr: 0x76,
Write: []byte{0x88}, W: []byte{0x88},
Read: []byte{0x10, 0x6e, 0x6c, 0x66, 0x32, 0x0, 0x5d, 0x95, 0xb8, 0xd5, 0xd0, 0xb, 0x77, 0x1e, 0x9d, 0xff, 0xf9, 0xff, 0xac, 0x26, 0xa, 0xd8, 0xbd, 0x10, 0x0, 0x4b}, R: []byte{0x10, 0x6e, 0x6c, 0x66, 0x32, 0x0, 0x5d, 0x95, 0xb8, 0xd5, 0xd0, 0xb, 0x77, 0x1e, 0x9d, 0xff, 0xf9, 0xff, 0xac, 0x26, 0xa, 0xd8, 0xbd, 0x10, 0x0, 0x4b},
}, },
// Calibration data. // Calibration data.
{Addr: 0x76, Write: []byte{0xe1}, Read: []byte{0x6e, 0x1, 0x0, 0x13, 0x5, 0x0, 0x1e}}, {Addr: 0x76, W: []byte{0xe1}, R: []byte{0x6e, 0x1, 0x0, 0x13, 0x5, 0x0, 0x1e}},
}, },
DontPanic: true, DontPanic: true,
} }
@ -257,19 +257,19 @@ func TestI2CSense_fail(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Chipd ID detection. // Chipd ID detection.
{Addr: 0x76, Write: []byte{0xd0}, Read: []byte{0x60}}, {Addr: 0x76, W: []byte{0xd0}, R: []byte{0x60}},
// Calibration data. // Calibration data.
{ {
Addr: 0x76, Addr: 0x76,
Write: []byte{0x88}, W: []byte{0x88},
Read: []byte{0x10, 0x6e, 0x6c, 0x66, 0x32, 0x0, 0x5d, 0x95, 0xb8, 0xd5, 0xd0, 0xb, 0x77, 0x1e, 0x9d, 0xff, 0xf9, 0xff, 0xac, 0x26, 0xa, 0xd8, 0xbd, 0x10, 0x0, 0x4b}, R: []byte{0x10, 0x6e, 0x6c, 0x66, 0x32, 0x0, 0x5d, 0x95, 0xb8, 0xd5, 0xd0, 0xb, 0x77, 0x1e, 0x9d, 0xff, 0xf9, 0xff, 0xac, 0x26, 0xa, 0xd8, 0xbd, 0x10, 0x0, 0x4b},
}, },
// Calibration data. // Calibration data.
{Addr: 0x76, Write: []byte{0xe1}, Read: []byte{0x6e, 0x1, 0x0, 0x13, 0x5, 0x0, 0x1e}}, {Addr: 0x76, W: []byte{0xe1}, R: []byte{0x6e, 0x1, 0x0, 0x13, 0x5, 0x0, 0x1e}},
// Configuration. // Configuration.
{Addr: 0x76, Write: []byte{0xf4, 0x6c, 0xf2, 0x3, 0xf5, 0xe0, 0xf4, 0x6f}, Read: nil}, {Addr: 0x76, W: []byte{0xf4, 0x6c, 0xf2, 0x3, 0xf5, 0xe0, 0xf4, 0x6f}, R: nil},
// Read. // Read.
{Addr: 0x76, Write: []byte{0xf7}}, {Addr: 0x76, W: []byte{0xf7}},
}, },
DontPanic: true, DontPanic: true,
} }
@ -292,21 +292,21 @@ func TestI2CSense_success(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Chipd ID detection. // Chipd ID detection.
{Addr: 0x76, Write: []byte{0xd0}, Read: []byte{0x60}}, {Addr: 0x76, W: []byte{0xd0}, R: []byte{0x60}},
// Calibration data. // Calibration data.
{ {
Addr: 0x76, Addr: 0x76,
Write: []byte{0x88}, W: []byte{0x88},
Read: []byte{0x10, 0x6e, 0x6c, 0x66, 0x32, 0x0, 0x5d, 0x95, 0xb8, 0xd5, 0xd0, 0xb, 0x77, 0x1e, 0x9d, 0xff, 0xf9, 0xff, 0xac, 0x26, 0xa, 0xd8, 0xbd, 0x10, 0x0, 0x4b}, R: []byte{0x10, 0x6e, 0x6c, 0x66, 0x32, 0x0, 0x5d, 0x95, 0xb8, 0xd5, 0xd0, 0xb, 0x77, 0x1e, 0x9d, 0xff, 0xf9, 0xff, 0xac, 0x26, 0xa, 0xd8, 0xbd, 0x10, 0x0, 0x4b},
}, },
// Calibration data. // Calibration data.
{Addr: 0x76, Write: []byte{0xe1}, Read: []byte{0x6e, 0x1, 0x0, 0x13, 0x5, 0x0, 0x1e}}, {Addr: 0x76, W: []byte{0xe1}, R: []byte{0x6e, 0x1, 0x0, 0x13, 0x5, 0x0, 0x1e}},
// Configuration. // Configuration.
{Addr: 0x76, Write: []byte{0xf4, 0x6c, 0xf2, 0x3, 0xf5, 0xe0, 0xf4, 0x6f}, Read: nil}, {Addr: 0x76, W: []byte{0xf4, 0x6c, 0xf2, 0x3, 0xf5, 0xe0, 0xf4, 0x6f}, R: nil},
// Read. // Read.
{Addr: 0x76, Write: []byte{0xf7}, Read: []byte{0x4a, 0x52, 0xc0, 0x80, 0x96, 0xc0, 0x7a, 0x76}}, {Addr: 0x76, W: []byte{0xf7}, R: []byte{0x4a, 0x52, 0xc0, 0x80, 0x96, 0xc0, 0x7a, 0x76}},
// Stop. // Stop.
{Addr: 0x76, Write: []byte{0xf4, 0x0}}, {Addr: 0x76, W: []byte{0xf4, 0x0}},
}, },
} }
dev, err := NewI2C(&bus, nil) dev, err := NewI2C(&bus, nil)

@ -75,15 +75,15 @@ func (s *SmokeTest) Run(args []string) (err error) {
fmt.Print("I²C recorder\n") fmt.Print("I²C recorder\n")
} }
for _, op := range i2cRecorder.Ops { for _, op := range i2cRecorder.Ops {
fmt.Print(" Write: ") fmt.Print(" W: ")
for i, b := range op.Write { for i, b := range op.W {
if i != 0 { if i != 0 {
fmt.Print(", ") fmt.Print(", ")
} }
fmt.Printf("0x%02X", b) fmt.Printf("0x%02X", b)
} }
fmt.Print("\n Read: ") fmt.Print("\n R: ")
for i, b := range op.Read { for i, b := range op.R {
if i != 0 { if i != 0 {
fmt.Print(", ") fmt.Print(", ")
} }
@ -93,12 +93,12 @@ func (s *SmokeTest) Run(args []string) (err error) {
} }
fmt.Print("\nSPI recorder\n") fmt.Print("\nSPI recorder\n")
for _, op := range spiRecorder.Ops { for _, op := range spiRecorder.Ops {
fmt.Print(" Write: ") fmt.Print(" W: ")
if len(op.Read) != 0 { if len(op.R) != 0 {
// Read data. // Read data.
fmt.Printf("0x%02X\n Read: ", op.Write[0]) fmt.Printf("0x%02X\n R: ", op.W[0])
// first byte is dummy. // first byte is dummy.
for i, b := range op.Read[1:] { for i, b := range op.R[1:] {
if i != 0 { if i != 0 {
fmt.Print(", ") fmt.Print(", ")
} }
@ -106,13 +106,13 @@ func (s *SmokeTest) Run(args []string) (err error) {
} }
} else { } else {
// Write-only command. // Write-only command.
for i, b := range op.Write { for i, b := range op.W {
if i != 0 { if i != 0 {
fmt.Print(", ") fmt.Print(", ")
} }
fmt.Printf("0x%02X", b) fmt.Printf("0x%02X", b)
} }
fmt.Print("\n Read: ") fmt.Print("\n R: ")
} }
fmt.Print("\n") fmt.Print("\n")
} }

@ -36,18 +36,18 @@ func TestTemperature(t *testing.T) {
ops := []onewiretest.IO{ ops := []onewiretest.IO{
// Match ROM + Read Scratchpad (init) // Match ROM + Read Scratchpad (init)
{ {
Write: []uint8{0x55, 0x28, 0xac, 0x41, 0xe, 0x7, 0x0, 0x0, 0x74, 0xbe}, W: []uint8{0x55, 0x28, 0xac, 0x41, 0xe, 0x7, 0x0, 0x0, 0x74, 0xbe},
Read: []uint8{0xe0, 0x1, 0x0, 0x0, 0x3f, 0xff, 0x10, 0x10, 0x3f}, R: []uint8{0xe0, 0x1, 0x0, 0x0, 0x3f, 0xff, 0x10, 0x10, 0x3f},
}, },
// Match ROM + Convert // Match ROM + Convert
{ {
Write: []uint8{0x55, 0x28, 0xac, 0x41, 0xe, 0x7, 0x0, 0x0, 0x74, 0x44}, W: []uint8{0x55, 0x28, 0xac, 0x41, 0xe, 0x7, 0x0, 0x0, 0x74, 0x44},
Pull: true, Pull: true,
}, },
// Match ROM + Read Scratchpad (read temp) // Match ROM + Read Scratchpad (read temp)
{ {
Write: []uint8{0x55, 0x28, 0xac, 0x41, 0xe, 0x7, 0x0, 0x0, 0x74, 0xbe}, W: []uint8{0x55, 0x28, 0xac, 0x41, 0xe, 0x7, 0x0, 0x0, 0x74, 0xbe},
Read: []uint8{0xe0, 0x1, 0x0, 0x0, 0x3f, 0xff, 0x10, 0x10, 0x3f}, R: []uint8{0xe0, 0x1, 0x0, 0x0, 0x3f, 0xff, 0x10, 0x10, 0x3f},
}, },
} }
var addr onewire.Address = 0x740000070e41ac28 var addr onewire.Address = 0x740000070e41ac28
@ -84,7 +84,7 @@ func TestConvertAll(t *testing.T) {
// set-up playback using the recording output. // set-up playback using the recording output.
ops := []onewiretest.IO{ ops := []onewiretest.IO{
// Skip ROM + Convert // Skip ROM + Convert
{Write: []uint8{0xcc, 0x44}, Read: []uint8(nil), Pull: true}, {W: []uint8{0xcc, 0x44}, R: []uint8(nil), Pull: true},
} }
bus := onewiretest.Playback{Ops: ops} bus := onewiretest.Playback{Ops: ops}
// Perform the conversion // Perform the conversion

@ -43,11 +43,11 @@ func Example() {
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
{Addr: 0x18, Write: []byte{0xf0}}, {Addr: 0x18, W: []byte{0xf0}},
{Addr: 0x18, Write: []byte{0xe1, 0xf0}, Read: []byte{0x18}}, {Addr: 0x18, W: []byte{0xe1, 0xf0}, R: []byte{0x18}},
{Addr: 0x18, Write: []byte{0xd2, 0xe1}, Read: []byte{0x1}}, {Addr: 0x18, W: []byte{0xd2, 0xe1}, R: []byte{0x1}},
{Addr: 0x18, Write: []byte{0xe1, 0xb4}}, {Addr: 0x18, W: []byte{0xe1, 0xb4}},
{Addr: 0x18, Write: []byte{0xc3, 0x6, 0x26, 0x46, 0x66, 0x86}}, {Addr: 0x18, W: []byte{0xc3, 0x6, 0x26, 0x46, 0x66, 0x86}},
}, },
} }
d, err := New(&bus, nil) d, err := New(&bus, nil)
@ -65,11 +65,11 @@ func TestNew(t *testing.T) {
func TestNew_opts(t *testing.T) { func TestNew_opts(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
{Addr: 0x18, Write: []byte{0xf0}}, {Addr: 0x18, W: []byte{0xf0}},
{Addr: 0x18, Write: []byte{0xe1, 0xf0}, Read: []byte{0x18}}, {Addr: 0x18, W: []byte{0xe1, 0xf0}, R: []byte{0x18}},
{Addr: 0x18, Write: []byte{0xd2, 0xe1}, Read: []byte{0x1}}, {Addr: 0x18, W: []byte{0xd2, 0xe1}, R: []byte{0x1}},
{Addr: 0x18, Write: []byte{0xe1, 0xb4}}, {Addr: 0x18, W: []byte{0xe1, 0xb4}},
{Addr: 0x18, Write: []byte{0xc3, 0x6, 0x26, 0x46, 0x66, 0x86}}, {Addr: 0x18, W: []byte{0xc3, 0x6, 0x26, 0x46, 0x66, 0x86}},
}, },
} }
opts := &Opts{Addr: 0x18} opts := &Opts{Addr: 0x18}
@ -114,7 +114,7 @@ func TestRecordInit(t *testing.T) {
// Output the recording. // Output the recording.
t.Logf("var ops = i2ctest.IO{\n") t.Logf("var ops = i2ctest.IO{\n")
for _, op := range i2cBus.Ops { for _, op := range i2cBus.Ops {
t.Logf(" {Addr: %#x, Write: %#v, Read: %#v},\n", op.Addr, op.Write, op.Read) t.Logf(" {Addr: %#x, W: %#v, R: %#v},\n", op.Addr, op.W, op.R)
} }
t.Logf("}\n") t.Logf("}\n")
} }

@ -107,9 +107,9 @@ func TestI2C_Draw_VerticalLSD_fast(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Startup initialization. // Startup initialization.
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
// Actual draw buffer. // Actual draw buffer.
{Addr: 0x3c, Write: buf}, {Addr: 0x3c, W: buf},
}, },
} }
dev, err := NewI2C(&bus, 128, 64, false) dev, err := NewI2C(&bus, 128, 64, false)
@ -135,13 +135,13 @@ func TestI2C_Halt_Write(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Startup initialization. // Startup initialization.
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
// Halt() // Halt()
{Addr: 0x3c, Write: []byte{0x0, 0xae}}, {Addr: 0x3c, W: []byte{0x0, 0xae}},
// transparent resume // transparent resume
{Addr: 0x3c, Write: []byte{0x0, 0xaf}}, {Addr: 0x3c, W: []byte{0x0, 0xaf}},
// Actual draw buffer. // Actual draw buffer.
{Addr: 0x3c, Write: buf}, {Addr: 0x3c, W: buf},
}, },
} }
dev, err := NewI2C(&bus, 128, 64, false) dev, err := NewI2C(&bus, 128, 64, false)
@ -165,9 +165,9 @@ func TestI2C_Halt_resume_fail(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Startup initialization. // Startup initialization.
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
// Halt() // Halt()
{Addr: 0x3c, Write: []byte{0x0, 0xae}}, {Addr: 0x3c, W: []byte{0x0, 0xae}},
}, },
DontPanic: true, DontPanic: true,
} }
@ -190,7 +190,7 @@ func TestI2C_Write_invalid_size(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Startup initialization. // Startup initialization.
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
}, },
} }
dev, err := NewI2C(&bus, 128, 64, false) dev, err := NewI2C(&bus, 128, 64, false)
@ -209,7 +209,7 @@ func TestI2C_Write_fail(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Startup initialization. // Startup initialization.
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
}, },
DontPanic: true, DontPanic: true,
} }
@ -229,7 +229,7 @@ func TestI2C_Draw_fail(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Startup initialization. // Startup initialization.
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
}, },
DontPanic: true, DontPanic: true,
} }
@ -250,9 +250,9 @@ func TestI2C_DrawGray(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Startup initialization. // Startup initialization.
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
// Actual draw buffer. // Actual draw buffer.
{Addr: 0x3c, Write: append([]byte{i2cData}, grayCheckboard()...)}, {Addr: 0x3c, W: append([]byte{i2cData}, grayCheckboard()...)},
}, },
} }
dev, err := NewI2C(&bus, 128, 64, false) dev, err := NewI2C(&bus, 128, 64, false)
@ -276,13 +276,13 @@ func TestI2C_DrawGray(t *testing.T) {
func TestI2C_Scroll(t *testing.T) { func TestI2C_Scroll(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
// Scroll Left. // Scroll Left.
{Addr: 0x3c, Write: []byte{0x0, 0x27, 0x0, 0x0, 0x6, 0x7, 0x0, 0xff, 0x2f}}, {Addr: 0x3c, W: []byte{0x0, 0x27, 0x0, 0x0, 0x6, 0x7, 0x0, 0xff, 0x2f}},
// Scroll UpRight. // Scroll UpRight.
{Addr: 0x3c, Write: []byte{0x0, 0x29, 0x0, 0x0, 0x6, 0x0, 0x1, 0x2f}}, {Addr: 0x3c, W: []byte{0x0, 0x29, 0x0, 0x0, 0x6, 0x0, 0x1, 0x2f}},
// StopScroll. // StopScroll.
{Addr: 0x3c, Write: []byte{0x0, 0x2e}}, {Addr: 0x3c, W: []byte{0x0, 0x2e}},
}, },
} }
dev, err := NewI2C(&bus, 128, 64, false) dev, err := NewI2C(&bus, 128, 64, false)
@ -315,10 +315,10 @@ func TestI2C_Scroll(t *testing.T) {
func TestI2C_SetContrast(t *testing.T) { func TestI2C_SetContrast(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
{Addr: 0x3c, Write: []byte{0x0, 0x81, 0x0}}, {Addr: 0x3c, W: []byte{0x0, 0x81, 0x0}},
{Addr: 0x3c, Write: []byte{0x0, 0x81, 0x7f}}, {Addr: 0x3c, W: []byte{0x0, 0x81, 0x7f}},
{Addr: 0x3c, Write: []byte{0x0, 0x81, 0xff}}, {Addr: 0x3c, W: []byte{0x0, 0x81, 0xff}},
}, },
} }
dev, err := NewI2C(&bus, 128, 64, false) dev, err := NewI2C(&bus, 128, 64, false)
@ -342,13 +342,13 @@ func TestI2C_SetContrast(t *testing.T) {
func TestI2C_Invert_Halt_resume(t *testing.T) { func TestI2C_Invert_Halt_resume(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
// Invert(true) // Invert(true)
{Addr: 0x3c, Write: []byte{0x0, 0xa7}}, {Addr: 0x3c, W: []byte{0x0, 0xa7}},
// Halt() // Halt()
{Addr: 0x3c, Write: []byte{0x0, 0xae}}, {Addr: 0x3c, W: []byte{0x0, 0xae}},
// transparent resume + Invert(false) // transparent resume + Invert(false)
{Addr: 0x3c, Write: []byte{0x0, 0xaf, 0xa6}}, {Addr: 0x3c, W: []byte{0x0, 0xaf, 0xa6}},
}, },
} }
dev, err := NewI2C(&bus, 128, 64, false) dev, err := NewI2C(&bus, 128, 64, false)
@ -372,11 +372,11 @@ func TestI2C_Invert_Halt_resume(t *testing.T) {
func TestI2C_Halt(t *testing.T) { func TestI2C_Halt(t *testing.T) {
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
// Halt() // Halt()
{Addr: 0x3c, Write: []byte{0x0, 0xae}}, {Addr: 0x3c, W: []byte{0x0, 0xae}},
// transparent resume + StopScroll() // transparent resume + StopScroll()
{Addr: 0x3c, Write: []byte{0x0, 0xaf, 0x2e}}, {Addr: 0x3c, W: []byte{0x0, 0xaf, 0x2e}},
}, },
DontPanic: true, DontPanic: true,
} }
@ -422,7 +422,7 @@ func TestSPI_3wire(t *testing.T) {
func TestSPI_4wire_String(t *testing.T) { func TestSPI_4wire_String(t *testing.T) {
bus := spitest.Playback{ bus := spitest.Playback{
Playback: conntest.Playback{ Playback: conntest.Playback{
Ops: []conntest.IO{{Write: getInitCmd(128, 64, false)}}, Ops: []conntest.IO{{W: getInitCmd(128, 64, false)}},
}, },
} }
dev, err := NewSPI(&bus, &gpiotest.Pin{N: "pin1", Num: 42}, 128, 64, false) dev, err := NewSPI(&bus, &gpiotest.Pin{N: "pin1", Num: 42}, 128, 64, false)
@ -447,11 +447,11 @@ func TestSPI_4wire_Write_differential(t *testing.T) {
bus := spitest.Playback{ bus := spitest.Playback{
Playback: conntest.Playback{ Playback: conntest.Playback{
Ops: []conntest.IO{ Ops: []conntest.IO{
{Write: getInitCmd(128, 64, false)}, {W: getInitCmd(128, 64, false)},
{Write: buf1}, {W: buf1},
// Reset to write only to the first page. // Reset to write only to the first page.
{Write: []byte{0x21, 0x0, 0x7f, 0x22, 0x1, 0x1}}, {W: []byte{0x21, 0x0, 0x7f, 0x22, 0x1, 0x1}},
{Write: buf2}, {W: buf2},
}, },
}, },
} }
@ -479,8 +479,8 @@ func TestSPI_4wire_Write_differential_fail(t *testing.T) {
bus := spitest.Playback{ bus := spitest.Playback{
Playback: conntest.Playback{ Playback: conntest.Playback{
Ops: []conntest.IO{ Ops: []conntest.IO{
{Write: getInitCmd(128, 64, false)}, {W: getInitCmd(128, 64, false)},
{Write: buf1}, {W: buf1},
}, },
DontPanic: true, DontPanic: true,
}, },
@ -506,9 +506,7 @@ func TestSPI_4wire_Write_differential_fail(t *testing.T) {
func TestSPI_4wire_gpio_fail(t *testing.T) { func TestSPI_4wire_gpio_fail(t *testing.T) {
bus := spitest.Playback{ bus := spitest.Playback{
Playback: conntest.Playback{ Playback: conntest.Playback{
Ops: []conntest.IO{ Ops: []conntest.IO{{W: getInitCmd(128, 64, false)}},
{Write: getInitCmd(128, 64, false)},
},
}, },
} }
pin := &failPin{fail: false} pin := &failPin{fail: false}
@ -543,7 +541,7 @@ func getI2CPlayback() *i2ctest.Playback {
return &i2ctest.Playback{ return &i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Startup initialization. // Startup initialization.
{Addr: 0x3c, Write: initCmdI2C()}, {Addr: 0x3c, W: initCmdI2C()},
}, },
} }
} }

@ -105,15 +105,15 @@ func (s *SmokeTest) Run(args []string) (err error) {
fmt.Print("I²C recorder\n") fmt.Print("I²C recorder\n")
} }
for _, op := range i2cRecorder.Ops { for _, op := range i2cRecorder.Ops {
fmt.Print(" Write: ") fmt.Print(" W: ")
for i, b := range op.Write { for i, b := range op.W {
if i != 0 { if i != 0 {
fmt.Print(", ") fmt.Print(", ")
} }
fmt.Printf("0x%02X", b) fmt.Printf("0x%02X", b)
} }
fmt.Print("\n Read: ") fmt.Print("\n R: ")
for i, b := range op.Read { for i, b := range op.R {
if i != 0 { if i != 0 {
fmt.Print(", ") fmt.Print(", ")
} }
@ -123,12 +123,12 @@ func (s *SmokeTest) Run(args []string) (err error) {
} }
fmt.Print("\nSPI recorder\n") fmt.Print("\nSPI recorder\n")
for _, op := range spiRecorder.Ops { for _, op := range spiRecorder.Ops {
fmt.Print(" Write: ") fmt.Print(" W: ")
if len(op.Read) != 0 { if len(op.R) != 0 {
// Read data. // Read data.
fmt.Printf("0x%02X\n Read: ", op.Write[0]) fmt.Printf("0x%02X\n R: ", op.W[0])
// first byte is dummy. // first byte is dummy.
for i, b := range op.Read[1:] { for i, b := range op.R[1:] {
if i != 0 { if i != 0 {
fmt.Print(", ") fmt.Print(", ")
} }
@ -136,13 +136,13 @@ func (s *SmokeTest) Run(args []string) (err error) {
} }
} else { } else {
// Write-only command. // Write-only command.
for i, b := range op.Write { for i, b := range op.W {
if i != 0 { if i != 0 {
fmt.Print(", ") fmt.Print(", ")
} }
fmt.Printf("0x%02X", b) fmt.Printf("0x%02X", b)
} }
fmt.Print("\n Read: ") fmt.Print("\n R: ")
} }
fmt.Print("\n") fmt.Print("\n")
} }

Loading…
Cancel
Save