mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-03 17:31:55 +00:00
ESP32 support and changes to SPI to support ESP32
This commit is contained in:
parent
713e7b0da9
commit
027484ef5e
@ -8,14 +8,42 @@
|
|||||||
#include <sta/bus/spi/spi.hpp>
|
#include <sta/bus/spi/spi.hpp>
|
||||||
|
|
||||||
#include <sta/devices/arduino/gpio_pin.hpp>
|
#include <sta/devices/arduino/gpio_pin.hpp>
|
||||||
|
#include <sta/devices/arduino/hal.hpp>
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
|
#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_PLATFORM_ARDUINO_DEVICE_ESP32
|
||||||
|
|
||||||
class ArduinoSPI : public SPI
|
class ArduinoSPI : public SPI
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ArduinoSPI(const SPISettings & settings, Mutex * mutex = nullptr);
|
#ifndef STA_PLATFORM_ARDUINO_DEVICE_ESP32
|
||||||
|
/**
|
||||||
|
* @brief Construct an SPI bus interface using the Arduino framework.
|
||||||
|
*
|
||||||
|
* @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(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
|
||||||
void transfer(uint8_t value) override;
|
void transfer(uint8_t value) override;
|
||||||
void transfer16(uint16_t value) override;
|
void transfer16(uint16_t value) override;
|
||||||
void transfer(const uint8_t * buffer, size_t size) override;
|
void transfer(const uint8_t * buffer, size_t size) override;
|
||||||
@ -27,7 +55,7 @@ namespace sta
|
|||||||
void acquire() override;
|
void acquire() override;
|
||||||
void release() override;
|
void release() override;
|
||||||
private:
|
private:
|
||||||
|
SPIClass spi_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ArduinoSPIDevice : public SPIDevice
|
class ArduinoSPIDevice : public SPIDevice
|
||||||
|
10
include/sta/devices/arduino/mcu/esp32_s3.hpp
Normal file
10
include/sta/devices/arduino/mcu/esp32_s3.hpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef STA_CORE_ARDUINO_MCU_ESP32_S3_HPP
|
||||||
|
#define STA_CORE_ARDUINO_MCU_ESP32_S3_HPP
|
||||||
|
|
||||||
|
#include <sta/devices/arduino/mcu/common.hpp>
|
||||||
|
|
||||||
|
#define STA_PLATFORM_ARDUINO_DEVICE_ESP32
|
||||||
|
|
||||||
|
#define STA_MCU_ESP32_S3
|
||||||
|
|
||||||
|
#endif // STA_CORE_ARDUINO_MCU_ESP32_S3_HPP
|
@ -3,4 +3,6 @@
|
|||||||
|
|
||||||
#include <sta/devices/arduino/mcu/common.hpp>
|
#include <sta/devices/arduino/mcu/common.hpp>
|
||||||
|
|
||||||
|
#define STA_PLATFORM_ARDUINO_DEVICE_ARDUINO
|
||||||
|
|
||||||
#endif // STA_CORE_ARDUINO_MCU_UNO_R3_HPPs
|
#endif // STA_CORE_ARDUINO_MCU_UNO_R3_HPPs
|
@ -2,24 +2,32 @@
|
|||||||
|
|
||||||
#include <sta/lang.hpp>
|
#include <sta/lang.hpp>
|
||||||
|
|
||||||
#include <sta/devices/arduino/hal.hpp>
|
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
ArduinoSPI::ArduinoSPI(const SPISettings & settings, Mutex * mutex /* = nullptr */)
|
#ifndef STA_PLATFORM_ARDUINO_DEVICE_ESP32
|
||||||
: SPI{ settings, mutex }
|
ArduinoSPI::ArduinoSPI(const SPISettings & settings, Mutex * mutex /* = sta::Mutex::ALWAYS_FREE */)
|
||||||
|
: SPI{ settings, mutex },
|
||||||
|
spi_{}
|
||||||
{
|
{
|
||||||
SPIClass::begin();
|
spi_.begin();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
ArduinoSPI::ArduinoSPI(SPIBus bus, const SPISettings & settings, Mutex * mutex /* = sta::Mutex::ALWAYS_FREE */)
|
||||||
|
: SPI{ settings, mutex },
|
||||||
|
spi_{ bus }
|
||||||
|
{
|
||||||
|
spi_.begin();
|
||||||
|
}
|
||||||
|
#endif // !STA_PLATFORM_ARDUINO_DEVICE_ESP32
|
||||||
|
|
||||||
void ArduinoSPI::transfer(uint8_t value)
|
void ArduinoSPI::transfer(uint8_t value)
|
||||||
{
|
{
|
||||||
SPIClass::transfer(value);
|
spi_.transfer(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoSPI::transfer16(uint16_t value)
|
void ArduinoSPI::transfer16(uint16_t value)
|
||||||
{
|
{
|
||||||
SPIClass::transfer16(value);
|
spi_.transfer16(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoSPI::transfer(const uint8_t * buffer, size_t size)
|
void ArduinoSPI::transfer(const uint8_t * buffer, size_t size)
|
||||||
@ -28,7 +36,7 @@ namespace sta
|
|||||||
uint8_t temp_buffer[size];
|
uint8_t temp_buffer[size];
|
||||||
memcpy(temp_buffer, buffer, size);
|
memcpy(temp_buffer, buffer, size);
|
||||||
|
|
||||||
SPIClass::transfer(temp_buffer, size);
|
spi_.transfer(temp_buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoSPI::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size)
|
void ArduinoSPI::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size)
|
||||||
@ -36,12 +44,12 @@ namespace sta
|
|||||||
// Copy txBuffer content into rxBuffer, SPIClass::transfer will store received values in rxBuffer.
|
// Copy txBuffer content into rxBuffer, SPIClass::transfer will store received values in rxBuffer.
|
||||||
memcpy(rxBuffer, txBuffer, size);
|
memcpy(rxBuffer, txBuffer, size);
|
||||||
|
|
||||||
SPIClass::transfer(rxBuffer, size);
|
spi_.transfer(rxBuffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoSPI::receive(uint8_t * buffer, size_t size)
|
void ArduinoSPI::receive(uint8_t * buffer, size_t size)
|
||||||
{
|
{
|
||||||
SPIClass::transfer(buffer, size);
|
spi_.transfer(buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoSPI::fill(uint8_t value, size_t count)
|
void ArduinoSPI::fill(uint8_t value, size_t count)
|
||||||
@ -49,7 +57,7 @@ namespace sta
|
|||||||
uint8_t temp_buffer[count];
|
uint8_t temp_buffer[count];
|
||||||
memset(temp_buffer, value, count);
|
memset(temp_buffer, value, count);
|
||||||
|
|
||||||
SPIClass::transfer(temp_buffer, count);
|
spi_.transfer(temp_buffer, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoSPI::acquire()
|
void ArduinoSPI::acquire()
|
||||||
@ -94,12 +102,12 @@ namespace sta
|
|||||||
|
|
||||||
hal::SPISettings halSettings(set.clkSpeed, bitOrder, dataMode);
|
hal::SPISettings halSettings(set.clkSpeed, bitOrder, dataMode);
|
||||||
|
|
||||||
SPIClass::beginTransaction(halSettings);
|
spi_.beginTransaction(halSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoSPI::release()
|
void ArduinoSPI::release()
|
||||||
{
|
{
|
||||||
SPIClass::endTransaction();
|
spi_.endTransaction();
|
||||||
|
|
||||||
SPI::release();
|
SPI::release();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user