spi

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DSSn = 0
	FRFn = 4
	SPOn = 6
	SPHn = 7
	SCRn = 8
)
View Source
const (
	PARTNUMBER1 uint32 = 0x0F << 0 //+ These bits read back as 0x0
	DESIGNER0   uint32 = 0x0F << 4 //+ These bits read back as 0x1
)

PERIPHID1 bits

View Source
const (
	PARTNUMBER1n = 0
	DESIGNER0n   = 4
)
View Source
const (
	DESIGNER1 uint32 = 0x0F << 0 //+ These bits read back as 0x4
	REVISION  uint32 = 0x0F << 4 //+ These bits return the peripheral revision
)

PERIPHID2 bits

View Source
const (
	DESIGNER1n = 0
	REVISIONn  = 4
)
View Source
const (
	FrameFormat = Config(FRF) // Frame format:
	MSPI        = Config(0)   // - Motorola SPI
	SyncSerial  = Config(FTI) // - Texas Instruments Synchronous Serial
	Microwire   = Config(FNM) // - National Semiconductor Microwire

	// For Motorola SPI frame format:
	CPHA0 = Config(0)   // sample on leading edge.
	CPHA1 = Config(SPH) // sample on trailing edge.
	CPOL0 = Config(0)   // clock idle state is 0.
	CPOL1 = Config(SPO) // clock idle state is 1.

	WordLen = Config(15) // Data word length:
	Word4b  = Config(3)  // - 4 bit
	Word5b  = Config(4)  // - 5 bit
	Word6b  = Config(5)  // - 6 bit
	Word7b  = Config(6)  // - 7 bit
	Word8b  = Config(7)  // - 8 bit
	Word9b  = Config(8)  // - 9 bit
	Word10b = Config(9)  // - 10 bit
	Word11b = Config(10) // - 11 bit
	Word12b = Config(11) // - 12 bit
	Word13b = Config(12) // - 13 bit
	Word14b = Config(13) // - 14 bit
	Word15b = Config(14) // - 15 bit
	Word16b = Config(15) // - 16 bit
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CR0

type CR0 uint32
const (
	DSS  CR0 = 0x0F << 0 //+ Data Size Select:
	DS4  CR0 = 0x03 << 0 //  4-bit data
	DS5  CR0 = 0x04 << 0 //  5-bit data
	DS6  CR0 = 0x05 << 0 //  6-bit data
	DS7  CR0 = 0x06 << 0 //  7-bit data
	DS8  CR0 = 0x07 << 0 //  8-bit data
	DS9  CR0 = 0x08 << 0 //  9-bit data
	DS10 CR0 = 0x09 << 0 //  10-bit data
	DS11 CR0 = 0x0A << 0 //  11-bit data
	DS12 CR0 = 0x0B << 0 //  12-bit data
	DS13 CR0 = 0x0C << 0 //  13-bit data
	DS14 CR0 = 0x0D << 0 //  14-bit data
	DS15 CR0 = 0x0E << 0 //  15-bit data
	DS16 CR0 = 0x0F << 0 //  16-bit data
	FRF  CR0 = 0x03 << 4 //+ Frame format:
	FMO  CR0 = 0x00 << 4 //  Motorola SPI frame format
	FTI  CR0 = 0x01 << 4 //  TI synchronous serial frame format
	FNM  CR0 = 0x02 << 4 //  National Microwire frame format
	SPO  CR0 = 0x01 << 6 //+ SSPCLKOUT polarity for Motorola SPI frame format.
	SPH  CR0 = 0x01 << 7 //+ SSPCLKOUT phase for Motorola SPI frame format.
	SCR  CR0 = 0xFF << 8 //+ Serial clock rate.
)

CR0 bits

type CR1

type CR1 uint32
const (
	LBM CR1 = 0x01 << 0 //+ Loop back mode.
	SSE CR1 = 0x01 << 1 //+ Synchronous serial port enable.
	MS  CR1 = 0x01 << 2 //+ Slave mode.
	SOD CR1 = 0x01 << 3 //+ Slave-mode output disable.
)

CR1 bits

type Config

type Config uint32

type DMACR

type DMACR uint32
const (
	RXDMAE DMACR = 0x01 << 0 //+ Receive DMA Enable.
	TXDMAE DMACR = 0x01 << 1 //+ Transmit DMA Enable.
)

DMACR bits

type INT

type INT uint32
const (
	RORI INT = 0x01 << 0 //+ Receive overrun interrupt.
	RTI  INT = 0x01 << 1 //+ Receive timeout interrupt.
	RXI  INT = 0x01 << 2 //+ Receive FIFO interrupt.
	TXI  INT = 0x01 << 3 //+ Transmit FIFO interrupt.
)

INT bits

type Master

type Master struct {
	sync.Mutex // helps in case of concurent use of Master (not used internally)
	// contains filtered or unexported fields
}

A Master is a driver to the SPI peripheral used in master mode.

func NewMaster

func NewMaster(p *Periph, rdma, wdma dma.Channel) *Master

NewMaster returns a new master-mode driver for p. If valid DMA channels are given, the DMA will be used for bigger data transfers.

func (*Master) Baudrate

func (d *Master) Baudrate() int

func (*Master) Config

func (d *Master) Config() Config

func (*Master) DMAISR

func (d *Master) DMAISR()

DMAISR should be configured as a DMA interrupt handler if DMA is used.

func (*Master) Disable

func (d *Master) Disable()

Disable waits for the last bit of the last transfer to be sent and next it disables the SPI peripheral.

func (*Master) Enable

func (d *Master) Enable()

func (*Master) Periph

func (d *Master) Periph() *Periph

Periph returns the underlying SPI peripheral.

func (*Master) Read

func (d *Master) Read(s []byte) (n int, err error)

Read implements io.Reader.

func (*Master) Read16

func (d *Master) Read16(s []uint16) (n int, err error)

Read16

func (*Master) ReadByte

func (d *Master) ReadByte() (b byte, err error)

func (*Master) ReadWord16

func (d *Master) ReadWord16() (w uint16, err error)

func (*Master) SetBaudrate

func (d *Master) SetBaudrate(baudrate int) (actual int)

func (*Master) SetConfig

func (d *Master) SetConfig(cfg Config)

func (*Master) SetRepW

func (d *Master) SetRepW(repw uint16)

func (*Master) Setup

func (d *Master) Setup(cfg Config, baudrate int) (actualBaud int)

Setup resets the underlying SPI peripheral and configures it according to the master driver needs. Next it calls the SetConfig and SetBaudrate methods with the provided arguments and enables the peripheral.

func (*Master) UsePin

func (d *Master) UsePin(pin iomux.Pin, sig Signal) bool

UsePin is a helper function that can be used to configure IO pins as required by the SPI peripheral. Only certain pins can be used (see datasheet). UsePin returns true on succes or false if it isn't possible to use a pin as a sig. See also Periph.Pins.

func (*Master) WaitTxDone

func (d *Master) WaitTxDone()

func (*Master) Write

func (d *Master) Write(s []byte) (n int, err error)

Write implements io.Writer.

func (*Master) Write16

func (d *Master) Write16(s []uint16) (n int, err error)

Write16

func (*Master) WriteByte

func (d *Master) WriteByte(b byte) error

func (*Master) WriteByteN

func (d *Master) WriteByteN(b byte, n int)

func (*Master) WriteRead

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

WriteRead writes n = min(len(out), len(in)) bytes to the transmit FIFO. At the same time it reads n bytes into in.

func (*Master) WriteRead16

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

WriteRead16 writes n = min(len(out), len(in)) 16-bit words to the transmit FIFO. At the same time it reads n words into in.

func (*Master) WriteReadByte

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

func (*Master) WriteReadWord16

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

func (*Master) WriteString

func (d *Master) WriteString(s string) (n int, err error)

WriteString implements io.StringWriter.

func (*Master) WriteStringRead

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

WriteStringRead works like WriteRead but writes a string.

func (*Master) WriteWord16

func (d *Master) WriteWord16(w uint16) error

func (*Master) WriteWord16N

func (d *Master) WriteWord16N(w uint16, n int)

type Periph

type Periph struct {
	CR0   mmio.R32[CR0]
	CR1   mmio.R32[CR1]
	DR    mmio.U32
	SR    mmio.R32[SR]
	CPSR  mmio.U32
	IMSC  mmio.R32[INT]
	RIS   mmio.R32[INT]
	MIS   mmio.R32[INT]
	ICR   mmio.R32[INT]
	DMACR mmio.R32[DMACR]

	PERIPHID0 mmio.U32
	PERIPHID1 mmio.U32
	PERIPHID2 mmio.U32
	PERIPHID3 mmio.U32
	PCELLID0  mmio.U32
	PCELLID1  mmio.U32
	PCELLID2  mmio.U32
	PCELLID3  mmio.U32
	// contains filtered or unexported fields
}

func SPI

func SPI(n int) *Periph

SPI returns the n-th SPI peripheral.

func (*Periph) Pins

func (p *Periph) Pins(sig Signal) []iomux.Pin

Pins returns the IO pins that can be used for the singal sig.

func (*Periph) SetReset

func (p *Periph) SetReset(assert bool)

SetReset allows to assert/deassert the reset signal to the SPI peripheral.

type SR

type SR uint32
const (
	TFE SR = 0x01 << 0 //+ Transmit FIFO empty.
	TNF SR = 0x01 << 1 //+ Transmit FIFO not full.
	RNE SR = 0x01 << 2 //+ Receive FIFO not empty.
	RFF SR = 0x01 << 3 //+ Receive FIFO full.
	BSY SR = 0x01 << 4 //+ PrimeCell SSP busy flag.
)

SR bits

type Signal

type Signal int8
const (
	RXD Signal = iota
	CSN
	SCK
	TXD
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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