Last active
October 10, 2021 10:36
-
-
Save hollyhockberry/34013d55c28020e555630f20495e0f71 to your computer and use it in GitHub Desktop.
M5Core2: LVGL Sample (with LGFX)
This file contains 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 <M5Core2.h> | |
#include <LovyanGFX.hpp> | |
constexpr uint16_t screenWidth = 320; | |
constexpr uint16_t screenHeight = 240; | |
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(); | |
::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! 9th 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