spi

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2019 License: BSD-3-Clause Imports: 11 Imported by: 0

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

View Source
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).
)
View Source
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).

)
View Source
const (
	ErrCRC     = Error(spi.CRCERR >> 3)
	ErrMode    = Error(spi.MODF >> 3)
	ErrOverrun = Error(spi.OVR >> 3)
)
View Source
const (
	Full    = Duplex(0)                         // Full-duplex mode.
	HalfIn  = Duplex(spi.BIDIMODE)              // Half-duplex input mode.
	HalfOut = Duplex(spi.BIDIMODE | spi.BIDIOE) // Half-duplex output mode.
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Conf

type Conf uint16

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

func NewDriver

func NewDriver(p *Periph, txdma, rxdma dma.Channel) *Driver

NewDriver provides convenient way to create heap allocated Driver struct.

func (*Driver) DMAISR

func (d *Driver) DMAISR(ch dma.Channel)

func (*Driver) Err

func (d *Driver) Err(clear bool) error

Err returns value of internal error variable and clears it if clear is true.

func (*Driver) ISR

func (d *Driver) ISR()

func (*Driver) Periph

func (d *Driver) Periph() *Periph

func (*Driver) RepeatByte

func (d *Driver) RepeatByte(b byte, n int)

func (*Driver) RepeatWord16

func (d *Driver) RepeatWord16(w uint16, n int)

func (*Driver) RxDMA

func (d *Driver) RxDMA() dma.Channel

func (*Driver) SetDeadline

func (d *Driver) SetDeadline(ns int64)

func (*Driver) TxDMA

func (d *Driver) TxDMA() dma.Channel

func (*Driver) WriteRead

func (d *Driver) WriteRead(out, in []byte) int

func (*Driver) WriteRead16

func (d *Driver) WriteRead16(out, in []uint16) int

func (*Driver) WriteReadByte

func (d *Driver) WriteReadByte(b byte) byte

WriteReadByte writes and reads byte.

func (*Driver) WriteReadMany

func (d *Driver) WriteReadMany(oi ...[]byte) int

func (*Driver) WriteReadMany16

func (d *Driver) WriteReadMany16(oi ...[]uint16) int

func (*Driver) WriteReadWord16

func (d *Driver) WriteReadWord16(w uint16) uint16

WriteReadWord16 writes and reads 16-bit word.

func (*Driver) WriteStringRead

func (d *Driver) WriteStringRead(out string, in []byte) int

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 Error

type Error byte

Error is a bitfield that encodes possible peripheral errors.

func (Error) Error

func (e Error) Error() string

type Event

type Event uint16

Event is a bitfield that encodes possible peripheral events.

type Periph

type Periph struct {
	// contains filtered or unexported fields
}

Periph represents SPI peripheral.

func (*Periph) BR

func (p *Periph) BR(baudrate int) Conf

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/p/bus package must be set before use this function.

func (*Periph) Baudrate

func (p *Periph) Baudrate(cfg Conf) int

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) Bus

func (p *Periph) Bus() bus.Bus

Bus returns a bus to which p is connected to.

func (*Periph) Conf

func (p *Periph) Conf() Conf

Conf returns the current configuration.

func (*Periph) Disable

func (p *Periph) Disable()

Disable disables p.

func (*Periph) DisableClock

func (p *Periph) DisableClock()

DisableClock disables clock for p.

func (*Periph) DisableDMA

func (p *Periph) DisableDMA(e Event)

DisableDMA disables generating of DMA requests by events e.

func (*Periph) DisableIRQ

func (p *Periph) DisableIRQ(e Event)

DisableIRQ disables generating of IRQ by events e.

func (*Periph) Duplex

func (p *Periph) Duplex() Duplex

func (*Periph) Enable

func (p *Periph) Enable()

Enable enables p.

func (*Periph) EnableClock

func (p *Periph) EnableClock(lp bool)

EnableClock enables clock for p. lp determines whether the clock remains on in low power (sleep) mode.

func (*Periph) EnableDMA

func (p *Periph) EnableDMA(e Event)

EnableDMA enables generating of DMA requests by events e.

func (*Periph) EnableIRQ

func (p *Periph) EnableIRQ(e Event)

EnableIRQ enables generating of IRQ by events e.

func (*Periph) Enabled

func (p *Periph) Enabled() bool

Enabled reports whether p is enabled.

func (*Periph) LoadByte

func (p *Periph) LoadByte() byte

LoadByte loads a byte from the data register. Use it only when 8-bit frame is configured.

func (*Periph) LoadWord16

func (p *Periph) LoadWord16() uint16

LoadWord16 loads a 16-bit word from the data register. Use it only when 16-bit word or data packing is configured.

func (*Periph) Reset

func (p *Periph) Reset()

Reset resets p.

func (*Periph) SetConf

func (p *Periph) SetConf(cfg Conf)

SetConf configures p.

func (*Periph) SetDuplex

func (p *Periph) SetDuplex(duplex Duplex)

func (*Periph) SetWordSize

func (p *Periph) SetWordSize(size int)

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) Status

func (p *Periph) Status() (Event, Error)

Status return current status of p.

func (*Periph) StoreByte

func (p *Periph) StoreByte(v byte)

StoreByte stores a byte to the data register. Use it only when 8-bit frame is configured.

func (*Periph) StoreWord16

func (p *Periph) StoreWord16(v uint16)

StoreWord16 stores a 16-bit word to the data register. Use it only when 16-bit word or data packing is configured.

func (*Periph) WordSize

func (p *Periph) WordSize() int

WordSize return currently used word size.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL