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
+10 -9
View File
@@ -14,7 +14,7 @@
#pragma once
#include "CoreDefines.h"
#include "Log.h"
#include "Logger.h"
#include <cassert>
@@ -28,17 +28,18 @@ namespace tt {
TT_NORETURN void _crash();
}
// TODO: Move crash logic to kernel namespace and consider refactoring to C++
/** Crash system with message. */
#define tt_crash(...) TT_ARG_CAT(_tt_crash,TT_ARGCOUNT(__VA_ARGS__))(__VA_ARGS__)
#define _tt_crash0() do { \
TT_LOG_E("crash", "at %s:%d", __FILE__, __LINE__); \
tt::Logger("Kernel").error("Crash at {}:{}", __FILE__, __LINE__); \
tt::_crash(); \
} while (0)
#define _tt_crash1(message) do { \
TT_LOG_E("crash", "%s\n\tat %s:%d", message, __FILE__, __LINE__); \
tt::_crash(); \
#define _tt_crash1(message) do { \
tt::Logger("Kernel").error("Crash: {}\n\tat {}:{}", message, __FILE__, __LINE__); \
tt::_crash(); \
} while (0)
/** Halt the system
@@ -50,11 +51,11 @@ namespace tt {
#define tt_check_internal(__e, __m) \
do { \
if (!(__e)) { \
TT_LOG_E("check", "%s", #__e); \
tt::Logger("Kernel").error("Check failed: {}", #__e); \
if (__m) { \
tt_crash_internal(#__m); \
tt_crash(__m); \
} else { \
tt_crash_internal(""); \
tt_crash(""); \
} \
} \
} while (0)
@@ -65,4 +66,4 @@ namespace tt {
* @param[in] optional message (const char*)
*/
#define tt_check(x, ...) if (!(x)) { TT_LOG_E("check", "Failed: %s", #x); tt::_crash(); }
#define tt_check(x, ...) if (!(x)) { tt::Logger("Kernel").error("Check failed: {}", #x); tt::_crash(); }
-10
View File
@@ -1,10 +0,0 @@
#pragma once
#ifdef ESP_PLATFORM
#include "LogEsp.h"
#else
#include "LogSimulator.h"
#endif
#include "LogMessages.h"
#include "LogCommon.h"
-19
View File
@@ -1,19 +0,0 @@
#pragma once
#ifdef ESP_PLATFORM
#include <esp_log.h>
#include "Tactility/LogCommon.h"
#define TT_LOG_E(tag, format, ...) \
ESP_LOGE(tag, format, ##__VA_ARGS__)
#define TT_LOG_W(tag, format, ...) \
ESP_LOGW(tag, format, ##__VA_ARGS__)
#define TT_LOG_I(tag, format, ...) \
ESP_LOGI(tag, format, ##__VA_ARGS__)
#define TT_LOG_D(tag, format, ...) \
ESP_LOGD(tag, format, ##__VA_ARGS__)
#define TT_LOG_V(tag, format, ...) \
ESP_LOGV(tag, format, ##__VA_ARGS__)
#endif // ESP_PLATFORM
+2 -11
View File
@@ -9,20 +9,11 @@
// Alloc
#define LOG_MESSAGE_ALLOC_FAILED "Out of memory"
#define LOG_MESSAGE_ALLOC_FAILED_FMT "Out of memory (failed to allocated %zu bytes)"
#define LOG_MESSAGE_ALLOC_FAILED_FMT "Out of memory (failed to allocated {} bytes)"
// Mutex
#define LOG_MESSAGE_MUTEX_LOCK_FAILED "Mutex acquisition timeout"
#define LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT "Mutex acquisition timeout (%s)"
// SPI
#define LOG_MESSAGE_SPI_INIT_START_FMT "SPI %d init"
#define LOG_MESSAGE_SPI_INIT_FAILED_FMT "SPI %d init failed"
// I2C
#define LOG_MESSAGE_I2C_INIT_START "I2C init"
#define LOG_MESSAGE_I2C_INIT_CONFIG_FAILED "I2C config failed"
#define LOG_MESSAGE_I2C_INIT_DRIVER_INSTALL_FAILED "I2C driver install failed"
#define LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT "Mutex acquisition timeout ({})"
// Power on
#define LOG_MESSAGE_POWER_ON_START "Power on"
@@ -1,27 +0,0 @@
#pragma once
#ifndef ESP_PLATFORM
#include "LogCommon.h"
#include <cstdarg>
#include <cstdio>
namespace tt {
void log(LogLevel level, const char* tag, const char* format, ...);
} // namespace
#define TT_LOG_E(tag, format, ...) \
tt::log(tt::LogLevel::Error, tag, format, ##__VA_ARGS__)
#define TT_LOG_W(tag, format, ...) \
tt::log(tt::LogLevel::Warning, tag, format, ##__VA_ARGS__)
#define TT_LOG_I(tag, format, ...) \
tt::log(tt::LogLevel::Info, tag, format, ##__VA_ARGS__)
#define TT_LOG_D(tag, format, ...) \
tt::log(tt::LogLevel::Debug, tag, format, ##__VA_ARGS__)
#define TT_LOG_V(tag, format, ...) \
tt::log(tt::LogLevel::Verbose, tag, format, ##__VA_ARGS__)
#endif // ESP_PLATFORM
+72
View File
@@ -0,0 +1,72 @@
#pragma once
#include "LoggerAdapter.h"
#include "LoggerSettings.h"
#ifdef ESP_PLATFORM
#include "LoggerAdapterEsp.h"
#else
#include "LoggerAdapterGeneric.h"
#endif
#include <format>
namespace tt {
#ifdef ESP_PLATFORM
static LoggerAdapter defaultLoggerAdapter = espLoggerAdapter;
#else
static LoggerAdapter defaultLoggerAdapter = genericLoggerAdapter;
#endif
class Logger {
const char* tag;
public:
explicit Logger(const char* tag) : tag(tag) {}
template <typename... Args>
void log(LogLevel level, std::format_string<Args...> format, Args&&... args) const {
std::string message = std::format(format, std::forward<Args>(args)...);
defaultLoggerAdapter(level, tag, message.c_str());
}
template <typename... Args>
void verbose(std::format_string<Args...> format, Args&&... args) const {
log(LogLevel::Verbose, format, std::forward<Args>(args)...);
}
template <typename... Args>
void debug(std::format_string<Args...> format, Args&&... args) const {
log(LogLevel::Debug, format, std::forward<Args>(args)...);
}
template <typename... Args>
void info(std::format_string<Args...> format, Args&&... args) const {
log(LogLevel::Info, format, std::forward<Args>(args)...);
}
template <typename... Args>
void warn(std::format_string<Args...> format, Args&&... args) const {
log(LogLevel::Warning, format, std::forward<Args>(args)...);
}
template <typename... Args>
void error(std::format_string<Args...> format, Args&&... args) const {
log(LogLevel::Error, format, std::forward<Args>(args)...);
}
bool isLoggingVerbose() const { return LogLevel::Verbose <= LOG_LEVEL; }
bool isLoggingDebug() const { return LogLevel::Debug <= LOG_LEVEL; }
bool isLoggingInfo() const { return LogLevel::Info <= LOG_LEVEL; }
bool isLoggingWarning() const { return LogLevel::Warning <= LOG_LEVEL; }
bool isLoggingError() const { return LogLevel::Error <= LOG_LEVEL; }
};
}
@@ -0,0 +1,10 @@
#pragma once
#include "LoggerCommon.h"
#include <functional>
namespace tt {
typedef std::function<void(LogLevel level, const char* tag, const char* message)> LoggerAdapter;
}
@@ -0,0 +1,35 @@
#pragma once
#include "LoggerAdapter.h"
#include "LoggerAdapterShared.h"
#include <esp_log.h>
#include <sstream>
namespace tt {
inline esp_log_level_t toEspLogLevel(LogLevel level) {
switch (level) {
case LogLevel::Error:
return ESP_LOG_ERROR;
case LogLevel::Warning:
return ESP_LOG_WARN;
case LogLevel::Info:
return ESP_LOG_INFO;
case LogLevel::Debug:
return ESP_LOG_DEBUG;
case LogLevel::Verbose:
default:
return ESP_LOG_VERBOSE;
}
}
static const LoggerAdapter espLoggerAdapter = [](LogLevel level, const char* tag, const char* message) {
constexpr auto COLOR_RESET = "\033[0m";
constexpr auto COLOR_GREY = "\033[37m";
std::stringstream buffer;
buffer << COLOR_GREY << esp_log_timestamp() << ' ' << toTagColour(level) << toPrefix(level) << COLOR_GREY << " [" << COLOR_RESET << tag << COLOR_GREY << "] " << toMessageColour(level) << message << COLOR_RESET << std::endl;
esp_log_write(toEspLogLevel(level), tag, "%s", buffer.str().c_str());
};
}
@@ -0,0 +1,35 @@
#pragma once
#include "LoggerAdapter.h"
#include "LoggerAdapterShared.h"
#include <cstdint>
#include <mutex>
#include <sstream>
#include <sys/time.h>
namespace tt {
static uint64_t getLogTimestamp() {
static uint64_t base = 0U;
static std::once_flag init_flag;
std::call_once(init_flag, []() {
timeval time {};
gettimeofday(&time, nullptr);
base = ((uint64_t)time.tv_sec * 1000U) + (time.tv_usec / 1000U);
});
timeval time {};
gettimeofday(&time, nullptr);
uint64_t now = ((uint64_t)time.tv_sec * 1000U) + (time.tv_usec / 1000U);
return now - base;
}
static const LoggerAdapter genericLoggerAdapter = [](LogLevel level, const char* tag, const char* message) {
constexpr auto COLOR_RESET = "\033[0m";
constexpr auto COLOR_GREY = "\033[37m";
std::stringstream buffer;
buffer << COLOR_GREY << getLogTimestamp() << ' ' << toTagColour(level) << toPrefix(level) << COLOR_GREY << " [" << COLOR_RESET << tag << COLOR_GREY << "] " << toMessageColour(level) << message << COLOR_RESET << std::endl;
printf(buffer.str().c_str());
};
}
@@ -0,0 +1,58 @@
#pragma once
#include "LoggerCommon.h"
namespace tt {
inline const char* toTagColour(LogLevel level) {
using enum LogLevel;
switch (level) {
case Error:
return "\033[1;31m";
case Warning:
return "\033[1;33m";
case Info:
return "\033[32m";
case Debug:
return "\033[36m";
case Verbose:
return "\033[37m";
default:
return "";
}
}
inline const char* toMessageColour(LogLevel level) {
using enum LogLevel;
switch (level) {
case Error:
return "\033[1;31m";
case Warning:
return "\033[1;33m";
case Info:
case Debug:
case Verbose:
return "\033[0m";
default:
return "";
}
}
inline char toPrefix(LogLevel level) {
using enum LogLevel;
switch (level) {
case Error:
return 'E';
case Warning:
return 'W';
case Info:
return 'I';
case Debug:
return 'D';
case Verbose:
default:
return 'V';
}
}
}
@@ -0,0 +1,9 @@
#pragma once
#include "LoggerCommon.h"
namespace tt {
constexpr auto LOG_LEVEL = LogLevel::Info;
}
@@ -2,9 +2,6 @@
#include <cstdio>
#include "Tactility/Thread.h"
#include "Check.h"
#include "CoreDefines.h"
#include "Log.h"
#include <Tactility/kernel/Kernel.h>
#include "Logger.h"