From 78ec09c494faadf9e7d06dc7d3e04531c3a34ff7 Mon Sep 17 00:00:00 2001 From: ailurux Date: Mon, 13 Mar 2023 15:14:32 +1100 Subject: Touchwheel test --- src/main/main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/main') diff --git a/src/main/main.cpp b/src/main/main.cpp index 91e17451..bd0a06af 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -35,6 +35,7 @@ #include "i2c.hpp" #include "spi.hpp" #include "storage.hpp" +#include "touchwheel.hpp" static const char* TAG = "MAIN"; @@ -102,6 +103,7 @@ extern "C" void app_main(void) { ESP_LOGI(TAG, "Enable power rails for development"); expander->with([&](auto& gpio) { gpio.set_pin(drivers::GpioExpander::AUDIO_POWER_ENABLE, 1); + gpio.set_pin(drivers::GpioExpander::DISPLAY_LED, 0); gpio.set_pin(drivers::GpioExpander::USB_INTERFACE_POWER_ENABLE, 0); gpio.set_pin(drivers::GpioExpander::SD_CARD_POWER_ENABLE, 1); gpio.set_pin(drivers::GpioExpander::SD_MUX_SWITCH, @@ -121,6 +123,15 @@ extern "C" void app_main(void) { storage = std::move(storage_res.value()); } + ESP_LOGI(TAG, "Init touch wheel"); + auto touchwheel_res = drivers::TouchWheel::create(expander); + std::shared_ptr touchwheel; + if (touchwheel_res.has_error()) { + ESP_LOGE(TAG, "Failed!"); + } else { + touchwheel = std::move(touchwheel_res.value()); + } + LvglArgs* lvglArgs = (LvglArgs*)calloc(1, sizeof(LvglArgs)); lvglArgs->gpio_expander = expander; xTaskCreateStaticPinnedToCore(&lvgl_main, "LVGL", kLvglStackSize, @@ -146,6 +157,8 @@ extern "C" void app_main(void) { console.Launch(); while (1) { + touchwheel->Update(); + ESP_LOGI(TAG, "Touch wheel pos: %d", touchwheel->GetTouchWheelData().wheel_position); vTaskDelay(pdMS_TO_TICKS(100)); } } -- cgit v1.2.3 From a0ae39befe11c2a5a78ee5877cd5dd9cda90e27c Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 30 Mar 2023 09:31:08 +1100 Subject: Update pinouts for R3 --- src/main/main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/main') diff --git a/src/main/main.cpp b/src/main/main.cpp index bd0a06af..57d88f96 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -102,12 +102,10 @@ extern "C" void app_main(void) { ESP_LOGI(TAG, "Enable power rails for development"); expander->with([&](auto& gpio) { - gpio.set_pin(drivers::GpioExpander::AUDIO_POWER_ENABLE, 1); - gpio.set_pin(drivers::GpioExpander::DISPLAY_LED, 0); - gpio.set_pin(drivers::GpioExpander::USB_INTERFACE_POWER_ENABLE, 0); - gpio.set_pin(drivers::GpioExpander::SD_CARD_POWER_ENABLE, 1); + gpio.set_pin(drivers::GpioExpander::SD_MUX_EN_ACTIVE_LOW, 0); gpio.set_pin(drivers::GpioExpander::SD_MUX_SWITCH, drivers::GpioExpander::SD_MUX_ESP); + gpio.set_pin(drivers::GpioExpander::SD_CARD_POWER_ENABLE, 1); }); ESP_LOGI(TAG, "Init battery measurement"); @@ -123,6 +121,7 @@ extern "C" void app_main(void) { storage = std::move(storage_res.value()); } + /* ESP_LOGI(TAG, "Init touch wheel"); auto touchwheel_res = drivers::TouchWheel::create(expander); std::shared_ptr touchwheel; @@ -131,6 +130,7 @@ extern "C" void app_main(void) { } else { touchwheel = std::move(touchwheel_res.value()); } + */ LvglArgs* lvglArgs = (LvglArgs*)calloc(1, sizeof(LvglArgs)); lvglArgs->gpio_expander = expander; @@ -157,8 +157,8 @@ extern "C" void app_main(void) { console.Launch(); while (1) { - touchwheel->Update(); - ESP_LOGI(TAG, "Touch wheel pos: %d", touchwheel->GetTouchWheelData().wheel_position); + //touchwheel->Update(); + //ESP_LOGI(TAG, "Touch wheel pos: %d", touchwheel->GetTouchWheelData().wheel_position); vTaskDelay(pdMS_TO_TICKS(100)); } } -- cgit v1.2.3 From 9799ab458d8ad870aaec048abf5b1b1d93aa7aff Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 30 Mar 2023 10:15:09 +1100 Subject: fix sd card on for dev + mux pin --- src/main/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/main.cpp b/src/main/main.cpp index 57d88f96..692b97fb 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -105,7 +105,7 @@ extern "C" void app_main(void) { gpio.set_pin(drivers::GpioExpander::SD_MUX_EN_ACTIVE_LOW, 0); gpio.set_pin(drivers::GpioExpander::SD_MUX_SWITCH, drivers::GpioExpander::SD_MUX_ESP); - gpio.set_pin(drivers::GpioExpander::SD_CARD_POWER_ENABLE, 1); + gpio.set_pin(drivers::GpioExpander::SD_CARD_POWER_ENABLE, 0); }); ESP_LOGI(TAG, "Init battery measurement"); -- cgit v1.2.3 From 1b245316fe282035f094a3656f717d419e8bd526 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 4 Apr 2023 14:48:35 +1000 Subject: fix up touchpad timeouts, make it less chatty --- src/main/main.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/main') diff --git a/src/main/main.cpp b/src/main/main.cpp index 692b97fb..8860befe 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -121,16 +122,9 @@ extern "C" void app_main(void) { storage = std::move(storage_res.value()); } - /* ESP_LOGI(TAG, "Init touch wheel"); - auto touchwheel_res = drivers::TouchWheel::create(expander); - std::shared_ptr touchwheel; - if (touchwheel_res.has_error()) { - ESP_LOGE(TAG, "Failed!"); - } else { - touchwheel = std::move(touchwheel_res.value()); - } - */ + std::unique_ptr touchwheel = + std::make_unique(); LvglArgs* lvglArgs = (LvglArgs*)calloc(1, sizeof(LvglArgs)); lvglArgs->gpio_expander = expander; @@ -156,9 +150,14 @@ extern "C" void app_main(void) { console::AppConsole console(playback.get()); console.Launch(); + uint8_t prev_position = 0; while (1) { - //touchwheel->Update(); - //ESP_LOGI(TAG, "Touch wheel pos: %d", touchwheel->GetTouchWheelData().wheel_position); + touchwheel->Update(); + auto wheel_data = touchwheel->GetTouchWheelData(); + if (wheel_data.wheel_position != prev_position) { + prev_position = wheel_data.wheel_position; + ESP_LOGI(TAG, "Touch wheel pos: %u", prev_position); + } vTaskDelay(pdMS_TO_TICKS(100)); } } -- cgit v1.2.3 From 3817ec0c77b8d44e54b35ea9f76e7bb4666c6c08 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 30 Mar 2023 10:21:33 +1100 Subject: turn on amp for development --- src/main/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main') diff --git a/src/main/main.cpp b/src/main/main.cpp index 8860befe..a30dc675 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -107,6 +107,7 @@ extern "C" void app_main(void) { gpio.set_pin(drivers::GpioExpander::SD_MUX_SWITCH, drivers::GpioExpander::SD_MUX_ESP); gpio.set_pin(drivers::GpioExpander::SD_CARD_POWER_ENABLE, 0); + gpio.set_pin(drivers::GpioExpander::AMP_EN, 1); }); ESP_LOGI(TAG, "Init battery measurement"); -- cgit v1.2.3 From 7c6fd654f50e6665efa4226c6b927f9762734182 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Sat, 1 Apr 2023 13:22:21 +1100 Subject: New pipeline building, still needs proper control --- src/main/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/main.cpp b/src/main/main.cpp index a30dc675..98a571b6 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -133,10 +133,10 @@ extern "C" void app_main(void) { (void*)lvglArgs, 1, sLvglStack, &sLvglTaskBuffer, 1); - std::shared_ptr playback; + std::unique_ptr playback; if (storage) { ESP_LOGI(TAG, "Init audio pipeline"); - auto playback_res = audio::AudioPlayback::create(expander, storage); + auto playback_res = audio::AudioPlayback::create(expander); if (playback_res.has_error()) { ESP_LOGE(TAG, "Failed! Playback will not work."); } else { -- cgit v1.2.3 From 3836768bb8b95188e6657ab69027d1d9e4b13a77 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 3 Apr 2023 14:06:30 +1000 Subject: new pipeline working(?), but the dac eludes me --- src/main/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/main.cpp b/src/main/main.cpp index 98a571b6..77a1e14b 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -41,7 +41,7 @@ static const char* TAG = "MAIN"; void IRAM_ATTR tick_hook(void) { - lv_tick_inc(1); + // lv_tick_inc(1); } static const size_t kLvglStackSize = 8 * 1024; -- cgit v1.2.3 From f9558044955827b476ce21548d544530c1457026 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 21 Apr 2023 10:00:05 +1000 Subject: use a freertos timer for lvgl ticks --- src/main/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/main.cpp b/src/main/main.cpp index 77a1e14b..b1cee384 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -18,6 +18,8 @@ #include "esp_log.h" #include "font/lv_font.h" #include "freertos/portmacro.h" +#include "freertos/projdefs.h" +#include "freertos/timers.h" #include "hal/gpio_types.h" #include "hal/spi_types.h" #include "lvgl/lvgl.h" @@ -40,8 +42,8 @@ static const char* TAG = "MAIN"; -void IRAM_ATTR tick_hook(void) { - // lv_tick_inc(1); +auto tick_hook(TimerHandle_t xTimer) -> void { + lv_tick_inc(1); } static const size_t kLvglStackSize = 8 * 1024; @@ -64,7 +66,7 @@ extern "C" void lvgl_main(void* voidArgs) { lv_init(); // LVGL has been initialised, so we can now start reporting ticks to it. - esp_register_freertos_tick_hook(&tick_hook); + xTimerCreate("lv_tick", pdMS_TO_TICKS(1), pdTRUE, NULL, &tick_hook); ESP_LOGI(TAG, "init display"); std::unique_ptr display = -- cgit v1.2.3 From cc3fd9571eadf8ad49bd7a5806a504555dc885db Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 21 Apr 2023 10:30:52 +1000 Subject: split out lvgl task into its own component --- src/main/CMakeLists.txt | 2 +- src/main/main.cpp | 70 +++---------------------------------------------- 2 files changed, 5 insertions(+), 67 deletions(-) (limited to 'src/main') diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index df0d929b..49a54cd5 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register( SRCS "main.cpp" "app_console.cpp" INCLUDE_DIRS "." - REQUIRES "audio" "drivers" "dev_console" "drivers") + REQUIRES "audio" "drivers" "dev_console" "ui") target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS}) diff --git a/src/main/main.cpp b/src/main/main.cpp index b1cee384..796c70f3 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -6,8 +6,6 @@ #include #include -#include "core/lv_disp.h" -#include "core/lv_obj_pos.h" #include "driver/gpio.h" #include "driver/i2c.h" #include "driver/sdspi_host.h" @@ -16,17 +14,10 @@ #include "esp_freertos_hooks.h" #include "esp_intr_alloc.h" #include "esp_log.h" -#include "font/lv_font.h" #include "freertos/portmacro.h" #include "freertos/projdefs.h" -#include "freertos/timers.h" #include "hal/gpio_types.h" #include "hal/spi_types.h" -#include "lvgl/lvgl.h" -#include "misc/lv_color.h" -#include "misc/lv_style.h" -#include "misc/lv_timer.h" -#include "widgets/lv_label.h" #include "app_console.hpp" #include "audio_playback.hpp" @@ -36,64 +27,13 @@ #include "display_init.hpp" #include "gpio_expander.hpp" #include "i2c.hpp" +#include "lvgl_task.hpp" #include "spi.hpp" #include "storage.hpp" #include "touchwheel.hpp" static const char* TAG = "MAIN"; -auto tick_hook(TimerHandle_t xTimer) -> void { - lv_tick_inc(1); -} - -static const size_t kLvglStackSize = 8 * 1024; -static StaticTask_t sLvglTaskBuffer = {}; -static StackType_t sLvglStack[kLvglStackSize] = {0}; - -struct LvglArgs { - drivers::GpioExpander* gpio_expander; -}; - -extern "C" void lvgl_main(void* voidArgs) { - ESP_LOGI(TAG, "starting LVGL task"); - LvglArgs* args = (LvglArgs*)voidArgs; - drivers::GpioExpander* gpio_expander = args->gpio_expander; - - // Dispose of the args now that we've gotten everything out of them. - delete args; - - ESP_LOGI(TAG, "init lvgl"); - lv_init(); - - // LVGL has been initialised, so we can now start reporting ticks to it. - xTimerCreate("lv_tick", pdMS_TO_TICKS(1), pdTRUE, NULL, &tick_hook); - - ESP_LOGI(TAG, "init display"); - std::unique_ptr display = - drivers::Display::create(gpio_expander, drivers::displays::kST7735R); - - lv_style_t style; - lv_style_init(&style); - lv_style_set_text_color(&style, LV_COLOR_MAKE(0xFF, 0, 0)); - // TODO: find a nice bitmap font for this display size and density. - // lv_style_set_text_font(&style, &lv_font_montserrat_24); - - auto label = lv_label_create(NULL); - lv_label_set_text(label, "COLOURS!!"); - lv_obj_add_style(label, &style, 0); - - lv_obj_center(label); - lv_scr_load(label); - - while (1) { - lv_timer_handler(); - vTaskDelay(pdMS_TO_TICKS(10)); - } - - // TODO: break from the loop to kill this task, so that we can do our RAII - // cleanup, unregister our tick callback and so on. -} - extern "C" void app_main(void) { ESP_LOGI(TAG, "Initialising peripherals"); @@ -129,11 +69,9 @@ extern "C" void app_main(void) { std::unique_ptr touchwheel = std::make_unique(); - LvglArgs* lvglArgs = (LvglArgs*)calloc(1, sizeof(LvglArgs)); - lvglArgs->gpio_expander = expander; - xTaskCreateStaticPinnedToCore(&lvgl_main, "LVGL", kLvglStackSize, - (void*)lvglArgs, 1, sLvglStack, - &sLvglTaskBuffer, 1); + std::atomic lvgl_quit; + TaskHandle_t lvgl_task_handle; + ui::StartLvgl(expander, &lvgl_quit, &lvgl_task_handle); std::unique_ptr playback; if (storage) { -- cgit v1.2.3 From 7083459cf3c62c32d0c039a4665e702d70a27bba Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 21 Apr 2023 15:27:57 +1000 Subject: wrap driver instance ownership + di in a class --- src/main/main.cpp | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) (limited to 'src/main') diff --git a/src/main/main.cpp b/src/main/main.cpp index 796c70f3..2a345899 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -11,6 +11,7 @@ #include "driver/sdspi_host.h" #include "driver/spi_common.h" #include "driver/spi_master.h" +#include "driver_cache.hpp" #include "esp_freertos_hooks.h" #include "esp_intr_alloc.h" #include "esp_log.h" @@ -39,50 +40,37 @@ extern "C" void app_main(void) { ESP_ERROR_CHECK(drivers::init_i2c()); ESP_ERROR_CHECK(drivers::init_spi()); + std::unique_ptr drivers = + std::make_unique(); ESP_LOGI(TAG, "Init GPIOs"); - drivers::GpioExpander* expander = new drivers::GpioExpander(); + drivers::GpioExpander* expander = drivers->AcquireGpios(); ESP_LOGI(TAG, "Enable power rails for development"); - expander->with([&](auto& gpio) { - gpio.set_pin(drivers::GpioExpander::SD_MUX_EN_ACTIVE_LOW, 0); - gpio.set_pin(drivers::GpioExpander::SD_MUX_SWITCH, - drivers::GpioExpander::SD_MUX_ESP); - gpio.set_pin(drivers::GpioExpander::SD_CARD_POWER_ENABLE, 0); - gpio.set_pin(drivers::GpioExpander::AMP_EN, 1); - }); + expander->with( + [&](auto& gpio) { gpio.set_pin(drivers::GpioExpander::AMP_EN, 1); }); ESP_LOGI(TAG, "Init battery measurement"); drivers::Battery* battery = new drivers::Battery(); ESP_LOGI(TAG, "it's reading %d mV!", (int)battery->Millivolts()); ESP_LOGI(TAG, "Init SD card"); - auto storage_res = drivers::SdStorage::create(expander); - std::shared_ptr storage; - if (storage_res.has_error()) { + auto storage = drivers->AcquireStorage(); + if (!storage) { ESP_LOGE(TAG, "Failed! Do you have an SD card?"); - } else { - storage = std::move(storage_res.value()); } ESP_LOGI(TAG, "Init touch wheel"); - std::unique_ptr touchwheel = - std::make_unique(); + std::shared_ptr touchwheel = + drivers->AcquireTouchWheel(); std::atomic lvgl_quit; TaskHandle_t lvgl_task_handle; - ui::StartLvgl(expander, &lvgl_quit, &lvgl_task_handle); - - std::unique_ptr playback; - if (storage) { - ESP_LOGI(TAG, "Init audio pipeline"); - auto playback_res = audio::AudioPlayback::create(expander); - if (playback_res.has_error()) { - ESP_LOGE(TAG, "Failed! Playback will not work."); - } else { - playback = std::move(playback_res.value()); - } - } + ui::StartLvgl(drivers.get(), &lvgl_quit, &lvgl_task_handle); + + ESP_LOGI(TAG, "Init audio pipeline"); + std::unique_ptr playback = + std::make_unique(drivers.get()); ESP_LOGI(TAG, "Waiting for background tasks before launching console..."); vTaskDelay(pdMS_TO_TICKS(1000)); -- cgit v1.2.3 From 84f45e604585ccfb96be64fc463f4b816faa44e1 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 21 Apr 2023 18:42:37 +1000 Subject: Don't crash if there's no sd card :) --- src/main/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/main.cpp b/src/main/main.cpp index 2a345899..2970285f 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -68,9 +68,11 @@ extern "C" void app_main(void) { TaskHandle_t lvgl_task_handle; ui::StartLvgl(drivers.get(), &lvgl_quit, &lvgl_task_handle); - ESP_LOGI(TAG, "Init audio pipeline"); - std::unique_ptr playback = - std::make_unique(drivers.get()); + std::unique_ptr playback; + if (storage) { + ESP_LOGI(TAG, "Init audio pipeline"); + playback = std::make_unique(drivers.get()); + } ESP_LOGI(TAG, "Waiting for background tasks before launching console..."); vTaskDelay(pdMS_TO_TICKS(1000)); -- cgit v1.2.3