spi

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2019 License: BSD-3-Clause Imports: 12 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  = 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.

)
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

func UsePinsMaster added in v0.2.1

func UsePinsMaster(af gpio.AltFunc, sck, mosi gpio.Pin, miso_nss ...gpio.Pin)

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.

func UsePinsSlave added in v0.2.1

func UsePinsSlave(af gpio.AltFunc, sck, miso gpio.Pin, mosi_nss ...gpio.Pin)

UsePinsSlave is helper function that can be used to configure GPIO pins as required by SPI slave if they all can use the same alternate function.

Types

type Config added in v0.2.1

type Config uint32

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) Disable added in v0.2.1

func (d *Driver) Disable()

Disable calls d.Periph().Disable().

func (*Driver) Enable added in v0.2.1

func (d *Driver) Enable()

Enable calls d.Periph().Enable().

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

Periph return the internal SPI peripheral used by Driver.

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) SetBaudrate added in v0.2.1

func (d *Driver) SetBaudrate(baudrate int)

SetBaudrate calls d.Periph().SetBaudrate(baudrate).

func (*Driver) SetDeadline

func (d *Driver) SetDeadline(ns int64)

func (*Driver) SetWordSize added in v0.2.1

func (d *Driver) SetWordSize(size int)

SetWordSize calls d.Periph().SetWordSize(size).

func (*Driver) Setup added in v0.2.1

func (d *Driver) Setup(conf Config, baudrate int)

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

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

func (p *Periph) Baudrate() int

Baudrate returns the currently configured baudrate.

func (*Periph) Bus

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

Bus returns a bus to which p is connected to.

func (*Periph) Config added in v0.2.1

func (p *Periph) Config() Config

Config returns the current p's 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) SetBaudrate added in v0.2.1

func (p *Periph) SetBaudrate(baudrate int)

SetBaudrate sets the baudrate (p must be disabled).

func (*Periph) SetConfig added in v0.2.1

func (p *Periph) SetConfig(conf Config, baudrate int)

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) 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 disabled peripheral before use this function. SetWordSize is mandatory for F0, F3, L4 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) 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.

func (*Periph) WordSize

func (p *Periph) WordSize() int

WordSize return currently used word size.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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