1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package driver contains interfaces to be implemented by various SPI implementations. 6 package driver // import "golang.org/x/exp/io/spi/driver" 7 8 const ( 9 Mode = iota 10 Bits 11 MaxSpeed 12 Order 13 Delay 14 CSChange 15 ) 16 17 // Opener is an interface to be implemented by the SPI driver to open 18 // a connection to an SPI device. 19 type Opener interface { 20 Open() (Conn, error) 21 } 22 23 // Conn is a connection to an SPI device. 24 // TODO(jbd): Extend the interface to query configuration values. 25 type Conn interface { 26 // Configure configures the SPI device. 27 // 28 // Available configuration keys are: 29 // - Mode, the SPI mode (valid values are 0, 1, 2 and 3). 30 // - Bits, bits per word (default is 8-bit per word). 31 // - Speed, the max clock speed (in Hz). 32 // - Order, bit order to be used in transfers. Zero value represents 33 // the MSB-first, non-zero values represent LSB-first encoding. 34 // - Delay, the pause time between frames (in usecs). 35 // Some SPI devices require a minimum amount of wait time after 36 // each frame write. If set, Delay amount of usecs are inserted after 37 // each write. 38 // - CSChange, whether to leave the device's chipselect active after a Tx. 39 // 40 // SPI devices can override these values. 41 Configure(k, v int) error 42 43 // Tx performs a SPI transaction: w is written if not nil, the result is 44 // put into r if not nil. len(w) must be equal to len(r), otherwise the 45 // driver should return an error. 46 Tx(w, r []byte) error 47 48 // Close frees the underlying resources and closes the connection. 49 Close() error 50 } 51