Updated SPI for ESP32

This commit is contained in:
dario
2024-04-13 19:31:13 +02:00
parent c843aaf33f
commit f29cd6eff2
5 changed files with 97 additions and 25 deletions

View File

@@ -14,7 +14,7 @@ namespace sta
{
public:
#ifdef STA_PLATFORM_ARDUINO_DEVICE_ESP32
ArduinoI2C(Mutex * mutex = nullptr, uint8_t sda = STA_ESP32_SDA_DEFAULT_PIN, uint8_t scl = STA_ESP32_SCL_DEFAULT_PIN, uint32_t frequency = 0U);
ArduinoI2C(Mutex * mutex = nullptr, uint8_t sda = STA_ESP32_SDA_DEFAULT, uint8_t scl = STA_ESP32_SCL_DEFAULT, uint32_t frequency = 0U);
#else
ArduinoI2C(Mutex * mutex = nullptr);
#endif // STA_PLATFORM_ARDUINO_DEVICE_ESP32

View File

@@ -12,21 +12,67 @@
namespace sta
{
#ifdef STA_PLATFORM_ARDUINO_DEVICE_ESP32
#ifdef STA_PLATFORM_ARDUINO_DEVICE_ESP32
enum SPIBus
{
BUS_HSPI = HSPI,
BUS_FSPI = FSPI
# ifndef STA_MCU_ESP32_S3
, BUS_VSPI = VSPI
# endif // !STA_MCU_ESP32_S3
# endif // STA_MCU_ESP32_S3
};
#endif // STA_PLATFORM_ARDUINO_DEVICE_ESP32
class ArduinoSPI : public SPI
{
public:
#ifndef STA_PLATFORM_ARDUINO_DEVICE_ESP32
#ifdef STA_PLATFORM_ARDUINO_DEVICE_ESP32
/**
* @brief
*
* @param settings
* @param mutex
* @param mosi
* @param miso
* @param clk
* @return ArduinoSPI
*/
static ArduinoSPI getHSPI(
const SPISettings & settings,
Mutex * mutex = sta::Mutex::ALWAYS_FREE,
uint8_t mosi = STA_ESP32_HSPI_MOSI_DEFAULT,
uint8_t miso = STA_ESP32_HSPI_MISO_DEFAULT,
uint8_t clk = STA_ESP32_HSPI_CLK_DEFAULT);
/**
* @brief
*
* @param settings
* @param mutex
* @param mosi
* @param miso
* @param clk
* @return ArduinoSPI
*/
static ArduinoSPI getFSPI(
const SPISettings & settings,
Mutex * mutex = sta::Mutex::ALWAYS_FREE,
uint8_t mosi = STA_ESP32_HSPI_MOSI_DEFAULT,
uint8_t miso = STA_ESP32_HSPI_MISO_DEFAULT,
uint8_t clk = STA_ESP32_HSPI_CLK_DEFAULT);
private:
/**
* @brief Construct an SPI bus interface using the Arduino framework. This constructor is used for ESP32.
*
* @param settings The settings for the spi bus. s
* @param mosi The master-out-slave-in pin.
* @param miso The master-in-slave-out pin.
* @param clk The clock used for synchronizing the bus communication.
* @param bus The bus to use. One of HSPI or FSPI.
* @param mutex A mutex for managing bus access in multithreaded applications. Default is a dummy mutex that is always free.
*/
ArduinoSPI(const SPISettings & settings, SPIBus bus, uint8_t mosi, uint8_t miso, uint8_t clk, Mutex * mutex = sta::Mutex::ALWAYS_FREE);
#else
/**
* @brief Construct an SPI bus interface using the Arduino framework.
*
@@ -34,16 +80,8 @@ namespace sta
* @param mutex A mutex for managing bus access in multithreaded applications. Default is a dummy mutex that is always free.
*/
ArduinoSPI(const SPISettings & settings, Mutex * mutex = sta::Mutex::ALWAYS_FREE);
#else
/**
* @brief Construct an SPI bus interface using the Arduino framework.
*
* @param bus The bus to use.
* @param settings The settings for the spi bus.
* @param mutex A mutex for managing bus access in multithreaded applications. Default is a dummy mutex that is always free.
*/
ArduinoSPI(SPIBus bus, const SPISettings & settings, Mutex * mutex = sta::Mutex::ALWAYS_FREE);
#endif // !STA_PLATFORM_ARDUINO_DEVICE_ESP32
public:
void transfer(uint8_t value) override;
void transfer16(uint16_t value) override;
void transfer(const uint8_t * buffer, size_t size) override;