mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
feat(example): make "LVGL_Arduino.ino" easier to use (#6001)
This commit is contained in:
parent
3e21769fa6
commit
b74d34407f
@ -1,5 +1,5 @@
|
||||
/*Using LVGL with Arduino requires some extra steps:
|
||||
*Be sure to read the docs here: https://docs.lvgl.io/master/get-started/platforms/arduino.html */
|
||||
*Be sure to read the docs here: https://docs.lvgl.io/master/integration/framework/arduino.html */
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
@ -15,9 +15,10 @@
|
||||
//#include <examples/lv_examples.h>
|
||||
//#include <demos/lv_demos.h>
|
||||
|
||||
/*Set to your screen resolution*/
|
||||
/*Set to your screen resolution and rotation*/
|
||||
#define TFT_HOR_RES 320
|
||||
#define TFT_VER_RES 240
|
||||
#define TFT_ROTATION LV_DISPLAY_ROTATION_0
|
||||
|
||||
/*LVGL draw into this buffer, 1/10 screen size usually works well. The size is in bytes*/
|
||||
#define DRAW_BUF_SIZE (TFT_HOR_RES * TFT_VER_RES / 10 * (LV_COLOR_DEPTH / 8))
|
||||
@ -95,6 +96,8 @@ void setup()
|
||||
#if LV_USE_TFT_ESPI
|
||||
/*TFT_eSPI can be enabled lv_conf.h to initialize the display in a simple way*/
|
||||
disp = lv_tft_espi_create(TFT_HOR_RES, TFT_VER_RES, draw_buf, sizeof(draw_buf));
|
||||
lv_display_set_rotation(disp, TFT_ROTATION);
|
||||
|
||||
#else
|
||||
/*Else create a display yourself*/
|
||||
disp = lv_display_create(TFT_HOR_RES, TFT_VER_RES);
|
||||
|
@ -26,6 +26,7 @@ typedef struct {
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * px_map);
|
||||
static void resolution_changed_event_cb(lv_event_t * e);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -53,9 +54,10 @@ lv_display_t * lv_tft_espi_create(uint32_t hor_res, uint32_t ver_res, void * buf
|
||||
|
||||
dsc->tft = new TFT_eSPI(hor_res, ver_res);
|
||||
dsc->tft->begin(); /* TFT init */
|
||||
dsc->tft->setRotation(3); /* Landscape orientation, flipped */
|
||||
dsc->tft->setRotation(0);
|
||||
lv_display_set_driver_data(disp, (void *)dsc);
|
||||
lv_display_set_flush_cb(disp, flush_cb);
|
||||
lv_display_add_event_cb(disp, resolution_changed_event_cb, LV_EVENT_RESOLUTION_CHANGED, NULL);
|
||||
lv_display_set_buffers(disp, (void *)buf, NULL, buf_size_bytes, LV_DISPLAY_RENDER_MODE_PARTIAL);
|
||||
return disp;
|
||||
}
|
||||
@ -80,4 +82,29 @@ static void flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * px_m
|
||||
|
||||
}
|
||||
|
||||
static void resolution_changed_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_display_t * disp = (lv_display_t *)lv_event_get_target(e);
|
||||
lv_tft_espi_t * dsc = (lv_tft_espi_t *)lv_display_get_driver_data(disp);
|
||||
int32_t hor_res = lv_display_get_horizontal_resolution(disp);
|
||||
int32_t ver_res = lv_display_get_vertical_resolution(disp);
|
||||
lv_display_rotation_t rot = lv_display_get_rotation(disp);
|
||||
|
||||
/* handle rotation */
|
||||
switch(rot) {
|
||||
case LV_DISPLAY_ROTATION_0:
|
||||
dsc->tft->setRotation(0); /* Portrait orientation */
|
||||
break;
|
||||
case LV_DISPLAY_ROTATION_90:
|
||||
dsc->tft->setRotation(1); /* Landscape orientation */
|
||||
break;
|
||||
case LV_DISPLAY_ROTATION_180:
|
||||
dsc->tft->setRotation(2); /* Portrait orientation, flipped */
|
||||
break;
|
||||
case LV_DISPLAY_ROTATION_270:
|
||||
dsc->tft->setRotation(3); /* Landscape orientation, flipped */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /*LV_USE_TFT_ESPI*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user