Hi, I have a library running (LVGL) with the ST7789_t3 driver on my Teensy 4.1, and I want to use DMA instead of blocking updates.
Currently, this is my code.
Pay attention to `my_disp_flush`, it is the part I want to use DMA in.
I have already implemented this functionality with my ESP32, and because of it, it gets higher performance than my Teensy. But I want to use my Teensy. Thank you.
Currently, this is my code.
Code:
#include <Arduino.h>
//LVGL>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <lvgl.h>
#include <ST7735_t3.h> // Hardware-specific library
#include <ST7789_t3.h> // Hardware-specific library
#include <SPI.h>
#define TFT_MISO 12
#define TFT_MOSI 11 //a12
#define TFT_SCK 13 //a13
#define TFT_DC 10
#define TFT_CS 9
#define TFT_RST 8
// For 1.54" TFT with ST7789
ST7789_t3 tft = ST7789_t3(TFT_CS, TFT_DC, TFT_RST);
/*Change to your screen resolution*/
static const uint32_t screenWidth = 320;
static const uint32_t screenHeight = 240;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[screenWidth * 10];
lv_disp_t *disp;
/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
tft.writeRect(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1), (uint16_t *)color_p);
lv_disp_flush_ready(disp);
}
// ENCODER
#define PIN_ENCODE_A 16
#define PIN_ENCODE_B 4
#define PIN_ENCODE_BTN 17
long enc_current_position = 1;
long enc_last_position = 0;
#include <RotaryEncoder.h> // https://github.com/mathertel/RotaryEncoder
RotaryEncoder encoder(PIN_ENCODE_A, PIN_ENCODE_B, RotaryEncoder::LatchMode::TWO03);
void enc_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
enc_current_position = encoder.getPosition();
data->enc_diff = enc_current_position - enc_last_position;
enc_last_position = enc_current_position;
data->state = digitalRead(PIN_ENCODE_BTN) ? LV_INDEV_STATE_REL : LV_INDEV_STATE_PR;
}
void enc_update() {
encoder.tick();
}
void setup()
{
lv_init();
tft.init(240, 320); // initialize a ST7789 chip, 240x240 pixels
tft.setRotation(1);
tft.fillScreen(ST7735_BLACK);
lv_disp_draw_buf_init(&draw_buf, buf, NULL, screenWidth * 10);
/*Initialize the display*/
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;
disp = lv_disp_drv_register(&disp_drv); /*Register the driver and save the created display objects*/
pinMode(PIN_ENCODE_BTN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(PIN_ENCODE_A), enc_update, CHANGE);
attachInterrupt(digitalPinToInterrupt(PIN_ENCODE_B), enc_update, CHANGE);
}
void loop()
{
lv_timer_handler(); /* let the GUI do its work */
}
Pay attention to `my_disp_flush`, it is the part I want to use DMA in.
I have already implemented this functionality with my ESP32, and because of it, it gets higher performance than my Teensy. But I want to use my Teensy. Thank you.