Neale Pickett
·
2026-02-16
pcf8575.go
1package pcf8575
2
3import (
4 "encoding/binary"
5 "tinygo.org/x/drivers"
6)
7
8type Device struct {
9 Addr uint16
10 I2C drivers.I2C
11}
12
13// Read value of all pins
14func (c *Device) Get() uint16 {
15 rxbuf := make([]byte, 2)
16 // If len(w) == 0, the low bit gets set
17 // see /usr/local/lib/tinygo/src/machine/machine_atsamd21.go
18 c.I2C.Tx(c.Addr, nil, rxbuf)
19 return binary.LittleEndian.Uint16(rxbuf)
20}
21
22// Put val onto all pins
23func (c *Device) Put(val uint16) {
24 txbuf := binary.LittleEndian.AppendUint16(nil, val)
25 rxbuf := []byte{}
26 c.I2C.Tx(c.Addr, txbuf, rxbuf)
27}