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:
Ken Van Hoeylandt
2026-01-06 22:35:39 +01:00
committed by GitHub
parent 719f7bcece
commit f620255c41
188 changed files with 1973 additions and 1755 deletions
+14 -14
View File
@@ -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;
+13 -13
View File
@@ -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;
}
+15 -15
View File
@@ -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;
}