Skip to content

Commit

Permalink
feat(display): allow configuration of display task stack size
Browse files Browse the repository at this point in the history
* Update display API to support configuring task stack size
* Reduced default stack size from 8192 to 4096 since task monitor showed >4k unused stack
  • Loading branch information
finger563 committed Jan 16, 2024
1 parent 59a252e commit 289d326
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions components/display/include/display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Display {
gpio_num_t backlight_pin; /**< GPIO pin for the backlight. */
bool backlight_on_value{
true}; /**< Value to write to the backlight pin to turn the backlight on. */
size_t stack_size_bytes{
4096}; /**< Size of the display task stack in bytes. */
std::chrono::duration<float> update_period{
0.01}; /**< How frequently to run the update function. */
bool double_buffered{
Expand Down Expand Up @@ -85,6 +87,8 @@ class Display {
gpio_num_t backlight_pin; /**< GPIO pin for the backlight. */
bool backlight_on_value{
true}; /**< Value to write to the backlight pin to turn the backlight on. */
size_t stack_size_bytes{
4096}; /**< Size of the display task stack in bytes. */
std::chrono::duration<float> update_period{
0.01}; /**< How frequently to run the update function. */
Rotation rotation{Rotation::LANDSCAPE}; /**< Default / Initial rotation of the display. */
Expand Down Expand Up @@ -122,7 +126,7 @@ class Display {
assert(vram_1_ != NULL);
}
created_vram_ = true;
init(config.flush_callback, config.software_rotation_enabled, config.rotation);
init(config.flush_callback, config.software_rotation_enabled, config.rotation, config.stack_size_bytes);
set_brightness(1.0f);
}

Expand All @@ -146,7 +150,7 @@ class Display {
update_period_(config.update_period),
logger_({.tag = "Display", .level = config.log_level}) {
logger_.debug("Initializing with non-allocating config!");
init(config.flush_callback, config.software_rotation_enabled, config.rotation);
init(config.flush_callback, config.software_rotation_enabled, config.rotation, config.stack_size_bytes);
}

/**
Expand Down Expand Up @@ -252,8 +256,9 @@ class Display {
* @param sw_rotation_enabled Whether to use software roation (slower) or
* not.
* @param rotation Default / initial rotation of the display.
* @param stack_size_bytes Size of the task stack in bytes.
*/
void init(flush_fn flush_callback, bool sw_rotation_enabled, Rotation rotation) {
void init(flush_fn flush_callback, bool sw_rotation_enabled, Rotation rotation, size_t stack_size_bytes = 4096) {
lv_init();

// Configure the LVGL display buffer with our pixel buffers
Expand All @@ -275,7 +280,7 @@ class Display {
task_ = Task::make_unique({
.name = "Display",
.callback = std::bind(&Display::update, this, _1, _2),
.stack_size_bytes = 4096 * 2,
.stack_size_bytes = stack_size_bytes,
.priority = 20,
.core_id = 0, // pin it to a core for maximum speed
});
Expand Down

0 comments on commit 289d326

Please sign in to comment.