Prusa MINI Firmware overview
SPIClass Class Reference

Wirish SPI interface. More...

#include <SPI.h>

Public Member Functions

 SPIClass ()
 
void begin (uint8_t _pin=CS_PIN_CONTROLLED_BY_USER)
 
void end (void)
 
void beginTransaction (SPISettings settings)
 
void endTransaction (void)
 
byte transfer (uint8_t _data, SPITransferMode _mode=SPI_LAST)
 
uint16_t transfer16 (uint16_t _data, SPITransferMode _mode=SPI_LAST)
 
uint8_t dmaTransfer (uint8_t *transmitBuf, uint8_t *receiveBuf, uint16_t length)
 
uint8_t dmaSend (uint8_t *buf, uint16_t length)
 
 SPIClass (uint32_t spiPortNumber)
 
void begin ()
 Equivalent to begin(SPI_1_125MHZ, MSBFIRST, 0). More...
 
void beginSlave (uint32_t bitOrder, uint32_t mode)
 Turn on a SPI port and set its GPIO pin modes for use as a slave. More...
 
void beginSlave ()
 Equivalent to beginSlave(MSBFIRST, 0). More...
 
void end ()
 Disables the SPI port, but leaves its GPIO pin modes unchanged. More...
 
void beginTransaction (SPISettings settings)
 
void beginTransaction (uint8_t pin, SPISettings settings)
 
void endTransaction ()
 
void beginTransactionSlave (SPISettings settings)
 
void setClockDivider (uint32_t clockDivider)
 
void setBitOrder (BitOrder bitOrder)
 
void setDataMode (uint8_t dataMode)
 
void attachInterrupt ()
 
void detachInterrupt ()
 
void setDataSize (uint32_t ds)
 
void onReceive (void(*)())
 
void onTransmit (void(*)())
 
uint16_t read ()
 Return the next unread byte/word. More...
 
void read (uint8_t *buffer, uint32_t length)
 Read length bytes, storing them into buffer. More...
 
void write (uint16_t data)
 Transmit one byte/word. More...
 
void write16 (uint16_t data)
 
void write (uint16_t data, uint32_t n)
 Transmit one byte/word a specified number of times. More...
 
void write (const void *buffer, uint32_t length)
 Transmit multiple bytes/words. More...
 
uint8_t transfer (uint8_t data) const
 Transmit a byte, then return the next unread byte. More...
 
uint16_t transfer16 (uint16_t data) const
 
uint8_t dmaTransfer (const void *transmitBuf, void *receiveBuf, uint16_t length)
 Sets up a DMA Transfer for "length" bytes. The transfer mode (8 or 16 bit mode) is evaluated from the SPI peripheral setting. More...
 
void dmaTransferSet (const void *transmitBuf, void *receiveBuf)
 
uint8_t dmaTransferRepeat (uint16_t length)
 
uint8_t dmaSend (const void *transmitBuf, uint16_t length, bool minc=1)
 Sets up a DMA Transmit for SPI 8 or 16 bit transfer mode. The transfer mode (8 or 16 bit mode) is evaluated from the SPI peripheral setting. More...
 
void dmaSendSet (const void *transmitBuf, bool minc)
 
uint8_t dmaSendRepeat (uint16_t length)
 
uint8_t dmaSendAsync (const void *transmitBuf, uint16_t length, bool minc=1)
 
uint8_t misoPin ()
 Return the number of the MISO (master in, slave out) pin. More...
 
uint8_t mosiPin ()
 Return the number of the MOSI (master out, slave in) pin. More...
 
uint8_t sckPin ()
 Return the number of the SCK (serial clock) pin. More...
 
uint8_t nssPin ()
 Return the number of the NSS (slave select) pin. More...
 
spi_dev * c_dev ()
 Get a pointer to the underlying libmaple spi_dev for this HardwareSPI instance. More...
 
spi_dev * dev ()
 
void setModule (int spi_num)
 Sets the number of the SPI peripheral to be used by this HardwareSPI instance. More...
 
uint8_t send (uint8_t data)
 Deprecated. More...
 
uint8_t send (uint8_t *data, uint32_t length)
 Deprecated. More...
 
uint8_t recv ()
 Deprecated. More...
 

Detailed Description

Wirish SPI interface.

This implementation uses software slave management, so the caller is responsible for controlling the slave select line.

Constructor & Destructor Documentation

◆ SPIClass() [1/2]

SPIClass::SPIClass ( )
42 {}

◆ SPIClass() [2/2]

SPIClass::SPIClass ( uint32_t  spiPortNumber)
Parameters
spiPortNumberNumber of the SPI port to manage.

Member Function Documentation

◆ begin() [1/2]

void SPIClass::begin ( uint8_t  _pin = CS_PIN_CONTROLLED_BY_USER)
43 {}
Here is the caller graph for this function:

◆ end() [1/2]

void SPIClass::end ( void  )
44 {}

◆ beginTransaction() [1/3]

void SPIClass::beginTransaction ( SPISettings  settings)
45 {}
Here is the caller graph for this function:

◆ endTransaction() [1/2]

void SPIClass::endTransaction ( void  )
46 {}

◆ transfer() [1/2]

byte SPIClass::transfer ( uint8_t  _data,
SPITransferMode  _mode = SPI_LAST 
)
49  {
50  uint8_t read;
51  dmaTransfer(&_data, &read, sizeof(_data));
52  return read;
53 }
Here is the call graph for this function:

◆ transfer16() [1/2]

uint16_t SPIClass::transfer16 ( uint16_t  _data,
SPITransferMode  _mode = SPI_LAST 
)
56  {
57  uint16_t read;
58  dmaTransfer((uint8_t *)&_data, (uint8_t *)&read, sizeof(_data));
59  return read;
60 }
Here is the call graph for this function:

◆ dmaTransfer() [1/2]

uint8_t SPIClass::dmaTransfer ( uint8_t transmitBuf,
uint8_t receiveBuf,
uint16_t  length 
)
62  {
64  return SPI_NOT_INITIALIZED;
65 
66  auto status = HAL_SPI_TransmitReceive(&hspi1, transmitBuf, receiveBuf, length, SPI_TRANSFER_TIMEOUT);
68 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dmaSend() [1/2]

uint8_t SPIClass::dmaSend ( uint8_t buf,
uint16_t  length 
)
70  {
72  return SPI_NOT_INITIALIZED;
73 
76 }
Here is the call graph for this function:

◆ begin() [2/2]

void SPIClass::begin ( )

Equivalent to begin(SPI_1_125MHZ, MSBFIRST, 0).

◆ beginSlave() [1/2]

void SPIClass::beginSlave ( uint32_t  bitOrder,
uint32_t  mode 
)

Turn on a SPI port and set its GPIO pin modes for use as a slave.

SPI port is enabled in full duplex mode, with software slave management.

Parameters
bitOrderEither LSBFIRST (little-endian) or MSBFIRST(big-endian)
modeSPI mode to use

◆ beginSlave() [2/2]

void SPIClass::beginSlave ( )

Equivalent to beginSlave(MSBFIRST, 0).

◆ end() [2/2]

void SPIClass::end ( )

Disables the SPI port, but leaves its GPIO pin modes unchanged.

◆ beginTransaction() [2/3]

void SPIClass::beginTransaction ( SPISettings  settings)
Here is the call graph for this function:

◆ beginTransaction() [3/3]

void SPIClass::beginTransaction ( uint8_t  pin,
SPISettings  settings 
)

◆ endTransaction() [2/2]

void SPIClass::endTransaction ( )

◆ beginTransactionSlave()

void SPIClass::beginTransactionSlave ( SPISettings  settings)

◆ setClockDivider()

void SPIClass::setClockDivider ( uint32_t  clockDivider)

◆ setBitOrder()

void SPIClass::setBitOrder ( BitOrder  bitOrder)

◆ setDataMode()

void SPIClass::setDataMode ( uint8_t  dataMode)

◆ attachInterrupt()

void SPIClass::attachInterrupt ( )

◆ detachInterrupt()

void SPIClass::detachInterrupt ( )

◆ setDataSize()

void SPIClass::setDataSize ( uint32_t  ds)

◆ onReceive()

void SPIClass::onReceive ( void(*)()  )

◆ onTransmit()

void SPIClass::onTransmit ( void(*)()  )

◆ read() [1/2]

uint16_t SPIClass::read ( )

Return the next unread byte/word.

If there is no unread byte/word waiting, this function will block until one is received.

Here is the caller graph for this function:

◆ read() [2/2]

void SPIClass::read ( uint8_t buffer,
uint32_t  length 
)

Read length bytes, storing them into buffer.

Parameters
bufferBuffer to store received bytes into.
lengthNumber of bytes to store in buffer. This function will block until the desired number of bytes have been read.

◆ write() [1/3]

void SPIClass::write ( uint16_t  data)

Transmit one byte/word.

Parameters
datato transmit.

◆ write16()

void SPIClass::write16 ( uint16_t  data)

◆ write() [2/3]

void SPIClass::write ( uint16_t  data,
uint32_t  n 
)

Transmit one byte/word a specified number of times.

Parameters
datato transmit.

◆ write() [3/3]

void SPIClass::write ( const void buffer,
uint32_t  length 
)

Transmit multiple bytes/words.

Parameters
bufferBytes/words to transmit.
lengthNumber of bytes/words in buffer to transmit.

◆ transfer() [2/2]

uint8_t SPIClass::transfer ( uint8_t  data) const

Transmit a byte, then return the next unread byte.

This function transmits before receiving.

Parameters
dataByte to transmit.
Returns
Next unread byte.

◆ transfer16() [2/2]

uint16_t SPIClass::transfer16 ( uint16_t  data) const

◆ dmaTransfer() [2/2]

uint8_t SPIClass::dmaTransfer ( const void transmitBuf,
void receiveBuf,
uint16_t  length 
)

Sets up a DMA Transfer for "length" bytes. The transfer mode (8 or 16 bit mode) is evaluated from the SPI peripheral setting.

This function transmits and receives to buffers.

Parameters
transmitBufbuffer Bytes to transmit. If passed as 0, it sends FF repeatedly for "length" bytes
receiveBufbuffer Bytes to save received data.
lengthNumber of bytes in buffer to transmit.

◆ dmaTransferSet()

void SPIClass::dmaTransferSet ( const void transmitBuf,
void receiveBuf 
)

◆ dmaTransferRepeat()

uint8_t SPIClass::dmaTransferRepeat ( uint16_t  length)

◆ dmaSend() [2/2]

uint8_t SPIClass::dmaSend ( const void transmitBuf,
uint16_t  length,
bool  minc = 1 
)

Sets up a DMA Transmit for SPI 8 or 16 bit transfer mode. The transfer mode (8 or 16 bit mode) is evaluated from the SPI peripheral setting.

This function only transmits and does not care about the RX fifo.

Parameters
databuffer half words to transmit,
lengthNumber of bytes in buffer to transmit.
mincSet to use Memory Increment mode, clear to use Circular mode.

◆ dmaSendSet()

void SPIClass::dmaSendSet ( const void transmitBuf,
bool  minc 
)

◆ dmaSendRepeat()

uint8_t SPIClass::dmaSendRepeat ( uint16_t  length)

◆ dmaSendAsync()

uint8_t SPIClass::dmaSendAsync ( const void transmitBuf,
uint16_t  length,
bool  minc = 1 
)

◆ misoPin()

uint8_t SPIClass::misoPin ( )

Return the number of the MISO (master in, slave out) pin.

◆ mosiPin()

uint8_t SPIClass::mosiPin ( )

Return the number of the MOSI (master out, slave in) pin.

◆ sckPin()

uint8_t SPIClass::sckPin ( )

Return the number of the SCK (serial clock) pin.

◆ nssPin()

uint8_t SPIClass::nssPin ( )

Return the number of the NSS (slave select) pin.

◆ c_dev()

spi_dev* SPIClass::c_dev ( )

Get a pointer to the underlying libmaple spi_dev for this HardwareSPI instance.

330 { return _currentSetting->spi_d; }

◆ dev()

spi_dev* SPIClass::dev ( )
332 { return _currentSetting->spi_d; }

◆ setModule()

void SPIClass::setModule ( int  spi_num)

Sets the number of the SPI peripheral to be used by this HardwareSPI instance.

Parameters
spi_numNumber of the SPI port. 1-2 in low density devices or 1-3 in high density devices.
341  {
342  _currentSetting = &_settings[spi_num - 1];// SPI channels are called 1 2 and 3 but the array is zero indexed

◆ send() [1/2]

uint8_t SPIClass::send ( uint8_t  data)

Deprecated.

Use HardwareSPI::transfer() instead.

See also
HardwareSPI::transfer()

◆ send() [2/2]

uint8_t SPIClass::send ( uint8_t data,
uint32_t  length 
)

Deprecated.

Use HardwareSPI::write() in combination with HardwareSPI::read() (or HardwareSPI::transfer()) instead.

See also
HardwareSPI::write()
HardwareSPI::read()
HardwareSPI::transfer()

◆ recv()

uint8_t SPIClass::recv ( )

Deprecated.

Use HardwareSPI::read() instead.

See also
HardwareSPI::read()
settings
MarlinSettings settings
Definition: configuration_store.cpp:344
hspi1
SPI_HandleTypeDef hspi1
SPIClass::beginTransaction
void beginTransaction(SPISettings settings)
Definition: SPI.cpp:45
hal_status_to_retval
static uint16_t hal_status_to_retval(HAL_StatusTypeDef status)
Definition: SPI.cpp:28
BOARD_SPI_DEFAULT_SS
#define BOARD_SPI_DEFAULT_SS
Definition: SPI.h:77
HAL_SPI_Initialized
int HAL_SPI_Initialized
Definition: main.c:107
SPIClass::read
uint16_t read()
Return the next unread byte/word.
uint8_t
const uint8_t[]
Definition: 404_html.c:3
status
static status_t status
Definition: filament_sensor.c:37
SPI_TRANSFER_TIMEOUT
#define SPI_TRANSFER_TIMEOUT
Definition: SPI.h:47
HAL_SPI_Transmit
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
HAL_SPI_TransmitReceive
HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
length
png_uint_32 length
Definition: png.c:2247
SPI_NOT_INITIALIZED
Definition: SPI.cpp:14
SPIClass::dmaTransfer
uint8_t dmaTransfer(uint8_t *transmitBuf, uint8_t *receiveBuf, uint16_t length)
Definition: SPI.cpp:62