Description
Takes 45 seconds to fill in screen on startup and button event takes 5 seconds
What MCU/Processor/Board and compiler are you using?
Arduino Giga, Addafruit RA8875, Adafruit 7" touchscreen
What do you want to achieve?
Trying to get basic functionality working on hardware
What have you tried so far?
The screen takes 45 seconds to fill in when the program starts it fills in from top to bottom, Button click takes 5 seconds to trigger event. Is this as fast as this setup is going to go? I’m using the adafruit RA8875 library maybe that is limiting the speed? Or do I have to tweak lv_config? Everting seems to work but very slow.
Code to reproduce
Add the relevant code snippets here.
The code block(s) should be between ```c
and ```
tags:
#include <Adafruit_RA8875.h>
#include <lvgl.h>
//#include "lv_conf.h"
#define RA8875_INT 3
#define RA8875_CS 10
#define RA8875_RESET 9
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 480
uint16_t tx, ty;
Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);
// Framebuffer: 40 lines for partial rendering
#define BUFFER_LINES 10
//static lv_color_t draw_buf1[SCREEN_WIDTH * BUFFER_LINES];
static lv_color_t draw_buf1[SCREEN_WIDTH * BUFFER_LINES];
static lv_draw_buf_t draw_buf;
static lv_display_t* disp;
lv_obj_t* TextBox;
int number = 0;
unsigned long previousMillis = 0;
const long interval = 100;
void log_print(lv_log_level_t level, const char * buf) {
LV_UNUSED(level);
Serial.println(buf);
Serial.flush();
}
// -------- LVGL DRAWING --------
void my_flush_cb(lv_display_t* disp_drv, const lv_area_t* area, uint8_t* px_map) {
lv_coord_t w = area->x2 - area->x1 + 1;
lv_coord_t h = area->y2 - area->y1 + 1;
tft.drawRGBBitmap(area->x1, area->y1, (uint16_t*)px_map, w, h);
lv_display_flush_ready(disp_drv);
}
// -------- LVGL TICK FUNCTION --------
static uint32_t my_tick_get_cb(void) {
return millis();
}
// -------- LVGL TOUCH DRIVER --------
static void my_touch_read_cb(lv_indev_t* indev, lv_indev_data_t* data) {
if (tft.touched()) {
//LV_LOG_USER("Touched");
float xScale = 1024.0F/tft.width();
float yScale = 1024.0F/tft.height();
uint16_t x, y;
if (tft.touchRead(&x, &y)) {
data->point.x = x/xScale;
data->point.y = y/yScale;
data->state = LV_INDEV_STATE_PRESSED;
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}
// -------- BUTTON EVENT HANDLER --------
static void btn_event_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
//LV_LOG_USER("in event");
lv_obj_t* btn = (lv_obj_t*)lv_event_get_target(e);
if(code == LV_EVENT_CLICKED) {
Serial.println("clicked");
}
else if(code == LV_EVENT_VALUE_CHANGED) {
//LV_LOG_USER("Toggled");
}
}
void setup() {
Serial.begin(115200);
while (!Serial);
// Init display
if (!tft.begin(RA8875_800x480)) {
Serial.println("RA8875 init failed!");
while (1);
}
tft.displayOn(true);
//tft.rotation(2);
tft.GPIOX(true);
tft.PWM1config(true, RA8875_PWM_CLK_DIV1024);
tft.PWM1out(255);
tft.touchEnable(true);
// Init LVGL
lv_init();
//lv_log_register_print_cb()
lv_log_register_print_cb(log_print);
lv_tick_set_cb(my_tick_get_cb);
lv_draw_buf_init(&draw_buf,
SCREEN_WIDTH,
BUFFER_LINES,
LV_COLOR_FORMAT_RGB565,
SCREEN_WIDTH * sizeof(lv_color_t),
draw_buf1,
sizeof(draw_buf1));
disp = lv_display_create(SCREEN_WIDTH, SCREEN_HEIGHT);
lv_display_set_flush_cb(disp, my_flush_cb);
lv_display_set_draw_buffers(disp, &draw_buf, NULL);
// Register touchscreen
lv_indev_t* indev_touch = lv_indev_create();
lv_indev_set_type(indev_touch, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev_touch, my_touch_read_cb);
// UI: Button
lv_obj_t* btn = lv_button_create(lv_screen_active());
lv_obj_set_size(btn, 200, 80);
//lv_obj_align(btn, LV_ALIGN_OUT_TOP_LEFT, 420, 10);
lv_obj_center(btn);
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL);
lv_obj_t* label = lv_label_create(btn);
lv_label_set_text(label, "Button");
lv_obj_center(label);
// UI: Text Box
TextBox = lv_textarea_create(lv_screen_active());
lv_obj_set_size(TextBox, 100, 60);
lv_obj_align(TextBox, LV_ALIGN_OUT_TOP_LEFT, 100, 50);
lv_textarea_set_one_line(TextBox, true);
lv_obj_set_style_text_align(TextBox, LV_TEXT_ALIGN_CENTER, 0);
}
void loop() {
lv_task_handler(); // let the GUI do its work
//lv_tick_inc(5); // tell LVGL how much time has passed
lv_tick_inc(5);
delay(5); // let this time pass
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
number = (number + 1) % 1000;
char buffer[8];
itoa(number, buffer, 10);
lv_textarea_set_text(TextBox, buffer);
}
}