Updated I2C for ESP32 and added mutex protection for printable serial

This commit is contained in:
dario
2024-04-13 17:45:53 +02:00
parent 56de6ac3e2
commit c843aaf33f
5 changed files with 36 additions and 11 deletions

View File

@@ -6,13 +6,18 @@
#include <sta/bus/i2c/device.hpp>
#include <sta/bus/i2c/i2c.hpp>
#include <sta/mutex.hpp>
namespace sta
{
class ArduinoI2C : public I2C
{
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);
#else
ArduinoI2C(Mutex * mutex = nullptr);
#endif // STA_PLATFORM_ARDUINO_DEVICE_ESP32
void transfer(uint8_t value) override;
void transfer16(uint16_t value) override;

View File

@@ -3,8 +3,13 @@
#include <sta/devices/arduino/mcu/common.hpp>
#define STA_MCU_LITTLE_ENDIAN
#define STA_PLATFORM_ARDUINO_DEVICE_ESP32
#define STA_MCU_ESP32_S3
#define STA_ESP32_SCL_DEFAULT_PIN 22
#define STA_ESP32_SDA_DEFAULT_PIN 21
#endif // STA_CORE_ARDUINO_MCU_ESP32_S3_HPP

View File

@@ -4,15 +4,20 @@
#include <sta/debug/printing/printable.hpp>
#ifdef STA_PLATFORM_ARDUINO
#include <sta/mutex.hpp>
namespace sta
{
class PrintableSerial: public Printable
{
public:
/**
* @brief Construct a new Printable Serial object
* @brief Printable implementation for Arduino Serial printing.
*
* @param baud The baud rate for serial printing.
* @param mutex An optional mutex to protect the serial bus.
*/
PrintableSerial(unsigned long baud);
PrintableSerial(unsigned long baud, Mutex * mutex = nullptr);
/**
* @brief Print string.
@@ -21,6 +26,8 @@ namespace sta
* @param length String length
*/
void print(const char * str, size_t length) override;
private:
Mutex * mutex_;
};
} // namespace sta