Hardware SPI class. More...

#include <SPI.h>

Inheritance diagram for SPIClass:
Collaboration diagram for SPIClass:

Public Types

using IoCallback = void(*)(uint16_t c, uint8_t bits, bool read)
 Used for testing purposes only. More...
 

Public Member Functions

 SPIClass ()
 
 SPIClass (const SPIClass &)=delete
 
SPIClassoperator= (const SPIClass &)=delete
 
bool setup (SpiBus id, SpiPins pins={})
 Alternative to defining bus and pin set in constructor. Use this method to change global SPI instance setup. More...
 
bool setup (SpiPins pins)
 
bool begin () override
 Initialize the SPI bus by setting SCK and MOSI to outputs, pulling SCK and MOSI low. More...
 
void end () override
 Disable the SPI bus (leaving pin modes unchanged). More...
 
uint8_t read8 () override
 Read one byte from SPI without setting up registers. More...
 
uint32_t transfer32 (uint32_t val, uint8_t bits=32) override
 Send/receive a word of variable size. More...
 
void transfer (uint8_t *buffer, size_t numberBytes) override
 Send/receive a variable-length block of data. More...
 
bool loopback (bool enable) override
 For testing, tie MISO <-> MOSI internally. More...
 
void setDebugIoCallback (IoCallback callback)
 Used for testing purposes only Must be called after begin(). More...
 
uint8_t transfer (uint8_t val)
 Send/receive one byte of data. More...
 
virtual void transfer (uint8_t *buffer, size_t size)=0
 Send/receive a variable-length block of data. More...
 
- Public Member Functions inherited from SPIBase
 SPIBase (const SpiPins &pins)
 
virtual ~SPIBase ()
 
void beginTransaction (SPISettings &settings)
 Initialize the SPI bus using the defined SPISettings. More...
 
void beginTransaction (const SPISettings &settings)
 
virtual void endTransaction ()
 Stop using the SPI bus. Normally this is called after de-asserting the chip select, to allow other libraries to use the SPI bus. More...
 
void write (uint8_t data)
 
void write16 (uint16_t data)
 
void write32 (uint32_t data)
 
uint8_t transfer (uint8_t val)
 Send/receive one byte of data. More...
 
uint16_t transfer16 (uint16_t val)
 Send/receive one 16-bit word of data. More...
 

Protected Member Functions

void prepare (SPISettings &settings) override
 Prepare/configure with settings. More...
 
- Protected Member Functions inherited from SPIBase
void assignDefaultPins (const SpiPins &defPins)
 Assign any default pins. More...
 

Additional Inherited Members

- Public Attributes inherited from SPIBase
SPISettings SPIDefaultSettings
 Default settings used by the SPI bus until reset by beginTransaction(SPISettings) More...
 
const SpiPinspins {mPins}
 
- Protected Attributes inherited from SPIBase
SpiPins mPins
 

Detailed Description

Hardware SPI class.

Member Typedef Documentation

◆ IoCallback

using SPIClass::IoCallback = void (*)(uint16_t c, uint8_t bits, bool read)

Used for testing purposes only.

Parameters
cValue being read/written
bitsSize of value in bits
readtrue for incoming value, false for outgoing

Constructor & Destructor Documentation

◆ SPIClass() [1/2]

SPIClass::SPIClass ( )

◆ SPIClass() [2/2]

SPIClass::SPIClass ( const SPIClass )
delete

Member Function Documentation

◆ begin()

bool SPIClass::begin ( )
overridevirtual

Initialize the SPI bus by setting SCK and MOSI to outputs, pulling SCK and MOSI low.

Implements SPIBase.

◆ end()

void SPIClass::end ( )
overridevirtual

Disable the SPI bus (leaving pin modes unchanged).

Implements SPIBase.

◆ loopback()

bool SPIClass::loopback ( bool  enable)
overridevirtual

For testing, tie MISO <-> MOSI internally.

Note: Not included in std Arduino lib

Implements SPIBase.

◆ operator=()

SPIClass& SPIClass::operator= ( const SPIClass )
delete

◆ prepare()

void SPIClass::prepare ( SPISettings settings)
overrideprotectedvirtual

Prepare/configure with settings.

Parameters
settingsinclude frequency, byte order and SPI mode

Implements SPIBase.

◆ read8()

uint8_t SPIClass::read8 ( )
overridevirtual

Read one byte from SPI without setting up registers.

Parameters
none
Return values
bytereceived

Used for performance tuning when doing continuous reads this method does not reset the registers, so make sure that a regular transfer(data) call was performed

Note: this method is not found on the Arduino API

USE WITH CARE !!

Reimplemented from SPIBase.

◆ setDebugIoCallback()

void SPIClass::setDebugIoCallback ( IoCallback  callback)

Used for testing purposes only Must be called after begin().

Used to verify serialisation/de-searialisation bit ordering

◆ setup() [1/2]

bool SPIClass::setup ( SpiBus  id,
SpiPins  pins = {} 
)

Alternative to defining bus and pin set in constructor. Use this method to change global SPI instance setup.

IMPORTANT: Must be called before begin().

◆ setup() [2/2]

bool SPIClass::setup ( SpiPins  pins)
inline

◆ transfer() [1/3]

void SPIClass::transfer ( uint8_t buffer,
size_t  size 
)
overridevirtual

Send/receive a variable-length block of data.

Parameters
bufferIN: The data to send; OUT: The received data
sizeNumber of bytes to transfer

Implements SPIBase.

◆ transfer() [2/3]

virtual void SPIBase::transfer

Send/receive a variable-length block of data.

Parameters
bufferIN: The data to send; OUT: The received data
sizeNumber of bytes to transfer

◆ transfer() [3/3]

uint8_t SPIBase::transfer
inline

Send/receive one byte of data.

Parameters
valThe byte to send
Return values
uint8_tThe received byte

◆ transfer32()

uint32_t SPIClass::transfer32 ( uint32_t  val,
uint8_t  bits = 32 
)
overridevirtual

Send/receive a word of variable size.

Parameters
valWord to send
bitsSize of word

Word is transferred either MSB first (bits-1) or LSB first (bit 0) depending on the currently applied bitOrder setting.

Reimplemented from SPIBase.


The documentation for this class was generated from the following file: