Last active
May 2, 2025 19:44
-
-
Save hollyhockberry/492282526896c84b04adc2974ca7affb to your computer and use it in GitHub Desktop.
M5Paper: LVGL Sample (with LGFX)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LGFX_AUTODETECT | |
#define LGFX_USE_V1 | |
#include <lvgl.h> | |
#include <M5EPD.h> | |
#include <LovyanGFX.hpp> | |
static const uint16_t screenWidth = 960; | |
static const uint16_t screenHeight = 540; | |
lv_disp_draw_buf_t draw_buf; | |
lv_color_t buf[screenWidth * 10]; | |
LGFX gfx; | |
void my_disp_flush(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) { | |
const u_long w = area->x2 - area->x1 + 1; | |
const u_long h = area->y2 - area->y1 + 1; | |
gfx.startWrite(); | |
gfx.setAddrWindow(area->x1, area->y1, w, h); | |
gfx.pushColors(static_cast<uint16_t *>(&color_p->full), w * h, true); | |
gfx.endWrite(); | |
::lv_disp_flush_ready(disp); | |
} | |
void setup() { | |
M5.begin(); | |
gfx.begin(); | |
gfx.setRotation(3); | |
::lv_init(); | |
::lv_disp_draw_buf_init(&draw_buf, buf, NULL, screenWidth * 10); | |
static lv_disp_drv_t disp_drv; | |
::lv_disp_drv_init(&disp_drv); | |
disp_drv.hor_res = screenWidth; | |
disp_drv.ver_res = screenHeight; | |
disp_drv.flush_cb = my_disp_flush; | |
disp_drv.draw_buf = &draw_buf; | |
::lv_disp_drv_register(&disp_drv); | |
/* Create simple label */ | |
lv_obj_t *label = ::lv_label_create(::lv_scr_act()); | |
::lv_label_set_text(label, "Aikatsu! 10th anniversary."); | |
::lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); | |
} | |
void loop() { | |
::lv_timer_handler(); | |
::delay(5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment