Documentation ¶
Overview ¶
Package spi provides access to the registers of the SPI peripheral. It also provides a driver that implements synchronous I/O.
Index ¶
- Constants
- func UsePinsMaster(af gpio.AltFunc, sck, mosi gpio.Pin, miso_nss ...gpio.Pin)
- func UsePinsSlave(af gpio.AltFunc, sck, miso gpio.Pin, mosi_nss ...gpio.Pin)
- 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) SetDeadline(ns int64)
- 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) 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 Duplex
- 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) Duplex() Duplex
- 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) SetDuplex(duplex Duplex)
- 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) TwoWireSetRx()
- func (p *Periph) TwoWireSetTx()
- func (p *Periph) WordSize() int
Constants ¶
const ( CPHA0 = Config(0) // Sample on first edge. CPHA1 = Config(spi.CPHA) // Sample on second edge. CPOL0 = Config(0) // Clock idle state is 0. CPOL1 = Config(spi.CPOL) // Clock idle state is 1. Slave = Config(0) // Slave mode. Master = Config(spi.MSTR) // Master mode. BR2 = Config(0) // Baud rate = PCLK/2 BR4 = Config(1 << spi.BRn) // Baud rate = PCLK/4. BR8 = Config(2 << spi.BRn) // Baud rate = PCLK/8. BR16 = Config(3 << spi.BRn) // Baud rate = PCLK/16. BR32 = Config(4 << spi.BRn) // Baud rate = PCLK/32. BR64 = Config(5 << spi.BRn) // Baud rate = PCLK/64. BR128 = Config(6 << spi.BRn) // Baud rate = PCLK/128. BR256 = Config(7 << spi.BRn) // Baud rate = PCLK/256. MSBF = Config(0) // Most significant bit first. LSBF = Config(spi.LSBFIRST) // Least significant bit first. HardSS = Config(0) // Hardware slave select. SoftSS = Config(spi.SSM) // Software slave select (use ISSLow, ISSHigh). ISSLow = Config(0) // Set NSS internally to low (used with SoftSS). ISSHigh = Config(spi.SSI) // Set NSS internally to high (used with SoftSS). SSInp = Config(0) // Set NSS as input (used with HardSS). SSOut = Config(spi.SSOE << 16) // set NSS as output (used with HardSS). ThreeWire = Config(0) // Three-wire mode (SCK, MOSI, MISO). TwoWire = Config(spi.BIDIMODE) // Two-wire mode (SCK, MOSI/MISO). Rx = Config(0) // Two-wire receive-only Tx = Config(spi.BIDIOE) // Two-wire transmit-only. )
const ( Err = Event(1) // Some hardware error occurs. RxNotEmpty = Event(spi.RXNE) << 1 // Receive buffer not empty. TxEmpty = Event(spi.TXE) << 1 // Transmit buffer empty. Busy = Event(spi.BSY) << 1 // Periph is busy (not a real event). )
Variables ¶
This section is empty.
Functions ¶
func UsePinsMaster ¶ added in v0.2.1
UsePinsMaster is helper function that can be used to configure GPIO pins as required by SPI master if they all can use the same alternate function.
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) SetDeadline ¶
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 calls d.Periph().TwoWireSetRx()
func (*Driver) TwoWireSetTx ¶ added in v0.2.1
func (d *Driver) TwoWireSetTx()
TwoWireSetTx calls d.Periph().TwoWireSetTx()
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 Duplex ¶
type Duplex uint16
Duplex describes duplex mode. In full-duplex mode transmission is performed using MOSI and MISO lines. In half-duplex mode only MOSI at master side and MISO at slave side are used.
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) 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.
func (*Periph) TwoWireSetRx ¶ added in v0.2.1
func (p *Periph) TwoWireSetRx()
TwoWireSetRx sets data direction to recevie in two-wire mode.
func (*Periph) TwoWireSetTx ¶ added in v0.2.1
func (p *Periph) TwoWireSetTx()
TwoWireSetTx sets data direction to transmit in two-wire mode.