Added STM32 platform for debugging and development

This commit is contained in:
Emanuele Trabattoni
2025-06-27 18:55:20 +02:00
parent 01db0e543f
commit 3d2d44c0bb
9 changed files with 171 additions and 94 deletions

View File

@@ -17,7 +17,7 @@ namespace drivers
const bool I2C::read(const uint8_t deviceAddr, const uint8_t deviceReg, const uint8_t len, std::vector<uint8_t> &data)
{
busy.try_lock();
//busy.try_lock();
Wire.beginTransmission(deviceAddr);
Wire.write(deviceReg);
switch (Wire.endTransmission(true))
@@ -25,19 +25,19 @@ namespace drivers
case 0:
break; // no error, break switch
case 1:
log_e("Data to long to fit in buffer: [%d]", len);
LOG_ERROR("Data to long to fit in buffer: [%d]", len);
case 2:
log_e("Received NAK on address transmit");
LOG_ERROR("Received NAK on address transmit");
case 3:
log_e("Received NAK on data transmit");
LOG_ERROR("Received NAK on data transmit");
case 4:
log_e("Unknown Error");
LOG_ERROR("Unknown Error");
return false;
}
const uint8_t nBytes = Wire.requestFrom(deviceAddr, len);
if (nBytes < len)
{
log_w("Received data is less than expected: len[%d], nBytes[%d]", len, nBytes);
LOG_ERROR("Received data is less than expected: len[%d], nBytes[%d]", len, nBytes);
}
data.clear();
data.resize(nBytes); // resize out buffer to received data len, no check if data len is correct
@@ -45,13 +45,13 @@ namespace drivers
{
data[i] = static_cast<uint8_t>(Wire.read());
}
busy.unlock();
//busy.unlock();
return true;
}
const bool I2C::write(const uint8_t deviceAddr, const uint8_t deviceReg, const std::vector<uint8_t> &data)
{
busy.lock();
//busy.lock();
Wire.beginTransmission(deviceAddr);
Wire.write(deviceReg);
for (auto d : data)
@@ -64,16 +64,16 @@ namespace drivers
case 0:
break; // no error, break switch
case 1:
log_e("Data to long to fit in buffer: [%d]", data.size());
LOG_ERROR("Data to long to fit in buffer: [%d]", data.size());
case 2:
log_e("Received NAK on address transmit");
LOG_ERROR("Received NAK on address transmit");
case 3:
log_e("Received NAK on data transmit");
LOG_ERROR("Received NAK on data transmit");
case 4:
log_e("Unknown Error");
LOG_ERROR("Unknown Error");
return false;
}
busy.unlock();
//busy.unlock();
return true;
}

View File

@@ -1,4 +1,7 @@
#pragma once
#include <DebugLog.h>
#include <Arduino.h>
#include <Wire.h>
#include <vector>
#include <mutex>
@@ -13,7 +16,7 @@ namespace drivers
{
private:
bool isInitialized = false;
std::mutex busy;
//std::mutex busy;
public:
I2C(void);