Skip to content

Commit

Permalink
Develop (#216)
Browse files Browse the repository at this point in the history
* Minor fix: add != NULL

* Fixed typo in log

* Pinned LVGL version to 9.2.0 (exact)

* Changed the order of enabling interrupts (#196)

Corrected interrupts leven pos/neg edge

* Remove sw_rotate (#210)

* Remove sw_rotate

* Removed unused code

* LVGL version to 9.2.2

* Enable all devices

* Updated markdown

* Lvgl9.2.2 (#211)

* Remove sw_rotate

* Removed unused code

* LVGL version to 9.2.2

* Enable all devices

* Updated markdown

* Test hardware rotation st7701

* Test use underlying driver for swap and mirror

* Reenabled code

* test

* Use define for DISPLAY_SOFTWARE_ROTATION

* Update boards to develop

* Added check for rst_gpio_num == GPIO_NUM_NC (#215)
  • Loading branch information
rzeldent authored Nov 8, 2024
1 parent a6ddcc0 commit 8ba252e
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 103 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ The following libraries are used from the [Espressif component registry](https:/

## Version history

- October 2024
- Fix for LVGL 9.2.2 that removed the sw_rotate flag
- August 2024
- LVGL 9.2
- New boards
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
"frameworks": "arduino",
"platforms": "espressif32",
"dependencies": {
"lvgl/lvgl": "^9.2.0"
"lvgl/lvgl": "^9.2.2"
}
}
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ build_flags =
'-D ESP_LCD_PANEL_IO_ADDITIONS_VER_PATCH=1'

lib_deps =
lvgl/lvgl@^9.2.0
lvgl/lvgl@^9.2.2
# The platformio.test_dir contains the test_main.cpp just to have an setup() and loop() function
# so it will compile
${platformio.test_dir}
Expand Down
19 changes: 12 additions & 7 deletions src/esp32_smartdisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ void smartdisplay_lcd_set_brightness_cb(smartdisplay_lcd_adaptive_brightness_cb_
log_v("adaptive_brightness_cb:0x%08x, interval:%u", cb, interval);

// Delete current timer if any
if (update_brightness_timer)
if (update_brightness_timer != NULL)
lv_timer_del(update_brightness_timer);

// Use callback for intensity or 50% default
if (cb && interval > 0)
if (cb != NULL && interval > 0)
update_brightness_timer = lv_timer_create(adaptive_brightness, interval, cb);
else
smartdisplay_lcd_set_backlight(0.5f);
Expand All @@ -107,7 +107,7 @@ void smartdisplay_lcd_set_brightness_cb(smartdisplay_lcd_adaptive_brightness_cb_
#ifdef BOARD_HAS_RGB_LED
void smartdisplay_led_set_rgb(bool r, bool g, bool b)
{
log_d("R:%d, G:%d, B:%d", r, b, b);
log_d("R:%d, G:%d, B:%d", r, g, b);

digitalWrite(RGB_LED_R, !r);
digitalWrite(RGB_LED_G, !g);
Expand Down Expand Up @@ -193,9 +193,11 @@ void smartdisplay_init()
#endif
// Setup TFT display
display = lvgl_lcd_init();

#ifndef DISPLAY_SOFTWARE_ROTATION
// Register callback for hardware rotation
if (!display->sw_rotate)
lv_display_add_event_cb(display, lvgl_display_resolution_changed_callback, LV_EVENT_RESOLUTION_CHANGED, NULL);
lv_display_add_event_cb(display, lvgl_display_resolution_changed_callback, LV_EVENT_RESOLUTION_CHANGED, NULL);
#endif

// Clear screen
lv_obj_clean(lv_scr_act());
Expand All @@ -214,10 +216,11 @@ void smartdisplay_init()
#endif
}

#ifndef DISPLAY_SOFTWARE_ROTATION
// Called when driver resolution is updated (including rotation)
// Top of the display is top left when connector is at the bottom
// The rotation values are relative to how you would rotate the physical display in the clockwise direction.
// Thus, LV_DISPLAY_ROTATION_90 means you rotate the hardware 90 degrees clockwise, and the display rotates 90 degrees counterclockwise to compensate.
// So, LV_DISPLAY_ROTATION_90 means you rotate the hardware 90 degrees clockwise, and the display rotates 90 degrees counterclockwise to compensate.
void lvgl_display_resolution_changed_callback(lv_event_t *event)
{
const esp_lcd_panel_handle_t panel_handle = display->user_data;
Expand All @@ -240,4 +243,6 @@ void lvgl_display_resolution_changed_callback(lv_event_t *event)
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y));
break;
}
}
}

#endif
47 changes: 27 additions & 20 deletions src/esp_touch_cst816s.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ esp_err_t cst816s_reset(esp_lcd_touch_handle_t th)
if (th == NULL)
return ESP_ERR_INVALID_ARG;

if (th->config.rst_gpio_num == GPIO_NUM_NC)
{
log_w("No RST pin defined");
return ESP_OK;
}

esp_err_t res;
// Set RST active
if ((res = gpio_set_level(th->config.rst_gpio_num, th->config.levels.reset)) != ESP_OK)
Expand Down Expand Up @@ -259,14 +265,29 @@ esp_err_t esp_lcd_touch_new_i2c_cst816s(const esp_lcd_panel_io_handle_t io, cons
memcpy(&th->config, config, sizeof(esp_lcd_touch_config_t));
portMUX_INITIALIZE(&th->data.lock);

// Reset controller
if ((res = cst816s_reset(th)) != ESP_OK)
{
log_e("GT911 reset failed");
cst816s_del(th);
return res;
}

// Read type and resolution
if ((res = cst816s_read_info(th)) != ESP_OK)
{
log_e("GT911 read info failed");
cst816s_del(th);
return res;
}

if (config->int_gpio_num != GPIO_NUM_NC)
{
esp_rom_gpio_pad_select_gpio(config->int_gpio_num);
const gpio_config_t cfg = {
.pin_bit_mask = BIT64(config->int_gpio_num),
.mode = GPIO_MODE_INPUT,
// If the user has provided a callback routine for the interrupt enable the interrupt mode on the negative edge.
.intr_type = config->interrupt_callback ? GPIO_INTR_NEGEDGE : GPIO_INTR_DISABLE};
.intr_type = config->levels.interrupt ? GPIO_INTR_POSEDGE : GPIO_INTR_NEGEDGE};
if ((res = gpio_config(&cfg)) != ESP_OK)
{
free(th);
Expand All @@ -278,9 +299,11 @@ esp_err_t esp_lcd_touch_new_i2c_cst816s(const esp_lcd_panel_io_handle_t io, cons
{
if ((res = esp_lcd_touch_register_interrupt_callback(th, config->interrupt_callback)) != ESP_OK)
{
gpio_reset_pin(th->config.int_gpio_num);
if (config->int_gpio_num != GPIO_NUM_NC)
gpio_reset_pin(th->config.int_gpio_num);

free(th);
log_e("Registering INT callback failed");
log_e("Registering interrupt callback failed");
return res;
}
}
Expand All @@ -306,22 +329,6 @@ esp_err_t esp_lcd_touch_new_i2c_cst816s(const esp_lcd_panel_io_handle_t io, cons
return res;
}
}

// Reset controller
if ((res = cst816s_reset(th)) != ESP_OK)
{
log_e("GT911 reset failed");
cst816s_del(th);
return res;
}

// Read type and resolution
if ((res = cst816s_read_info(th)) != ESP_OK)
{
log_e("GT911 read info failed");
cst816s_del(th);
return res;
}
}

log_d("handle:0x%08x", th);
Expand Down
78 changes: 38 additions & 40 deletions src/esp_touch_gt911.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ esp_err_t gt911_reset(esp_lcd_touch_handle_t th)
if (th == NULL)
return ESP_ERR_INVALID_ARG;

if (th->config.rst_gpio_num == GPIO_NUM_NC)
{
log_w("No RST pin defined");
return ESP_OK;
}

esp_err_t res;
// Set RST active
if ((res = gpio_set_level(th->config.rst_gpio_num, th->config.levels.reset)) != ESP_OK)
Expand Down Expand Up @@ -397,53 +403,19 @@ esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const
memcpy(&th->config, config, sizeof(esp_lcd_touch_config_t));
portMUX_INITIALIZE(&th->data.lock);

if (config->int_gpio_num != GPIO_NUM_NC)
// Initialize RST pin
if (config->rst_gpio_num != GPIO_NUM_NC)
{
esp_rom_gpio_pad_select_gpio(config->int_gpio_num);
esp_rom_gpio_pad_select_gpio(config->rst_gpio_num);
const gpio_config_t cfg = {
.pin_bit_mask = BIT64(config->int_gpio_num),
.mode = GPIO_MODE_INPUT,
// If the user has provided a callback routine for the interrupt enable the interrupt mode on the negative edge.
.intr_type = config->interrupt_callback ? GPIO_INTR_NEGEDGE : GPIO_INTR_DISABLE};
.pin_bit_mask = BIT64(config->rst_gpio_num),
.mode = GPIO_MODE_OUTPUT};
if ((res = gpio_config(&cfg)) != ESP_OK)
{
free(th);
log_e("Configuring GPIO for INT failed");
log_e("Configuring or setting GPIO for RST failed");
return res;
}

if (config->interrupt_callback != NULL)
{
if ((res = esp_lcd_touch_register_interrupt_callback(th, config->interrupt_callback)) != ESP_OK)
{
gpio_reset_pin(th->config.int_gpio_num);
free(th);
log_e("Registering INT callback failed");
return res;
}
}

if (config->rst_gpio_num != GPIO_NUM_NC)
{
esp_rom_gpio_pad_select_gpio(config->rst_gpio_num);
const gpio_config_t cfg = {
.pin_bit_mask = BIT64(config->rst_gpio_num),
.mode = GPIO_MODE_OUTPUT};
if ((res = gpio_config(&cfg)) != ESP_OK)
{
if (th->config.int_gpio_num != GPIO_NUM_NC)
{
if (config->interrupt_callback != NULL)
gpio_isr_handler_remove(th->config.int_gpio_num);

gpio_reset_pin(th->config.int_gpio_num);
}

free(th);
log_e("Configuring or setting GPIO for RST failed");
return res;
}
}
}

// Reset controller
Expand All @@ -462,6 +434,32 @@ esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const
return res;
}

if (config->int_gpio_num != GPIO_NUM_NC)
{
esp_rom_gpio_pad_select_gpio(config->int_gpio_num);
const gpio_config_t cfg = {
.pin_bit_mask = BIT64(config->int_gpio_num),
.mode = GPIO_MODE_INPUT,
.intr_type = config->levels.interrupt ? GPIO_INTR_POSEDGE : GPIO_INTR_NEGEDGE};
if ((res = gpio_config(&cfg)) != ESP_OK)
{
free(th);
log_e("Configuring GPIO for INT failed");
return res;
}

if (config->interrupt_callback != NULL)
{
if ((res = esp_lcd_touch_register_interrupt_callback(th, config->interrupt_callback)) != ESP_OK)
{
gpio_reset_pin(th->config.int_gpio_num);
free(th);
log_e("Registering interrupt callback failed");
return res;
}
}
}

log_d("handle:0x%08x", th);
*handle = th;

Expand Down
5 changes: 2 additions & 3 deletions src/esp_touch_xpt2046.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ esp_err_t esp_lcd_touch_new_spi_xpt2046(const esp_lcd_panel_io_handle_t io, cons
const gpio_config_t cfg = {
.pin_bit_mask = BIT64(config->int_gpio_num),
.mode = GPIO_MODE_INPUT,
// If the user has provided a callback routine for the interrupt enable the interrupt mode on the negative edge.
.intr_type = config->interrupt_callback ? GPIO_INTR_NEGEDGE : GPIO_INTR_DISABLE};
.intr_type = config->levels.interrupt ? GPIO_INTR_POSEDGE : GPIO_INTR_NEGEDGE};
if ((res = gpio_config(&cfg)) != ESP_OK)
{
free(th);
Expand All @@ -219,7 +218,7 @@ esp_err_t esp_lcd_touch_new_spi_xpt2046(const esp_lcd_panel_io_handle_t io, cons
{
gpio_reset_pin(th->config.int_gpio_num);
free(th);
log_e("Registering INT callback failed");
log_e("Registering interrupt callback failed");
return res;
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/lvgl_panel_gc9a01_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bool gc9a01_color_trans_done(esp_lcd_panel_io_handle_t panel_io_handle, esp_lcd_

void gc9a01_lv_flush(lv_display_t *display, const lv_area_t *area, uint8_t *px_map)
{
// Hardware rotation is supported
log_v("display:0x%08x, area:%0x%08x, color_map:0x%08x", display, area, px_map);

esp_lcd_panel_handle_t panel_handle = display->user_data;
Expand All @@ -40,10 +41,6 @@ lv_display_t *lvgl_lcd_init()
void *drawBuffer = heap_caps_malloc(drawBufferSize, LVGL_BUFFER_MALLOC_FLAGS);
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);

// Hardware rotation is supported
display->sw_rotate = 0;
display->rotation = LV_DISPLAY_ROTATION_0;

// Create SPI bus
const spi_bus_config_t spi_bus_config = {
.mosi_io_num = GC9A01_SPI_BUS_MOSI_IO_NUM,
Expand Down
5 changes: 1 addition & 4 deletions src/lvgl_panel_ili9341_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bool ili9341_color_trans_done(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_

void ili9341_lv_flush(lv_display_t *display, const lv_area_t *area, uint8_t *px_map)
{
// Hardware rotation is supported
esp_lcd_panel_handle_t panel_handle = display->user_data;
uint32_t pixels = lv_area_get_size(area);
uint16_t *p = (uint16_t *)px_map;
Expand All @@ -36,10 +37,6 @@ lv_display_t *lvgl_lcd_init()
void *drawBuffer = heap_caps_malloc(drawBufferSize, LVGL_BUFFER_MALLOC_FLAGS);
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);

// Hardware rotation is supported
display->sw_rotate = 0;
display->rotation = LV_DISPLAY_ROTATION_0;

// Create SPI bus
const spi_bus_config_t spi_bus_config = {
.mosi_io_num = ILI9341_SPI_BUS_MOSI_IO_NUM,
Expand Down
5 changes: 1 addition & 4 deletions src/lvgl_panel_st7262_par.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bool direct_io_frame_trans_done(esp_lcd_panel_handle_t panel, esp_lcd_rgb_panel_

void direct_io_lv_flush(lv_display_t *display, const lv_area_t *area, uint8_t *px_map)
{
// Hardware rotation is not supported
const esp_lcd_panel_handle_t panel_handle = display->user_data;

lv_display_rotation_t rotation = lv_display_get_rotation(display);
Expand Down Expand Up @@ -68,10 +69,6 @@ lv_display_t *lvgl_lcd_init()
void *drawBuffer = heap_caps_malloc(drawBufferSize, LVGL_BUFFER_MALLOC_FLAGS);
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);

// Hardware rotation is not supported
display->sw_rotate = 1;
display->rotation = LV_DISPLAY_ROTATION_0;

// Create direct_io panel handle
const esp_lcd_rgb_panel_config_t rgb_panel_config = {
.clk_src = ST7262_PANEL_CONFIG_CLK_SRC,
Expand Down
Loading

0 comments on commit 8ba252e

Please sign in to comment.