New logging and more (#446)
- `TT_LOG_*` macros are replaced by `Logger` via `#include<Tactility/Logger.h>` - Changed default timezone to Europe/Amsterdam - Fix for logic bug in unPhone hardware - Fix for init/deinit in DRV2605 driver - Other fixes - Removed optimization that broke unPhone (disabled the moving of heap-related functions to flash)
This commit is contained in:
committed by
GitHub
parent
719f7bcece
commit
f620255c41
@@ -1,6 +1,6 @@
|
||||
#include <Tactility/hal/Device.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/RecursiveMutex.h>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -10,7 +10,7 @@ std::vector<std::shared_ptr<Device>> devices;
|
||||
RecursiveMutex mutex;
|
||||
static Device::Id nextId = 0;
|
||||
|
||||
constexpr auto TAG = "devices";
|
||||
static const auto LOGGER = Logger("Devices");
|
||||
|
||||
Device::Device() : id(nextId++) {}
|
||||
|
||||
@@ -26,9 +26,9 @@ void registerDevice(const std::shared_ptr<Device>& device) {
|
||||
|
||||
if (findDevice(device->getId()) == nullptr) {
|
||||
devices.push_back(device);
|
||||
TT_LOG_I(TAG, "Registered %s with id %lu", device->getName().c_str(), device->getId());
|
||||
LOGGER.info("Registered {} with id {}", device->getName(), device->getId());
|
||||
} else {
|
||||
TT_LOG_W(TAG, "Device %s with id %lu was already registered", device->getName().c_str(), device->getId());
|
||||
LOGGER.warn("Device {} with id {} was already registered", device->getName(), device->getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ void deregisterDevice(const std::shared_ptr<Device>& device) {
|
||||
return device->getId() == id_to_remove;
|
||||
});
|
||||
if (remove_iterator != devices.end()) {
|
||||
TT_LOG_I(TAG, "Deregistering %s with id %lu", device->getName().c_str(), device->getId());
|
||||
LOGGER.info("Deregistering {} with id {}", device->getName(), device->getId());
|
||||
devices.erase(remove_iterator);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "Deregistering %s with id %lu failed: not found", device->getName().c_str(), device->getId());
|
||||
LOGGER.warn("Deregistering {} with id {} failed: not found", device->getName(), device->getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "Tactility/Tactility.h"
|
||||
#include "Tactility/hal/Configuration.h"
|
||||
#include "Tactility/hal/Device.h"
|
||||
#include "Tactility/hal/gps/GpsInit.h"
|
||||
#include "Tactility/hal/i2c/I2cInit.h"
|
||||
#include "Tactility/hal/power/PowerDevice.h"
|
||||
#include "Tactility/hal/spi/SpiInit.h"
|
||||
#include "Tactility/hal/uart/UartInit.h"
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <Tactility/hal/Device.h>
|
||||
#include <Tactility/hal/gps/GpsInit.h>
|
||||
#include <Tactility/hal/i2c/I2cInit.h>
|
||||
#include <Tactility/hal/power/PowerDevice.h>
|
||||
#include <Tactility/hal/spi/SpiInit.h>
|
||||
#include <Tactility/hal/uart/UartInit.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <Tactility/hal/sdcard/SdCardMounting.h>
|
||||
@@ -14,10 +15,10 @@
|
||||
|
||||
namespace tt::hal {
|
||||
|
||||
constexpr auto* TAG = "Hal";
|
||||
static const auto LOGGER = Logger("Hal");
|
||||
|
||||
void registerDevices(const Configuration& configuration) {
|
||||
TT_LOG_I(TAG, "Registering devices");
|
||||
LOGGER.info("Registering devices");
|
||||
|
||||
auto devices = configuration.createDevices();
|
||||
for (auto& device : devices) {
|
||||
@@ -36,27 +37,27 @@ void registerDevices(const Configuration& configuration) {
|
||||
}
|
||||
|
||||
static void startDisplays() {
|
||||
TT_LOG_I(TAG, "Starting displays & touch");
|
||||
LOGGER.info("Starting displays & touch");
|
||||
auto displays = hal::findDevices<display::DisplayDevice>(Device::Type::Display);
|
||||
for (auto& display : displays) {
|
||||
TT_LOG_I(TAG, "%s starting", display->getName().c_str());
|
||||
LOGGER.info("{} starting", display->getName());
|
||||
if (!display->start()) {
|
||||
TT_LOG_E(TAG, "%s start failed", display->getName().c_str());
|
||||
LOGGER.error("{} start failed", display->getName());
|
||||
} else {
|
||||
TT_LOG_I(TAG, "%s started", display->getName().c_str());
|
||||
LOGGER.info("{} started", display->getName());
|
||||
|
||||
if (display->supportsBacklightDuty()) {
|
||||
TT_LOG_I(TAG, "Setting backlight");
|
||||
LOGGER.info("Setting backlight");
|
||||
display->setBacklightDuty(0);
|
||||
}
|
||||
|
||||
auto touch = display->getTouchDevice();
|
||||
if (touch != nullptr) {
|
||||
TT_LOG_I(TAG, "%s starting", touch->getName().c_str());
|
||||
LOGGER.info("{} starting", touch->getName());
|
||||
if (!touch->start()) {
|
||||
TT_LOG_E(TAG, "%s start failed", touch->getName().c_str());
|
||||
LOGGER.error("{} start failed", touch->getName());
|
||||
} else {
|
||||
TT_LOG_I(TAG, "%s started", touch->getName().c_str());
|
||||
LOGGER.info("{} started", touch->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +80,7 @@ void init(const Configuration& configuration) {
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootInitUartEnd);
|
||||
|
||||
if (configuration.initBoot != nullptr) {
|
||||
TT_LOG_I(TAG, "Init power");
|
||||
LOGGER.info("Init power");
|
||||
tt_check(configuration.initBoot(), "Init power failed");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <Tactility/hal/gps/GpsInit.h>
|
||||
#include <Tactility/hal/gps/Probe.h>
|
||||
#include <Tactility/hal/uart/Uart.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <minmea.h>
|
||||
@@ -10,24 +10,25 @@
|
||||
namespace tt::hal::gps {
|
||||
|
||||
constexpr uint32_t GPS_UART_BUFFER_SIZE = 256;
|
||||
constexpr const char* TAG = "GpsDevice";
|
||||
|
||||
static const auto LOGGER = Logger("GpsDevice");
|
||||
|
||||
int32_t GpsDevice::threadMain() {
|
||||
uint8_t buffer[GPS_UART_BUFFER_SIZE];
|
||||
|
||||
auto uart = uart::open(configuration.uartName);
|
||||
if (uart == nullptr) {
|
||||
TT_LOG_E(TAG, "Failed to open UART %s", configuration.uartName);
|
||||
LOGGER.error("Failed to open UART {}", configuration.uartName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!uart->start()) {
|
||||
TT_LOG_E(TAG, "Failed to start UART %s", configuration.uartName);
|
||||
LOGGER.error("Failed to start UART {}", configuration.uartName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!uart->setBaudRate((int)configuration.baudRate)) {
|
||||
TT_LOG_E(TAG, "Failed to set baud rate to %lu for UART %s", configuration.baudRate, configuration.uartName);
|
||||
if (!uart->setBaudRate(static_cast<int>(configuration.baudRate))) {
|
||||
LOGGER.error("Failed to set baud rate to {} for UART {}", configuration.baudRate, configuration.uartName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -35,7 +36,7 @@ int32_t GpsDevice::threadMain() {
|
||||
if (model == GpsModel::Unknown) {
|
||||
model = probe(*uart);
|
||||
if (model == GpsModel::Unknown) {
|
||||
TT_LOG_E(TAG, "Probe failed");
|
||||
LOGGER.error("Probe failed");
|
||||
setState(State::Error);
|
||||
return -1;
|
||||
}
|
||||
@@ -45,7 +46,7 @@ int32_t GpsDevice::threadMain() {
|
||||
mutex.unlock();
|
||||
|
||||
if (!init(*uart, model)) {
|
||||
TT_LOG_E(TAG, "Init failed");
|
||||
LOGGER.error("Init failed");
|
||||
setState(State::Error);
|
||||
return -1;
|
||||
}
|
||||
@@ -63,7 +64,7 @@ int32_t GpsDevice::threadMain() {
|
||||
|
||||
if (bytes_read > 0U) {
|
||||
|
||||
TT_LOG_I(TAG, "[%ul] %s", bytes_read, buffer);
|
||||
LOGGER.info("[{}] {}", bytes_read, reinterpret_cast<const char*>(buffer));
|
||||
|
||||
switch (minmea_sentence_id((char*)buffer, false)) {
|
||||
case MINMEA_SENTENCE_RMC:
|
||||
@@ -74,9 +75,11 @@ int32_t GpsDevice::threadMain() {
|
||||
(*subscription.onData)(getId(), rmc_frame);
|
||||
}
|
||||
mutex.unlock();
|
||||
TT_LOG_D(TAG, "RMC %f lat, %f lon, %f m/s", minmea_tocoord(&rmc_frame.latitude), minmea_tocoord(&rmc_frame.longitude), minmea_tofloat(&rmc_frame.speed));
|
||||
if (LOGGER.isLoggingDebug()) {
|
||||
LOGGER.debug("RMC {} lat, {} lon, {} m/s", minmea_tocoord(&rmc_frame.latitude), minmea_tocoord(&rmc_frame.longitude), minmea_tofloat(&rmc_frame.speed));
|
||||
}
|
||||
} else {
|
||||
TT_LOG_W(TAG, "RMC parse error: %s", buffer);
|
||||
LOGGER.error("RMC parse error: {}", reinterpret_cast<const char*>(buffer));
|
||||
}
|
||||
break;
|
||||
case MINMEA_SENTENCE_GGA:
|
||||
@@ -87,9 +90,11 @@ int32_t GpsDevice::threadMain() {
|
||||
(*subscription.onData)(getId(), gga_frame);
|
||||
}
|
||||
mutex.unlock();
|
||||
TT_LOG_D(TAG, "GGA %f lat, %f lon", minmea_tocoord(&gga_frame.latitude), minmea_tocoord(&gga_frame.longitude));
|
||||
if (LOGGER.isLoggingDebug()) {
|
||||
LOGGER.debug("GGA {} lat, {} lon", minmea_tocoord(&gga_frame.latitude), minmea_tocoord(&gga_frame.longitude));
|
||||
}
|
||||
} else {
|
||||
TT_LOG_W(TAG, "GGA parse error: %s", buffer);
|
||||
LOGGER.error("GGA parse error: {}", reinterpret_cast<const char*>(buffer));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -99,7 +104,7 @@ int32_t GpsDevice::threadMain() {
|
||||
}
|
||||
|
||||
if (uart->isStarted() && !uart->stop()) {
|
||||
TT_LOG_W(TAG, "Failed to stop UART %s", configuration.uartName);
|
||||
LOGGER.warn("Failed to stop UART {}", configuration.uartName);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -110,13 +115,13 @@ bool GpsDevice::start() {
|
||||
lock.lock();
|
||||
|
||||
if (thread != nullptr && thread->getState() != Thread::State::Stopped) {
|
||||
TT_LOG_W(TAG, "Already started");
|
||||
LOGGER.warn("Already started");
|
||||
return true;
|
||||
}
|
||||
|
||||
threadInterrupted = false;
|
||||
|
||||
TT_LOG_I(TAG, "Starting thread");
|
||||
LOGGER.info("Starting thread");
|
||||
setState(State::PendingOn);
|
||||
|
||||
thread = std::make_unique<Thread>(
|
||||
@@ -129,7 +134,7 @@ bool GpsDevice::start() {
|
||||
thread->setPriority(tt::Thread::Priority::High);
|
||||
thread->start();
|
||||
|
||||
TT_LOG_I(TAG, "Starting finished");
|
||||
LOGGER.info("Starting finished");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
#include <Tactility/hal/gps/GpsDevice.h>
|
||||
#include <Tactility/hal/gps/Ublox.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace tt::hal::gps {
|
||||
|
||||
constexpr auto TAG = "gps";
|
||||
static const auto LOGGER = Logger("Gps");
|
||||
|
||||
bool initMtk(uart::Uart& uart);
|
||||
bool initMtkL76b(uart::Uart& uart);
|
||||
@@ -112,7 +112,7 @@ GpsResponse getACKCas(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32
|
||||
// Check for an ACK-ACK for the specified class and message id
|
||||
if ((msg_cls == 0x05) && (msg_msg_id == 0x01) && payload_cls == class_id && payload_msg == msg_id) {
|
||||
#ifdef GPS_DEBUG
|
||||
LOG_INFO("Got ACK for class %02X message %02X in %dms", class_id, msg_id, millis() - startTime);
|
||||
LOGGER.info("Got ACK for class {:02X} message {:02X} in {} ms", class_id, msg_id, kernel::getMillis() - startTime);
|
||||
#endif
|
||||
return GpsResponse::Ok;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ GpsResponse getACKCas(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32
|
||||
// Check for an ACK-NACK for the specified class and message id
|
||||
if ((msg_cls == 0x05) && (msg_msg_id == 0x00) && payload_cls == class_id && payload_msg == msg_id) {
|
||||
#ifdef GPS_DEBUG
|
||||
LOG_WARN("Got NACK for class %02X message %02X in %dms", class_id, msg_id, millis() - startTime);
|
||||
LOGGER.warn("Got NACK for class {:02X} message {:02X} in {} ms", class_id, msg_id, millis() - startTime);
|
||||
#endif
|
||||
return GpsResponse::NotAck;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ bool init(uart::Uart& uart, GpsModel type) {
|
||||
return initUc6580(uart);
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Init not implemented %d", static_cast<int>(type));
|
||||
LOGGER.info("Init not implemented {}", static_cast<int>(type));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -213,14 +213,14 @@ bool initAtgm336h(uart::Uart& uart) {
|
||||
int msglen = makeCASPacket(buffer, 0x06, 0x07, sizeof(_message_CAS_CFG_NAVX_CONF), _message_CAS_CFG_NAVX_CONF);
|
||||
uart.writeBytes(buffer, msglen);
|
||||
if (getACKCas(uart, 0x06, 0x07, 250) != GpsResponse::Ok) {
|
||||
TT_LOG_W(TAG, "ATGM336H: Could not set Config");
|
||||
LOGGER.warn("ATGM336H: Could not set Config");
|
||||
}
|
||||
|
||||
// Set the update frequence to 1Hz
|
||||
msglen = makeCASPacket(buffer, 0x06, 0x04, sizeof(_message_CAS_CFG_RATE_1HZ), _message_CAS_CFG_RATE_1HZ);
|
||||
uart.writeBytes(buffer, msglen);
|
||||
if (getACKCas(uart, 0x06, 0x04, 250) != GpsResponse::Ok) {
|
||||
TT_LOG_W(TAG, "ATGM336H: Could not set Update Frequency");
|
||||
LOGGER.warn("ATGM336H: Could not set Update Frequency");
|
||||
}
|
||||
|
||||
// Set the NEMA output messages
|
||||
@@ -232,7 +232,7 @@ bool initAtgm336h(uart::Uart& uart) {
|
||||
msglen = makeCASPacket(buffer, 0x06, 0x01, sizeof(cas_cfg_msg_packet), cas_cfg_msg_packet);
|
||||
uart.writeBytes(buffer, msglen);
|
||||
if (getACKCas(uart, 0x06, 0x01, 250) != GpsResponse::Ok) {
|
||||
TT_LOG_W(TAG, "ATGM336H: Could not enable NMEA MSG: %d", fields[i]);
|
||||
LOGGER.warn("ATGM336H: Could not enable NMEA MSG: {}", fields[i]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "Tactility/hal/gps/GpsDevice.h"
|
||||
#include "Tactility/hal/gps/Ublox.h"
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/hal/uart/Uart.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#define TAG "gps"
|
||||
static const auto LOGGER = tt::Logger("Gps");
|
||||
|
||||
#define GPS_UART_BUFFER_SIZE 256
|
||||
|
||||
using namespace tt;
|
||||
@@ -59,13 +61,13 @@ GpsResponse getAck(uart::Uart& uart, const char* message, uint32_t waitMillis) {
|
||||
if ((bytesRead == 767) || (b == '\r')) {
|
||||
if (strnstr((char*)buffer, message, bytesRead) != nullptr) {
|
||||
#ifdef GPS_DEBUG
|
||||
LOG_DEBUG("Found: %s", message); // Log the found message
|
||||
LOGGER.debug("Found: {}", message); // Log the found message
|
||||
#endif
|
||||
return GpsResponse::Ok;
|
||||
} else {
|
||||
bytesRead = 0;
|
||||
#ifdef GPS_DEBUG
|
||||
LOG_DEBUG(debugmsg.c_str());
|
||||
LOGGER.debug("{}", debugmsg);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -77,15 +79,15 @@ GpsResponse getAck(uart::Uart& uart, const char* message, uint32_t waitMillis) {
|
||||
/**
|
||||
* From: https://github.com/meshtastic/firmware/blob/f81d3b045dd1b7e3ca7870af3da915ff4399ea98/src/gps/GPS.cpp
|
||||
*/
|
||||
#define PROBE_SIMPLE(UART, CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \
|
||||
do { \
|
||||
TT_LOG_I(TAG, "Probing for %s (%s)", CHIP, TOWRITE); \
|
||||
UART.flushInput(); \
|
||||
UART.writeString(TOWRITE "\r\n", TIMEOUT); \
|
||||
if (getAck(UART, RESPONSE, TIMEOUT) == GpsResponse::Ok) { \
|
||||
TT_LOG_I(TAG, "Probe detected %s %s", CHIP, #DRIVER); \
|
||||
return DRIVER; \
|
||||
} \
|
||||
#define PROBE_SIMPLE(UART, CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \
|
||||
do { \
|
||||
LOGGER.info("Probing for {} ({})", CHIP, TOWRITE); \
|
||||
UART.flushInput(); \
|
||||
UART.writeString(TOWRITE "\r\n", TIMEOUT); \
|
||||
if (getAck(UART, RESPONSE, TIMEOUT) == GpsResponse::Ok) { \
|
||||
LOGGER.info("Probe detected {} {}", CHIP, #DRIVER); \
|
||||
return DRIVER; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
@@ -132,7 +134,7 @@ GpsModel probe(uart::Uart& uart) {
|
||||
if (ublox_result != GpsModel::Unknown) {
|
||||
return ublox_result;
|
||||
} else {
|
||||
TT_LOG_W(TAG, "No GNSS Module (baudrate %lu)", uart.getBaudRate());
|
||||
LOGGER.warn("No GNSS Module (baud rate {})", uart.getBaudRate());
|
||||
return GpsModel::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
#include <Tactility/hal/gps/Satellites.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
namespace tt::hal::gps {
|
||||
|
||||
constexpr auto TAG = "Satellites";
|
||||
static const auto LOGGER = Logger("Satellites");
|
||||
|
||||
constexpr bool hasTimeElapsed(TickType_t now, TickType_t timeInThePast, TickType_t expireTimeInTicks) {
|
||||
return (TickType_t)(now - timeInThePast) >= expireTimeInTicks;
|
||||
@@ -35,7 +33,9 @@ SatelliteStorage::SatelliteRecord* SatelliteStorage::findUnusedRecord() {
|
||||
if (!result.empty()) {
|
||||
auto* record = &result.front();
|
||||
record->inUse = true;
|
||||
TT_LOG_D(TAG, "Found unused record");
|
||||
if (LOGGER.isLoggingDebug()) {
|
||||
LOGGER.debug("Found unused record");
|
||||
}
|
||||
return record;
|
||||
} else {
|
||||
return nullptr;
|
||||
@@ -53,7 +53,9 @@ SatelliteStorage::SatelliteRecord* SatelliteStorage::findRecordToRecycle() {
|
||||
for (int i = 0; i < records.size(); ++i) {
|
||||
// First try to find a record that is "old enough"
|
||||
if (hasTimeElapsed(now, records[i].lastUpdated, expire_duration)) {
|
||||
TT_LOG_D(TAG, "! [%d] %lu < %lu", i, records[i].lastUpdated, expire_duration);
|
||||
if (LOGGER.isLoggingDebug()) {
|
||||
LOGGER.debug("! [{}] {} < {}", i, records[i].lastUpdated, expire_duration);
|
||||
}
|
||||
candidate_index = i;
|
||||
break;
|
||||
}
|
||||
@@ -62,13 +64,17 @@ SatelliteStorage::SatelliteRecord* SatelliteStorage::findRecordToRecycle() {
|
||||
if (records[i].inUse && records[i].lastUpdated < candidate_age) {
|
||||
candidate_index = i;
|
||||
candidate_age = records[i].lastUpdated;
|
||||
TT_LOG_D(TAG, "? [%d] %lu < %lu", i, records[i].lastUpdated, candidate_age);
|
||||
if (LOGGER.isLoggingDebug()) {
|
||||
LOGGER.debug("? [{}] {} < {}", i, records[i].lastUpdated, candidate_age);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert(candidate_index != -1);
|
||||
|
||||
TT_LOG_D(TAG, "Recycled record %d", candidate_index);
|
||||
if (LOGGER.isLoggingDebug()) {
|
||||
LOGGER.debug("Recycled record {}", candidate_index);
|
||||
}
|
||||
|
||||
return &records[candidate_index];
|
||||
}
|
||||
@@ -95,7 +101,9 @@ void SatelliteStorage::notify(const minmea_sat_info& data) {
|
||||
record->inUse = true;
|
||||
record->lastUpdated = kernel::getTicks();
|
||||
record->data = data;
|
||||
TT_LOG_D(TAG, "Updated satellite %d: elevation %d, azimuth %d, snr %d", record->data.nr, record->data.elevation, record->data.elevation, record->data.snr);
|
||||
if (LOGGER.isLoggingDebug()) {
|
||||
LOGGER.debug("Updated satellite {}: elevation {}, azimuth {}, snr {}", record->data.nr, record->data.elevation, record->data.elevation, record->data.snr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#include <Tactility/hal/gps/UbloxMessages.h>
|
||||
#include <Tactility/hal/uart/Uart.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace tt::hal::gps::ublox {
|
||||
|
||||
constexpr auto TAG = "ublox";
|
||||
static const auto LOGGER = Logger("Ublox");
|
||||
|
||||
bool initUblox6(uart::Uart& uart);
|
||||
bool initUblox789(uart::Uart& uart, GpsModel model);
|
||||
@@ -19,7 +19,7 @@ bool initUblox10(uart::Uart& uart);
|
||||
auto msglen = makePacket(TYPE, ID, DATA, sizeof(DATA), BUFFER); \
|
||||
UART.writeBytes(BUFFER, sizeof(BUFFER)); \
|
||||
if (getAck(UART, TYPE, ID, TIMEOUT) != GpsResponse::Ok) { \
|
||||
TT_LOG_I(TAG, "Sending packet failed: %s", #ERRMSG); \
|
||||
LOGGER.info("Sending packet failed: {}", #ERRMSG); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -82,7 +82,7 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
|
||||
while (kernel::getTicks() - startTime < waitMillis) {
|
||||
if (ack > 9) {
|
||||
#ifdef GPS_DEBUG
|
||||
TT_LOG_I(TAG, "Got ACK for class %02X message %02X in %lums", class_id, msg_id, kernel::getMillis() - startTime);
|
||||
LOGGER.info("Got ACK for class {:02X} message {:02X} in {}ms", class_id, msg_id, kernel::getMillis() - startTime);
|
||||
#endif
|
||||
return GpsResponse::Ok; // ACK received
|
||||
}
|
||||
@@ -93,7 +93,7 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
|
||||
if (sCounter == 26) {
|
||||
#ifdef GPS_DEBUG
|
||||
|
||||
TT_LOG_I(TAG, "%s", debugmsg.c_str());
|
||||
LOGGER.info("%s", debugmsg.c_str());
|
||||
#endif
|
||||
return GpsResponse::FrameErrors;
|
||||
}
|
||||
@@ -108,9 +108,9 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
|
||||
} else {
|
||||
if (ack == 3 && b == 0x00) { // UBX-ACK-NAK message
|
||||
#ifdef GPS_DEBUG
|
||||
TT_LOG_I(TAG, "%s", debugmsg.c_str());
|
||||
LOGGER.info("%s", debugmsg.c_str());
|
||||
#endif
|
||||
TT_LOG_W(TAG, "Got NAK for class %02X message %02X", class_id, msg_id);
|
||||
LOGGER.warn("Got NAK for class {:02X} message {:02X}", class_id, msg_id);
|
||||
return GpsResponse::NotAck; // NAK received
|
||||
}
|
||||
ack = 0; // Reset the acknowledgement counter
|
||||
@@ -118,8 +118,8 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
|
||||
}
|
||||
}
|
||||
#ifdef GPS_DEBUG
|
||||
TT_LOG_I(TAG, "%s", debugmsg.c_str());
|
||||
TT_LOG_W(TAG, "No response for class %02X message %02X", class_id, msg_id);
|
||||
LOGGER.info("%s", debugmsg.c_str());
|
||||
LOGGER.warn("No response for class %02X message %02X", class_id, msg_id);
|
||||
#endif
|
||||
return GpsResponse::None; // No response received within timeout
|
||||
}
|
||||
@@ -180,7 +180,7 @@ static int getAck(uart::Uart& uart, uint8_t* buffer, uint16_t size, uint8_t requ
|
||||
} else {
|
||||
// return payload length
|
||||
#ifdef GPS_DEBUG
|
||||
TT_LOG_I(TAG, "Got ACK for class %02X message %02X in %lums", requestedClass, requestedId, kernel::getMillis() - startTime);
|
||||
LOGGER.info("Got ACK for class {:02X} message {:02X} in {}ms", requestedClass, requestedId, kernel::getMillis() - startTime);
|
||||
#endif
|
||||
return needRead;
|
||||
}
|
||||
@@ -195,8 +195,6 @@ static int getAck(uart::Uart& uart, uint8_t* buffer, uint16_t size, uint8_t requ
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define DETECTED_MESSAGE "%s detected, using %s Module"
|
||||
|
||||
static struct uBloxGnssModelInfo {
|
||||
char swVersion[30];
|
||||
char hwVersion[10];
|
||||
@@ -206,7 +204,8 @@ static struct uBloxGnssModelInfo {
|
||||
} ublox_info;
|
||||
|
||||
GpsModel probe(uart::Uart& uart) {
|
||||
TT_LOG_I(TAG, "Probing for U-blox");
|
||||
LOGGER.info("Probing for U-blox");
|
||||
constexpr auto DETECTED_MESSAGE = "{} detected, using {} Module";
|
||||
|
||||
uint8_t cfg_rate[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00};
|
||||
checksum(cfg_rate, sizeof(cfg_rate));
|
||||
@@ -215,10 +214,10 @@ GpsModel probe(uart::Uart& uart) {
|
||||
// Check that the returned response class and message ID are correct
|
||||
GpsResponse response = getAck(uart, 0x06, 0x08, 750);
|
||||
if (response == GpsResponse::None) {
|
||||
TT_LOG_W(TAG, "No GNSS Module (baudrate %lu)", uart.getBaudRate());
|
||||
LOGGER.warn("No GNSS Module (baudrate {})", uart.getBaudRate());
|
||||
return GpsModel::Unknown;
|
||||
} else if (response == GpsResponse::FrameErrors) {
|
||||
TT_LOG_W(TAG, "UBlox Frame Errors (baudrate %lu)", uart.getBaudRate());
|
||||
LOGGER.warn("UBlox Frame Errors (baudrate {})", uart.getBaudRate());
|
||||
}
|
||||
|
||||
uint8_t buffer[256];
|
||||
@@ -256,12 +255,12 @@ GpsModel probe(uart::Uart& uart) {
|
||||
break;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Module Info : ");
|
||||
TT_LOG_I(TAG, "Soft version: %s", ublox_info.swVersion);
|
||||
TT_LOG_I(TAG, "Hard version: %s", ublox_info.hwVersion);
|
||||
TT_LOG_I(TAG, "Extensions:%d", ublox_info.extensionNo);
|
||||
LOGGER.info("Module Info:");
|
||||
LOGGER.info("Soft version: {}", ublox_info.swVersion);
|
||||
LOGGER.info("Hard version: {}", ublox_info.hwVersion);
|
||||
LOGGER.info("Extensions: {}", ublox_info.extensionNo);
|
||||
for (int i = 0; i < ublox_info.extensionNo; i++) {
|
||||
TT_LOG_I(TAG, " %s", ublox_info.extension[i]);
|
||||
LOGGER.info(" %s", ublox_info.extension[i]);
|
||||
}
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
@@ -274,29 +273,29 @@ GpsModel probe(uart::Uart& uart) {
|
||||
char* ptr = nullptr;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
strncpy((char*)buffer, &(ublox_info.extension[i][8]), sizeof(buffer));
|
||||
TT_LOG_I(TAG, "Protocol Version:%s", (char*)buffer);
|
||||
LOGGER.info("Protocol Version: {}", (char*)buffer);
|
||||
if (strlen((char*)buffer)) {
|
||||
ublox_info.protocol_version = strtoul((char*)buffer, &ptr, 10);
|
||||
TT_LOG_I(TAG, "ProtVer=%d", ublox_info.protocol_version);
|
||||
LOGGER.info("ProtVer={}", ublox_info.protocol_version);
|
||||
} else {
|
||||
ublox_info.protocol_version = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strncmp(ublox_info.hwVersion, "00040007", 8) == 0) {
|
||||
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 6", "6");
|
||||
LOGGER.info(DETECTED_MESSAGE, "U-blox 6", "6");
|
||||
return GpsModel::UBLOX6;
|
||||
} else if (strncmp(ublox_info.hwVersion, "00070000", 8) == 0) {
|
||||
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 7", "7");
|
||||
LOGGER.info(DETECTED_MESSAGE, "U-blox 7", "7");
|
||||
return GpsModel::UBLOX7;
|
||||
} else if (strncmp(ublox_info.hwVersion, "00080000", 8) == 0) {
|
||||
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 8", "8");
|
||||
LOGGER.info(DETECTED_MESSAGE, "U-blox 8", "8");
|
||||
return GpsModel::UBLOX8;
|
||||
} else if (strncmp(ublox_info.hwVersion, "00190000", 8) == 0) {
|
||||
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 9", "9");
|
||||
LOGGER.info(DETECTED_MESSAGE, "U-blox 9", "9");
|
||||
return GpsModel::UBLOX9;
|
||||
} else if (strncmp(ublox_info.hwVersion, "000A0000", 8) == 0) {
|
||||
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 10", "10");
|
||||
LOGGER.info(DETECTED_MESSAGE, "U-blox 10", "10");
|
||||
return GpsModel::UBLOX10;
|
||||
}
|
||||
}
|
||||
@@ -305,7 +304,7 @@ GpsModel probe(uart::Uart& uart) {
|
||||
}
|
||||
|
||||
bool init(uart::Uart& uart, GpsModel model) {
|
||||
TT_LOG_I(TAG, "U-blox init");
|
||||
LOGGER.info("U-blox init");
|
||||
switch (model) {
|
||||
case GpsModel::UBLOX6:
|
||||
return initUblox6(uart);
|
||||
@@ -316,7 +315,7 @@ bool init(uart::Uart& uart, GpsModel model) {
|
||||
case GpsModel::UBLOX10:
|
||||
return initUblox10(uart);
|
||||
default:
|
||||
TT_LOG_E(TAG, "Unknown or unsupported U-blox model");
|
||||
LOGGER.error("Unknown or unsupported U-blox model");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -365,9 +364,9 @@ bool initUblox10(uart::Uart& uart) {
|
||||
auto packet_size = makePacket(0x06, 0x09, _message_SAVE_10, sizeof(_message_SAVE_10), buffer);
|
||||
uart.writeBytes(buffer, packet_size);
|
||||
if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) {
|
||||
TT_LOG_W(TAG, "Unable to save GNSS module config");
|
||||
LOGGER.warn("Unable to save GNSS module config");
|
||||
} else {
|
||||
TT_LOG_I(TAG, "GNSS module configuration saved!");
|
||||
LOGGER.info("GNSS module configuration saved!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -375,7 +374,7 @@ bool initUblox10(uart::Uart& uart) {
|
||||
bool initUblox789(uart::Uart& uart, GpsModel model) {
|
||||
uint8_t buffer[256];
|
||||
if (model == GpsModel::UBLOX7) {
|
||||
TT_LOG_D(TAG, "Set GPS+SBAS");
|
||||
LOGGER.debug("Set GPS+SBAS");
|
||||
auto msglen = makePacket(0x06, 0x3e, _message_GNSS_7, sizeof(_message_GNSS_7), buffer);
|
||||
uart.writeBytes(buffer, msglen);
|
||||
} else { // 8,9
|
||||
@@ -385,12 +384,12 @@ bool initUblox789(uart::Uart& uart, GpsModel model) {
|
||||
|
||||
if (getAck(uart, 0x06, 0x3e, 800) == GpsResponse::NotAck) {
|
||||
// It's not critical if the module doesn't acknowledge this configuration.
|
||||
TT_LOG_D(TAG, "reconfigure GNSS - defaults maintained. Is this module GPS-only?");
|
||||
LOGGER.debug("reconfigure GNSS - defaults maintained. Is this module GPS-only?");
|
||||
} else {
|
||||
if (model == GpsModel::UBLOX7) {
|
||||
TT_LOG_I(TAG, "GPS+SBAS configured");
|
||||
LOGGER.info("GPS+SBAS configured");
|
||||
} else { // 8,9
|
||||
TT_LOG_I(TAG, "GPS+SBAS+GLONASS+Galileo configured");
|
||||
LOGGER.info("GPS+SBAS+GLONASS+Galileo configured");
|
||||
}
|
||||
// Documentation say, we need wait at least 0.5s after reconfiguration of GNSS module, before sending next
|
||||
// commands for the M8 it tends to be more. 1 sec should be enough
|
||||
@@ -439,9 +438,9 @@ bool initUblox789(uart::Uart& uart, GpsModel model) {
|
||||
auto packet_size = makePacket(0x06, 0x09, _message_SAVE, sizeof(_message_SAVE), buffer);
|
||||
uart.writeBytes(buffer, packet_size);
|
||||
if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) {
|
||||
TT_LOG_W(TAG, "Unable to save GNSS module config");
|
||||
LOGGER.warn("Unable to save GNSS module config");
|
||||
} else {
|
||||
TT_LOG_I(TAG, "GNSS module configuration saved!");
|
||||
LOGGER.info("GNSS module configuration saved!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -473,9 +472,9 @@ bool initUblox6(uart::Uart& uart) {
|
||||
auto packet_size = makePacket(0x06, 0x09, _message_SAVE, sizeof(_message_SAVE), buffer);
|
||||
uart.writeBytes(buffer, packet_size);
|
||||
if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) {
|
||||
TT_LOG_W(TAG, "Unable to save GNSS module config");
|
||||
LOGGER.warn("Unable to save GNSS module config");
|
||||
} else {
|
||||
TT_LOG_I(TAG, "GNSS module config saved!");
|
||||
LOGGER.info("GNSS module config saved!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "Tactility/hal/i2c/I2c.h"
|
||||
#include <Tactility/hal/i2c/I2c.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
|
||||
namespace tt::hal::i2c {
|
||||
|
||||
constexpr auto TAG = "i2c";
|
||||
static const auto LOGGER = Logger("I2C");
|
||||
|
||||
struct Data {
|
||||
Mutex mutex;
|
||||
@@ -18,12 +18,12 @@ struct Data {
|
||||
static const uint8_t ACK_CHECK_EN = 1;
|
||||
static Data dataArray[I2C_NUM_MAX];
|
||||
|
||||
bool init(const std::vector<i2c::Configuration>& configurations) {
|
||||
TT_LOG_I(TAG, "Init");
|
||||
bool init(const std::vector<Configuration>& configurations) {
|
||||
LOGGER.info("Init");
|
||||
for (const auto& configuration: configurations) {
|
||||
#ifdef ESP_PLATFORM
|
||||
if (configuration.config.mode != I2C_MODE_MASTER) {
|
||||
TT_LOG_E(TAG, "Currently only master mode is supported");
|
||||
LOGGER.error("Currently only master mode is supported");
|
||||
return false;
|
||||
}
|
||||
#endif // ESP_PLATFORM
|
||||
@@ -51,10 +51,10 @@ bool configure(i2c_port_t port, const i2c_config_t& configuration) {
|
||||
|
||||
Data& data = dataArray[port];
|
||||
if (data.isStarted) {
|
||||
TT_LOG_E(TAG, "(%d) Cannot reconfigure while interface is started", port);
|
||||
LOGGER.error("({}) Cannot reconfigure while interface is started", static_cast<int>(port));
|
||||
return false;
|
||||
} else if (!data.configuration.isMutable) {
|
||||
TT_LOG_E(TAG, "(%d) Mutation not allowed because configuration is immutable", port);
|
||||
LOGGER.error("({}) Mutation not allowed because configuration is immutable", static_cast<int>(port));
|
||||
return false;
|
||||
} else {
|
||||
data.configuration.config = configuration;
|
||||
@@ -70,32 +70,32 @@ bool start(i2c_port_t port) {
|
||||
Configuration& config = data.configuration;
|
||||
|
||||
if (data.isStarted) {
|
||||
TT_LOG_E(TAG, "(%d) Starting: Already started", port);
|
||||
LOGGER.error("({}) Starting: Already started", static_cast<int>(port));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data.isConfigured) {
|
||||
TT_LOG_E(TAG, "(%d) Starting: Not configured", port);
|
||||
LOGGER.error("({}) Starting: Not configured", static_cast<int>(port));
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_err_t result = i2c_param_config(port, &config.config);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "(%d) Starting: Failed to configure: %s", port, esp_err_to_name(result));
|
||||
LOGGER.error("({}) Starting: Failed to configure: {}", static_cast<int>(port), esp_err_to_name(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
result = i2c_driver_install(port, config.config.mode, 0, 0, 0);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "(%d) Starting: Failed to install driver: %s", port, esp_err_to_name(result));
|
||||
LOGGER.error("({}) Starting: Failed to install driver: {}", static_cast<int>(port), esp_err_to_name(result));
|
||||
return false;
|
||||
}
|
||||
#endif // ESP_PLATFORM
|
||||
|
||||
data.isStarted = true;
|
||||
|
||||
TT_LOG_I(TAG, "(%d) Started", port);
|
||||
LOGGER.info("({}) Started", static_cast<int>(port));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -107,26 +107,26 @@ bool stop(i2c_port_t port) {
|
||||
Configuration& config = data.configuration;
|
||||
|
||||
if (!config.isMutable) {
|
||||
TT_LOG_E(TAG, "(%d) Stopping: Not allowed for immutable configuration", port);
|
||||
LOGGER.error("({}) Stopping: Not allowed for immutable configuration", static_cast<int>(port));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data.isStarted) {
|
||||
TT_LOG_E(TAG, "(%d) Stopping: Not started", port);
|
||||
LOGGER.error("({}) Stopping: Not started", static_cast<int>(port));
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_err_t result = i2c_driver_delete(port);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "(%d) Stopping: Failed to delete driver: %s", port, esp_err_to_name(result));
|
||||
LOGGER.error("({}) Stopping: Failed to delete driver: {}", static_cast<int>(port), esp_err_to_name(result));
|
||||
return false;
|
||||
}
|
||||
#endif // ESP_PLATFORM
|
||||
|
||||
data.isStarted = false;
|
||||
|
||||
TT_LOG_I(TAG, "(%d) Stopped", port);
|
||||
LOGGER.info("({}) Stopped", static_cast<int>(port));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ bool isStarted(i2c_port_t port) {
|
||||
bool masterRead(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout) {
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ bool masterRead(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize
|
||||
bool masterReadRegister(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout) {
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ bool masterReadRegister(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t*
|
||||
bool masterWrite(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ bool masterWriteRegister(i2c_port_t port, uint8_t address, uint8_t reg, const ui
|
||||
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ bool masterWriteRegisterArray(i2c_port_t port, uint8_t address, const uint8_t* d
|
||||
bool masterWriteRead(i2c_port_t port, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout) {
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ bool masterWriteRead(i2c_port_t port, uint8_t address, const uint8_t* writeData,
|
||||
bool masterHasDeviceAtAddress(i2c_port_t port, uint8_t address, TickType_t timeout) {
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
#include <Tactility/hal/sdcard/SdCardMounting.h>
|
||||
#include <Tactility/hal/sdcard/SdCardDevice.h>
|
||||
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <format>
|
||||
|
||||
namespace tt::hal::sdcard {
|
||||
|
||||
constexpr auto* TAG = "SdCardMounting";
|
||||
static const auto LOGGER = Logger("SdCardMounting");
|
||||
constexpr auto* TT_SDCARD_MOUNT_POINT = "/sdcard";
|
||||
|
||||
static void mount(const std::shared_ptr<SdCardDevice>& sdcard, const std::string& path) {
|
||||
TT_LOG_I(TAG, "Mounting sdcard at %s", path.c_str());
|
||||
LOGGER.info("Mounting sdcard at {}", path);
|
||||
if (!sdcard->mount(path)) {
|
||||
TT_LOG_W(TAG, "SD card mount failed for %s (init can continue)", path.c_str());
|
||||
LOGGER.warn("SD card mount failed for {} (init can continue)", path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#if defined(ESP_PLATFORM) && defined(SOC_SDMMC_HOST_SUPPORTED)
|
||||
|
||||
#include <Tactility/hal/sdcard/SdmmcDevice.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <esp_vfs_fat.h>
|
||||
#include <sdmmc_cmd.h>
|
||||
@@ -13,10 +13,10 @@
|
||||
|
||||
namespace tt::hal::sdcard {
|
||||
|
||||
constexpr auto* TAG = "SdmmcDevice";
|
||||
static const auto LOGGER = Logger("SdmmcDevice");
|
||||
|
||||
bool SdmmcDevice::mountInternal(const std::string& newMountPath) {
|
||||
TT_LOG_I(TAG, "Mounting %s", newMountPath.c_str());
|
||||
LOGGER.info("Mounting {}", newMountPath);
|
||||
|
||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
.format_if_mount_failed = config->formatOnMountFailed,
|
||||
@@ -49,9 +49,9 @@ bool SdmmcDevice::mountInternal(const std::string& newMountPath) {
|
||||
|
||||
if (result != ESP_OK || card == nullptr) {
|
||||
if (result == ESP_FAIL) {
|
||||
TT_LOG_E(TAG, "Mounting failed. Ensure the card is formatted with FAT.");
|
||||
LOGGER.error("Mounting failed. Ensure the card is formatted with FAT.");
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Mounting failed (%s)", esp_err_to_name(result));
|
||||
LOGGER.error("Mounting failed ({})", esp_err_to_name(result));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -66,11 +66,11 @@ bool SdmmcDevice::mount(const std::string& newMountPath) {
|
||||
lock.lock();
|
||||
|
||||
if (mountInternal(newMountPath)) {
|
||||
TT_LOG_I(TAG, "Mounted at %s", newMountPath.c_str());
|
||||
LOGGER.info("Mounted at {}", newMountPath);
|
||||
sdmmc_card_print_info(stdout, card);
|
||||
return true;
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Mount failed for %s", newMountPath.c_str());
|
||||
LOGGER.error("Mount failed for {}", newMountPath);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -80,16 +80,16 @@ bool SdmmcDevice::unmount() {
|
||||
lock.lock();
|
||||
|
||||
if (card == nullptr) {
|
||||
TT_LOG_E(TAG, "Can't unmount: not mounted");
|
||||
LOGGER.error("Can't unmount: not mounted");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_vfs_fat_sdcard_unmount(mountPath.c_str(), card) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Unmount failed for %s", mountPath.c_str());
|
||||
LOGGER.error("Unmount failed for {}", mountPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Unmounted %s", mountPath.c_str());
|
||||
LOGGER.info("Unmounted {}", mountPath);
|
||||
mountPath = "";
|
||||
card = nullptr;
|
||||
return true;
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
#include <Tactility/hal/gpio/Gpio.h>
|
||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <esp_vfs_fat.h>
|
||||
#include <sdmmc_cmd.h>
|
||||
|
||||
namespace tt::hal::sdcard {
|
||||
|
||||
constexpr auto* TAG = "SpiSdCardDevice";
|
||||
static const auto LOGGER = Logger("SpiSdCardDevice");
|
||||
|
||||
/**
|
||||
* Before we can initialize the sdcard's SPI communications, we have to set all
|
||||
@@ -19,7 +19,7 @@ constexpr auto* TAG = "SpiSdCardDevice";
|
||||
* @return success result
|
||||
*/
|
||||
bool SpiSdCardDevice::applyGpioWorkAround() {
|
||||
TT_LOG_D(TAG, "init");
|
||||
LOGGER.info("applyGpioWorkAround");
|
||||
|
||||
uint64_t pin_bit_mask = BIT64(config->spiPinCs);
|
||||
for (auto const& pin: config->csPinWorkAround) {
|
||||
@@ -27,13 +27,13 @@ bool SpiSdCardDevice::applyGpioWorkAround() {
|
||||
}
|
||||
|
||||
if (!gpio::configureWithPinBitmask(pin_bit_mask, gpio::Mode::Output, false, false)) {
|
||||
TT_LOG_E(TAG, "GPIO init failed");
|
||||
LOGGER.error("GPIO work-around failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto const& pin: config->csPinWorkAround) {
|
||||
if (!gpio::setLevel(pin, true)) {
|
||||
TT_LOG_E(TAG, "Failed to set board CS pin high");
|
||||
LOGGER.error("Failed to set board CS pin high");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ bool SpiSdCardDevice::applyGpioWorkAround() {
|
||||
}
|
||||
|
||||
bool SpiSdCardDevice::mountInternal(const std::string& newMountPath) {
|
||||
TT_LOG_I(TAG, "Mounting %s", newMountPath.c_str());
|
||||
LOGGER.info("Mounting {}", newMountPath);
|
||||
|
||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
.format_if_mount_failed = config->formatOnMountFailed,
|
||||
@@ -71,9 +71,9 @@ bool SpiSdCardDevice::mountInternal(const std::string& newMountPath) {
|
||||
|
||||
if (result != ESP_OK || card == nullptr) {
|
||||
if (result == ESP_FAIL) {
|
||||
TT_LOG_E(TAG, "Mounting failed. Ensure the card is formatted with FAT.");
|
||||
LOGGER.error("Mounting failed. Ensure the card is formatted with FAT.");
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Mounting failed (%s)", esp_err_to_name(result));
|
||||
LOGGER.error("Mounting failed ({})", esp_err_to_name(result));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -88,16 +88,16 @@ bool SpiSdCardDevice::mount(const std::string& newMountPath) {
|
||||
lock.lock();
|
||||
|
||||
if (!applyGpioWorkAround()) {
|
||||
TT_LOG_E(TAG, "Failed to apply GPIO work-around");
|
||||
LOGGER.error("Failed to apply GPIO work-around");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mountInternal(newMountPath)) {
|
||||
TT_LOG_I(TAG, "Mounted at %s", newMountPath.c_str());
|
||||
LOGGER.info("Mounted at {}", newMountPath);
|
||||
sdmmc_card_print_info(stdout, card);
|
||||
return true;
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Mount failed for %s", newMountPath.c_str());
|
||||
LOGGER.error("Mount failed for {}", newMountPath);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -107,16 +107,16 @@ bool SpiSdCardDevice::unmount() {
|
||||
lock.lock();
|
||||
|
||||
if (card == nullptr) {
|
||||
TT_LOG_E(TAG, "Can't unmount: not mounted");
|
||||
LOGGER.error("Can't unmount: not mounted");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_vfs_fat_sdcard_unmount(mountPath.c_str(), card) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Unmount failed for %s", mountPath.c_str());
|
||||
LOGGER.error("Unmount failed for {}", mountPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Unmounted %s", mountPath.c_str());
|
||||
LOGGER.info("Unmounted {}", mountPath);
|
||||
mountPath = "";
|
||||
card = nullptr;
|
||||
return true;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <Tactility/hal/spi/Spi.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/RecursiveMutex.h>
|
||||
|
||||
namespace tt::hal::spi {
|
||||
|
||||
constexpr auto* TAG = "SPI";
|
||||
static const auto LOGGER = Logger("SPI");
|
||||
|
||||
struct Data {
|
||||
std::shared_ptr<Lock> lock;
|
||||
@@ -17,7 +17,7 @@ struct Data {
|
||||
static Data dataArray[SPI_HOST_MAX];
|
||||
|
||||
bool init(const std::vector<Configuration>& configurations) {
|
||||
TT_LOG_I(TAG, "Init");
|
||||
LOGGER.info("Init");
|
||||
for (const auto& configuration: configurations) {
|
||||
Data& data = dataArray[configuration.device];
|
||||
data.configuration = configuration;
|
||||
@@ -48,10 +48,10 @@ bool configure(spi_host_device_t device, const spi_bus_config_t& configuration)
|
||||
|
||||
Data& data = dataArray[device];
|
||||
if (data.isStarted) {
|
||||
TT_LOG_E(TAG, "(%d) Cannot reconfigure while interface is started", device);
|
||||
LOGGER.error("({}) Cannot reconfigure while interface is started", static_cast<int>(device));
|
||||
return false;
|
||||
} else if (!data.configuration.isMutable) {
|
||||
TT_LOG_E(TAG, "(%d) Mutation not allowed by original configuration", device);
|
||||
LOGGER.error("({}) Mutation not allowed by original configuration", static_cast<int>(device));
|
||||
return false;
|
||||
} else {
|
||||
data.configuration.config = configuration;
|
||||
@@ -66,12 +66,12 @@ bool start(spi_host_device_t device) {
|
||||
Data& data = dataArray[device];
|
||||
|
||||
if (data.isStarted) {
|
||||
TT_LOG_E(TAG, "(%d) Starting: Already started", device);
|
||||
LOGGER.error("({}) Starting: Already started", static_cast<int>(device));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data.isConfigured) {
|
||||
TT_LOG_E(TAG, "(%d) Starting: Not configured", device);
|
||||
LOGGER.error("({}) Starting: Not configured", static_cast<int>(device));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ bool start(spi_host_device_t device) {
|
||||
|
||||
auto result = spi_bus_initialize(device, &data.configuration.config, data.configuration.dma);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "(%d) Starting: Failed to initialize: %s", device, esp_err_to_name(result));
|
||||
LOGGER.error("({}) Starting: Failed to initialize: {}", static_cast<int>(device), esp_err_to_name(result));
|
||||
return false;
|
||||
} else {
|
||||
data.isStarted = true;
|
||||
@@ -91,7 +91,7 @@ bool start(spi_host_device_t device) {
|
||||
|
||||
#endif
|
||||
|
||||
TT_LOG_I(TAG, "(%d) Started", device);
|
||||
LOGGER.info("({}) Started", static_cast<int>(device));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -103,12 +103,12 @@ bool stop(spi_host_device_t device) {
|
||||
Configuration& config = data.configuration;
|
||||
|
||||
if (!config.isMutable) {
|
||||
TT_LOG_E(TAG, "(%d) Stopping: Not allowed, immutable", device);
|
||||
LOGGER.error("({}) Stopping: Not allowed, immutable", static_cast<int>(device));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data.isStarted) {
|
||||
TT_LOG_E(TAG, "(%d) Stopping: Not started", device);
|
||||
LOGGER.error("({}) Stopping: Not started", static_cast<int>(device));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ bool stop(spi_host_device_t device) {
|
||||
|
||||
auto result = spi_bus_free(device);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "(%d) Stopping: Failed to free device: %s", device, esp_err_to_name(result));
|
||||
LOGGER.error("({}) Stopping: Failed to free device: {}", static_cast<int>(device), esp_err_to_name(result));
|
||||
return false;
|
||||
} else {
|
||||
data.isStarted = false;
|
||||
@@ -128,7 +128,7 @@ bool stop(spi_host_device_t device) {
|
||||
|
||||
#endif
|
||||
|
||||
TT_LOG_I(TAG, "(%d) Stopped", device);
|
||||
LOGGER.info("({}) Stopped", static_cast<int>(device));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "Tactility/hal/uart/Uart.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
|
||||
#include <ranges>
|
||||
@@ -15,10 +15,10 @@
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#define TAG "uart"
|
||||
|
||||
namespace tt::hal::uart {
|
||||
|
||||
static const auto LOGGER = Logger("UART");
|
||||
|
||||
constexpr uint32_t uartIdNotInUse = 0;
|
||||
|
||||
struct UartEntry {
|
||||
@@ -30,7 +30,7 @@ static std::vector<UartEntry> uartEntries = {};
|
||||
static uint32_t lastUartId = uartIdNotInUse;
|
||||
|
||||
bool init(const std::vector<Configuration>& configurations) {
|
||||
TT_LOG_I(TAG, "Init");
|
||||
LOGGER.info("Init");
|
||||
for (const auto& configuration: configurations) {
|
||||
uartEntries.push_back({
|
||||
.usageId = uartIdNotInUse,
|
||||
@@ -78,7 +78,7 @@ size_t Uart::readUntil(std::byte* buffer, size_t bufferSize, uint8_t untilByte,
|
||||
TickType_t now = kernel::getTicks();
|
||||
if (now > (start_time + timeout)) {
|
||||
#ifdef DEBUG_READ_UNTIL
|
||||
TT_LOG_W(TAG, "readUntil() timeout");
|
||||
LOGGER.warn("readUntil() timeout");
|
||||
#endif
|
||||
break;
|
||||
} else {
|
||||
@@ -102,26 +102,26 @@ size_t Uart::readUntil(std::byte* buffer, size_t bufferSize, uint8_t untilByte,
|
||||
|
||||
static std::unique_ptr<Uart> open(UartEntry& entry) {
|
||||
if (entry.usageId != uartIdNotInUse) {
|
||||
TT_LOG_E(TAG, "UART in use: %s", entry.configuration.name.c_str());
|
||||
LOGGER.error("UART in use: {}", entry.configuration.name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto uart = create(entry.configuration);
|
||||
assert(uart != nullptr);
|
||||
entry.usageId = uart->getId();
|
||||
TT_LOG_I(TAG, "Opened %lu", entry.usageId);
|
||||
LOGGER.info("Opened {}", entry.usageId);
|
||||
return uart;
|
||||
}
|
||||
|
||||
std::unique_ptr<Uart> open(uart_port_t port) {
|
||||
TT_LOG_I(TAG, "Open %d", port);
|
||||
LOGGER.info("Open {}", static_cast<int>(port));
|
||||
|
||||
auto result = std::views::filter(uartEntries, [port](auto& entry) {
|
||||
return entry.configuration.port == port;
|
||||
});
|
||||
|
||||
if (result.empty()) {
|
||||
TT_LOG_E(TAG, "UART not found: %d", port);
|
||||
LOGGER.error("UART not found: {}", static_cast<int>(port));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -129,14 +129,14 @@ std::unique_ptr<Uart> open(uart_port_t port) {
|
||||
}
|
||||
|
||||
std::unique_ptr<Uart> open(std::string name) {
|
||||
TT_LOG_I(TAG, "Open %s", name.c_str());
|
||||
LOGGER.info("Open {}", name);
|
||||
|
||||
auto result = std::views::filter(uartEntries, [&name](auto& entry) {
|
||||
return entry.configuration.name == name;
|
||||
});
|
||||
|
||||
if (result.empty()) {
|
||||
TT_LOG_E(TAG, "UART not found: %s", name.c_str());
|
||||
LOGGER.error("UART not found: {}", name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ std::unique_ptr<Uart> open(std::string name) {
|
||||
}
|
||||
|
||||
void close(uint32_t uartId) {
|
||||
TT_LOG_I(TAG, "Close %lu", uartId);
|
||||
LOGGER.info("Close {}", uartId);
|
||||
auto result = std::views::filter(uartEntries, [&uartId](auto& entry) {
|
||||
return entry.usageId == uartId;
|
||||
});
|
||||
@@ -153,7 +153,7 @@ void close(uint32_t uartId) {
|
||||
auto& entry = *result.begin();
|
||||
entry.usageId = uartIdNotInUse;
|
||||
} else {
|
||||
TT_LOG_W(TAG, "Auto-closing UART, but can't find it");
|
||||
LOGGER.warn("Auto-closing UART, but can't find it");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ std::vector<std::string> getNames() {
|
||||
#else
|
||||
DIR* dir = opendir("/dev");
|
||||
if (dir == nullptr) {
|
||||
TT_LOG_E(TAG, "Failed to read /dev");
|
||||
LOGGER.error("Failed to read /dev");
|
||||
return names;
|
||||
}
|
||||
struct dirent* current_entry;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <Tactility/hal/uart/UartEsp.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
|
||||
@@ -11,16 +11,16 @@
|
||||
|
||||
namespace tt::hal::uart {
|
||||
|
||||
constexpr auto TAG = "uart";
|
||||
static const auto LOGGER = Logger("UART");
|
||||
|
||||
bool UartEsp::start() {
|
||||
TT_LOG_I(TAG, "[%s] Starting", configuration.name.c_str());
|
||||
LOGGER.info("[{}] Starting", configuration.name);
|
||||
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
if (started) {
|
||||
TT_LOG_E(TAG, "[%s] Starting: Already started", configuration.name.c_str());
|
||||
LOGGER.error("[{}] Starting: Already started", configuration.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -33,53 +33,53 @@ bool UartEsp::start() {
|
||||
|
||||
esp_err_t result = uart_param_config(configuration.port, &configuration.config);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "[%s] Starting: Failed to configure: %s", configuration.name.c_str(), esp_err_to_name(result));
|
||||
LOGGER.error("[{}] Starting: Failed to configure: {}", configuration.name, esp_err_to_name(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (uart_is_driver_installed(configuration.port)) {
|
||||
TT_LOG_W(TAG, "[%s] Driver was still installed. You probably forgot to stop, or another system uses/used the driver.", configuration.name.c_str());
|
||||
LOGGER.error("[{}] Driver was still installed. You probably forgot to stop, or another system uses/used the driver.", configuration.name);
|
||||
uart_driver_delete(configuration.port);
|
||||
}
|
||||
|
||||
result = uart_set_pin(configuration.port, configuration.txPin, configuration.rxPin, configuration.rtsPin, configuration.ctsPin);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "[%s] Starting: Failed set pins: %s", configuration.name.c_str(), esp_err_to_name(result));
|
||||
LOGGER.error("[{}] Starting: Failed set pins: {}", configuration.name, esp_err_to_name(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
result = uart_driver_install(configuration.port, (int)configuration.rxBufferSize, (int)configuration.txBufferSize, 0, nullptr, intr_alloc_flags);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "[%s] Starting: Failed to install driver: %s", configuration.name.c_str(), esp_err_to_name(result));
|
||||
LOGGER.error("[{}] Starting: Failed to install driver: {}", configuration.name, esp_err_to_name(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
started = true;
|
||||
|
||||
TT_LOG_I(TAG, "[%s] Started", configuration.name.c_str());
|
||||
LOGGER.info("[{}] Started", configuration.name);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UartEsp::stop() {
|
||||
TT_LOG_I(TAG, "[%s] Stopping", configuration.name.c_str());
|
||||
LOGGER.info("[{}] Stopping", configuration.name);
|
||||
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
if (!started) {
|
||||
TT_LOG_E(TAG, "[%s] Stopping: Not started", configuration.name.c_str());
|
||||
LOGGER.error("[{}] Stopping: Not started", configuration.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_err_t result = uart_driver_delete(configuration.port);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "[%s] Stopping: Failed to delete driver: %s", configuration.name.c_str(), esp_err_to_name(result));
|
||||
LOGGER.error("[{}] Stopping: Failed to delete driver: {}", configuration.name, esp_err_to_name(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
started = false;
|
||||
|
||||
TT_LOG_I(TAG, "[%s] Stopped", configuration.name.c_str());
|
||||
LOGGER.info("[{}] Stopped", configuration.name);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <Tactility/hal/uart/UartPosix.h>
|
||||
#include <Tactility/hal/uart/Uart.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
@@ -12,20 +12,20 @@
|
||||
|
||||
namespace tt::hal::uart {
|
||||
|
||||
constexpr auto TAG = "uart";
|
||||
static const auto LOGGER = Logger("UART");
|
||||
|
||||
bool UartPosix::start() {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
if (device != nullptr) {
|
||||
TT_LOG_E(TAG, "[%s] Starting: Already started", configuration.name.c_str());
|
||||
LOGGER.error("[{}] Starting: Already started", configuration.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto file = fopen(configuration.name.c_str(), "w");
|
||||
if (file == nullptr) {
|
||||
TT_LOG_E(TAG, "[%s] Open device failed", configuration.name.c_str());
|
||||
LOGGER.error("[{}] Open device failed", configuration.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -33,16 +33,16 @@ bool UartPosix::start() {
|
||||
|
||||
struct termios tty;
|
||||
if (tcgetattr(fileno(file), &tty) < 0) {
|
||||
printf("[%s] tcgetattr failed: %s\n", configuration.name.c_str(), strerror(errno));
|
||||
LOGGER.error("[{}] tcgetattr failed: {}", configuration.name, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cfsetospeed(&tty, (speed_t)configuration.baudRate) == -1) {
|
||||
TT_LOG_E(TAG, "[%s] Setting output speed failed", configuration.name.c_str());
|
||||
LOGGER.error("[{}] Setting output speed failed", configuration.name);
|
||||
}
|
||||
|
||||
if (cfsetispeed(&tty, (speed_t)configuration.baudRate) == -1) {
|
||||
TT_LOG_E(TAG, "[%s] Setting input speed failed", configuration.name.c_str());
|
||||
LOGGER.error("[{}] Setting input speed failed", configuration.name);
|
||||
}
|
||||
|
||||
tty.c_cflag |= (CLOCAL | CREAD); /* ignore modem controls */
|
||||
@@ -61,13 +61,13 @@ bool UartPosix::start() {
|
||||
tty.c_cc[VTIME] = 1;
|
||||
|
||||
if (tcsetattr(fileno(file), TCSANOW, &tty) != 0) {
|
||||
printf("[%s] tcsetattr failed: %s\n", configuration.name.c_str(), strerror(errno));
|
||||
LOGGER.error("[{}] tcsetattr failed: {}", configuration.name, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
device = std::move(new_device);
|
||||
|
||||
TT_LOG_I(TAG, "[%s] Started", configuration.name.c_str());
|
||||
LOGGER.info("[{}] Started", configuration.name);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -76,13 +76,13 @@ bool UartPosix::stop() {
|
||||
lock.lock();
|
||||
|
||||
if (device == nullptr) {
|
||||
TT_LOG_E(TAG, "[%s] Stopping: Not started", configuration.name.c_str());
|
||||
LOGGER.error("[{}] Stopping: Not started", configuration.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
device = nullptr;
|
||||
|
||||
TT_LOG_I(TAG, "[%s] Stopped", configuration.name.c_str());
|
||||
LOGGER.info("[{}] Stopped", configuration.name);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ void UartPosix::flushInput() {
|
||||
uint32_t UartPosix::getBaudRate() {
|
||||
struct termios tty;
|
||||
if (tcgetattr(fileno(device.get()), &tty) < 0) {
|
||||
printf("[%s] tcgetattr failed: %s\n", configuration.name.c_str(), strerror(errno));
|
||||
LOGGER.error("[{}] tcgetattr failed: {}", configuration.name, strerror(errno));
|
||||
return false;
|
||||
} else {
|
||||
return (uint32_t)cfgetispeed(&tty);
|
||||
@@ -154,17 +154,17 @@ bool UartPosix::setBaudRate(uint32_t baudRate, TickType_t timeout) {
|
||||
|
||||
struct termios tty;
|
||||
if (tcgetattr(fileno(device.get()), &tty) < 0) {
|
||||
printf("[%s] tcgetattr failed: %s\n", configuration.name.c_str(), strerror(errno));
|
||||
LOGGER.error("[{}] tcgetattr failed: {}", configuration.name, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cfsetospeed(&tty, (speed_t)configuration.baudRate) == -1) {
|
||||
TT_LOG_E(TAG, "[%s] Failed to set output speed", configuration.name.c_str());
|
||||
LOGGER.error("[{}] Failed to set output speed", configuration.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cfsetispeed(&tty, (speed_t)configuration.baudRate) == -1) {
|
||||
TT_LOG_E(TAG, "[%s] Failed to set input speed", configuration.name.c_str());
|
||||
LOGGER.error("[{}] Failed to set input speed", configuration.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||
#include <Tactility/hal/usb/UsbTusb.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
namespace tt::hal::usb {
|
||||
|
||||
constexpr auto* TAG = "usb";
|
||||
static const auto LOGGER = Logger("USB");
|
||||
|
||||
constexpr auto BOOT_FLAG_SDMMC = 42; // Existing
|
||||
constexpr auto BOOT_FLAG_FLASH = 43; // For flash mode
|
||||
|
||||
@@ -32,13 +33,13 @@ sdmmc_card_t* _Nullable getCard() {
|
||||
}
|
||||
|
||||
if (usable_sdcard == nullptr) {
|
||||
TT_LOG_W(TAG, "Couldn't find a mounted SpiSdCard");
|
||||
LOGGER.warn("Couldn't find a mounted SpiSdCard");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto* sdmmc_card = usable_sdcard->getCard();
|
||||
if (sdmmc_card == nullptr) {
|
||||
TT_LOG_W(TAG, "SD card has no card object available");
|
||||
LOGGER.warn("SD card has no card object available");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -55,7 +56,7 @@ bool isSupported() {
|
||||
|
||||
bool startMassStorageWithSdmmc() {
|
||||
if (!canStartNewMode()) {
|
||||
TT_LOG_E(TAG, "Can't start");
|
||||
LOGGER.error("Can't start");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -63,7 +64,7 @@ bool startMassStorageWithSdmmc() {
|
||||
currentMode = Mode::MassStorageSdmmc;
|
||||
return true;
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to init mass storage");
|
||||
LOGGER.error("Failed to init mass storage");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -96,7 +97,7 @@ void rebootIntoMassStorageSdmmc() {
|
||||
// NEW: Flash mass storage functions
|
||||
bool startMassStorageWithFlash() {
|
||||
if (!canStartNewMode()) {
|
||||
TT_LOG_E(TAG, "Can't start flash mass storage");
|
||||
LOGGER.error("Can't start flash mass storage");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -104,7 +105,7 @@ bool startMassStorageWithFlash() {
|
||||
currentMode = Mode::MassStorageFlash;
|
||||
return true;
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to init flash mass storage");
|
||||
LOGGER.error("Failed to init flash mass storage");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "Tactility/hal/usb/Usb.h"
|
||||
|
||||
#define TAG "usb"
|
||||
|
||||
namespace tt::hal::usb {
|
||||
|
||||
bool startMassStorageWithSdmmc() { return false; }
|
||||
|
||||
@@ -7,16 +7,17 @@
|
||||
|
||||
#if CONFIG_TINYUSB_MSC_ENABLED == 1
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <tinyusb.h>
|
||||
#include <tusb_msc_storage.h>
|
||||
#include <wear_levelling.h>
|
||||
|
||||
#define TAG "usb"
|
||||
#define EPNUM_MSC 1
|
||||
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_MSC_DESC_LEN)
|
||||
#define SECTOR_SIZE 512
|
||||
|
||||
static const auto LOGGER = tt::Logger("USB");
|
||||
|
||||
namespace tt::hal::usb {
|
||||
extern sdmmc_card_t* _Nullable getCard();
|
||||
}
|
||||
@@ -93,9 +94,9 @@ static uint8_t const msc_hs_configuration_desc[] = {
|
||||
|
||||
static void storage_mount_changed_cb(tinyusb_msc_event_t* event) {
|
||||
if (event->mount_changed_data.is_mounted) {
|
||||
TT_LOG_I(TAG, "MSC Mounted");
|
||||
LOGGER.info("MSC Mounted");
|
||||
} else {
|
||||
TT_LOG_I(TAG, "MSC Unmounted");
|
||||
LOGGER.info("MSC Unmounted");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +122,7 @@ static bool ensureDriverInstalled() {
|
||||
};
|
||||
|
||||
if (tinyusb_driver_install(&tusb_cfg) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to install TinyUSB driver");
|
||||
LOGGER.error("Failed to install TinyUSB driver");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -136,7 +137,7 @@ bool tusbStartMassStorageWithSdmmc() {
|
||||
|
||||
auto* card = tt::hal::usb::getCard();
|
||||
if (card == nullptr) {
|
||||
TT_LOG_E(TAG, "SD card not mounted");
|
||||
LOGGER.error("SD card not mounted");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -155,21 +156,21 @@ bool tusbStartMassStorageWithSdmmc() {
|
||||
|
||||
auto result = tinyusb_msc_storage_init_sdmmc(&config_sdmmc);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "TinyUSB SDMMC init failed: %s", esp_err_to_name(result));
|
||||
LOGGER.error("TinyUSB SDMMC init failed: {}", esp_err_to_name(result));
|
||||
} else {
|
||||
TT_LOG_I(TAG, "TinyUSB SDMMC init success");
|
||||
LOGGER.info("TinyUSB SDMMC init success");
|
||||
}
|
||||
|
||||
return result == ESP_OK;
|
||||
}
|
||||
|
||||
bool tusbStartMassStorageWithFlash() {
|
||||
TT_LOG_I(TAG, "Starting flash MSC");
|
||||
LOGGER.info("Starting flash MSC");
|
||||
ensureDriverInstalled();
|
||||
|
||||
wl_handle_t handle = tt::getDataPartitionWlHandle();
|
||||
if (handle == WL_INVALID_HANDLE) {
|
||||
TT_LOG_E(TAG, "WL not mounted for /data");
|
||||
LOGGER.error("WL not mounted for /data");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -188,9 +189,9 @@ bool tusbStartMassStorageWithFlash() {
|
||||
|
||||
esp_err_t result = tinyusb_msc_storage_init_spiflash(&config_flash);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "TinyUSB flash init failed: %s", esp_err_to_name(result));
|
||||
LOGGER.error("TinyUSB flash init failed: {}", esp_err_to_name(result));
|
||||
} else {
|
||||
TT_LOG_I(TAG, "TinyUSB flash init success");
|
||||
LOGGER.info("TinyUSB flash init success");
|
||||
}
|
||||
return result == ESP_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user