starting with launch screen
This commit is contained in:
17
include/gfx/lgfx.h
Normal file
17
include/gfx/lgfx.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define LGFX_USE_V1
|
||||||
|
|
||||||
|
#include <LovyanGFX.hpp>
|
||||||
|
|
||||||
|
class LGFX : public lgfx::LGFX_Device
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
lgfx::Panel_ST7796 _panel_instance;
|
||||||
|
lgfx::Bus_Parallel8 _bus_instance;
|
||||||
|
lgfx::Light_PWM _light_instance;
|
||||||
|
lgfx::Touch_FT5x06 _touch_instance;
|
||||||
|
|
||||||
|
public:
|
||||||
|
LGFX();
|
||||||
|
};
|
4
include/gfx/lv_setup.h
Normal file
4
include/gfx/lv_setup.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void lv_begin();
|
||||||
|
void lv_handler();
|
3
include/ui/launch_screen.h
Normal file
3
include/ui/launch_screen.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void ui_LaunchScreen_open();
|
@@ -36,4 +36,4 @@ lib_ldf_mode = deep
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
me-no-dev/AsyncTCP @ ^1.1.1
|
me-no-dev/AsyncTCP @ ^1.1.1
|
||||||
lovyan03/LovyanGFX @ ^1.1.8
|
lovyan03/LovyanGFX @ ^1.1.8
|
||||||
lvgl/lvgl @ ^8.3.7
|
lvgl/lvgl @ ^8.3.9
|
||||||
|
83
src/gfx/lgfx.cpp
Normal file
83
src/gfx/lgfx.cpp
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#include "gfx/lgfx.h"
|
||||||
|
|
||||||
|
LGFX::LGFX()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
auto cfg = _bus_instance.config();
|
||||||
|
|
||||||
|
// cfg.i2s_port = I2S_NUM_0;
|
||||||
|
cfg.freq_write = 20000000;
|
||||||
|
cfg.pin_wr = 47;
|
||||||
|
cfg.pin_rd = -1;
|
||||||
|
cfg.pin_rs = 0;
|
||||||
|
cfg.pin_d0 = 9;
|
||||||
|
cfg.pin_d1 = 46;
|
||||||
|
cfg.pin_d2 = 3;
|
||||||
|
cfg.pin_d3 = 8;
|
||||||
|
cfg.pin_d4 = 18;
|
||||||
|
cfg.pin_d5 = 17;
|
||||||
|
cfg.pin_d6 = 16;
|
||||||
|
cfg.pin_d7 = 15;
|
||||||
|
|
||||||
|
_bus_instance.config(cfg);
|
||||||
|
_panel_instance.setBus(&_bus_instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto cfg = _panel_instance.config();
|
||||||
|
|
||||||
|
cfg.pin_cs = -1;
|
||||||
|
cfg.pin_rst = 4;
|
||||||
|
cfg.pin_busy = -1;
|
||||||
|
cfg.panel_width = SCREEN_HEIGHT;
|
||||||
|
cfg.panel_height = SCREEN_WIDTH;
|
||||||
|
cfg.offset_x = 0;
|
||||||
|
cfg.offset_y = 0;
|
||||||
|
cfg.offset_rotation = 0;
|
||||||
|
cfg.dummy_read_pixel = 8;
|
||||||
|
cfg.dummy_read_bits = 1;
|
||||||
|
cfg.readable = true;
|
||||||
|
cfg.invert = true;
|
||||||
|
cfg.rgb_order = false;
|
||||||
|
cfg.dlen_16bit = false;
|
||||||
|
cfg.bus_shared = true;
|
||||||
|
cfg.memory_width = SCREEN_HEIGHT;
|
||||||
|
cfg.memory_height = SCREEN_WIDTH;
|
||||||
|
|
||||||
|
_panel_instance.config(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto cfg = _light_instance.config();
|
||||||
|
|
||||||
|
cfg.pin_bl = 45;
|
||||||
|
cfg.invert = false;
|
||||||
|
cfg.freq = 44100;
|
||||||
|
cfg.pwm_channel = 7;
|
||||||
|
|
||||||
|
_light_instance.config(cfg);
|
||||||
|
_panel_instance.setLight(&_light_instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto cfg = _touch_instance.config();
|
||||||
|
|
||||||
|
cfg.x_min = 0;
|
||||||
|
cfg.x_max = 319;
|
||||||
|
cfg.y_min = 0;
|
||||||
|
cfg.y_max = 479;
|
||||||
|
cfg.pin_int = 7;
|
||||||
|
cfg.bus_shared = true;
|
||||||
|
cfg.offset_rotation = 0;
|
||||||
|
cfg.i2c_port = 1;
|
||||||
|
cfg.i2c_addr = 0x38;
|
||||||
|
cfg.pin_sda = 6;
|
||||||
|
cfg.pin_scl = 5;
|
||||||
|
cfg.freq = 400000;
|
||||||
|
|
||||||
|
_touch_instance.config(cfg);
|
||||||
|
_panel_instance.setTouch(&_touch_instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
setPanel(&_panel_instance);
|
||||||
|
}
|
84
src/gfx/lv_setup.cpp
Normal file
84
src/gfx/lv_setup.cpp
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#include "gfx/lv_setup.h"
|
||||||
|
|
||||||
|
#include <lvgl.h>
|
||||||
|
#include <gfx/lgfx.h>
|
||||||
|
|
||||||
|
#define LV_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT)
|
||||||
|
|
||||||
|
LGFX tft;
|
||||||
|
|
||||||
|
void lv_handler()
|
||||||
|
{
|
||||||
|
static uint32_t previousUpdate = 0;
|
||||||
|
static uint32_t interval = 0;
|
||||||
|
|
||||||
|
if (millis() - previousUpdate > interval)
|
||||||
|
{
|
||||||
|
previousUpdate = millis();
|
||||||
|
interval = lv_timer_handler(); // Update the UI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void flush_cb(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
|
||||||
|
{
|
||||||
|
uint32_t w = (area->x2 - area->x1 + 1);
|
||||||
|
uint32_t h = (area->y2 - area->y1 + 1);
|
||||||
|
|
||||||
|
tft.startWrite();
|
||||||
|
tft.setAddrWindow(area->x1, area->y1, w, h);
|
||||||
|
tft.writePixels((lgfx::rgb565_t *)&color_p->full, w * h);
|
||||||
|
tft.endWrite();
|
||||||
|
|
||||||
|
lv_disp_flush_ready(disp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void read_cb(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
|
||||||
|
{
|
||||||
|
uint16_t touchX, touchY;
|
||||||
|
bool touched = tft.getTouch(&touchX, &touchY);
|
||||||
|
if (touched)
|
||||||
|
{
|
||||||
|
data->point.x = touchX;
|
||||||
|
data->point.y = touchY;
|
||||||
|
data->state = LV_INDEV_STATE_PR;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data->state = LV_INDEV_STATE_REL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_cb(const char *buf)
|
||||||
|
{
|
||||||
|
log_d("%s", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lv_begin()
|
||||||
|
{
|
||||||
|
tft.init();
|
||||||
|
tft.setRotation(1);
|
||||||
|
|
||||||
|
lv_log_register_print_cb(print_cb);
|
||||||
|
|
||||||
|
lv_init();
|
||||||
|
|
||||||
|
static lv_disp_draw_buf_t draw_buf;
|
||||||
|
static lv_color_t *buf1, *buf2;
|
||||||
|
buf1 = (lv_color_t *)heap_caps_malloc(LV_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
|
||||||
|
buf2 = (lv_color_t *)heap_caps_malloc(LV_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
|
||||||
|
lv_disp_draw_buf_init(&draw_buf, buf1, buf2, LV_BUF_SIZE);
|
||||||
|
|
||||||
|
static lv_disp_drv_t disp_drv;
|
||||||
|
lv_disp_drv_init(&disp_drv);
|
||||||
|
disp_drv.hor_res = SCREEN_WIDTH;
|
||||||
|
disp_drv.ver_res = SCREEN_HEIGHT;
|
||||||
|
disp_drv.flush_cb = flush_cb;
|
||||||
|
disp_drv.draw_buf = &draw_buf;
|
||||||
|
lv_disp_drv_register(&disp_drv);
|
||||||
|
|
||||||
|
static lv_indev_drv_t indev_drv;
|
||||||
|
lv_indev_drv_init(&indev_drv);
|
||||||
|
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||||
|
indev_drv.read_cb = read_cb;
|
||||||
|
lv_indev_drv_register(&indev_drv);
|
||||||
|
}
|
16
src/main.cpp
16
src/main.cpp
@@ -18,22 +18,16 @@
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
// put function declarations here:
|
#include "gfx/lv_setup.h"
|
||||||
int myFunction(int, int);
|
#include "ui/launch_screen.h"
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// put your setup code here, to run once:
|
lv_begin();
|
||||||
int result = myFunction(2, 3);
|
ui_LaunchScreen_open();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// put your main code here, to run repeatedly:
|
lv_handler();
|
||||||
}
|
|
||||||
|
|
||||||
// put function definitions here:
|
|
||||||
int myFunction(int x, int y)
|
|
||||||
{
|
|
||||||
return x + y;
|
|
||||||
}
|
}
|
||||||
|
22
src/ui/launch_screen.cpp
Normal file
22
src/ui/launch_screen.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "ui/launch_screen.h"
|
||||||
|
|
||||||
|
#include <lvgl.h>
|
||||||
|
|
||||||
|
lv_obj_t *ui_SplashScreen;
|
||||||
|
|
||||||
|
void ui_LaunchScreen_open()
|
||||||
|
{
|
||||||
|
// Create a screen
|
||||||
|
ui_SplashScreen = lv_obj_create(NULL);
|
||||||
|
lv_obj_clear_flag(ui_SplashScreen, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
lv_obj_set_style_bg_color(ui_SplashScreen, lv_color_make(0x78, 0x94, 0xa7), 0);
|
||||||
|
|
||||||
|
// Create a label
|
||||||
|
lv_obj_t *label = lv_label_create(ui_SplashScreen);
|
||||||
|
lv_label_set_text(label, "Hello world!");
|
||||||
|
|
||||||
|
// Align the label to the center
|
||||||
|
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0);
|
||||||
|
|
||||||
|
lv_disp_load_scr(ui_SplashScreen);
|
||||||
|
}
|
Reference in New Issue
Block a user