Skip to content

Commit 43c78c6

Browse files
Thread, Timer and flash.sh improvements (#165)
- Various improvements to Thread and Timer: - Remove "mark as static" option as it is unused - Implemented core pinning for ESP32 platforms - Use `TickType_t` consistently (instead of `uint32_t`) - Use `enum class` instead of `enum` - Fix for `flash.sh` not working when using `pip` to install `esptool`
1 parent 5d189fe commit 43c78c6

File tree

20 files changed

+151
-198
lines changed

20 files changed

+151
-198
lines changed

Boards/LilygoTdeck/Source/Lvgl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
bool tdeck_init_lvgl() {
1515
static lv_disp_t* display = nullptr;
1616
const lvgl_port_cfg_t lvgl_cfg = {
17-
.task_priority = tt::THREAD_PRIORITY_RENDER,
17+
.task_priority = static_cast<UBaseType_t>(tt::THREAD_PRIORITY_RENDER),
1818
.task_stack = TDECK_LVGL_TASK_STACK_DEPTH,
1919
.task_affinity = -1, // core pinning
2020
.task_max_sleep_ms = 500,

Boards/M5stackCore2/Source/InitLvgl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
bool initLvgl() {
1414
const lvgl_port_cfg_t lvgl_cfg = {
15-
.task_priority = tt::THREAD_PRIORITY_RENDER,
15+
.task_priority = static_cast<UBaseType_t>(tt::THREAD_PRIORITY_RENDER),
1616
.task_stack = CORE2_LVGL_TASK_STACK_DEPTH,
1717
.task_affinity = -1, // core pinning
1818
.task_max_sleep_ms = 500,

Boards/M5stackCoreS3/Source/InitLvgl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
bool initLvgl() {
1414
const lvgl_port_cfg_t lvgl_cfg = {
15-
.task_priority = tt::THREAD_PRIORITY_RENDER,
15+
.task_priority = static_cast<UBaseType_t>(tt::THREAD_PRIORITY_RENDER),
1616
.task_stack = CORE2_LVGL_TASK_STACK_DEPTH,
1717
.task_affinity = -1, // core pinning
1818
.task_max_sleep_ms = 500,

Boards/Simulator/Source/LvglTask.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void lvgl_task_start() {
6565
"lvgl",
6666
8192,
6767
nullptr,
68-
tt::Thread::PriorityHigh, // Should be higher than main app task
68+
static_cast<UBaseType_t>(tt::Thread::Priority::High), // Should be higher than main app task
6969
nullptr
7070
);
7171

Boards/Simulator/Source/Main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void freertosMain() {
2929
"main",
3030
8192,
3131
nullptr,
32-
tt::Thread::PriorityNormal,
32+
static_cast<UBaseType_t>(tt::Thread::Priority::Normal),
3333
nullptr
3434
);
3535

Boards/YellowBoard/Source/Lvgl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
bool twodotfour_lvgl_init() {
99
const lvgl_port_cfg_t lvgl_cfg = {
10-
.task_priority = tt::THREAD_PRIORITY_RENDER,
10+
.task_priority = static_cast<UBaseType_t>(tt::THREAD_PRIORITY_RENDER),
1111
.task_stack = 8096,
1212
.task_affinity = -1, // core pinning
1313
.task_max_sleep_ms = 500,

Buildscripts/Flashing/flash.sh

+22-9
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,35 @@ function is_bin_in_path {
2121

2222
function require_bin {
2323
program=$1
24-
tip=$2
2524
if ! is_bin_in_path $program; then
26-
echo -e "\e[31m⚠️ $program not found!\n\t$tip\e[0m"
25+
exit 1
26+
else
27+
exit 0
2728
fi
2829
}
2930

30-
require_bin esptool.py "install esptool from your package manager or install python and run 'pip install esptool'"
31-
require_bin jq "install jq from your package manager or install python and run 'pip install jq'"
31+
# Find either esptool (installed via system package manager) or esptool.py (installed via pip)
32+
if ! is_bin_in_path esptool; then
33+
if ! is_bin_in_path esptool.py; then
34+
echo "\e[31m⚠️ esptool not found! Install it from your package manager or install python and run 'pip install esptool'\e[0m"
35+
exit 1
36+
else
37+
esptoolPath=esptool.py
38+
fi
39+
else
40+
esptoolPath=esptool
41+
fi
3242

33-
if [[ $1 -eq 0 ]]; then
43+
# Ensure the port was specified
44+
if [ -z "$1" ]; then
3445
echo -e "\e[31m⚠️ Must Specify port as argument. For example:\n\tflash.sh /dev/ttyACM0\n\tflash.sh /dev/ttyUSB0\e[0m"
3546
exit -1
3647
fi
3748

49+
# Take the flash_arg file contents and join each line in the file into a single line
50+
flash_args=`grep \n Binaries/flash_args | awk '{print}' ORS=' '`
3851
cd Binaries
39-
# Create flash command based on partitions
40-
KEY_VALUES=`jq -r '.flash_files | keys[] as $k | "\($k) \(.[$k])"' flasher_args.json | tr "\n" " "`
41-
esptool.py --port $1 erase_flash
42-
esptool.py --port $1 --connect-attempts 10 -b 460800 write_flash $KEY_VALUES
52+
$esptoolPath --port $1 erase_flash
53+
$esptoolPath --port $1 write_flash $flash_args
54+
cd -
55+

Documentation/ideas.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@
2828
- Attach ELF data to wrapper app (as app data) (check that app state is "running"!) so you can run more than 1 external apps at a time.
2929
We'll need to keep track of all manifest instances, so that the wrapper can look up the relevant manifest for the relevant callbacks.
3030
- T-Deck: Clear screen before turning on blacklight
31-
- Audio player app
32-
- Audio recording app
3331
- T-Deck: Use knob for UI selection
3432
- Crash monitoring: Keep track of which system phase the app crashed in (e.g. which app in which state)
3533
- AppContext's onResult should pass the app id (or launch request id!) that was started, so we can differentiate between multiple types of apps being launched
36-
- Loader: Use main dispatcher instead of Thread
3734
- Create more unit tests for `tactility-core` and `tactility` (PC-only for now)
3835
- Show a warning screen if firmware encryption or secure boot are off when saving WiFi credentials.
3936
- Show a warning screen when a user plugs in the SD card on a device that only supports mounting at boot.
@@ -45,6 +42,8 @@
4542
- Support hot-plugging SD card
4643

4744
# Nice-to-haves
45+
- Audio player app
46+
- Audio recording app
4847
- OTA updates
4948
- Web flasher
5049
- T-Deck Plus: Create separate board config?

TactilityC/Source/tt_init.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ const struct esp_elfsym elf_symbols[] {
7474
ESP_ELFSYM_EXPORT(tt_thread_alloc_ext),
7575
ESP_ELFSYM_EXPORT(tt_thread_free),
7676
ESP_ELFSYM_EXPORT(tt_thread_set_name),
77-
ESP_ELFSYM_EXPORT(tt_thread_mark_as_static),
78-
ESP_ELFSYM_EXPORT(tt_thread_is_marked_as_static),
7977
ESP_ELFSYM_EXPORT(tt_thread_set_stack_size),
8078
ESP_ELFSYM_EXPORT(tt_thread_set_callback),
8179
ESP_ELFSYM_EXPORT(tt_thread_set_priority),

TactilityC/Source/tt_thread.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ void tt_thread_set_name(ThreadHandle handle, const char* name) {
3131
HANDLE_AS_THREAD(handle)->setName(name);
3232
}
3333

34-
void tt_thread_mark_as_static(ThreadHandle handle) {
35-
HANDLE_AS_THREAD(handle)->markAsStatic();
36-
}
37-
38-
bool tt_thread_is_marked_as_static(ThreadHandle handle) {
39-
return HANDLE_AS_THREAD(handle)->isMarkedAsStatic();
40-
}
41-
4234
void tt_thread_set_stack_size(ThreadHandle handle, size_t size) {
4335
HANDLE_AS_THREAD(handle)->setStackSize(size);
4436
}

TactilityC/Source/tt_thread.h

+8-10
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ typedef int32_t (*ThreadCallback)(void* context);
3838
typedef void (*ThreadStateCallback)(ThreadState state, void* context);
3939

4040
typedef enum {
41-
ThreadPriorityNone = 0, /**< Uninitialized, choose system default */
42-
ThreadPriorityIdle = 1,
43-
ThreadPriorityLowest = 2,
44-
ThreadPriorityLow = 3,
45-
ThreadPriorityNormal = 4,
46-
ThreadPriorityHigh = 5,
47-
ThreadPriorityHigher = 6,
48-
ThreadPriorityHighest = 7
41+
ThreadPriorityNone = 0U, /**< Uninitialized, choose system default */
42+
ThreadPriorityIdle = 1U,
43+
ThreadPriorityLowest = 2U,
44+
ThreadPriorityLow = 3U,
45+
ThreadPriorityNormal = 4U,
46+
ThreadPriorityHigh = 5U,
47+
ThreadPriorityHigher = 6U,
48+
ThreadPriorityHighest = 7U
4949
} ThreadPriority;
5050

5151
ThreadHandle tt_thread_alloc();
@@ -57,8 +57,6 @@ ThreadHandle tt_thread_alloc_ext(
5757
);
5858
void tt_thread_free(ThreadHandle handle);
5959
void tt_thread_set_name(ThreadHandle handle, const char* name);
60-
void tt_thread_mark_as_static(ThreadHandle handle);
61-
bool tt_thread_is_marked_as_static(ThreadHandle handle);
6260
void tt_thread_set_stack_size(ThreadHandle handle, size_t size);
6361
void tt_thread_set_callback(ThreadHandle handle, ThreadCallback callback, void* _Nullable callbackContext);
6462
void tt_thread_set_priority(ThreadHandle handle, ThreadPriority priority);

TactilityC/Source/tt_timer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ bool tt_timer_set_pending_callback(TimerHandle handle, TimerPendingCallback call
5858
);
5959
}
6060

61-
void tt_timer_set_thread_priority(TimerHandle handle, TimerThreadPriority priority) {
62-
((TimerWrapper*)handle)->timer->setThreadPriority((tt::Timer::ThreadPriority)priority);
61+
void tt_timer_set_thread_priority(TimerHandle handle, ThreadPriority priority) {
62+
((TimerWrapper*)handle)->timer->setThreadPriority((tt::Thread::Priority)priority);
6363
}
6464

6565
}

TactilityC/Source/tt_timer.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "tt_thread.h"
34
#include <freertos/FreeRTOS.h>
45

56
#ifdef __cplusplus
@@ -16,11 +17,6 @@ typedef enum {
1617
TimerTypePeriodic = 1 ///< Repeating timer.
1718
} TimerType;
1819

19-
typedef enum {
20-
TimerThreadPriorityNormal, /**< Lower then other threads */
21-
TimerThreadPriorityElevated, /**< Same as other threads */
22-
} TimerThreadPriority;
23-
2420
typedef void (*TimerCallback)(void* context);
2521
typedef void (*TimerPendingCallback)(void* context, uint32_t arg);
2622

@@ -32,7 +28,7 @@ bool tt_timer_stop(TimerHandle handle);
3228
bool tt_timer_is_running(TimerHandle handle);
3329
uint32_t tt_timer_get_expire_time(TimerHandle handle);
3430
bool tt_timer_set_pending_callback(TimerHandle handle, TimerPendingCallback callback, void* callbackContext, uint32_t callbackArg, TickType_t timeoutTicks);
35-
void tt_timer_set_thread_priority(TimerHandle handle, TimerThreadPriority priority);
31+
void tt_timer_set_thread_priority(TimerHandle handle, ThreadPriority priority);
3632

3733
#ifdef __cplusplus
3834
}

TactilityCore/Source/DispatcherThread.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ DispatcherThread::DispatcherThread(const std::string& threadName, size_t threadS
1818
}
1919

2020
DispatcherThread::~DispatcherThread() {
21-
if (thread->getState() != Thread::StateStopped) {
21+
if (thread->getState() != Thread::State::Stopped) {
2222
stop();
2323
}
2424
}

0 commit comments

Comments
 (0)