PL::SpiController class

class SpiController : public PL::Lockable

SPI controller class.

Public Functions

SpiController(std::shared_ptr<Spi> spi, uint8_t mode, int sclkFrequency, int csPin)

Creates an SPI controller.

Parameters:
  • spi – SPI interface

  • mode – SPI mode (0, 1, 2 or 3)

  • sclkFrequency – SCLK frequency in Hz

  • csPin – CS pin

virtual esp_err_t Lock(TickType_t timeout = portMAX_DELAY) override

Locks the object.

Parameters:

timeout – timeout in FreeRTOS ticks

Returns:

error code

virtual esp_err_t Unlock() override

Unlocks the object.

Returns:

error code

esp_err_t Initialize()

Initializes the controller.

Returns:

error code

esp_err_t Transaction(uint16_t command, uint64_t address, const void *writeData, void *readData, size_t dataSize)

Executes SPI controller transaction.

Parameters:
  • command – command bits

  • address – address bits

  • writeData – data bits to write to the target (can be NULL)

  • readData – data bits read from the target (can be NULL)

  • dataSize – data size in bits

Returns:

error code

esp_err_t SetNumberOfCommandBits(int numberOfCommandBits)

Sets the number of command bits (first written bits before read, may be called only before Initialize)

Parameters:

numberOfCommandBits – number of command bits (0..16)

esp_err_t SetNumberOfAddressBits(int numberOfAddressBits)

Sets the number of address bits (bits written after command bits before read, may be called only before Initialize)

Parameters:

numberOfAddressBits – number of address bits (0..64)

esp_err_t SetMaxSclkMisoDelay(int delay)

Sets the max delay between the SCLK edge and the valid MISO level (may be called only before Initialize)

Parameters:

delay – delay in ns