Skip to content

Commit

Permalink
rotation test
Browse files Browse the repository at this point in the history
  • Loading branch information
rzeldent committed Mar 17, 2024
1 parent 6b7c024 commit dd29e66
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#default_envs = esp32-2432S032C
#default_envs = esp32-2432S032N
#default_envs = esp32-2432S032R
#default_envs = esp32-3248S035C
default_envs = esp32-3248S035C
#default_envs = esp32-3248S035R
#default_envs = esp32-4827S043C
#default_envs = esp32-4827S043N
Expand Down
33 changes: 30 additions & 3 deletions src/esp32_smartdisplay.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <esp32_smartdisplay.h>
#include <esp_lcd_panel_ops.h>

#ifdef BOARD_HAS_TOUCH
#include <esp_lcd_touch.h>
Expand Down Expand Up @@ -136,17 +137,41 @@ touch_calibration_data_t smartdisplay_compute_touch_calibration(const lv_point_t
};
#endif

// Called when driver parameters are updated (rotation)
// Top of the display is top left when connector is at the bottom
static void lvgl_update_callback(lv_disp_drv_t *drv)
{
const esp_lcd_panel_handle_t panel_handle = disp_drv.user_data;
switch (drv->rotated)
{
case LV_DISP_ROT_NONE:
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, LCD_SWAP_XY));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, LCD_MIRROR_X, LCD_MIRROR_Y));
break;
case LV_DISP_ROT_90:
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !LCD_SWAP_XY));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !LCD_MIRROR_X, LCD_MIRROR_Y));
break;
case LV_DISP_ROT_180:
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, LCD_SWAP_XY));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !LCD_MIRROR_X, !LCD_MIRROR_Y));
break;
case LV_DISP_ROT_270:
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !LCD_SWAP_XY));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, LCD_MIRROR_X, !LCD_MIRROR_Y));
break;
}
}

void smartdisplay_init()
{
log_d("smartdisplay_init");
#ifdef BOARD_HAS_RGB_LED
// Setup RGB LED. High is off
pinMode(RGB_LED_R, OUTPUT);
digitalWrite(RGB_LED_R, true);
pinMode(RGB_LED_G, OUTPUT);
digitalWrite(RGB_LED_G, true);
pinMode(RGB_LED_B, OUTPUT);
digitalWrite(RGB_LED_B, true);
smartdisplay_led_set_rgb(false, false, false);
#endif

#ifdef BOARD_HAS_CDS
Expand Down Expand Up @@ -183,6 +208,8 @@ void smartdisplay_init()
disp_drv.draw_buf = (lv_disp_draw_buf_t *)malloc(sizeof(lv_disp_draw_buf_t));
void *drawBuffer = heap_caps_malloc(sizeof(lv_color_t) * LVGL_BUFFER_PIXELS, LVGL_BUFFER_MALLOC_FLAGS);
lv_disp_draw_buf_init(disp_drv.draw_buf, drawBuffer, NULL, LVGL_BUFFER_PIXELS);
// Register callback for changes to the driver parameters (rotation!)
disp_drv.drv_update_cb = lvgl_update_callback;
// Initialize specific driver
lvgl_lcd_init(&disp_drv);
__attribute__((unused)) lv_disp_t *display = lv_disp_drv_register(&disp_drv);
Expand Down
2 changes: 1 addition & 1 deletion src/lvgl_touch_cst816s_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv)
.levels = {
.reset = CST816S_TOUCH_CONFIG_LEVELS_RESET,
.interrupt = CST816S_TOUCH_CONFIG_LEVELS_INTERRUPT},
.flags = {.swap_xy = TOUCH_MIRROR_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y},
.flags = {.swap_xy = TOUCH_SWAP_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y},
.user_data = io_handle};
log_d("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels:{reset:%d, interrupt:%d}, flags:{swap_xy:%d, mirror_x:%d, mirror_y:%d}, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data);
esp_lcd_touch_handle_t touch_handle;
Expand Down
2 changes: 1 addition & 1 deletion src/lvgl_touch_gt911_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv)
.levels = {
.reset = GT911_TOUCH_CONFIG_LEVELS_RESET,
.interrupt = GT911_TOUCH_CONFIG_LEVELS_INTERRUPT},
.flags = {.swap_xy = TOUCH_MIRROR_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y},
.flags = {.swap_xy = TOUCH_SWAP_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y},
.user_data = io_handle};
log_d("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels:{reset:%d, interrupt:%d}, flags:{swap_xy:%d, mirror_x:%d, mirror_y:%d}, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data);
esp_lcd_touch_handle_t touch_handle;
Expand Down
2 changes: 1 addition & 1 deletion src/lvgl_touch_xpt2046_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv)
.levels = {
.reset = XPT2046_TOUCH_CONFIG_LEVELS_RESET,
.interrupt = XPT2046_TOUCH_CONFIG_LEVELS_INTERRUPT},
.flags = {.swap_xy = TOUCH_MIRROR_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y},
.flags = {.swap_xy = TOUCH_SWAP_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y},
.user_data = io_handle};
log_d("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels:{reset:%d, interrupt:%d}, flags:{swap_xy:%d, mirror_x:%d, mirror_y:%d}, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data);
esp_lcd_touch_handle_t touch_handle;
Expand Down

0 comments on commit dd29e66

Please sign in to comment.