12#include "isobus/utility/to_string.hpp"
19 deviceConfig(deviceConfig),
20 hostDevice(hostDevice),
21 spiMutex(xSemaphoreCreateMutex()),
40 LOG_CRITICAL(
"[SPI-ESP] Failed to add SPI device: " + isobus::to_string(esp_err_to_name(error)));
43 return ESP_OK == error;
48 esp_err_t error = spi_bus_remove_device(
spiDevice);
51 LOG_ERROR(
"[SPI-ESP] Failed to remove SPI device: " + isobus::to_string(esp_err_to_name(error)));
53 if (ESP_ERR_INVALID_STATE == error || ESP_OK == error)
65 spi_transaction_t transaction;
66 std::memset(&transaction, 0,
sizeof(transaction));
77 transaction.rx_buffer =
nullptr;
80 esp_err_t error = spi_device_transmit(
spiDevice, &transaction);
84 LOG_WARNING(
"[SPI-ESP] Failed to transmit SPI transaction frame: " + isobus::to_string(esp_err_to_name(error)));
91 LOG_ERROR(
"[SPI-ESP] Failed to obtain SPI mutex in transmit().");
97 LOG_CRITICAL(
"[SPI-ESP] SPI device not initialized, pherhaps you forgot to call init()?");
A class that acts as a logging sink. The intent is that someone could make their own derived class of...
void transmit(SPITransactionFrame *frame) override
Write (and read) a frame to the SPI bus.
bool init()
Initialize the SPI device.
bool success
The status of the current transaction.
void deinit()
Deinitialize the SPI device.
bool end_transaction() override
End the transaction. This function returns the status since the last end_transaction().
virtual ~SPIInterfaceESP()
Destructor of a SPI device on an ESP platform.
const SemaphoreHandle_t spiMutex
A mutex to prevent concurrent access to the SPI bus.
bool initialized
The status of the device.
spi_device_handle_t spiDevice
A handle to the SPI device.
SPIInterfaceESP(const spi_device_interface_config_t *deviceConfig, const spi_host_device_t hostDevice)
Constructor of a SPI device on an ESP platform.
const spi_device_interface_config_t * deviceConfig
The configuration of the SPI device.
static constexpr std::uint32_t MAX_TIME_TO_WAIT
timeout of 5 seconds for spi related calls, mostly arbitrary.
const spi_host_device_t hostDevice
The host spi device.
A class containing the data for a single SPI transaction.
const std::vector< std::uint8_t > * get_tx_buffer() const
Get the buffer to transmit.
bool get_is_read() const
Get whether the interface should read the response to the write operation.
std::vector< std::uint8_t > & get_rx_buffer()
Get the buffer to store the response in.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
A (synchronous) implementation for SPI communication with (CAN) hardware devices on ESP platforms.