Changeset - ef80f76e5ec7
[Not reviewed]
default
2 2 0
Ethan Zonca - 17 months ago 2024-01-11 20:19:47
ez@ethanzonca.com
Remove unused helpers
4 files changed with 2 insertions and 344 deletions:
0 comments (0 inline, 0 general)
main/CMakeLists.txt
Show inline comments
 
idf_component_register(SRCS "main.c" "wifi.c" "usb_cdc.c" "can.c" "display.c" "ui_helpers.c"
 
idf_component_register(SRCS "main.c" "wifi.c" "usb_cdc.c" "can.c" "display.c"
 
                       INCLUDE_DIRS .)
main/display.c
Show inline comments
 
//
 
// display
 
//
 

	
 
#include "display.h"
 
#include "esp_err.h"
 
#include "esp_log.h"
 
#include "esp_check.h"
 
#include "driver/i2c.h"
 
#include "driver/gpio.h"
 
#include "driver/spi_master.h"
 
#include "esp_lcd_panel_io.h"
 
#include "esp_lcd_panel_vendor.h"
 
#include "esp_lcd_panel_ops.h"
 
#include "esp_lvgl_port.h"
 

	
 

	
 
#include <stdio.h>
 
#include "esp_timer.h"
 
#include "esp_heap_caps.h"
 
#include "freertos/FreeRTOS.h"
 
#include "freertos/task.h"
 
#include "ui_helpers.h"
 
// #include "ui_helpers.h"
 

	
 
static const char *TAG = "LVGL_SETUP";
 
static void lvgl_timer_task(void *arg);
 

	
 
static lv_obj_t *ui_Screen1;
 
static lv_obj_t *ui_redsquare;
 

	
 
static lv_obj_t *meter;
 
static lv_obj_t *ue_img_logo;
 
static lv_obj_t *esp_img_logo;
 

	
 
static lv_obj_t *ui_Dropdown2;
 

	
 
LV_IMG_DECLARE(ue_logo)
 
LV_IMG_DECLARE(esp_logo)
 
LV_IMG_DECLARE(red_square)
 

	
 
#define BSP_NULL_CHECK(x, ret) assert(x)
 

	
 
static SemaphoreHandle_t lvgl_mux;  // LVGL mutex
 
static SemaphoreHandle_t touch_mux; // Touch mutex
 

	
 
static void bsp_touchpad_read(lv_indev_drv_t *drv, lv_indev_data_t *data)
 
{
 
    uint16_t touchpad_x[1] = {0};
 
    uint16_t touchpad_y[1] = {0};
 
    uint8_t touchpad_cnt = 0;
 

	
 
    /* Read data from touch controller into memory */
 
    if (xSemaphoreTake(touch_mux, 0) == pdTRUE)
 
    {
 
        esp_lcd_touch_read_data(drv->user_data);
 
    }
 
    /* Get coordinates */
 
    bool touchpad_pressed = esp_lcd_touch_get_coordinates(drv->user_data, touchpad_x, touchpad_y, NULL, &touchpad_cnt, 1);
 

	
 
    if (touchpad_pressed && touchpad_cnt > 0)
 
    {
 
        data->point.x = touchpad_x[0];
 
        data->point.y = touchpad_y[0];
 
        data->state = LV_INDEV_STATE_PRESSED;
 
        printf("data->point.x = %u \n", data->point.x);
 
        printf("data->point.y = %u \n", data->point.y);
 
    }
 
    else
 
    {
 
        data->state = LV_INDEV_STATE_RELEASED;
 
    }
 
}
 

	
 
static void touch_callback(esp_lcd_touch_handle_t tp)
 
{
 
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
 
    xSemaphoreGiveFromISR(touch_mux, &xHigherPriorityTaskWoken);
 

	
 
    if (xHigherPriorityTaskWoken)
 
    {
 
        portYIELD_FROM_ISR();
 
    }
 
}
 

	
 
static void set_value(void *indic, int32_t v)
 
{
 
    lv_meter_set_indicator_end_value(meter, indic, v);
 
}
 

	
 
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
 
{
 
    lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
 
    lv_disp_flush_ready(disp_driver);
 
    return false;
 
}
 

	
 
static void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
 
{
 
    esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data;
 
    int offsetx1 = area->x1;
 
    int offsetx2 = area->x2;
 
    int offsety1 = area->y1;
 
    int offsety2 = area->y2;
 
    // copy a buffer's content to a specific area of the display
 
    esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
 
}
 

	
 
static void example_increase_lvgl_tick(void *arg)
 
{
 
    /* Tell LVGL how many milliseconds has elapsed */
 
    lv_tick_inc(EXAMPLE_LVGL_TICK_PERIOD_MS);
 
}
 

	
 
void display_init()
 
{
 

	
 
    static lv_disp_draw_buf_t disp_buf; // contains internal graphic buffer(s) called draw buffer(s)
 
    static lv_disp_drv_t disp_drv;      // contains callback functions
 

	
 
    gpio_config_t pwr_gpio_config =
 
        {
 
            .mode = GPIO_MODE_OUTPUT,
 
            .pin_bit_mask = 1ULL << EXAMPLE_PIN_NUM_POWER};
 
    ESP_ERROR_CHECK(gpio_config(&pwr_gpio_config));
 
    gpio_set_level(EXAMPLE_PIN_NUM_POWER, EXAMPLE_LCD_BK_LIGHT_ON_LEVEL);
 

	
 
    gpio_config_t input_conf =
 
        {
 
            .mode = GPIO_MODE_INPUT,
 
            .pull_up_en = GPIO_PULLUP_ENABLE,
 
            .pin_bit_mask = 1ULL << PIN_LCD_RD};
 
    ESP_ERROR_CHECK(gpio_config(&input_conf));
 

	
 
    gpio_config_t bk_gpio_config =
 
        {
 
            .mode = GPIO_MODE_OUTPUT,
 
            .pin_bit_mask = 1ULL << EXAMPLE_PIN_NUM_BK_LIGHT};
 
    ESP_ERROR_CHECK(gpio_config(&bk_gpio_config));
 
    gpio_set_level(EXAMPLE_PIN_NUM_BK_LIGHT, EXAMPLE_LCD_BK_LIGHT_ON_LEVEL);
 

	
 
    ESP_LOGI(TAG, "Initialize Intel 8080 bus");
 
    esp_lcd_i80_bus_handle_t i80_bus = NULL;
 
    esp_lcd_i80_bus_config_t bus_config = {
 
        .clk_src = LCD_CLK_SRC_DEFAULT,
 
        .dc_gpio_num = EXAMPLE_PIN_NUM_DC,
 
        .wr_gpio_num = EXAMPLE_PIN_NUM_PCLK,
 
        .data_gpio_nums = {
 
            EXAMPLE_PIN_NUM_DATA0,
 
            EXAMPLE_PIN_NUM_DATA1,
 
            EXAMPLE_PIN_NUM_DATA2,
 
            EXAMPLE_PIN_NUM_DATA3,
 
            EXAMPLE_PIN_NUM_DATA4,
 
            EXAMPLE_PIN_NUM_DATA5,
 
            EXAMPLE_PIN_NUM_DATA6,
 
            EXAMPLE_PIN_NUM_DATA7,
 
        },
 
        .bus_width = 8,
 
        .max_transfer_bytes = LVGL_LCD_BUF_SIZE * sizeof(uint16_t)
 
        //.psram_trans_align = EXAMPLE_PSRAM_DATA_ALIGNMENT,
 
        //.sram_trans_align = 4,
 
    };
 
    ESP_ERROR_CHECK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
 
    esp_lcd_panel_io_handle_t io_handle = NULL;
 
    esp_lcd_panel_io_i80_config_t io_config = {
 
        .cs_gpio_num = EXAMPLE_PIN_NUM_CS,
 
        .pclk_hz = EXAMPLE_LCD_PIXEL_CLOCK_HZ,
 
        .trans_queue_depth = 20,
 
        .dc_levels = {
 
            .dc_idle_level = 0,
 
            .dc_cmd_level = 0,
 
            .dc_dummy_level = 0,
 
            .dc_data_level = 1,
 
        },
 

	
 
        .on_color_trans_done = example_notify_lvgl_flush_ready,
 
        .user_ctx = &disp_drv,
 
        .lcd_cmd_bits = EXAMPLE_LCD_CMD_BITS,
 
        .lcd_param_bits = EXAMPLE_LCD_PARAM_BITS,
 
    };
 
    ESP_ERROR_CHECK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
 

	
 
    esp_lcd_panel_handle_t panel_handle = NULL;
 

	
 
    ESP_LOGI(TAG, "Install LCD driver of st7789");
 
    esp_lcd_panel_dev_config_t panel_config = {
 
        .reset_gpio_num = EXAMPLE_PIN_NUM_RST,
 
        .rgb_endian = ESP_LCD_COLOR_SPACE_RGB,
 
        .bits_per_pixel = 16,
 
    };
 
    ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle));
 

	
 
    esp_lcd_panel_reset(panel_handle);
 
    esp_lcd_panel_init(panel_handle);
 
    esp_lcd_panel_invert_color(panel_handle, true);
 

	
 
    esp_lcd_panel_swap_xy(panel_handle, true);
 

	
 
    esp_lcd_panel_mirror(panel_handle, false, true);
 

	
 
    // the gap is LCD panel specific, even panels with the same driver IC, can have different gap value
 
    esp_lcd_panel_set_gap(panel_handle, 0, 35);
 

	
 
    esp_lcd_panel_io_tx_param(io_handle, 0xF2, (uint8_t[]){0}, 1); // 3Gamma function disable
 
    esp_lcd_panel_io_tx_param(io_handle, 0x26, (uint8_t[]){1}, 1); // Gamma curve 1 selected
 
    esp_lcd_panel_io_tx_param(io_handle, 0xE0, (uint8_t[]){        // Set positive gamma
 
                                                           0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00},
 
                              15);
 
    esp_lcd_panel_io_tx_param(io_handle, 0xE1, (uint8_t[]){// Set negative gamma
 
                                                           0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F},
 
                              15);
 

	
 
    ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
 

	
 
#if USE_TOUCH_DISPLAY
 
    // CST816 TOUCH TESTING FUNCTION
main/ui_helpers.c
Show inline comments
 
deleted file
main/ui_helpers.h
Show inline comments
 
deleted file
0 comments (0 inline, 0 general)