Documentation
¶
Overview ¶
Package spi provides access to the registers of SPI peripheral. It also provides the driver that implements synchronous I/O.
Index ¶
- Constants
- type Conf
- type Driver
- func (d *Driver) DMAISR(ch *dma.Channel)
- 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) SetDeadline(deadline int64)
- 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) Conf
- func (p *Periph) Baudrate(cfg Conf) uint
- func (p *Periph) Bus() system.Bus
- func (p *Periph) Conf() Conf
- 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) SetConf(cfg Conf)
- 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) WordSize() int
Constants ¶
const ( CPHA0 = Conf(0) // Sample on first edge. CPHA1 = Conf(spi.CPHA) // Sample on second edge. CPOL0 = Conf(0) // Clock idle state is 0. CPOL1 = Conf(spi.CPOL) // Clock idle state is 1. Slave = Conf(0) // Slave mode. Master = Conf(spi.MSTR) // Master mode. BR2 = Conf(0) // Baud rate = PCLK/2 BR4 = Conf(1 << spi.BRn) // Baud rate = PCLK/4. BR8 = Conf(2 << spi.BRn) // Baud rate = PCLK/8. BR16 = Conf(3 << spi.BRn) // Baud rate = PCLK/16. BR32 = Conf(4 << spi.BRn) // Baud rate = PCLK/32. BR64 = Conf(5 << spi.BRn) // Baud rate = PCLK/64. BR128 = Conf(6 << spi.BRn) // Baud rate = PCLK/128. BR256 = Conf(7 << spi.BRn) // Baud rate = PCLK/256. MSBF = Conf(0) // Most significant bit first. LSBF = Conf(spi.LSBFIRST) // Least significant bit first. HardSS = Conf(0) // Hardware slave select. SoftSS = Conf(spi.SSM) // Software slave select (use ISSLow, ISSHigh). ISSLow = Conf(0) // Set NSS internally to low (requires SoftSS). ISSHigh = Conf(spi.SSI) // Set NSS internally to high (requires SoftSS). )
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 ¶
This section is empty.
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
func MakeDriver ¶
MakeDriver returns initialized SPI driver that uses provided SPI peripheral and DMA channels.
func (*Driver) RepeatByte ¶
func (*Driver) RepeatWord16 ¶
func (*Driver) SetDeadline ¶
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 baud rate bits of configuration. BR guarantees that returned value will set baud rate to the value closest to but not greater than baudrate. APB1 and APB2 clock in stm32/hal/system package must be set properly before use this function.
func (*Periph) Baudrate ¶
Baudrate returns real baudrate bit/s that will be set by cfg. APB1 and APB2 clock in stm32/hal/system package must be set properly before use this function.
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) 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 disable peripheral before use this function. SetWordSize is mandatory for F0, F3, L4 if you use Driver 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.