mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-04-18 17:35:05 +00:00
Various improvements (#461)
* **New Features** * Time and delay utilities added (ticks, ms, µs); SD card now uses an expansion-header CS pin; HTTP downloads warn when run on the GUI task and yield to avoid blocking. * **Bug Fixes / Reliability** * Many hard-crash paths converted to guarded checks to reduce abrupt termination and improve stability. * **Tests** * Unit tests added to validate time and delay accuracy. * **Chores** * License header and build/macro updates.
This commit is contained in:
parent
619b5aa53b
commit
e6abd496f9
@ -46,14 +46,6 @@ void getLimit() {
|
||||
}
|
||||
```
|
||||
|
||||
### Preprocessor
|
||||
|
||||
Preprocessor functions are written in snake-case and prefixed with `tt_`, for example:
|
||||
|
||||
```c++
|
||||
#define tt_check(x) if (!(x)) { /* .. */ }
|
||||
```
|
||||
|
||||
### Type names
|
||||
|
||||
Consts are lower camel case with capital letters.
|
||||
|
||||
@ -29,7 +29,7 @@ static bool keyboard_i2c_read(uint8_t* output) {
|
||||
* @param indev_drv
|
||||
* @param data
|
||||
*/
|
||||
static void keyboard_read_callback(TT_UNUSED lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
static void keyboard_read_callback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
static uint8_t last_buffer = 0x00;
|
||||
uint8_t read_buffer = 0x00;
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||
|
||||
constexpr auto SDCARD_PIN_CS = GPIO_NUM_12;
|
||||
constexpr auto EXPANSION_HEADER_PIN_CS = GPIO_NUM_5;
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
@ -14,7 +15,7 @@ std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::hal::spi::getLock(SPI3_HOST),
|
||||
std::vector<gpio_num_t>(),
|
||||
std::vector { EXPANSION_HEADER_PIN_CS },
|
||||
SPI3_HOST
|
||||
);
|
||||
|
||||
|
||||
@ -18,6 +18,9 @@ dpi=294
|
||||
[lvgl]
|
||||
colorDepth=16
|
||||
|
||||
[cdn]
|
||||
warningMessage=Only the original hardware variant with the ILI9881C display is supported for now
|
||||
|
||||
[sdkconfig]
|
||||
CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=16
|
||||
CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT=30
|
||||
|
||||
@ -52,7 +52,7 @@ static void lvgl_unlock() {
|
||||
}
|
||||
|
||||
void lvgl_task_interrupt() {
|
||||
tt_check(task_lock(portMAX_DELAY));
|
||||
check(task_lock(portMAX_DELAY));
|
||||
task_set_running(false); // interrupt task with boolean as flag
|
||||
task_unlock();
|
||||
}
|
||||
@ -75,7 +75,7 @@ void lvgl_task_start() {
|
||||
assert(task_result == pdTRUE);
|
||||
}
|
||||
|
||||
static void lvgl_task(TT_UNUSED void* arg) {
|
||||
static void lvgl_task(void* arg) {
|
||||
LOGGER.info("LVGL task started");
|
||||
|
||||
/** Ideally. the display handle would be created during Simulator.start(),
|
||||
|
||||
@ -15,7 +15,7 @@ void setMain(MainFunction newMainFunction) {
|
||||
mainFunction = newMainFunction;
|
||||
}
|
||||
|
||||
static void freertosMainTask(TT_UNUSED void* parameter) {
|
||||
static void freertosMainTask(void* parameter) {
|
||||
LOGGER.info("starting app_main()");
|
||||
assert(simulator::mainFunction);
|
||||
mainFunction();
|
||||
|
||||
@ -17,7 +17,7 @@ static bool initBoot() {
|
||||
return true;
|
||||
}
|
||||
|
||||
TT_UNUSED static void deinitPower() {
|
||||
static void deinitPower() {
|
||||
lvgl_task_interrupt();
|
||||
while (lvgl_task_is_running()) {
|
||||
tt::kernel::delayMillis(10);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "SdlTouch.h"
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
|
||||
/** Hack: variable comes from LvglTask.cpp */
|
||||
@ -14,11 +15,11 @@ public:
|
||||
std::string getDescription() const override { return ""; }
|
||||
|
||||
bool start() override { return true; }
|
||||
bool stop() override { tt_crash("Not supported"); }
|
||||
bool stop() override { check(false, "Not supported"); }
|
||||
|
||||
bool supportsLvgl() const override { return true; }
|
||||
bool startLvgl() override { return displayHandle != nullptr; }
|
||||
bool stopLvgl() override { tt_crash("Not supported"); }
|
||||
bool stopLvgl() override { check(false, "Not supported"); }
|
||||
lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; }
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable getTouchDevice() override { return std::make_shared<SdlTouch>(); }
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/keyboard/KeyboardDevice.h>
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
|
||||
class SdlKeyboard final : public tt::hal::keyboard::KeyboardDevice {
|
||||
@ -17,7 +18,7 @@ public:
|
||||
return handle != nullptr;
|
||||
}
|
||||
|
||||
bool stopLvgl() override { tt_crash("Not supported"); }
|
||||
bool stopLvgl() override { check(false, "Not supported"); }
|
||||
|
||||
bool isAttached() const override { return true; }
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/touch/TouchDevice.h"
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
|
||||
class SdlTouch final : public tt::hal::touch::TouchDevice {
|
||||
@ -15,7 +16,7 @@ public:
|
||||
|
||||
bool start() override { return true; }
|
||||
|
||||
bool stop() override { tt_crash("Not supported"); }
|
||||
bool stop() override { check(false, "Not supported"); }
|
||||
|
||||
bool supportsLvgl() const override { return true; }
|
||||
|
||||
@ -24,7 +25,7 @@ public:
|
||||
return handle != nullptr;
|
||||
}
|
||||
|
||||
bool stopLvgl() override { tt_crash("Not supported"); }
|
||||
bool stopLvgl() override { check(false, "Not supported"); }
|
||||
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return handle; }
|
||||
|
||||
|
||||
@ -6,10 +6,7 @@
|
||||
static const auto LOGGER = tt::Logger("DRV2605");
|
||||
|
||||
Drv2605::Drv2605(i2c_port_t port, bool autoPlayStartupBuzz) : I2cDevice(port, ADDRESS), autoPlayStartupBuzz(autoPlayStartupBuzz) {
|
||||
if (!init()) {
|
||||
LOGGER.error("Failed to initialize DRV2605");
|
||||
tt_crash();
|
||||
}
|
||||
check(init(), "Initialize DRV2605");
|
||||
|
||||
if (autoPlayStartupBuzz) {
|
||||
setWaveFormForBuzz();
|
||||
|
||||
@ -10,9 +10,10 @@
|
||||
static const auto LOGGER = tt::Logger("EspLcdDisplay");
|
||||
|
||||
EspLcdDisplay::~EspLcdDisplay() {
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
tt_crash("DisplayDriver is still in use. This will cause memory access violations.");
|
||||
}
|
||||
check(
|
||||
displayDriver == nullptr || displayDriver.use_count() < 2, // 1 reference is held by this class
|
||||
"DisplayDriver is still in use. This will cause memory access violations."
|
||||
);
|
||||
}
|
||||
|
||||
bool EspLcdDisplay::start() {
|
||||
@ -115,7 +116,7 @@ std::shared_ptr<tt::hal::display::DisplayDriver> EspLcdDisplay::getDisplayDriver
|
||||
} else if (lvgl_port_config.color_format == LV_COLOR_FORMAT_RGB888) {
|
||||
color_format = tt::hal::display::ColorFormat::RGB888;
|
||||
} else {
|
||||
tt_crash("unsupported driver");
|
||||
check(false, "unsupported driver");
|
||||
}
|
||||
|
||||
displayDriver = std::make_shared<EspLcdDisplayDriver>(
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
#include <esp_lcd_types.h>
|
||||
#include <esp_lvgl_port_disp.h>
|
||||
|
||||
class TT_DEPRECATED EspLcdDisplay : public tt::hal::display::DisplayDevice {
|
||||
/** @deprecated use EspLcdDisplayV2 */
|
||||
class EspLcdDisplay : public tt::hal::display::DisplayDevice {
|
||||
|
||||
esp_lcd_panel_io_handle_t _Nullable ioHandle = nullptr;
|
||||
esp_lcd_panel_handle_t _Nullable panelHandle = nullptr;
|
||||
@ -29,7 +30,7 @@ protected:
|
||||
|
||||
virtual bool isRgbPanel() const { return false; }
|
||||
|
||||
virtual lvgl_port_display_rgb_cfg_t getLvglPortDisplayRgbConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) { tt_crash("Not supported"); }
|
||||
virtual lvgl_port_display_rgb_cfg_t getLvglPortDisplayRgbConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) { check(false, "Not supported"); }
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@ -18,9 +18,10 @@ inline unsigned int getBufferSize(const std::shared_ptr<EspLcdConfiguration>& co
|
||||
}
|
||||
|
||||
EspLcdDisplayV2::~EspLcdDisplayV2() {
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
tt_crash("DisplayDriver is still in use. This will cause memory access violations.");
|
||||
}
|
||||
check(
|
||||
displayDriver == nullptr || displayDriver.use_count() < 2, // 1 reference is held by this class
|
||||
"DisplayDriver is still in use. This will cause memory access violations."
|
||||
);
|
||||
}
|
||||
|
||||
bool EspLcdDisplayV2::applyConfiguration() const {
|
||||
@ -215,7 +216,7 @@ std::shared_ptr<tt::hal::display::DisplayDriver> EspLcdDisplayV2::getDisplayDriv
|
||||
} else if (lvgl_port_config.color_format == LV_COLOR_FORMAT_RGB888) {
|
||||
color_format = tt::hal::display::ColorFormat::RGB888;
|
||||
} else {
|
||||
tt_crash("unsupported driver");
|
||||
check(false, "unsupported driver");
|
||||
}
|
||||
|
||||
displayDriver = std::make_shared<EspLcdDisplayDriver>(
|
||||
|
||||
@ -53,7 +53,7 @@ protected:
|
||||
|
||||
virtual bool isRgbPanel() const { return false; }
|
||||
|
||||
virtual lvgl_port_display_rgb_cfg_t getLvglPortDisplayRgbConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) { tt_crash("Not supported"); }
|
||||
virtual lvgl_port_display_rgb_cfg_t getLvglPortDisplayRgbConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) { check(false, "Not supported"); }
|
||||
|
||||
// Hook for MIPI-DSI DPI panels to let LVGL port use DSI-specific path
|
||||
virtual bool useDsiPanel() const { return false; }
|
||||
|
||||
@ -12,9 +12,10 @@
|
||||
static const auto LOGGER = tt::Logger("RgbDisplay");
|
||||
|
||||
RgbDisplay::~RgbDisplay() {
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
tt_crash("DisplayDriver is still in use. This will cause memory access violations.");
|
||||
}
|
||||
check(
|
||||
displayDriver == nullptr || displayDriver.use_count() == 0,
|
||||
"DisplayDriver is still in use. This will cause memory access violations."
|
||||
);
|
||||
}
|
||||
|
||||
bool RgbDisplay::start() {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <Tactility/ErrorEsp32.h>
|
||||
|
||||
error_t esp_err_to_error(esp_err_t error) {
|
||||
|
||||
@ -46,12 +46,12 @@ private:
|
||||
|
||||
int findAppInStack(const std::string& id) const;
|
||||
|
||||
bool onStart(TT_UNUSED ServiceContext& service) override {
|
||||
bool onStart(ServiceContext& service) override {
|
||||
dispatcherThread->start();
|
||||
return true;
|
||||
}
|
||||
|
||||
void onStop(TT_UNUSED ServiceContext& service) override {
|
||||
void onStop(ServiceContext& service) override {
|
||||
// Send stop signal to thread and wait for thread to finish
|
||||
mutex.withLock([this] {
|
||||
dispatcherThread->stop();
|
||||
|
||||
@ -53,10 +53,10 @@ class AppInstance : public AppContext {
|
||||
#ifdef ESP_PLATFORM
|
||||
return createElfApp(manifest);
|
||||
#else
|
||||
tt_crash("not supported");
|
||||
check(false, "not supported");
|
||||
#endif
|
||||
} else {
|
||||
tt_crash("not implemented");
|
||||
check(false, "not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,13 @@ constexpr auto GUI_THREAD_FLAG_INPUT = (1 << 1);
|
||||
constexpr auto GUI_THREAD_FLAG_EXIT = (1 << 2);
|
||||
constexpr auto GUI_THREAD_FLAG_ALL = (GUI_THREAD_FLAG_DRAW | GUI_THREAD_FLAG_INPUT | GUI_THREAD_FLAG_EXIT);
|
||||
|
||||
/**
|
||||
* Output a log warning if the current task is the GUI task.
|
||||
* This is meant for code that should either create their own task or use a different task to execute on.
|
||||
* @param[in] context a descriptive name or label that refers to the caller of this function
|
||||
*/
|
||||
void warnIfRunningOnGuiTask(const char* context);
|
||||
|
||||
class GuiService final : public Service {
|
||||
|
||||
// Thread and lock
|
||||
@ -46,7 +53,7 @@ class GuiService final : public Service {
|
||||
void redraw();
|
||||
|
||||
void lock() const {
|
||||
tt_check(mutex.lock(pdMS_TO_TICKS(1000)));
|
||||
check(mutex.lock(pdMS_TO_TICKS(1000)));
|
||||
}
|
||||
|
||||
void unlock() const {
|
||||
@ -59,9 +66,9 @@ class GuiService final : public Service {
|
||||
|
||||
public:
|
||||
|
||||
bool onStart(TT_UNUSED ServiceContext& service) override;
|
||||
bool onStart(ServiceContext& service) override;
|
||||
|
||||
void onStop(TT_UNUSED ServiceContext& service) override;
|
||||
void onStop(ServiceContext& service) override;
|
||||
|
||||
void requestDraw();
|
||||
|
||||
|
||||
@ -95,7 +95,7 @@ public:
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
auto parameters = app.getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
check(parameters != nullptr, "Parameters missing");
|
||||
|
||||
std::string title = getTitleParameter(app.getParameters());
|
||||
lv_obj_t* toolbar = lvgl::toolbar_create(parent, title);
|
||||
|
||||
@ -4,9 +4,9 @@
|
||||
#include <Tactility/app/AppContext.h>
|
||||
#include <Tactility/app/AppManifest.h>
|
||||
#include <Tactility/app/alertdialog/AlertDialog.h>
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/lvgl/Style.h>
|
||||
#include <Tactility/lvgl/Toolbar.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <format>
|
||||
@ -27,7 +27,7 @@ class AppDetailsApp : public App {
|
||||
|
||||
std::shared_ptr<AppManifest> manifest;
|
||||
|
||||
static void onPressUninstall(TT_UNUSED lv_event_t* event) {
|
||||
static void onPressUninstall(lv_event_t* event) {
|
||||
auto* self = static_cast<AppDetailsApp*>(lv_event_get_user_data(event));
|
||||
std::vector<std::string> choices = {
|
||||
"Yes",
|
||||
@ -40,7 +40,7 @@ public:
|
||||
|
||||
void onCreate(AppContext& app) override {
|
||||
const auto parameters = app.getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
check(parameters != nullptr, "Parameters missing");
|
||||
auto app_id = parameters->getString("appId");
|
||||
manifest = findAppManifestById(app_id);
|
||||
assert(manifest != nullptr);
|
||||
@ -86,7 +86,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void onResult(TT_UNUSED AppContext& appContext, TT_UNUSED LaunchId launchId, TT_UNUSED Result result, std::unique_ptr<Bundle> bundle) override {
|
||||
void onResult(AppContext& appContext, LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle) override {
|
||||
if (result != Result::Ok || bundle == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ class AppHubApp final : public App {
|
||||
|
||||
public:
|
||||
|
||||
void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) override {
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
|
||||
|
||||
|
||||
@ -186,7 +186,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) override {
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ class AppListApp final : public App {
|
||||
|
||||
public:
|
||||
|
||||
void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) override {
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
auto* toolbar = lvgl::toolbar_create(parent, app);
|
||||
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ class AppSettingsApp final : public App {
|
||||
|
||||
public:
|
||||
|
||||
void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) override {
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
auto* toolbar = lvgl::toolbar_create(parent, "Installed Apps");
|
||||
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
|
||||
|
||||
|
||||
@ -170,7 +170,7 @@ public:
|
||||
thread.join();
|
||||
}
|
||||
|
||||
void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) override {
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
lvgl::obj_set_style_bg_blacken(parent);
|
||||
lv_obj_set_style_border_width(parent, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_radius(parent, 0, LV_STATE_DEFAULT);
|
||||
|
||||
@ -17,7 +17,7 @@ static const auto LOGGER = Logger("CrashDiagnostics");
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
void onContinuePressed(TT_UNUSED lv_event_t* event) {
|
||||
void onContinuePressed(lv_event_t* event) {
|
||||
stop(manifest.appId);
|
||||
launcher::start();
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void onHide(TT_UNUSED AppContext& app) override {
|
||||
void onHide(AppContext& app) override {
|
||||
if (displaySettingsUpdated) {
|
||||
// Dispatch it, so file IO doesn't block the UI
|
||||
const settings::display::DisplaySettings settings_to_save = displaySettings;
|
||||
|
||||
@ -27,7 +27,7 @@ public:
|
||||
view->init(appContext, parent);
|
||||
}
|
||||
|
||||
void onResult(AppContext& appContext, TT_UNUSED LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle) override {
|
||||
void onResult(AppContext& appContext, LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle) override {
|
||||
view->onResult(launchId, result, std::move(bundle));
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
#include <Tactility/app/files/View.h>
|
||||
#include <Tactility/app/files/SupportedFiles.h>
|
||||
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/app/alertdialog/AlertDialog.h>
|
||||
#include <Tactility/app/imageviewer/ImageViewer.h>
|
||||
#include <Tactility/app/inputdialog/InputDialog.h>
|
||||
#include <Tactility/app/notes/Notes.h>
|
||||
#include <Tactility/app/ElfApp.h>
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/kernel/Platform.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
@ -58,7 +59,7 @@ static void onDeletePressedCallback(lv_event_t* event) {
|
||||
view->onDeletePressed();
|
||||
}
|
||||
|
||||
static void onNavigateUpPressedCallback(TT_UNUSED lv_event_t* event) {
|
||||
static void onNavigateUpPressedCallback(lv_event_t* event) {
|
||||
auto* view = static_cast<View*>(lv_event_get_user_data(event));
|
||||
view->onNavigateUpPressed();
|
||||
}
|
||||
@ -179,7 +180,7 @@ void View::onDirEntryLongPressed(int32_t index) {
|
||||
}
|
||||
|
||||
void View::createDirEntryWidget(lv_obj_t* list, dirent& dir_entry) {
|
||||
tt_check(list);
|
||||
check(list);
|
||||
const char* symbol;
|
||||
if (dir_entry.d_type == file::TT_DT_DIR || dir_entry.d_type == file::TT_DT_CHR) {
|
||||
symbol = LV_SYMBOL_DIRECTORY;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include <Tactility/app/fileselection/View.h>
|
||||
|
||||
#include <Tactility/app/alertdialog/AlertDialog.h>
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
@ -30,7 +31,7 @@ static void onDirEntryPressedCallback(lv_event_t* event) {
|
||||
view->onDirEntryPressed(index);
|
||||
}
|
||||
|
||||
static void onNavigateUpPressedCallback(TT_UNUSED lv_event_t* event) {
|
||||
static void onNavigateUpPressedCallback(lv_event_t* event) {
|
||||
auto* view = static_cast<View*>(lv_event_get_user_data(event));
|
||||
view->onNavigateUpPressed();
|
||||
}
|
||||
@ -126,7 +127,7 @@ void View::onPathTextChanged(lv_event_t* event) {
|
||||
}
|
||||
|
||||
void View::createDirEntryWidget(lv_obj_t* list, dirent& dir_entry) {
|
||||
tt_check(list);
|
||||
check(list);
|
||||
const char* symbol;
|
||||
if (dir_entry.d_type == file::TT_DT_DIR || dir_entry.d_type == file::TT_DT_CHR) {
|
||||
symbol = LV_SYMBOL_DIRECTORY;
|
||||
|
||||
@ -318,7 +318,7 @@ class GpsSettingsApp final : public App {
|
||||
}
|
||||
}
|
||||
|
||||
void onGpsToggled(TT_UNUSED lv_event_t* event) {
|
||||
void onGpsToggled(lv_event_t* event) {
|
||||
bool wants_on = lv_obj_has_state(switchWidget, LV_STATE_CHECKED);
|
||||
auto state = service->getState();
|
||||
bool is_on = (state == service::gps::State::On) || (state == service::gps::State::OnPending);
|
||||
|
||||
@ -325,7 +325,7 @@ void I2cScannerApp::selectBus(int32_t selected) {
|
||||
updateViews();
|
||||
}
|
||||
|
||||
void I2cScannerApp::onPressScan(TT_UNUSED lv_event_t* event) {
|
||||
void I2cScannerApp::onPressScan(lv_event_t* event) {
|
||||
if (scanState == ScanStateScanning) {
|
||||
stopScanning();
|
||||
} else {
|
||||
|
||||
@ -45,7 +45,7 @@ class ImageViewerApp final : public App {
|
||||
lv_obj_align_to(file_label, wrapper, LV_ALIGN_BOTTOM_LEFT, 0, 0);
|
||||
|
||||
std::shared_ptr<const Bundle> bundle = app.getParameters();
|
||||
tt_check(bundle != nullptr, "Parameters not set");
|
||||
check(bundle != nullptr, "Parameters not set");
|
||||
std::string file_argument;
|
||||
if (bundle->optString(IMAGE_VIEWER_FILE_ARGUMENT, file_argument)) {
|
||||
std::string prefixed_path = lvgl::PATH_PREFIX + file_argument;
|
||||
|
||||
@ -79,7 +79,7 @@ public:
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
auto parameters = app.getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
check(parameters != nullptr, "Parameters missing");
|
||||
|
||||
std::string title = getTitleParameter(app.getParameters());
|
||||
auto* toolbar = lvgl::toolbar_create(parent, title);
|
||||
|
||||
@ -170,7 +170,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void onHide(TT_UNUSED AppContext& app) override {
|
||||
void onHide(AppContext& app) override {
|
||||
if (updated) {
|
||||
const auto copy = kbSettings;
|
||||
getMainDispatcher().dispatch([copy]{ settings::keyboard::save(copy); });
|
||||
|
||||
@ -76,7 +76,7 @@ class LauncherApp final : public App {
|
||||
return show_power_button;
|
||||
}
|
||||
|
||||
static void onAppPressed(TT_UNUSED lv_event_t* e) {
|
||||
static void onAppPressed(lv_event_t* e) {
|
||||
auto* appId = static_cast<const char*>(lv_event_get_user_data(e));
|
||||
start(appId);
|
||||
}
|
||||
@ -90,7 +90,7 @@ class LauncherApp final : public App {
|
||||
|
||||
public:
|
||||
|
||||
void onCreate(TT_UNUSED AppContext& app) override {
|
||||
void onCreate(AppContext& app) override {
|
||||
settings::BootSettings boot_properties;
|
||||
if (settings::loadBootSettings(boot_properties) && !boot_properties.autoStartAppId.empty()) {
|
||||
LOGGER.info("Starting {}", boot_properties.autoStartAppId);
|
||||
@ -98,7 +98,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) override {
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
auto* buttons_wrapper = lv_obj_create(parent);
|
||||
|
||||
auto ui_scale = hal::getConfiguration()->uiScale;
|
||||
|
||||
@ -149,7 +149,7 @@ public:
|
||||
lv_obj_add_event_cb(languageDropdown, onLanguageSet, LV_EVENT_VALUE_CHANGED, this);
|
||||
}
|
||||
|
||||
void onHide(TT_UNUSED AppContext& app) override {
|
||||
void onHide(AppContext& app) override {
|
||||
if (settingsUpdated && regionTextArea) {
|
||||
settings::SystemSettings sysSettings;
|
||||
if (settings::loadSystemSettings(sysSettings)) {
|
||||
|
||||
@ -183,7 +183,7 @@ public:
|
||||
update_timer.start();
|
||||
}
|
||||
|
||||
void onHide(TT_UNUSED AppContext& app) override {
|
||||
void onHide(AppContext& app) override {
|
||||
update_timer.stop();
|
||||
}
|
||||
};
|
||||
|
||||
@ -58,14 +58,14 @@ std::shared_ptr<ScreenshotApp> _Nullable optApp() {
|
||||
}
|
||||
}
|
||||
|
||||
static void onStartPressedCallback(TT_UNUSED lv_event_t* event) {
|
||||
static void onStartPressedCallback(lv_event_t* event) {
|
||||
auto app = optApp();
|
||||
if (app != nullptr) {
|
||||
app->onStartPressed();
|
||||
}
|
||||
}
|
||||
|
||||
static void onModeSetCallback(TT_UNUSED lv_event_t* event) {
|
||||
static void onModeSetCallback(lv_event_t* event) {
|
||||
auto app = optApp();
|
||||
if (app != nullptr) {
|
||||
app->onModeSet();
|
||||
|
||||
@ -80,7 +80,7 @@ public:
|
||||
lv_obj_set_flex_grow(list, 1);
|
||||
|
||||
auto parameters = app.getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
check(parameters != nullptr, "Parameters missing");
|
||||
std::string items_concatenated;
|
||||
if (parameters->optString(PARAMETER_BUNDLE_KEY_ITEMS, items_concatenated)) {
|
||||
std::vector<std::string> items = string::split(items_concatenated, PARAMETER_ITEM_CONCATENATION_TOKEN);
|
||||
|
||||
@ -16,7 +16,7 @@ static void onAppPressed(lv_event_t* e) {
|
||||
}
|
||||
|
||||
static void createWidget(const std::shared_ptr<AppManifest>& manifest, void* parent) {
|
||||
tt_check(parent);
|
||||
check(parent);
|
||||
auto* list = (lv_obj_t*)parent;
|
||||
const void* icon = !manifest->appIcon.empty() ? manifest->appIcon.c_str() : TT_ASSETS_APP_ICON_FALLBACK;
|
||||
auto* btn = lv_list_add_button(list, icon, manifest->appName.c_str());
|
||||
|
||||
@ -692,7 +692,7 @@ class SystemInfoApp final : public App {
|
||||
tasksTimer.start(); // Tasks/CPU: every 15s
|
||||
}
|
||||
|
||||
void onHide(TT_UNUSED AppContext& app) override {
|
||||
void onHide(AppContext& app) override {
|
||||
memoryTimer.stop();
|
||||
tasksTimer.stop();
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ public:
|
||||
lv_label_set_text(timeZoneLabel, timeZoneName.c_str());
|
||||
}
|
||||
|
||||
void onResult(AppContext& app, TT_UNUSED LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle) override {
|
||||
void onResult(AppContext& app, LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle) override {
|
||||
if (result == Result::Ok && bundle != nullptr) {
|
||||
const auto name = timezone::getResultName(*bundle);
|
||||
const auto code = timezone::getResultCode(*bundle);
|
||||
|
||||
@ -73,12 +73,12 @@ class TimeZoneApp final : public App {
|
||||
lv_obj_t* listWidget = nullptr;
|
||||
lv_obj_t* filterTextareaWidget = nullptr;
|
||||
|
||||
static void onTextareaValueChangedCallback(TT_UNUSED lv_event_t* e) {
|
||||
static void onTextareaValueChangedCallback(lv_event_t* e) {
|
||||
auto* app = (TimeZoneApp*)lv_event_get_user_data(e);
|
||||
app->onTextareaValueChanged(e);
|
||||
}
|
||||
|
||||
void onTextareaValueChanged(TT_UNUSED lv_event_t* e) {
|
||||
void onTextareaValueChanged(lv_event_t* e) {
|
||||
if (mutex.lock(100 / portTICK_PERIOD_MS)) {
|
||||
if (updateTimer->isRunning()) {
|
||||
updateTimer->stop();
|
||||
|
||||
@ -197,7 +197,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void onHide(TT_UNUSED AppContext& app) override {
|
||||
void onHide(AppContext& app) override {
|
||||
if (updated) {
|
||||
const auto copy = tbSettings;
|
||||
getMainDispatcher().dispatch([copy]{ settings::trackball::save(copy); });
|
||||
|
||||
@ -11,12 +11,12 @@
|
||||
|
||||
namespace tt::app::usbsettings {
|
||||
|
||||
static void onRebootMassStorageSdmmc(TT_UNUSED lv_event_t* event) {
|
||||
static void onRebootMassStorageSdmmc(lv_event_t* event) {
|
||||
hal::usb::rebootIntoMassStorageSdmmc();
|
||||
}
|
||||
|
||||
// Flash reboot handler
|
||||
static void onRebootMassStorageFlash(TT_UNUSED lv_event_t* event) {
|
||||
static void onRebootMassStorageFlash(lv_event_t* event) {
|
||||
hal::usb::rebootIntoMassStorageFlash();
|
||||
}
|
||||
|
||||
|
||||
@ -183,7 +183,7 @@ class WebServerSettingsApp final : public App {
|
||||
}
|
||||
|
||||
public:
|
||||
void onCreate(TT_UNUSED AppContext& app) override {
|
||||
void onCreate(AppContext& app) override {
|
||||
wsSettings = settings::webserver::loadOrGetDefault();
|
||||
originalSettings = wsSettings;
|
||||
}
|
||||
@ -353,7 +353,7 @@ public:
|
||||
"AP mode uses the password configured above.");
|
||||
}
|
||||
|
||||
void onHide(TT_UNUSED AppContext& app) override {
|
||||
void onHide(AppContext& app) override {
|
||||
if (updated) {
|
||||
// Read values from text areas
|
||||
if (textAreaApPassword) {
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <Tactility/app/AppContext.h>
|
||||
#include <Tactility/app/AppManifest.h>
|
||||
#include <Tactility/app/alertdialog/AlertDialog.h>
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/lvgl/Style.h>
|
||||
@ -34,7 +35,7 @@ class WifiApSettings : public App {
|
||||
std::string ssid;
|
||||
PubSub<service::wifi::WifiEvent>::SubscriptionHandle wifiSubscription = nullptr;
|
||||
|
||||
static void onPressForget(TT_UNUSED lv_event_t* event) {
|
||||
static void onPressForget(lv_event_t* event) {
|
||||
std::vector<std::string> choices = {
|
||||
"Yes",
|
||||
"No"
|
||||
@ -61,7 +62,7 @@ class WifiApSettings : public App {
|
||||
static void onPressConnect(lv_event_t* event) {
|
||||
auto app = getCurrentAppContext();
|
||||
auto parameters = app->getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
check(parameters != nullptr, "Parameters missing");
|
||||
|
||||
std::string ssid = parameters->getString("ssid");
|
||||
service::wifi::settings::WifiApSettings settings;
|
||||
@ -124,7 +125,7 @@ public:
|
||||
|
||||
void onCreate(AppContext& app) override {
|
||||
const auto parameters = app.getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
check(parameters != nullptr, "Parameters missing");
|
||||
ssid = parameters->getString("ssid");
|
||||
}
|
||||
|
||||
@ -209,7 +210,7 @@ public:
|
||||
viewEnabled = false;
|
||||
}
|
||||
|
||||
void onResult(TT_UNUSED AppContext& appContext, TT_UNUSED LaunchId launchId, TT_UNUSED Result result, std::unique_ptr<Bundle> bundle) override {
|
||||
void onResult(AppContext& appContext, LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle) override {
|
||||
if (result != Result::Ok || bundle == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -220,7 +221,7 @@ public:
|
||||
}
|
||||
|
||||
auto parameters = appContext.getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
check(parameters != nullptr, "Parameters missing");
|
||||
|
||||
std::string ssid = parameters->getString("ssid");
|
||||
if (!service::wifi::settings::remove(ssid.c_str())) {
|
||||
|
||||
@ -21,7 +21,7 @@ void View::resetErrors() {
|
||||
lv_obj_add_flag(connection_error, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
static void onConnect(TT_UNUSED lv_event_t* event) {
|
||||
static void onConnect(lv_event_t* event) {
|
||||
auto wifi = std::static_pointer_cast<WifiConnect>(getCurrentApp());
|
||||
auto& view = wifi->getView();
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ constexpr auto* WIFI_CONNECT_PARAM_PASSWORD = "password"; // String
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
static void onConnect(const service::wifi::settings::WifiApSettings& ap_settings, bool remember, TT_UNUSED void* parameter) {
|
||||
static void onConnect(const service::wifi::settings::WifiApSettings& ap_settings, bool remember, void* parameter) {
|
||||
auto* wifi = static_cast<WifiConnect*>(parameter);
|
||||
wifi->getState().setApSettings(ap_settings);
|
||||
wifi->getState().setConnecting(true);
|
||||
@ -88,7 +88,7 @@ void WifiConnect::onShow(AppContext& app, lv_obj_t* parent) {
|
||||
unlock();
|
||||
}
|
||||
|
||||
void WifiConnect::onHide(TT_UNUSED AppContext& app) {
|
||||
void WifiConnect::onHide(AppContext& app) {
|
||||
// No need to lock view, as this is called from within Gui's LVGL context
|
||||
lock();
|
||||
viewEnabled = false;
|
||||
|
||||
@ -131,7 +131,7 @@ void WifiManage::onShow(AppContext& app, lv_obj_t* parent) {
|
||||
}
|
||||
}
|
||||
|
||||
void WifiManage::onHide(TT_UNUSED AppContext& app) {
|
||||
void WifiManage::onHide(AppContext& app) {
|
||||
lock();
|
||||
service::wifi::getPubsub()->unsubscribe(wifiSubscription);
|
||||
wifiSubscription = nullptr;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <Tactility/hal/Device.h>
|
||||
#include <Tactility/hal/gps/GpsInit.h>
|
||||
@ -68,20 +69,19 @@ void init(const Configuration& configuration) {
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootInitHalBegin);
|
||||
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootInitI2cBegin);
|
||||
tt_check(i2c::init(configuration.i2c), "I2C init failed");
|
||||
check(i2c::init(configuration.i2c), "I2C init failed");
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootInitI2cEnd);
|
||||
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootInitSpiBegin);
|
||||
tt_check(spi::init(configuration.spi), "SPI init failed");
|
||||
check(spi::init(configuration.spi), "SPI init failed");
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootInitSpiEnd);
|
||||
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootInitUartBegin);
|
||||
tt_check(uart::init(configuration.uart), "UART init failed");
|
||||
check(uart::init(configuration.uart), "UART init failed");
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootInitUartEnd);
|
||||
|
||||
if (configuration.initBoot != nullptr) {
|
||||
LOGGER.info("Init boot");
|
||||
tt_check(configuration.initBoot(), "Init boot failed");
|
||||
check(configuration.initBoot(), "Init boot failed");
|
||||
}
|
||||
|
||||
registerDevices(configuration);
|
||||
|
||||
@ -139,7 +139,7 @@ GpsResponse getACKCas(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32
|
||||
bool init(uart::Uart& uart, GpsModel type) {
|
||||
switch (type) {
|
||||
case GpsModel::Unknown:
|
||||
tt_crash();
|
||||
check(false);
|
||||
case GpsModel::AG3335:
|
||||
case GpsModel::AG3352:
|
||||
return initAg33xx(uart);
|
||||
|
||||
@ -202,7 +202,7 @@ bool masterWrite(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t
|
||||
}
|
||||
|
||||
bool masterWriteRegister(i2c_port_t port, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
||||
tt_check(reg != 0);
|
||||
check(reg != 0);
|
||||
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
|
||||
#include <Tactility/CoreDefines.h>
|
||||
#include <list>
|
||||
|
||||
namespace tt::kernel {
|
||||
@ -53,7 +54,7 @@ static const char* getEventName(SystemEvent event) {
|
||||
return TT_STRINGIFY(Time);
|
||||
}
|
||||
|
||||
tt_crash(); // Missing case above
|
||||
check(false); // Missing case above
|
||||
}
|
||||
|
||||
void publishSystemEvent(SystemEvent event) {
|
||||
@ -83,7 +84,7 @@ SystemEventSubscription subscribeSystemEvent(SystemEvent event, OnSystemEvent ha
|
||||
mutex.unlock();
|
||||
return id;
|
||||
} else {
|
||||
tt_crash();
|
||||
check(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ static void anim_rotation_callback(void* var, int32_t v) {
|
||||
lv_obj_set_style_transform_rotation(object, v, 0);
|
||||
}
|
||||
|
||||
static void spinner_constructor(TT_UNUSED const lv_obj_class_t* object_class, lv_obj_t* object) {
|
||||
static void spinner_constructor(const lv_obj_class_t* object_class, lv_obj_t* object) {
|
||||
lv_obj_remove_flag(object, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
||||
lv_anim_t a;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#define LV_USE_PRIVATE_API 1 // For actual lv_obj_t declaration
|
||||
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
@ -10,7 +11,6 @@
|
||||
#include <Tactility/RecursiveMutex.h>
|
||||
#include <Tactility/settings/Time.h>
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <Tactility/Timer.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
@ -116,7 +116,7 @@ static void statusbar_pubsub_event(Statusbar* statusbar) {
|
||||
}
|
||||
}
|
||||
|
||||
static void onTimeChanged(TT_UNUSED kernel::SystemEvent event) {
|
||||
static void onTimeChanged(kernel::SystemEvent event) {
|
||||
if (statusbar_data.mutex.lock()) {
|
||||
statusbar_data.time_update_timer->reset(5);
|
||||
statusbar_data.mutex.unlock();
|
||||
@ -142,7 +142,7 @@ static void statusbar_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
|
||||
}
|
||||
}
|
||||
|
||||
static void statusbar_destructor(TT_UNUSED const lv_obj_class_t* class_p, lv_obj_t* obj) {
|
||||
static void statusbar_destructor(const lv_obj_class_t* class_p, lv_obj_t* obj) {
|
||||
auto* statusbar = (Statusbar*)obj;
|
||||
statusbar_data.pubsub->unsubscribe(statusbar->pubsub_subscription);
|
||||
}
|
||||
@ -215,7 +215,7 @@ static void update_main(Statusbar* statusbar) {
|
||||
}
|
||||
}
|
||||
|
||||
static void statusbar_event(TT_UNUSED const lv_obj_class_t* class_p, lv_event_t* event) {
|
||||
static void statusbar_event(const lv_obj_class_t* class_p, lv_event_t* event) {
|
||||
// Call the ancestor's event handler
|
||||
lv_result_t result = lv_obj_event_base(&statusbar_class, event);
|
||||
if (result != LV_RES_OK) {
|
||||
@ -258,7 +258,7 @@ void statusbar_icon_remove(int8_t id) {
|
||||
if (LOGGER.isLoggingDebug()) {
|
||||
LOGGER.debug("id {}: remove", id);
|
||||
}
|
||||
tt_check(id >= 0 && id < STATUSBAR_ICON_LIMIT);
|
||||
check(id >= 0 && id < STATUSBAR_ICON_LIMIT);
|
||||
statusbar_data.mutex.lock();
|
||||
StatusbarIcon* icon = &statusbar_data.icons[id];
|
||||
icon->claimed = false;
|
||||
@ -276,10 +276,10 @@ void statusbar_icon_set_image(int8_t id, const std::string& image) {
|
||||
LOGGER.debug("id {}: set image {}", id, image);
|
||||
}
|
||||
}
|
||||
tt_check(id >= 0 && id < STATUSBAR_ICON_LIMIT);
|
||||
check(id >= 0 && id < STATUSBAR_ICON_LIMIT);
|
||||
statusbar_data.mutex.lock();
|
||||
StatusbarIcon* icon = &statusbar_data.icons[id];
|
||||
tt_check(icon->claimed);
|
||||
check(icon->claimed);
|
||||
icon->image = image;
|
||||
statusbar_data.mutex.unlock();
|
||||
statusbar_data.pubsub->publish(nullptr);
|
||||
@ -289,10 +289,10 @@ void statusbar_icon_set_visibility(int8_t id, bool visible) {
|
||||
if (LOGGER.isLoggingDebug()) {
|
||||
LOGGER.debug("id {}: set visibility {}", id, visible);
|
||||
}
|
||||
tt_check(id >= 0 && id < STATUSBAR_ICON_LIMIT);
|
||||
check(id >= 0 && id < STATUSBAR_ICON_LIMIT);
|
||||
statusbar_data.mutex.lock();
|
||||
StatusbarIcon* icon = &statusbar_data.icons[id];
|
||||
tt_check(icon->claimed);
|
||||
check(icon->claimed);
|
||||
icon->visible = visible;
|
||||
statusbar_data.mutex.unlock();
|
||||
statusbar_data.pubsub->publish(nullptr);
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include <Tactility/lvgl/Toolbar.h>
|
||||
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/service/loader/Loader.h>
|
||||
#include <Tactility/lvgl/Spinner.h>
|
||||
|
||||
@ -63,7 +64,7 @@ static const lv_obj_class_t toolbar_class = {
|
||||
.theme_inheritable = false
|
||||
};
|
||||
|
||||
static void stop_app(TT_UNUSED lv_event_t* event) {
|
||||
static void stop_app(lv_event_t* event) {
|
||||
app::stop();
|
||||
}
|
||||
|
||||
@ -166,7 +167,7 @@ void toolbar_set_nav_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callb
|
||||
|
||||
lv_obj_t* toolbar_add_button_action(lv_obj_t* obj, const char* imageOrButton, bool isImage, lv_event_cb_t callback, void* user_data) {
|
||||
auto* toolbar = reinterpret_cast<Toolbar*>(obj);
|
||||
tt_check(toolbar->action_count < TOOLBAR_ACTION_LIMIT, "max actions reached");
|
||||
check(toolbar->action_count < TOOLBAR_ACTION_LIMIT, "max actions reached");
|
||||
toolbar->action_count++;
|
||||
|
||||
auto ui_scale = hal::getConfiguration()->uiScale;
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/network/Http.h>
|
||||
|
||||
#include "Tactility/service/gui/GuiService.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/network/EspHttpClient.h>
|
||||
#include <esp_http_client.h>
|
||||
@ -19,7 +21,8 @@ void download(
|
||||
const std::function<void()>& onSuccess,
|
||||
const std::function<void(const char* errorMessage)>& onError
|
||||
) {
|
||||
LOGGER.info("Downloading {} to {}", url, downloadFilePath);
|
||||
service::gui::warnIfRunningOnGuiTask("HTTP");
|
||||
LOGGER.info("Downloading from {} to {}", url, downloadFilePath);
|
||||
#ifdef ESP_PLATFORM
|
||||
getMainDispatcher().dispatch([url, certFilePath, downloadFilePath, onSuccess, onError] {
|
||||
LOGGER.info("Loading certificate");
|
||||
@ -90,6 +93,7 @@ void download(
|
||||
onError("Failed to write all bytes");
|
||||
return;
|
||||
}
|
||||
taskYIELD();
|
||||
}
|
||||
fclose(file);
|
||||
LOGGER.info("Downloaded {} to {}", url, downloadFilePath);
|
||||
|
||||
@ -59,7 +59,7 @@ class DisplayIdleService final : public Service {
|
||||
}
|
||||
|
||||
public:
|
||||
bool onStart(TT_UNUSED ServiceContext& service) override {
|
||||
bool onStart(ServiceContext& service) override {
|
||||
// Load settings once at startup and cache them
|
||||
// This eliminates file I/O from timer callback (prevents watchdog timeout)
|
||||
cachedDisplaySettings = settings::display::loadOrGetDefault();
|
||||
@ -73,7 +73,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
void onStop(TT_UNUSED ServiceContext& service) override {
|
||||
void onStop(ServiceContext& service) override {
|
||||
if (timer) {
|
||||
timer->stop();
|
||||
timer = nullptr;
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#include <Tactility/service/gui/GuiService.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <Tactility/app/AppInstance.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
@ -15,6 +17,15 @@ extern const ServiceManifest manifest;
|
||||
static const auto LOGGER = Logger("GuiService");
|
||||
using namespace loader;
|
||||
|
||||
constexpr auto* GUI_TASK_NAME = "gui";
|
||||
|
||||
void warnIfRunningOnGuiTask(const char* context) {
|
||||
const char* task_name = pcTaskGetName(nullptr);
|
||||
if (strcmp(GUI_TASK_NAME, task_name) == 0) {
|
||||
LOGGER.warn("{} shouldn't run on the GUI task", context);
|
||||
}
|
||||
}
|
||||
|
||||
// region AppManifest
|
||||
|
||||
void GuiService::onLoaderEvent(LoaderService::Event event) {
|
||||
@ -114,7 +125,7 @@ void GuiService::redraw() {
|
||||
unlock();
|
||||
}
|
||||
|
||||
bool GuiService::onStart(TT_UNUSED ServiceContext& service) {
|
||||
bool GuiService::onStart(ServiceContext& service) {
|
||||
auto* screen_root = lv_screen_active();
|
||||
if (screen_root == nullptr) {
|
||||
LOGGER.error("No display found");
|
||||
@ -122,11 +133,13 @@ bool GuiService::onStart(TT_UNUSED ServiceContext& service) {
|
||||
}
|
||||
|
||||
thread = new Thread(
|
||||
"gui",
|
||||
GUI_TASK_NAME,
|
||||
4096, // Last known minimum was 2800 for launching desktop
|
||||
[]() { return guiMain(); }
|
||||
);
|
||||
|
||||
thread->setPriority(THREAD_PRIORITY_SERVICE);
|
||||
|
||||
const auto loader = findLoaderService();
|
||||
assert(loader != nullptr);
|
||||
loader_pubsub_subscription = loader->getPubsub()->subscribe([this](auto event) {
|
||||
@ -169,7 +182,7 @@ bool GuiService::onStart(TT_UNUSED ServiceContext& service) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void GuiService::onStop(TT_UNUSED ServiceContext& service) {
|
||||
void GuiService::onStop(ServiceContext& service) {
|
||||
lock();
|
||||
|
||||
const auto loader = findLoaderService();
|
||||
@ -186,7 +199,7 @@ void GuiService::onStop(TT_UNUSED ServiceContext& service) {
|
||||
|
||||
unlock();
|
||||
|
||||
tt_check(lvgl::lock(1000 / portTICK_PERIOD_MS));
|
||||
check(lvgl::lock(1000 / portTICK_PERIOD_MS));
|
||||
lv_group_delete(keyboardGroup);
|
||||
lvgl::unlock();
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ static void show_keyboard(lv_event_t* event) {
|
||||
}
|
||||
}
|
||||
|
||||
static void hide_keyboard(TT_UNUSED lv_event_t* event) {
|
||||
static void hide_keyboard(lv_event_t* event) {
|
||||
auto service = findService();
|
||||
if (service != nullptr) {
|
||||
service->softwareKeyboardHide();
|
||||
@ -53,7 +53,7 @@ void GuiService::keyboardAddTextArea(lv_obj_t* textarea) {
|
||||
lock();
|
||||
|
||||
if (isStarted) {
|
||||
tt_check(lvgl::lock(0), "lvgl should already be locked before calling this method");
|
||||
check(lvgl::lock(0), "lvgl should already be locked before calling this method");
|
||||
|
||||
if (softwareKeyboardIsEnabled()) {
|
||||
lv_obj_add_event_cb(textarea, show_keyboard, LV_EVENT_FOCUSED, nullptr);
|
||||
|
||||
@ -58,7 +58,7 @@ class KeyboardIdleService final : public Service {
|
||||
}
|
||||
|
||||
public:
|
||||
bool onStart(TT_UNUSED ServiceContext& service) override {
|
||||
bool onStart(ServiceContext& service) override {
|
||||
// Load settings once at startup and cache them
|
||||
// This eliminates file I/O from timer callback (prevents watchdog timeout)
|
||||
cachedKeyboardSettings = settings::keyboard::loadOrGetDefault();
|
||||
@ -72,7 +72,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
void onStop(TT_UNUSED ServiceContext& service) override {
|
||||
void onStop(ServiceContext& service) override {
|
||||
if (timer) {
|
||||
timer->stop();
|
||||
timer = nullptr;
|
||||
|
||||
@ -245,7 +245,7 @@ void LoaderService::transitionAppToState(const std::shared_ptr<app::AppInstance>
|
||||
switch (state) {
|
||||
using enum app::State;
|
||||
case Initial:
|
||||
tt_crash(LOG_MESSAGE_ILLEGAL_STATE);
|
||||
check(false, LOG_MESSAGE_ILLEGAL_STATE);
|
||||
case Created:
|
||||
assert(app->getState() == app::State::Initial);
|
||||
app->getApp()->onCreate(*app);
|
||||
|
||||
@ -107,7 +107,7 @@ void ScreenshotTask::taskStart() {
|
||||
return;
|
||||
}
|
||||
|
||||
tt_check(thread == nullptr);
|
||||
check(thread == nullptr);
|
||||
thread = new Thread(
|
||||
"screenshot",
|
||||
8192,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include <Tactility/lvgl/Statusbar.h>
|
||||
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/hal/power/PowerDevice.h>
|
||||
#include <Tactility/hal/sdcard/SdCardDevice.h>
|
||||
#include <Tactility/Logger.h>
|
||||
@ -71,7 +72,7 @@ static const char* getWifiStatusIcon(wifi::RadioState state, bool secure) {
|
||||
rssi = wifi::getRssi();
|
||||
return getWifiStatusIconForRssi(rssi);
|
||||
default:
|
||||
tt_crash("not implemented");
|
||||
check(false, "not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +86,7 @@ static const char* getSdCardStatusIcon(hal::sdcard::SdCardDevice::State state) {
|
||||
case Timeout:
|
||||
return STATUSBAR_ICON_SDCARD_ALERT;
|
||||
default:
|
||||
tt_crash("Unhandled SdCard state");
|
||||
check(false, "Unhandled SdCard state");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/service/webserver/WebServerService.h>
|
||||
#include <Tactility/service/webserver/AssetVersion.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
@ -93,7 +94,7 @@ static void publish_event(WebServerService* webserver, WebServerEvent event) {
|
||||
std::shared_ptr<PubSub<WebServerEvent>> getPubsub() {
|
||||
WebServerService* webserver = g_webServerInstance.load();
|
||||
if (webserver == nullptr) {
|
||||
tt_crash("Service not running");
|
||||
check(false, "Service not running");
|
||||
}
|
||||
|
||||
return webserver->getPubsub();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include <Tactility/service/wifi/Wifi.h>
|
||||
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/CoreDefines.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
|
||||
@ -22,7 +23,7 @@ const char* radioStateToString(RadioState state) {
|
||||
case Off:
|
||||
return TT_STRINGIFY(Off);
|
||||
}
|
||||
tt_crash("not implemented");
|
||||
check(false, "not implemented");
|
||||
}
|
||||
|
||||
extern const ServiceManifest manifest;
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
#include <Tactility/service/wifi/Wifi.h>
|
||||
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/EventGroup.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
@ -140,7 +141,7 @@ static std::shared_ptr<Wifi> wifi_singleton;
|
||||
std::shared_ptr<PubSub<WifiEvent>> getPubsub() {
|
||||
auto wifi = wifi_singleton;
|
||||
if (wifi == nullptr) {
|
||||
tt_crash("Service not running");
|
||||
check(false, "Service not running");
|
||||
}
|
||||
|
||||
return wifi->pubsub;
|
||||
@ -472,7 +473,7 @@ static void dispatchAutoConnect(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
}
|
||||
|
||||
static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
|
||||
static void eventHandler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
|
||||
auto wifi = wifi_singleton;
|
||||
if (wifi == nullptr) {
|
||||
LOGGER.error("eventHandler: no wifi instance");
|
||||
|
||||
@ -76,7 +76,7 @@ void setScanRecords(uint16_t records) {
|
||||
}
|
||||
|
||||
std::vector<ApRecord> getScanResults() {
|
||||
tt_check(wifi);
|
||||
check(wifi);
|
||||
|
||||
std::vector<ApRecord> records;
|
||||
records.push_back((ApRecord) {
|
||||
@ -145,14 +145,14 @@ class WifiService final : public Service {
|
||||
|
||||
public:
|
||||
|
||||
bool onStart(TT_UNUSED ServiceContext& service) override {
|
||||
tt_check(wifi == nullptr);
|
||||
bool onStart(ServiceContext& service) override {
|
||||
check(wifi == nullptr);
|
||||
wifi = new Wifi();
|
||||
return true;
|
||||
}
|
||||
|
||||
void onStop(TT_UNUSED ServiceContext& service) override {
|
||||
tt_check(wifi != nullptr);
|
||||
void onStop(ServiceContext& service) override {
|
||||
check(wifi != nullptr);
|
||||
delete wifi;
|
||||
wifi = nullptr;
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ void tt_app_register(
|
||||
reinterpret_cast<tt::app::OnResult>(appRegistration.onResult)
|
||||
);
|
||||
#else
|
||||
tt_crash("TactilityC is not intended for PC/Simulator");
|
||||
check(false, "TactilityC is not intended for PC/Simulator");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ static tt::hal::Device::Type toTactilityDeviceType(DeviceType type) {
|
||||
case DEVICE_TYPE_GPS:
|
||||
return tt::hal::Device::Type::Gps;
|
||||
default:
|
||||
tt_crash("Device::Type not supported");
|
||||
check(false, "Device::Type not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ static ColorFormat toColorFormat(tt::hal::display::ColorFormat format) {
|
||||
case tt::hal::display::ColorFormat::RGB888:
|
||||
return COLOR_FORMAT_RGB888;
|
||||
default:
|
||||
tt_crash("ColorFormat not supported");
|
||||
check(false, "ColorFormat not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ if (DEFINED ENV{ESP_IDF_VERSION})
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Include/"
|
||||
REQUIRES TactilityFreeRtos mbedtls nvs_flash esp_rom
|
||||
REQUIRES TactilityFreeRtos TactilityKernel mbedtls nvs_flash esp_rom
|
||||
)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
@ -26,8 +26,9 @@ else()
|
||||
add_definitions(-D_Nullable=)
|
||||
add_definitions(-D_Nonnull=)
|
||||
|
||||
target_link_libraries(TactilityCore
|
||||
PUBLIC TactilityFreeRtos
|
||||
PUBLIC mbedtls
|
||||
target_link_libraries(TactilityCore PUBLIC
|
||||
TactilityFreeRtos
|
||||
TactilityKernel
|
||||
mbedtls
|
||||
)
|
||||
endif()
|
||||
@ -1,69 +0,0 @@
|
||||
/**
|
||||
* @file check.h
|
||||
*
|
||||
* Tactility crash and check functions.
|
||||
*
|
||||
* The main problem with crashing is that you can't do anything without disturbing registers,
|
||||
* and if you disturb registers, you won't be able to see the correct register values in the debugger.
|
||||
*
|
||||
* Current solution works around it by passing the message through r12 and doing some magic with registers in crash function.
|
||||
* r0-r10 are stored in the ram2 on crash routine start and restored at the end.
|
||||
* The only register that is going to be lost is r11.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "CoreDefines.h"
|
||||
#include "Logger.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#define TT_NORETURN [[noreturn]]
|
||||
|
||||
/** Crash system */
|
||||
namespace tt {
|
||||
/**
|
||||
* Don't call this directly. Use tt_crash() as it will trace info.
|
||||
*/
|
||||
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::Logger("Kernel").error("Crash at {}:{}", __FILE__, __LINE__); \
|
||||
tt::_crash(); \
|
||||
} while (0)
|
||||
|
||||
#define _tt_crash1(message) do { \
|
||||
tt::Logger("Kernel").error("Crash: {}\n\tat {}:{}", message, __FILE__, __LINE__); \
|
||||
tt::_crash(); \
|
||||
} while (0)
|
||||
|
||||
/** Halt the system
|
||||
* @param[in] optional message (const char*)
|
||||
*/
|
||||
#define tt_halt(...) M_APPLY(__tt_halt, M_IF_EMPTY(__VA_ARGS__)((NULL), (__VA_ARGS__)))
|
||||
|
||||
/** Check condition and crash if check failed */
|
||||
#define tt_check_internal(__e, __m) \
|
||||
do { \
|
||||
if (!(__e)) { \
|
||||
tt::Logger("Kernel").error("Check failed: {}", #__e); \
|
||||
if (__m) { \
|
||||
tt_crash(__m); \
|
||||
} else { \
|
||||
tt_crash(""); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/** Check condition and crash if failed
|
||||
*
|
||||
* @param[in] condition to check
|
||||
* @param[in] optional message (const char*)
|
||||
*/
|
||||
|
||||
#define tt_check(x, ...) if (!(x)) { tt::Logger("Kernel").error("Check failed: {}", #x); tt::_crash(); }
|
||||
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define TT_UNUSED __attribute__((unused))
|
||||
|
||||
#define TT_STRINGIFY(x) #x
|
||||
|
||||
// region Variable arguments support
|
||||
|
||||
@ -2,6 +2,5 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "Check.h"
|
||||
#include "CoreDefines.h"
|
||||
#include "Logger.h"
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
#include <Tactility/Check.h>
|
||||
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/freertoscompat/Task.h>
|
||||
|
||||
static const auto LOGGER = tt::Logger("kernel");
|
||||
|
||||
static void logMemoryInfo() {
|
||||
#ifdef ESP_PLATFORM
|
||||
LOGGER.error("default caps:");
|
||||
LOGGER.error(" total: {}", heap_caps_get_total_size(MALLOC_CAP_DEFAULT));
|
||||
LOGGER.error(" free: {}", heap_caps_get_free_size(MALLOC_CAP_DEFAULT));
|
||||
LOGGER.error(" min free: {}", heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT));
|
||||
LOGGER.error("internal caps:");
|
||||
LOGGER.error(" total: {}", heap_caps_get_total_size(MALLOC_CAP_INTERNAL));
|
||||
LOGGER.error(" free: {}", heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
|
||||
LOGGER.error(" min free: {}", heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void logTaskInfo() {
|
||||
const char* name = pcTaskGetName(nullptr);
|
||||
const char* safe_name = name ? name : "main";
|
||||
LOGGER.error("Task: {}", safe_name);
|
||||
LOGGER.error("Stack watermark: {}", uxTaskGetStackHighWaterMark(NULL) * 4);
|
||||
}
|
||||
|
||||
namespace tt {
|
||||
|
||||
TT_NORETURN void _crash() {
|
||||
logTaskInfo();
|
||||
logMemoryInfo();
|
||||
// TODO: Add breakpoint when debugger is attached.
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_system_abort("System halted. Connect debugger for more info.");
|
||||
#endif
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
}
|
||||
@ -29,7 +29,7 @@ static void get_hardware_key(uint8_t key[32]) {
|
||||
// MAC can be 6 or 8 bytes
|
||||
size_t mac_length = esp_mac_addr_len_get(ESP_MAC_EFUSE_FACTORY);
|
||||
LOGGER.info("Using MAC with length {}", mac_length);
|
||||
tt_check(mac_length <= 8);
|
||||
check(mac_length <= 8);
|
||||
ESP_ERROR_CHECK(esp_read_mac(mac, ESP_MAC_EFUSE_FACTORY));
|
||||
|
||||
// Fill buffer with repeating MAC
|
||||
@ -68,13 +68,13 @@ static void get_nvs_key(uint8_t key[32]) {
|
||||
|
||||
if (result != ESP_OK) {
|
||||
LOGGER.error("Failed to get key from NVS ({})", esp_err_to_name(result));
|
||||
tt_crash("NVS error");
|
||||
check(false, "NVS error");
|
||||
}
|
||||
|
||||
size_t length = 32;
|
||||
if (nvs_get_blob(handle, "key", key, &length) == ESP_OK) {
|
||||
LOGGER.info("Fetched key from NVS ({} bytes)", length);
|
||||
tt_check(length == 32);
|
||||
check(length == 32);
|
||||
} else {
|
||||
// TODO: Improved randomness
|
||||
esp_cpu_cycle_count_t cycle_count = esp_cpu_get_cycle_count();
|
||||
@ -144,7 +144,7 @@ static int aes256CryptCbc(
|
||||
const unsigned char* input,
|
||||
unsigned char* output
|
||||
) {
|
||||
tt_check(key && iv && input && output);
|
||||
check(key && iv && input && output);
|
||||
|
||||
if ((length % 16) || (length == 0)) {
|
||||
return -1; // TODO: Proper error code from mbed lib?
|
||||
@ -163,7 +163,7 @@ static int aes256CryptCbc(
|
||||
}
|
||||
|
||||
int encrypt(const uint8_t iv[16], const uint8_t* inData, uint8_t* outData, size_t dataLength) {
|
||||
tt_check(dataLength % 16 == 0, "Length is not a multiple of 16 bytes (for AES 256");
|
||||
check(dataLength % 16 == 0, "Length is not a multiple of 16 bytes (for AES 256)");
|
||||
uint8_t key[32];
|
||||
getKey(key);
|
||||
|
||||
@ -175,7 +175,7 @@ int encrypt(const uint8_t iv[16], const uint8_t* inData, uint8_t* outData, size_
|
||||
}
|
||||
|
||||
int decrypt(const uint8_t iv[16], const uint8_t* inData, uint8_t* outData, size_t dataLength) {
|
||||
tt_check(dataLength % 16 == 0, "Length is not a multiple of 16 bytes (for AES 256");
|
||||
check(dataLength % 16 == 0, "Length is not a multiple of 16 bytes (for AES 256)");
|
||||
uint8_t key[32];
|
||||
getKey(key);
|
||||
|
||||
|
||||
32
TactilityKernel/Include/Tactility/Check.h
Normal file
32
TactilityKernel/Include/Tactility/Check.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
__attribute__((noreturn)) extern void __crash(void);
|
||||
|
||||
#define CHECK_GET_MACRO(_1, _2, NAME, ...) NAME
|
||||
#define check(...) CHECK_GET_MACRO(__VA_ARGS__, CHECK_MSG, CHECK_NO_MSG)(__VA_ARGS__)
|
||||
|
||||
#define CHECK_NO_MSG(condition) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
LOG_E("Error", "Check failed: %s at %s:%d", #condition, __FILE__, __LINE__); \
|
||||
__crash(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_MSG(condition, message) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
LOG_E("Error", "Check failed: %s at %s:%d", message, __FILE__, __LINE__); \
|
||||
__crash(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
54
TactilityKernel/Include/Tactility/Delay.h
Normal file
54
TactilityKernel/Include/Tactility/Delay.h
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "Time.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <rom/ets_sys.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <Tactility/Check.h>
|
||||
#include "Tactility/FreeRTOS/FreeRTOS.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Delay the current task for the specified amount of ticks
|
||||
* @warning Does not work in ISR context
|
||||
*/
|
||||
static inline void delay_ticks(TickType_t ticks) {
|
||||
check(xPortInIsrContext() == pdFALSE);
|
||||
if (ticks == 0U) {
|
||||
taskYIELD();
|
||||
} else {
|
||||
vTaskDelay(ticks);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay the current task for the specified amount of milliseconds
|
||||
* @warning Does not work in ISR context
|
||||
*/
|
||||
static inline void delay_millis(uint32_t milliSeconds) {
|
||||
delay_ticks(millis_to_ticks(milliSeconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stall the currently active CPU core for the specified amount of microseconds.
|
||||
* This does not allow other tasks to run on the stalled CPU core.
|
||||
*/
|
||||
static inline void delay_micros(uint32_t microseconds) {
|
||||
#ifdef ESP_PLATFORM
|
||||
ets_delay_us(microseconds);
|
||||
#else
|
||||
usleep(microseconds);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -5,6 +5,6 @@
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
#ifndef ESP_PLATFORM
|
||||
#define xPortInIsrContext(x) (false)
|
||||
#define xPortInIsrContext() (pdFALSE)
|
||||
#define vPortAssertIfInISR()
|
||||
#endif
|
||||
|
||||
65
TactilityKernel/Include/Tactility/Time.h
Normal file
65
TactilityKernel/Include/Tactility/Time.h
Normal file
@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Tactility/FreeRTOS/task.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <esp_timer.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
// Projects that include this header must align with Tactility's frequency (e.g. apps)
|
||||
static_assert(configTICK_RATE_HZ == 1000);
|
||||
|
||||
static inline uint32_t get_tick_frequency() {
|
||||
return configTICK_RATE_HZ;
|
||||
}
|
||||
|
||||
/** @return the amount of ticks that have passed since FreeRTOS' main task started */
|
||||
static inline TickType_t get_ticks() {
|
||||
if (xPortInIsrContext() == pdTRUE) {
|
||||
return xTaskGetTickCountFromISR();
|
||||
} else {
|
||||
return xTaskGetTickCount();
|
||||
}
|
||||
}
|
||||
|
||||
/** @return the milliseconds that have passed since FreeRTOS' main task started */
|
||||
static inline size_t get_millis() {
|
||||
return get_ticks() * portTICK_PERIOD_MS;
|
||||
}
|
||||
|
||||
/** @return the frequency at which the kernel task schedulers operate */
|
||||
uint32_t kernel_get_tick_frequency();
|
||||
|
||||
/** @return the microseconds that have passed since boot */
|
||||
static inline int64_t get_micros_since_boot() {
|
||||
#ifdef ESP_PLATFORM
|
||||
return esp_timer_get_time();
|
||||
#else
|
||||
timespec ts;
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
|
||||
return (static_cast<int64_t>(ts.tv_sec) * 1000000LL) + (ts.tv_nsec / 1000);
|
||||
}
|
||||
timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
return (static_cast<int64_t>(tv.tv_sec) * 1000000LL) + tv.tv_usec;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Convert seconds to ticks */
|
||||
static inline TickType_t seconds_to_ticks(uint32_t seconds) {
|
||||
return static_cast<uint64_t>(seconds) * 1000U / portTICK_PERIOD_MS;
|
||||
}
|
||||
|
||||
/** Convert milliseconds to ticks */
|
||||
static inline TickType_t millis_to_ticks(uint32_t milliSeconds) {
|
||||
#if configTICK_RATE_HZ == 1000
|
||||
return static_cast<TickType_t>(milliSeconds);
|
||||
#else
|
||||
return static_cast<TickType_t>(((float)configTICK_RATE_HZ) / 1000.0f * (float)milliSeconds);
|
||||
#endif
|
||||
}
|
||||
@ -5,21 +5,21 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/Error.h>
|
||||
#include <Tactility/FreeRTOS/event_groups.h>
|
||||
|
||||
static inline void event_group_construct(EventGroupHandle_t* eventGroup) {
|
||||
assert(xPortInIsrContext() == pdFALSE);
|
||||
check(xPortInIsrContext() == pdFALSE);
|
||||
*eventGroup = xEventGroupCreate();
|
||||
}
|
||||
|
||||
static inline void event_group_destruct(EventGroupHandle_t* eventGroup) {
|
||||
assert(xPortInIsrContext() == pdFALSE);
|
||||
assert(*eventGroup != NULL);
|
||||
check(xPortInIsrContext() == pdFALSE);
|
||||
check(*eventGroup != NULL);
|
||||
vEventGroupDelete(*eventGroup);
|
||||
*eventGroup = NULL;
|
||||
}
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/FreeRTOS/semphr.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -28,17 +30,17 @@ inline static void mutex_destruct(struct Mutex* mutex) {
|
||||
}
|
||||
|
||||
inline static void mutex_lock(struct Mutex* mutex) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
check(xPortInIsrContext() != pdTRUE);
|
||||
xSemaphoreTake(mutex->handle, portMAX_DELAY);
|
||||
}
|
||||
|
||||
inline static bool mutex_try_lock(struct Mutex* mutex) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
check(xPortInIsrContext() != pdTRUE);
|
||||
return xSemaphoreTake(mutex->handle, 0) == pdTRUE;
|
||||
}
|
||||
|
||||
inline static bool mutex_try_lock_timed(struct Mutex* mutex, TickType_t timeout) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
check(xPortInIsrContext() != pdTRUE);
|
||||
return xSemaphoreTake(mutex->handle, timeout) == pdTRUE;
|
||||
}
|
||||
|
||||
@ -51,7 +53,7 @@ inline static bool mutex_is_locked(struct Mutex* mutex) {
|
||||
}
|
||||
|
||||
inline static void mutex_unlock(struct Mutex* mutex) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
check(xPortInIsrContext() != pdTRUE);
|
||||
xSemaphoreGive(mutex->handle);
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/FreeRTOS/semphr.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -19,14 +19,14 @@ inline static void recursive_mutex_construct(struct RecursiveMutex* mutex) {
|
||||
}
|
||||
|
||||
inline static void recursive_mutex_destruct(struct RecursiveMutex* mutex) {
|
||||
assert(mutex->handle != NULL);
|
||||
vPortAssertIfInISR();
|
||||
check(mutex->handle != NULL);
|
||||
check(xPortInIsrContext() != pdTRUE);
|
||||
vSemaphoreDelete(mutex->handle);
|
||||
mutex->handle = NULL;
|
||||
}
|
||||
|
||||
inline static void recursive_mutex_lock(struct RecursiveMutex* mutex) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
check(xPortInIsrContext() != pdTRUE);
|
||||
xSemaphoreTakeRecursive(mutex->handle, portMAX_DELAY);
|
||||
}
|
||||
|
||||
@ -39,17 +39,17 @@ inline static bool recursive_mutex_is_locked(struct RecursiveMutex* mutex) {
|
||||
}
|
||||
|
||||
inline static bool recursive_mutex_try_lock(struct RecursiveMutex* mutex) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
check(xPortInIsrContext() != pdTRUE);
|
||||
return xSemaphoreTakeRecursive(mutex->handle, 0) == pdTRUE;
|
||||
}
|
||||
|
||||
inline static bool recursive_mutex_try_lock_timed(struct RecursiveMutex* mutex, TickType_t timeout) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
check(xPortInIsrContext() != pdTRUE);
|
||||
return xSemaphoreTakeRecursive(mutex->handle, timeout) == pdTRUE;
|
||||
}
|
||||
|
||||
inline static void recursive_mutex_unlock(struct RecursiveMutex* mutex) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
check(xPortInIsrContext() != pdTRUE);
|
||||
xSemaphoreGiveRecursive(mutex->handle);
|
||||
}
|
||||
|
||||
|
||||
39
TactilityKernel/Source/Crash.cpp
Normal file
39
TactilityKernel/Source/Crash.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/FreeRTOS/task.h>
|
||||
|
||||
static const auto* TAG = LOG_TAG("Kernel");
|
||||
|
||||
static void log_memory_info() {
|
||||
#ifdef ESP_PLATFORM
|
||||
LOG_E(TAG, "Default memory caps:");
|
||||
LOG_E(TAG, " Total: %" PRIu64, static_cast<uint64_t>(heap_caps_get_total_size(MALLOC_CAP_DEFAULT)));
|
||||
LOG_E(TAG, " Free: %" PRIu64, static_cast<uint64_t>(heap_caps_get_free_size(MALLOC_CAP_DEFAULT)));
|
||||
LOG_E(TAG, " Min free: %" PRIu64, static_cast<uint64_t>(heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT)));
|
||||
LOG_E(TAG, "Internal memory caps:");
|
||||
LOG_E(TAG, " Total: %" PRIu64, static_cast<uint64_t>(heap_caps_get_total_size(MALLOC_CAP_INTERNAL)));
|
||||
LOG_E(TAG, " Free: %" PRIu64, static_cast<uint64_t>(heap_caps_get_free_size(MALLOC_CAP_INTERNAL)));
|
||||
LOG_E(TAG, " Min free: %" PRIu64, static_cast<uint64_t>(heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL)));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void log_task_info() {
|
||||
const char* name = pcTaskGetName(nullptr);
|
||||
const char* safe_name = name ? name : "main";
|
||||
LOG_E(TAG, "Task: %s", safe_name);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((noreturn)) void __crash(void) {
|
||||
log_task_info();
|
||||
log_memory_info();
|
||||
// TODO: Add breakpoint when debugger is attached.
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_system_abort("System halted. Connect debugger for more info.");
|
||||
#else
|
||||
while (true) { /* Indefinite lock-up */ }
|
||||
#endif
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
}
|
||||
@ -70,7 +70,6 @@ static error_t driver_remove(Driver* driver) {
|
||||
|
||||
ledger.lock();
|
||||
const auto iterator = std::ranges::find(ledger.drivers, driver);
|
||||
// check that there actually is a 3 in our vector
|
||||
if (iterator == ledger.drivers.end()) {
|
||||
ledger.unlock();
|
||||
return ERROR_NOT_FOUND;
|
||||
@ -184,7 +183,7 @@ error_t driver_unbind(Driver* driver, Device* device) {
|
||||
driver_internal_data(driver)->use_count--;
|
||||
driver_unlock(driver);
|
||||
|
||||
LOG_I(TAG, "unbound %s to %s", driver->name, device->name);
|
||||
LOG_I(TAG, "unbound %s from %s", driver->name, device->name);
|
||||
|
||||
return ERROR_NONE;
|
||||
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
void log_generic(const char* tag, const char* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
@ -16,4 +18,6 @@ void log_generic(const char* tag, const char* format, ...) {
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -48,7 +48,7 @@ error_t event_group_wait(
|
||||
uint32_t* outFlags,
|
||||
TickType_t timeout
|
||||
) {
|
||||
if (xPortInIsrContext()) {
|
||||
if (xPortInIsrContext() == pdTRUE) {
|
||||
return ERROR_ISR_STATUS;
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ add_test(NAME TactilityTests
|
||||
target_link_libraries(TactilityTests PRIVATE
|
||||
Tactility
|
||||
TactilityCore
|
||||
Tactility
|
||||
TactilityKernel
|
||||
Simulator
|
||||
SDL2::SDL2-static SDL2-static
|
||||
)
|
||||
|
||||
@ -20,6 +20,7 @@ add_test(NAME TactilityCoreTests
|
||||
|
||||
target_link_libraries(TactilityCoreTests PUBLIC
|
||||
TactilityCore
|
||||
TactilityKernel
|
||||
TactilityFreeRtos
|
||||
freertos_kernel
|
||||
)
|
||||
|
||||
30
Tests/TactilityKernel/TimeAndDelay.cpp
Normal file
30
Tests/TactilityKernel/TimeAndDelay.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "doctest.h"
|
||||
#include <Tactility/Time.h>
|
||||
#include <Tactility/Delay.h>
|
||||
|
||||
TEST_CASE("delay ticks should be accurate within 1 tick") {
|
||||
auto start_time = get_ticks();
|
||||
delay_ticks(100);
|
||||
auto end_time = get_ticks();
|
||||
auto difference = end_time - start_time;
|
||||
CHECK_EQ(difference >= 100, true);
|
||||
CHECK_EQ(difference <= 101, true);
|
||||
}
|
||||
|
||||
TEST_CASE("delay millis should be accurate within 1 tick") {
|
||||
auto start_time = get_millis();
|
||||
delay_millis(100);
|
||||
auto end_time = get_millis();
|
||||
auto difference = end_time - start_time;
|
||||
CHECK_EQ(difference >= 100, true);
|
||||
CHECK_EQ(difference <= 101, true);
|
||||
}
|
||||
|
||||
TEST_CASE("microsecond time should be accurate within 1 tick") {
|
||||
auto start_time = get_micros_since_boot();
|
||||
delay_millis(100);
|
||||
auto end_time = get_micros_since_boot();
|
||||
auto difference = (end_time - start_time) / 1000;
|
||||
CHECK_EQ(difference >= 99, true);
|
||||
CHECK_EQ(difference <= 101, true);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user