tetris impl

This commit is contained in:
2024-08-09 11:20:42 -05:00
parent b6eac70c2c
commit 074faf8879
6 changed files with 78 additions and 1735 deletions
+25 -66
View File
@@ -10,15 +10,11 @@ static lv_disp_drv_t lv_disp_drv;
static lv_disp_t *lv_display = NULL;
static lv_color_t *lv_buf_1 = NULL;
static lv_color_t *lv_buf_2 = NULL;
static lv_obj_t *meter = NULL;
static lv_style_t style_screen;
lv_obj_t* screen;
static lv_style_t style_screen;
static void update_meter_value(void *indic, int32_t v)
{
lv_meter_set_indicator_end_value(meter, (lv_meter_indicator_t*)indic, v);
}
SemaphoreHandle_t xGuiSemaphore;
static bool notify_lvgl_flush_ready(
esp_lcd_panel_io_handle_t panel_io,
@@ -40,7 +36,7 @@ static void lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
}
static void IRAM_ATTR lvgl_tick_cb(void *param) {
static void IRAM_ATTR lv_tick_task(void *param) {
lv_tick_inc(LVGL_UPDATE_PERIOD_MS);
}
@@ -121,7 +117,8 @@ static void initialize_display() {
#endif
}
static void initialize_lvgl() {
static void guiTask(void *pvParameter) {
xGuiSemaphore = xSemaphoreCreateMutex();
ESP_LOGI(TAG, "Initializing LVGL");
lv_init();
ESP_LOGI(TAG, "Allocating %zu bytes for LVGL buffer", LV_BUFFER_SIZE * sizeof(lv_color_t));
@@ -145,86 +142,48 @@ static void initialize_lvgl() {
ESP_LOGI(TAG, "Creating LVGL tick timer");
const esp_timer_create_args_t lvgl_tick_timer_args = {
.callback = &lvgl_tick_cb,
.arg = NULL,
.dispatch_method = ESP_TIMER_TASK,
.name = "lvgl_tick",
.skip_unhandled_events = false
.callback = &lv_tick_task,
// .dispatch_method = ESP_TIMER_TASK,
.name = "periodic_gui",
// .skip_unhandled_events = false
};
esp_timer_handle_t lvgl_tick_timer = NULL;
ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, LVGL_UPDATE_PERIOD_MS * 1000));
esp_timer_handle_t periodic_timer;
ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &periodic_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, LVGL_UPDATE_PERIOD_MS * 1000));
screen = lv_disp_get_scr_act(NULL);
lv_style_init(&style_screen);
lv_style_set_bg_color(&style_screen, lv_color_black());
lv_obj_add_style(lv_scr_act(), &style_screen, LV_STATE_DEFAULT);
}
void create_demo_ui() {
// Create a meter which can be animated.
meter = lv_meter_create(screen);
lv_obj_center(meter);
lv_obj_set_size(meter, 200, 200);
while (1) {
/* Delay 1 tick (assumes FreeRTOS tick is 10ms */
vTaskDelay(pdMS_TO_TICKS(10));
// Add a scale first
lv_meter_scale_t *scale = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale, 41, 2, 10, lv_palette_main(LV_PALETTE_GREY));
lv_meter_set_scale_major_ticks(meter, scale, 8, 4, 15, lv_color_black(), 10);
/* Try to take the semaphore, call lvgl related function on success */
if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY)) {
lv_task_handler();
xSemaphoreGive(xGuiSemaphore);
}
}
lv_meter_indicator_t *indic;
// Add a blue arc to the start
indic = lv_meter_add_arc(meter, scale, 3, lv_palette_main(LV_PALETTE_BLUE), 0);
lv_meter_set_indicator_start_value(meter, indic, 0);
lv_meter_set_indicator_end_value(meter, indic, 20);
// Make the tick lines blue at the start of the scale
indic = lv_meter_add_scale_lines(meter, scale, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_BLUE), false, 0);
lv_meter_set_indicator_start_value(meter, indic, 0);
lv_meter_set_indicator_end_value(meter, indic, 20);
// Add a red arc to the end
indic = lv_meter_add_arc(meter, scale, 3, lv_palette_main(LV_PALETTE_RED), 0);
lv_meter_set_indicator_start_value(meter, indic, 80);
lv_meter_set_indicator_end_value(meter, indic, 100);
// Make the tick lines red at the end of the scale
indic = lv_meter_add_scale_lines(meter, scale, lv_palette_main(LV_PALETTE_RED), lv_palette_main(LV_PALETTE_RED), false, 0);
lv_meter_set_indicator_start_value(meter, indic, 80);
lv_meter_set_indicator_end_value(meter, indic, 100);
// Add a needle line indicator
indic = lv_meter_add_needle_line(meter, scale, 4, lv_palette_main(LV_PALETTE_GREY), -10);
// Create an animation to set the value
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_exec_cb(&a, update_meter_value);
lv_anim_set_var(&a, indic);
lv_anim_set_values(&a, 0, 100);
lv_anim_set_time(&a, 2000);
lv_anim_set_repeat_delay(&a, 100);
lv_anim_set_playback_time(&a, 500);
lv_anim_set_playback_delay(&a, 100);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_start(&a);
vTaskDelete(NULL);
}
static void tick_timer_task(void* arg) {
while (1)
{
lv_task_handler();
vTaskDelay(pdMS_TO_TICKS(10));
lv_timer_handler();
}
}
void init_tft() {
initialize_spi();
initialize_display();
initialize_lvgl();
xTaskCreatePinnedToCore(guiTask, "gui", 4096*2, NULL, 5, NULL, 1);
xTaskCreate(tick_timer_task, "tick_lvgl", 4096, NULL, 5, NULL);
// xTaskCreatePinnedToCore(tick_timer_task, "tick_lvgl", 4096, NULL, 5, NULL, 1);
ESP_LOGI(TAG, "TFT initialization Successful");
}
+2
View File
@@ -64,6 +64,8 @@
extern lv_obj_t* screen;
extern SemaphoreHandle_t xGuiSemaphore;
void create_demo_ui();
void init_tft();