diff --git a/main/drivers/CMakeLists.txt b/main/drivers/CMakeLists.txt index 9378bbb..69a6fa7 100644 --- a/main/drivers/CMakeLists.txt +++ b/main/drivers/CMakeLists.txt @@ -8,6 +8,7 @@ set(SOURCES "sd.cpp" "speaker.cpp" "sseg.cpp" + "tft.cpp" "wires.cpp" ) diff --git a/main/drivers/bottom_half.h b/main/drivers/bottom_half.h index e84acf4..f484f10 100644 --- a/main/drivers/bottom_half.h +++ b/main/drivers/bottom_half.h @@ -65,8 +65,6 @@ bool get_touch_state(void); bool get_touch_pressed(void); bool get_touch_released(void); -static void poll_bottom_task(void *arg); - void init_bottom_half(); #endif /* BOTTOM_HALF_HPP */ \ No newline at end of file diff --git a/main/drivers/tft.hpp b/main/drivers/tft.cpp similarity index 70% rename from main/drivers/tft.hpp rename to main/drivers/tft.cpp index 7ccc762..e34ac02 100644 --- a/main/drivers/tft.hpp +++ b/main/drivers/tft.cpp @@ -1,68 +1,6 @@ -#ifndef TFT_HPP -#define TFT_HPP +#include "tft.h" -/* - * Adapted from an example under the MIT license: - * Copyright © 2022 atanisoft (github.com/atanisoft) - * - * MIT LICENSE: - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sdkconfig.h" - -// Uncomment the following line to enable using double buffering of LVGL color -// data. -// #define USE_DOUBLE_BUFFERING 1 - -static const char *TFT_TAG = "tft_driver"; - -// rotation swaps the horizontal and vertical pixel counts -#define DISPLAY_HORIZONTAL_PIXELS 480 -#define DISPLAY_VERTICAL_PIXELS 320 -#define DISPLAY_COMMAND_BITS 8 -#define DISPLAY_PARAMETER_BITS 8 -#define DISPLAY_REFRESH_HZ 40000000 -#define DISPLAY_SPI_QUEUE_LEN 10 -#define SPI_MAX_TRANSFER_SIZE 32768 - -#define TFT_PIN_MOSI GPIO_NUM_17 -#define TFT_PIN_MISO GPIO_NUM_18 -#define TFT_PIN_CLK GPIO_NUM_16 -#define TFT_PIN_CS GPIO_NUM_NC -#define TFT_PIN_DC GPIO_NUM_15 -#define TFT_PIN_RESET GPIO_NUM_8 - -#define TFT_INVERT_COLOR false - -// Default to 50 lines of color data -#define LV_BUFFER_SIZE DISPLAY_HORIZONTAL_PIXELS * 50 -#define LVGL_UPDATE_PERIOD_MS 5 - -#define BACKLIGHT_LEDC_MODE LEDC_LOW_SPEED_MODE -#define BACKLIGHT_LEDC_CHANNEL LEDC_CHANNEL_0 -#define BACKLIGHT_LEDC_TIMER LEDC_TIMER_1 -#define BACKLIGHT_LEDC_TIMER_RESOLUTION LEDC_TIMER_10_BIT -#define BACKLIGHT_LEDC_FRQUENCY 5000 +static const char* TAG = "tft"; static esp_lcd_panel_io_handle_t lcd_io_handle = NULL; static esp_lcd_panel_handle_t lcd_handle = NULL; @@ -104,8 +42,8 @@ static void IRAM_ATTR lvgl_tick_cb(void *param) { lv_tick_inc(LVGL_UPDATE_PERIOD_MS); } -void initialize_spi() { - ESP_LOGI(TFT_TAG, "Initializing SPI bus (MOSI:%d, MISO:%d, CLK:%d)", +static void initialize_spi() { + ESP_LOGI(TAG, "Initializing SPI bus (MOSI:%d, MISO:%d, CLK:%d)", TFT_PIN_MOSI, TFT_PIN_MISO, TFT_PIN_CLK); spi_bus_config_t bus = { @@ -128,7 +66,7 @@ void initialize_spi() { ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &bus, SPI_DMA_CH_AUTO)); } -void initialize_display() { +static void initialize_display() { const esp_lcd_panel_io_spi_config_t io_config = { .cs_gpio_num = TFT_PIN_CS, .dc_gpio_num = TFT_PIN_DC, @@ -181,19 +119,19 @@ void initialize_display() { #endif } -void initialize_lvgl() { - ESP_LOGI(TFT_TAG, "Initializing LVGL"); +static void initialize_lvgl() { + ESP_LOGI(TAG, "Initializing LVGL"); lv_init(); - ESP_LOGI(TFT_TAG, "Allocating %zu bytes for LVGL buffer", LV_BUFFER_SIZE * sizeof(lv_color_t)); + ESP_LOGI(TAG, "Allocating %zu bytes for LVGL buffer", LV_BUFFER_SIZE * sizeof(lv_color_t)); lv_buf_1 = (lv_color_t *)heap_caps_malloc(LV_BUFFER_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA); #if USE_DOUBLE_BUFFERING - ESP_LOGI(TFT_TAG, "Allocating %zu bytes for second LVGL buffer", LV_BUFFER_SIZE * sizeof(lv_color_t)); + ESP_LOGI(TAG, "Allocating %zu bytes for second LVGL buffer", LV_BUFFER_SIZE * sizeof(lv_color_t)); lv_buf_2 = (lv_color_t *)heap_caps_malloc(LV_BUFFER_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA); #endif - ESP_LOGI(TFT_TAG, "Creating LVLG display buffer"); + ESP_LOGI(TAG, "Creating LVLG display buffer"); lv_disp_draw_buf_init(&lv_disp_buf, lv_buf_1, lv_buf_2, LV_BUFFER_SIZE); - ESP_LOGI(TFT_TAG, "Initializing %dx%d display", DISPLAY_HORIZONTAL_PIXELS, DISPLAY_VERTICAL_PIXELS); + ESP_LOGI(TAG, "Initializing %dx%d display", DISPLAY_HORIZONTAL_PIXELS, DISPLAY_VERTICAL_PIXELS); lv_disp_drv_init(&lv_disp_drv); lv_disp_drv.hor_res = DISPLAY_HORIZONTAL_PIXELS; lv_disp_drv.ver_res = DISPLAY_VERTICAL_PIXELS; @@ -203,7 +141,7 @@ void initialize_lvgl() { // lv_disp_drv.rotated = LV_DISP_ROT_90; lv_display = lv_disp_drv_register(&lv_disp_drv); - ESP_LOGI(TFT_TAG, "Creating LVGL tick timer"); + ESP_LOGI(TAG, "Creating LVGL tick timer"); const esp_timer_create_args_t lvgl_tick_timer_args = { .callback = &lvgl_tick_cb, .arg = NULL, @@ -273,7 +211,7 @@ void create_demo_ui() { lv_anim_start(&a); } -void tick_timer_task(void* arg) { +static void tick_timer_task(void* arg) { while (1) { vTaskDelay(pdMS_TO_TICKS(10)); @@ -288,7 +226,5 @@ void init_tft() { xTaskCreate(tick_timer_task, "tick_lvgl", 4096, NULL, 5, NULL); - ESP_LOGI(TFT_TAG, "TFT initialization Successful"); + ESP_LOGI(TAG, "TFT initialization Successful"); } - -#endif /* TFT_HPP */ \ No newline at end of file diff --git a/main/drivers/tft.h b/main/drivers/tft.h new file mode 100644 index 0000000..a186b19 --- /dev/null +++ b/main/drivers/tft.h @@ -0,0 +1,68 @@ +#ifndef TFT_H +#define TFT_H + +/* + * Adapted from an example under the MIT license: + * Copyright © 2022 atanisoft (github.com/atanisoft) + * + * MIT LICENSE: + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sdkconfig.h" + +// Uncomment the following line to enable using double buffering of LVGL color +// data. +// #define USE_DOUBLE_BUFFERING 1 + +// rotation swaps the horizontal and vertical pixel counts +#define DISPLAY_HORIZONTAL_PIXELS 480 +#define DISPLAY_VERTICAL_PIXELS 320 +#define DISPLAY_COMMAND_BITS 8 +#define DISPLAY_PARAMETER_BITS 8 +#define DISPLAY_REFRESH_HZ 40000000 +#define DISPLAY_SPI_QUEUE_LEN 10 +#define SPI_MAX_TRANSFER_SIZE 32768 + +#define TFT_PIN_MOSI GPIO_NUM_17 +#define TFT_PIN_MISO GPIO_NUM_18 +#define TFT_PIN_CLK GPIO_NUM_16 +#define TFT_PIN_CS GPIO_NUM_NC +#define TFT_PIN_DC GPIO_NUM_15 +#define TFT_PIN_RESET GPIO_NUM_8 + +#define TFT_INVERT_COLOR false + +// Default to 50 lines of color data +#define LV_BUFFER_SIZE DISPLAY_HORIZONTAL_PIXELS * 50 +#define LVGL_UPDATE_PERIOD_MS 5 + +#define BACKLIGHT_LEDC_MODE LEDC_LOW_SPEED_MODE +#define BACKLIGHT_LEDC_CHANNEL LEDC_CHANNEL_0 +#define BACKLIGHT_LEDC_TIMER LEDC_TIMER_1 +#define BACKLIGHT_LEDC_TIMER_RESOLUTION LEDC_TIMER_10_BIT +#define BACKLIGHT_LEDC_FRQUENCY 5000 + +void create_demo_ui(); +void init_tft(); + +#endif /* TFT_H */ \ No newline at end of file diff --git a/main/main.cpp b/main/main.cpp index 91b04bc..010c506 100755 --- a/main/main.cpp +++ b/main/main.cpp @@ -4,7 +4,7 @@ #include "freertos/task.h" #include "driver/uart.h" #include "driver/i2c.h" -#include "drivers/tft.hpp" +#include "drivers/tft.h" #include "drivers/wires.h" #include "drivers/bottom_half.h" #include "drivers/sd.h" @@ -16,13 +16,13 @@ #include "helper.h" -#include "steps/step0.hpp" -#include "steps/step1.hpp" -#include "steps/step2.hpp" +#include "steps/step0.h" +#include "steps/step1.h" +#include "steps/step2.h" #include "steps/step3.hpp" #include "steps/step4.hpp" #include "steps/step5.hpp" -#include "steps/step6.hpp" +#include "steps/step6.h" static const char *TAG = "main"; diff --git a/main/steps/CMakeLists.txt b/main/steps/CMakeLists.txt index 20a414f..6e58d27 100644 --- a/main/steps/CMakeLists.txt +++ b/main/steps/CMakeLists.txt @@ -1,4 +1,10 @@ set(SOURCES + "setup_wires.cpp" + "step0.cpp" + "step1.cpp" + "step2.cpp" + "step4.cpp" + "step6.cpp" "wires_puzzle.cpp" ) diff --git a/main/steps/setup_wires.hpp b/main/steps/setup_wires.cpp similarity index 91% rename from main/steps/setup_wires.hpp rename to main/steps/setup_wires.cpp index 7cb5a95..7f7d926 100644 --- a/main/steps/setup_wires.hpp +++ b/main/steps/setup_wires.cpp @@ -1,12 +1,6 @@ -#ifndef SETUP_WIRES_HPP -#define SETUP_WIRES_HPP +#include "setup_wires.h" -#include "../drivers/bottom_half.h" -#include "../drivers/char_lcd.h" -#include "wires_puzzle.h" -#include - -uint8_t wires_state = 0; +static uint8_t wires_state = 0; void print_wires(WireColor* wires, int editing_idx) { bool cut[NUM_WIRES]; @@ -89,5 +83,3 @@ void setup_wires(void) { vTaskDelay(pdMS_TO_TICKS(10)); } } - -#endif /* SETUP_WIRES_HPP */ \ No newline at end of file diff --git a/main/steps/setup_wires.h b/main/steps/setup_wires.h new file mode 100644 index 0000000..d0f36d2 --- /dev/null +++ b/main/steps/setup_wires.h @@ -0,0 +1,12 @@ +#ifndef SETUP_WIRES_H +#define SETUP_WIRES_H + +#include "../drivers/bottom_half.h" +#include "../drivers/char_lcd.h" +#include "../drivers/wires.h" +#include "wires_puzzle.h" +#include + +void setup_wires(void); + +#endif /* SETUP_WIRES_H */ diff --git a/main/steps/step0.hpp b/main/steps/step0.cpp similarity index 89% rename from main/steps/step0.hpp rename to main/steps/step0.cpp index c64fee8..55e43fd 100644 --- a/main/steps/step0.hpp +++ b/main/steps/step0.cpp @@ -1,14 +1,6 @@ -#ifndef STEP_0_HPP -#define STEP_0_HPP +#include "step0.h" -#include "../drivers/bottom_half.h" -#include "../drivers/char_lcd.h" -#include "../drivers/wires.h" -#include "setup_wires.hpp" - -static const char *STEP0_TAG = "step0"; - -#define STRING_MAX_LEN 8 +static const char* TAG = "step0"; /// Wait for "*9819" void step0(void) { @@ -71,5 +63,3 @@ void step0(void) { vTaskDelay(pdMS_TO_TICKS(10)); } } - -#endif /* STEP_0_HPP */ \ No newline at end of file diff --git a/main/steps/step0.h b/main/steps/step0.h new file mode 100644 index 0000000..0a4afe5 --- /dev/null +++ b/main/steps/step0.h @@ -0,0 +1,14 @@ +#ifndef STEP_0_H +#define STEP_0_H + +#include "../drivers/bottom_half.h" +#include "../drivers/char_lcd.h" +#include "../drivers/wires.h" +#include "setup_wires.h" + +#define STRING_MAX_LEN 8 + +/// Wait for "*9819" +void step0(void); + +#endif /* STEP_0_H */ \ No newline at end of file diff --git a/main/steps/step1.hpp b/main/steps/step1.cpp similarity index 92% rename from main/steps/step1.hpp rename to main/steps/step1.cpp index c030dbe..f35a0ae 100644 --- a/main/steps/step1.hpp +++ b/main/steps/step1.cpp @@ -1,7 +1,4 @@ -#ifndef STEP_1_HPP -#define STEP_1_HPP - -#include +#include "step1.h" static const char *STEP1_TAG = "step1"; @@ -26,15 +23,16 @@ static uint8_t NEOPIXEL_COLORS[4][3] = { {15, 0, 20}, }; -std::random_device my_rd; -std::mt19937 my_gen(my_rd()); -std::uniform_int_distribution<> zero_to_one(0, 1); -std::uniform_int_distribution<> zero_to_two(0, 2); -std::uniform_int_distribution<> zero_to_three(0, 3); +static std::random_device my_rd; +static std::mt19937 my_gen(my_rd()); +static std::uniform_int_distribution<> zero_to_one(0, 1); +static std::uniform_int_distribution<> zero_to_two(0, 2); +static std::uniform_int_distribution<> zero_to_three(0, 3); static lv_obj_t *scr; static lv_obj_t *text = NULL; +static lv_style_t style_screen; static lv_style_t green_text; static lv_style_t red_text; static lv_style_t yellow_text; @@ -49,7 +47,7 @@ static lv_style_t* color_styles[] = { &purple_text }; -void init_step(void) { +static void init_step(void) { scr = lv_disp_get_scr_act(NULL); // Set the background color of the display to black. @@ -83,12 +81,12 @@ void init_step(void) { text = lv_label_create(scr); } -void clean_up_step(void) { +static void clean_up_step(void) { lv_obj_clean(text); lv_obj_clean(scr); } -void generate_switch_leds(void) { +static void generate_switch_leds(void) { int colors[4] = {0, 1, 2, 3}; int idx = zero_to_three(my_gen); @@ -114,7 +112,7 @@ void generate_switch_leds(void) { led_strip_refresh(leds); } -int generate_part_a(void) { +static int generate_part_a(void) { int text_color = zero_to_three(my_gen); int text_idx = zero_to_three(my_gen); @@ -130,7 +128,7 @@ int generate_part_a(void) { return text_color; } -int generate_part_b(void) { +static int generate_part_b(void) { int is_color = zero_to_one(my_gen) == 0; if (is_color) { return generate_part_a(); @@ -151,7 +149,7 @@ int generate_part_b(void) { return text_number; } -int generate_part_c(void) { +static int generate_part_c(void) { int type = zero_to_two(my_gen); if (type != 0) { return generate_part_b(); @@ -170,7 +168,7 @@ int generate_part_c(void) { return text_color + 4; } -void part_a(void) { +static void part_a(void) { stop_module_timer(); set_module_time(30); @@ -209,7 +207,7 @@ void part_a(void) { play_raw(MOUNT_POINT "/correct.pcm"); } -void part_b(void) { +static void part_b(void) { stop_module_timer(); set_module_time(25); @@ -248,7 +246,7 @@ void part_b(void) { play_raw(MOUNT_POINT "/correct.pcm"); } -void part_c(void) { +static void part_c(void) { stop_module_timer(); set_module_time(20); @@ -304,7 +302,3 @@ void step1(void) { part_c(); clean_up_step(); } - - - -#endif /* STEP_1_HPP */ \ No newline at end of file diff --git a/main/steps/step1.h b/main/steps/step1.h new file mode 100644 index 0000000..07e827c --- /dev/null +++ b/main/steps/step1.h @@ -0,0 +1,15 @@ +#ifndef STEP_1_H +#define STEP_1_H + +#include +#include "../drivers/bottom_half.h" +#include "../drivers/tft.h" +#include "../drivers/leds.h" +#include "../drivers/wires.h" +#include "../drivers/speaker.h" +#include "../drivers/game_timer.h" +#include "../drivers/char_lcd.h" + +void step1(void); + +#endif /* STEP_1_H */ diff --git a/main/steps/step2.hpp b/main/steps/step2.cpp similarity index 100% rename from main/steps/step2.hpp rename to main/steps/step2.cpp diff --git a/main/steps/step2.h b/main/steps/step2.h new file mode 100644 index 0000000..861c766 --- /dev/null +++ b/main/steps/step2.h @@ -0,0 +1,10 @@ +#ifndef STEP_2_HPP +#define STEP_2_HPP + +static const char *STEP2_TAG = "step2"; + +void step2(void) { + +} + +#endif /* STEP_2_HPP */ \ No newline at end of file diff --git a/main/steps/step4.cpp b/main/steps/step4.cpp new file mode 100644 index 0000000..3ca27d0 --- /dev/null +++ b/main/steps/step4.cpp @@ -0,0 +1,5 @@ +static const char *TAG = "step4"; + +void step4(void) { + +} diff --git a/main/steps/step4.h b/main/steps/step4.h new file mode 100644 index 0000000..fd0bec1 --- /dev/null +++ b/main/steps/step4.h @@ -0,0 +1,6 @@ +#ifndef STEP_4_H +#define STEP_4_H + +void step4(void); + +#endif /* STEP_4_H */ \ No newline at end of file diff --git a/main/steps/step4.hpp b/main/steps/step4.hpp deleted file mode 100644 index 2f0f5af..0000000 --- a/main/steps/step4.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STEP_4_HPP -#define STEP_4_HPP - -static const char *STEP4_TAG = "step4"; - -void step4(void) { - -} - -#endif /* STEP_4_HPP */ \ No newline at end of file diff --git a/main/steps/step6.hpp b/main/steps/step6.cpp similarity index 86% rename from main/steps/step6.hpp rename to main/steps/step6.cpp index 9c7b1af..5689ea4 100644 --- a/main/steps/step6.hpp +++ b/main/steps/step6.cpp @@ -1,15 +1,9 @@ -#ifndef STEP_6_HPP -#define STEP_6_HPP +#include "step6.h" -#include "wires_puzzle.h" -#include "drivers/wires.h" -#include "drivers/bottom_half.h" - -static const char *STEP6_TAG = "step6"; +static const char *TAG = "step6"; static uint8_t cut_wires = 0; - void step6(void) { get_cut_wires(); clear_all_pressed_released(); @@ -53,5 +47,3 @@ void step6(void) { vTaskDelay(pdMS_TO_TICKS(10)); } } - -#endif /* STEP_6_HPP */ \ No newline at end of file diff --git a/main/steps/step6.h b/main/steps/step6.h new file mode 100644 index 0000000..e6eeee9 --- /dev/null +++ b/main/steps/step6.h @@ -0,0 +1,12 @@ +#ifndef STEP_6_H +#define STEP_6_H + +#include "wires_puzzle.h" +#include "drivers/wires.h" +#include "drivers/bottom_half.h" +#include "drivers/sd.h" +#include "drivers/speaker.h" + +void step6(void); + +#endif /* STEP_6_H */ \ No newline at end of file