Checkpoint
This commit is contained in:
54 files changed
+6855
-526
No files matched your search
@@ -167,6 +167,9 @@ func InvalidMode(mode string) error {
|
||||
type Conn interface {
|
||||
// Tx transfers data over the bus.
|
||||
Tx(data []byte, isCommand bool) error
|
||||
|
||||
// Rx receives data over the bus.
|
||||
Rx(command byte, data []byte) error
|
||||
}
|
||||
|
||||
type i2cConn struct {
|
||||
@@ -181,6 +184,10 @@ func (c i2cConn) Tx(data []byte, isCommand bool) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (c i2cConn) Rx(command byte, data []byte) error {
|
||||
return errors.New("not implemented")
|
||||
}
|
||||
|
||||
// OpenI2C opens the named I²C bus and connects to the device at addr.
|
||||
func OpenI2C(name, addr string) (Conn, error) {
|
||||
log := logrus.WithFields(logrus.Fields{
|
||||
@@ -228,6 +235,21 @@ func (c spiConn) Tx(data []byte, isCommand bool) (err error) {
|
||||
return c.conn.Tx(data, nil)
|
||||
}
|
||||
|
||||
func (c spiConn) Rx(command byte, data []byte) (err error) {
|
||||
if c.dc == nil {
|
||||
return errors.New("3-wire SPI mode is not implemented")
|
||||
}
|
||||
|
||||
if err := c.Tx([]byte{command}, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.dc.Out(gpio.High); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// OpenSPI opens the named SPI port and connects to the device.
|
||||
func OpenSPI(name, resetPin, dcPin string) (Conn, error) {
|
||||
log := logrus.WithFields(logrus.Fields{
|
||||
|
||||
Reference in new issue
Block a user