Screen changed to landscape, #define to configure screen to landscape or portrait.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
dependencies:
|
||||
idf: ">=5.2"
|
||||
espressif/esp_lvgl_port: "^2"
|
||||
espressif/esp_lcd_ili9341: "^2"
|
||||
atanisoft/esp_lcd_touch_xpt2046: "^1"
|
||||
|
||||
85
main/main.c
85
main/main.c
@@ -6,7 +6,6 @@
|
||||
* dependencies:
|
||||
* idf: ">=5.2"
|
||||
* espressif/esp_lvgl_port: "^2"
|
||||
* espressif/esp_lcd_ili9341: "^1"
|
||||
* atanisoft/esp_lcd_touch_xpt2046: "^1"
|
||||
*
|
||||
* main/CMakeLists.txt:
|
||||
@@ -29,7 +28,7 @@
|
||||
|
||||
static const char *TAG = "cyd";
|
||||
|
||||
/* ---- Display: ILI9341 on SPI2 (HSPI) ---- */
|
||||
/* ---- Display: ST7789 on SPI2 (HSPI) ---- */
|
||||
#define LCD_HOST SPI2_HOST
|
||||
#define PIN_LCD_SCLK 14
|
||||
#define PIN_LCD_MOSI 13
|
||||
@@ -45,20 +44,53 @@ static const char *TAG = "cyd";
|
||||
#define PIN_TP_MOSI 32
|
||||
#define PIN_TP_MISO 39 /* input-only pin, fine for MISO */
|
||||
#define PIN_TP_CS 33
|
||||
#define PIN_TP_IRQ 36 /* input-only pin */
|
||||
#define PIN_TP_IRQ 36 /* input-only pin, unused: we poll */
|
||||
|
||||
/* Native panel geometry. The ST7789 GRAM is always 240x320; landscape comes
|
||||
* from MADCTL, not from changing these. */
|
||||
#define PANEL_H_RES 240
|
||||
#define PANEL_V_RES 320
|
||||
|
||||
/* 1 = landscape (320x240), 0 = portrait (240x320). This switch has to drive
|
||||
* the LVGL canvas size, the panel MADCTL and the touch axis mapping together,
|
||||
* or touch coordinates land in a different space than the pixels. */
|
||||
#define LCD_LANDSCAPE 1
|
||||
|
||||
#if LCD_LANDSCAPE
|
||||
#define LCD_H_RES PANEL_V_RES /* 320 */
|
||||
#define LCD_V_RES PANEL_H_RES /* 240 */
|
||||
#else
|
||||
#define LCD_H_RES PANEL_H_RES /* 240 */
|
||||
#define LCD_V_RES PANEL_V_RES /* 320 */
|
||||
#endif
|
||||
|
||||
/* Panel MADCTL transform. */
|
||||
#define DISP_SWAP_XY (LCD_LANDSCAPE ? true : false)
|
||||
#define DISP_MIRROR_X (LCD_LANDSCAPE ? true : false)
|
||||
#define DISP_MIRROR_Y false
|
||||
|
||||
/* Touch transform, tuned by eye -- the resistive film is glued on independently
|
||||
* of the controller's MADCTL. Mind the order: esp_lcd_touch mirrors in
|
||||
* panel-native space and swaps last, so with TP_SWAP_XY set the flags come out
|
||||
* crossed: TP_MIRROR_Y flips the reported x, TP_MIRROR_X flips reported y.
|
||||
*
|
||||
* Verified on this board: corner taps TL/TR/BR/BL read (28,25) (285,22)
|
||||
* (284,213) (22,210). The film stops responding ~25 px in from every edge, so
|
||||
* the extreme corners are unreachable -- avoid edge-hugging widgets. */
|
||||
#define TP_SWAP_XY 1
|
||||
#define TP_MIRROR_X 0
|
||||
#define TP_MIRROR_Y 0
|
||||
|
||||
#define LCD_H_RES 240
|
||||
#define LCD_V_RES 320
|
||||
#define LCD_CMD_BITS 8
|
||||
#define LCD_PARAM_BITS 8
|
||||
#define LCD_PIXEL_CLOCK_HZ (40 * 1000 * 1000)
|
||||
|
||||
/* XPT2046 is slow — datasheet max is ~2.5 MHz. Going faster gives
|
||||
/* XPT2046 is slow -- datasheet max is ~2.5 MHz. Going faster gives
|
||||
* garbage coordinates that look like random taps. */
|
||||
#define TOUCH_CLOCK_HZ (2 * 1000 * 1000)
|
||||
|
||||
/* Partial draw buffer. No PSRAM on this board, so keep it modest:
|
||||
* 240 * 40 * 2 bytes = 19.2 KB per buffer, doubled = 38.4 KB. */
|
||||
* 320 * 40 * 2 bytes = 25.6 KB per buffer, doubled = 51.2 KB. */
|
||||
#define LVGL_BUF_LINES 40
|
||||
|
||||
static esp_lcd_panel_handle_t s_panel = NULL;
|
||||
@@ -66,6 +98,7 @@ static esp_lcd_panel_io_handle_t s_panel_io = NULL;
|
||||
static esp_lcd_touch_handle_t s_touch = NULL;
|
||||
static lv_display_t *s_disp = NULL;
|
||||
static lv_indev_t *s_indev = NULL;
|
||||
static lv_obj_t *s_temp_label = NULL;
|
||||
|
||||
static void backlight_init(void)
|
||||
{
|
||||
@@ -134,15 +167,18 @@ static void touch_init(void)
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(
|
||||
(esp_lcd_spi_bus_handle_t)TOUCH_HOST, &tp_io_cfg, &tp_io));
|
||||
|
||||
/* x_max/y_max are the *pre-swap* extents: the driver scales the raw ADC
|
||||
* against them and mirrors against them, and only then does esp_lcd_touch
|
||||
* swap the axes. So they stay panel-native regardless of LCD_LANDSCAPE. */
|
||||
const esp_lcd_touch_config_t tp_cfg = {
|
||||
.x_max = LCD_H_RES,
|
||||
.y_max = LCD_V_RES,
|
||||
.x_max = PANEL_H_RES,
|
||||
.y_max = PANEL_V_RES,
|
||||
.rst_gpio_num = GPIO_NUM_NC,
|
||||
.int_gpio_num = GPIO_NUM_NC,
|
||||
.flags = {
|
||||
.swap_xy = 0,
|
||||
.mirror_x = 1,
|
||||
.mirror_y = 0,
|
||||
.swap_xy = TP_SWAP_XY,
|
||||
.mirror_x = TP_MIRROR_X,
|
||||
.mirror_y = TP_MIRROR_Y,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_touch_new_spi_xpt2046(tp_io, &tp_cfg, &s_touch));
|
||||
@@ -162,9 +198,9 @@ static void lvgl_init(void)
|
||||
.vres = LCD_V_RES,
|
||||
.monochrome = false,
|
||||
.rotation = {
|
||||
.swap_xy = false,
|
||||
.mirror_x = false,
|
||||
.mirror_y = false,
|
||||
.swap_xy = DISP_SWAP_XY,
|
||||
.mirror_x = DISP_MIRROR_X,
|
||||
.mirror_y = DISP_MIRROR_Y,
|
||||
},
|
||||
.flags = {
|
||||
.buff_dma = true,
|
||||
@@ -179,6 +215,12 @@ static void lvgl_init(void)
|
||||
s_indev = lvgl_port_add_touch(&touch_cfg);
|
||||
}
|
||||
|
||||
static void arc_changed_cb(lv_event_t *e)
|
||||
{
|
||||
lv_obj_t *arc = lv_event_get_target(e);
|
||||
lv_label_set_text_fmt(s_temp_label, "%d \xC2\xB0""C", (int)lv_arc_get_value(arc));
|
||||
}
|
||||
|
||||
static void build_ui(void)
|
||||
{
|
||||
/* Any LVGL call from outside the port task must be locked. */
|
||||
@@ -190,18 +232,19 @@ static void build_ui(void)
|
||||
lv_obj_t *scr = lv_screen_active();
|
||||
|
||||
lv_obj_t *label = lv_label_create(scr);
|
||||
lv_label_set_text(label, "Reflow Plate");
|
||||
lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 20);
|
||||
lv_label_set_text(label, "Reflow Plate V0.1");
|
||||
lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 8);
|
||||
|
||||
lv_obj_t *arc = lv_arc_create(scr);
|
||||
lv_obj_set_size(arc, 180, 180);
|
||||
lv_obj_set_size(arc, 160, 160);
|
||||
lv_arc_set_range(arc, 0, 260);
|
||||
lv_arc_set_value(arc, 25);
|
||||
lv_obj_center(arc);
|
||||
lv_obj_add_event_cb(arc, arc_changed_cb, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
lv_obj_t *temp = lv_label_create(scr);
|
||||
lv_label_set_text(temp, "25 \xC2\xB0""C");
|
||||
lv_obj_center(temp);
|
||||
s_temp_label = lv_label_create(scr);
|
||||
lv_label_set_text(s_temp_label, "25 \xC2\xB0""C");
|
||||
lv_obj_center(s_temp_label);
|
||||
|
||||
lvgl_port_unlock();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user