Documentation ¶
Overview ¶
Package spi provides unified way to configure/use SPI peripherals. It also provides a driver for synchronous I/O.
Index ¶
- Constants
- type Config
- type Driver
- func (d *Driver) DMAISR(ch dma.Channel)
- func (d *Driver) Disable()
- func (d *Driver) Enable()
- func (d *Driver) Err(clear bool) error
- func (d *Driver) ISR()
- func (d *Driver) Periph() *Periph
- func (d *Driver) RepeatByte(b byte, n int)
- func (d *Driver) RepeatWord16(w uint16, n int)
- func (d *Driver) RxDMA() dma.Channel
- func (d *Driver) SetBaudrate(baudrate int)
- func (d *Driver) SetTimeout(timeout time.Duration)
- func (d *Driver) SetWordSize(size int)
- func (d *Driver) Setup(conf Config, baudrate int)
- func (d *Driver) TwoWireSetRx()
- func (d *Driver) TwoWireSetTx()
- func (d *Driver) TxDMA() dma.Channel
- func (d *Driver) UsePinMaster(pin gpio.Pin, sig Signal)
- func (d *Driver) UsePinSlave(pin gpio.Pin, sig Signal)
- func (d *Driver) WriteRead(out, in []byte) int
- func (d *Driver) WriteRead16(out, in []uint16) int
- func (d *Driver) WriteReadByte(b byte) byte
- func (d *Driver) WriteReadMany(oi ...[]byte) int
- func (d *Driver) WriteReadMany16(oi ...[]uint16) int
- func (d *Driver) WriteReadWord16(w uint16) uint16
- func (d *Driver) WriteStringRead(out string, in []byte) int
- type DriverError
- type Error
- type Event
- type Periph
- func (p *Periph) BR(baudrate int) Config
- func (p *Periph) Baudrate() int
- func (p *Periph) Bus() bus.Bus
- func (p *Periph) Config() Config
- func (p *Periph) Disable()
- func (p *Periph) DisableClock()
- func (p *Periph) DisableDMA(e Event)
- func (p *Periph) DisableIRQ(e Event)
- func (p *Periph) EditConfig(from, to Config)
- func (p *Periph) Enable()
- func (p *Periph) EnableClock(lp bool)
- func (p *Periph) EnableDMA(e Event)
- func (p *Periph) EnableIRQ(e Event)
- func (p *Periph) Enabled() bool
- func (p *Periph) LoadByte() byte
- func (p *Periph) LoadWord16() uint16
- func (p *Periph) Reset()
- func (p *Periph) SetBaudrate(baudrate int)
- func (p *Periph) SetConfig(conf Config, baudrate int)
- func (p *Periph) SetWordSize(size int)
- func (p *Periph) Status() (Event, Error)
- func (p *Periph) StoreByte(v byte)
- func (p *Periph) StoreWord16(v uint16)
- func (p *Periph) WordSize() int
- type Signal
Constants ¶
const ( CPHA0 = Config(0) // Sample on first edge. CPHA1 = Config(cpha) // Sample on second edge. CPOL0 = Config(0) // Clock idle state is 0. CPOL1 = Config(cpol) // Clock idle state is 1. Slave = Config(0) // Slave mode. Master = Config(mstr) // Master mode. BR2 = Config(0) // Baud rate = PCLK/2 BR4 = Config(1 << brn) // Baud rate = PCLK/4. BR8 = Config(2 << brn) // Baud rate = PCLK/8. BR16 = Config(3 << brn) // Baud rate = PCLK/16. BR32 = Config(4 << brn) // Baud rate = PCLK/32. BR64 = Config(5 << brn) // Baud rate = PCLK/64. BR128 = Config(6 << brn) // Baud rate = PCLK/128. BR256 = Config(7 << brn) // Baud rate = PCLK/256. MSBF = Config(0) // Most significant bit first. LSBF = Config(lsbfirst) // Least significant bit first. HardSS = Config(0) // Hardware slave select. SoftSS = Config(ssm) // Software slave select (use ISSLow, ISSHigh). ISSLow = Config(0) // Set NSS internally to low (used with SoftSS). ISSHigh = Config(ssi) // Set NSS internally to high (used with SoftSS). SSInp = Config(0) // Set NSS as input (used with HardSS). SSOut = Config(ssoe << 16) // set NSS as output (used with HardSS). ThreeWire = Config(0) // Three-wire mode (SCK, MOSI, MISO). TwoWire = Config(bidimode) // Two-wire mode (SCK, MOSI/MISO). TxRx = Config(0) // Three-wire transimt and receive. RxOnly = Config(rxonly) // Three-wire receive only. Rx = Config(0) // Two-wire receive-only. Tx = Config(bidioe) // Two-wire transmit-only. )
const ( Err = Event(1) // Some hardware error occurs. RxNotEmpty = Event(rxne) << 1 // Receive buffer not empty. TxEmpty = Event(txe) << 1 // Transmit buffer empty. Busy = Event(bsy) << 1 // Periph is busy (not a real event). )
const ( ErrCRC = Error(crcerr >> 3) ErrMode = Error(modf >> 3) ErrOverrun = Error(ovr >> 3) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
func (*Driver) Disable ¶ added in v0.2.1
func (d *Driver) Disable()
Disable calls d.Periph().Disable().
func (*Driver) RepeatByte ¶
func (*Driver) RepeatWord16 ¶
func (*Driver) SetBaudrate ¶ added in v0.2.1
SetBaudrate calls d.Periph().SetBaudrate(baudrate).
func (*Driver) SetTimeout ¶ added in v0.3.0
func (*Driver) SetWordSize ¶ added in v0.2.1
SetWordSize calls d.Periph().SetWordSize(size).
func (*Driver) Setup ¶ added in v0.2.1
Setup enables clock source, resets peripheral, then calls d.Periph().SetConfig(conf, baudrate) to configure it.
func (*Driver) TwoWireSetRx ¶ added in v0.2.1
func (d *Driver) TwoWireSetRx()
TwoWireSetRx can be used in two-wire mode to set data direction to recevie.
func (*Driver) TwoWireSetTx ¶ added in v0.2.1
func (d *Driver) TwoWireSetTx()
TwoWireSetRx can be used in two-wire mode to set data direction to transimit.
func (*Driver) UsePinMaster ¶ added in v0.7.1
UsePinMaster is a helper function that can be used to configure GPIO pins as required by SPI master device. Only certain pins can be used (see datasheet).
func (*Driver) UsePinSlave ¶ added in v0.7.1
UsePinSlave is a helper function that can be used to configure GPIO pins as required by SPI slave device. Only certain pins can be used (see datasheet).
func (*Driver) WriteRead16 ¶
func (*Driver) WriteReadByte ¶
WriteReadByte writes and reads byte.
func (*Driver) WriteReadMany ¶
func (*Driver) WriteReadMany16 ¶
func (*Driver) WriteReadWord16 ¶
WriteReadWord16 writes and reads 16-bit word.
type DriverError ¶
type DriverError byte
const ErrTimeout DriverError = 1
func (DriverError) Error ¶
func (e DriverError) Error() string
type Periph ¶
type Periph struct {
// contains filtered or unexported fields
}
Periph represents SPI peripheral.
func (*Periph) BR ¶
BR calculates the baud rate bits of configuration. BR guarantees that the returned bits corresponds to the value closest to but not greater than baudrate.
func (*Periph) DisableDMA ¶
DisableDMA disables generating of DMA requests by events e.
func (*Periph) DisableIRQ ¶
DisableIRQ disables generating of IRQ by events e.
func (*Periph) EditConfig ¶ added in v0.2.3
EditConfig changes configuration.
func (*Periph) EnableClock ¶
EnableClock enables clock for p. lp determines whether the clock remains on in low power (sleep) mode.
func (*Periph) LoadByte ¶
LoadByte loads a byte from the data register. Use it only when 8-bit frame is configured.
func (*Periph) LoadWord16 ¶
LoadWord16 loads a 16-bit word from the data register. Use it only when 16-bit word or data packing is configured.
func (*Periph) SetBaudrate ¶ added in v0.2.1
SetBaudrate sets the baudrate (p must be disabled).
func (*Periph) SetConfig ¶ added in v0.2.1
SetConfig configures p (p must be disabled). If baudrate > 0 it replaces the BR bits in conf with the ones calculated from baudrate.
func (*Periph) SetWordSize ¶
SetWordSize sets size of data word. All families support 8 and 16-bit words, F0, F3, L4 supports 4 to 16-bit. Some families require disabled peripheral before use this function. SetWordSize is mandatory for F0, F3, L4 because the default reset configuration does not work.
func (*Periph) StoreByte ¶
StoreByte stores a byte to the data register. Use it only when 8-bit frame is configured.
func (*Periph) StoreWord16 ¶
StoreWord16 stores a 16-bit word to the data register. Use it only when 16-bit word or data packing is configured.