acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

LvglBenchmark.ino (6602B)

      1 /*******************************************************************************
      2  * LVGL Benchmark
      3  * This is a benchmark demo for LVGL - Light and Versatile Graphics Library
      4  * import from: https://github.com/lvgl/lv_demos.git
      5  *
      6  * Dependent libraries:
      7  * LVGL: https://github.com/lvgl/lvgl.git
      8  *
      9  * LVGL Configuration file:
     10  * Copy your_arduino_path/libraries/lvgl/lv_conf_template.h
     11  * to your_arduino_path/libraries/lv_conf.h
     12  * 
     13  * In lv_conf.h around line 15, enable config file:
     14  * #if 1 // Set it to "1" to enable content
     15  * 
     16  * Then find and set:
     17  * #define LV_COLOR_DEPTH     16
     18  * #define LV_TICK_CUSTOM     1
     19  *
     20  * For SPI/parallel 8 display set color swap can be faster, parallel 16/RGB screen don't swap!
     21  * #define LV_COLOR_16_SWAP   1 // for SPI and parallel 8
     22  * #define LV_COLOR_16_SWAP   0 // for parallel 16 and RGB
     23  *
     24  * Enable LVGL Demo Benchmark
     25  * #define LV_USE_DEMO_BENCHMARK 1
     26  *
     27  * Enables support for compressed fonts.
     28  * #define LV_USE_FONT_COMPRESSED 1
     29  ******************************************************************************/
     30 #include "lv_demo_benchmark.h"
     31 
     32 /*******************************************************************************
     33  * Start of Arduino_GFX setting
     34  *
     35  * Arduino_GFX try to find the settings depends on selected board in Arduino IDE
     36  * Or you can define the display dev kit not in the board list
     37  * Defalult pin list for non display dev kit:
     38  * Arduino Nano, Micro and more: CS:  9, DC:  8, RST:  7, BL:  6, SCK: 13, MOSI: 11, MISO: 12
     39  * ESP32 various dev board     : CS:  5, DC: 27, RST: 33, BL: 22, SCK: 18, MOSI: 23, MISO: nil
     40  * ESP32-C3 various dev board  : CS:  7, DC:  2, RST:  1, BL:  3, SCK:  4, MOSI:  6, MISO: nil
     41  * ESP32-S2 various dev board  : CS: 34, DC: 38, RST: 33, BL: 21, SCK: 36, MOSI: 35, MISO: nil
     42  * ESP32-S3 various dev board  : CS: 40, DC: 41, RST: 42, BL: 48, SCK: 36, MOSI: 35, MISO: nil
     43  * ESP8266 various dev board   : CS: 15, DC:  4, RST:  2, BL:  5, SCK: 14, MOSI: 13, MISO: 12
     44  * Raspberry Pi Pico dev board : CS: 17, DC: 27, RST: 26, BL: 28, SCK: 18, MOSI: 19, MISO: 16
     45  * RTL8720 BW16 old patch core : CS: 18, DC: 17, RST:  2, BL: 23, SCK: 19, MOSI: 21, MISO: 20
     46  * RTL8720_BW16 Official core  : CS:  9, DC:  8, RST:  6, BL:  3, SCK: 10, MOSI: 12, MISO: 11
     47  * RTL8722 dev board           : CS: 18, DC: 17, RST: 22, BL: 23, SCK: 13, MOSI: 11, MISO: 12
     48  * RTL8722_mini dev board      : CS: 12, DC: 14, RST: 15, BL: 13, SCK: 11, MOSI:  9, MISO: 10
     49  * Seeeduino XIAO dev board    : CS:  3, DC:  2, RST:  1, BL:  0, SCK:  8, MOSI: 10, MISO:  9
     50  * Teensy 4.1 dev board        : CS: 39, DC: 41, RST: 40, BL: 22, SCK: 13, MOSI: 11, MISO: 12
     51  ******************************************************************************/
     52 #include <Arduino_GFX_Library.h>
     53 
     54 #define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
     55 
     56 /* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */
     57 #if defined(DISPLAY_DEV_KIT)
     58 Arduino_GFX *gfx = create_default_Arduino_GFX();
     59 #else /* !defined(DISPLAY_DEV_KIT) */
     60 
     61 /* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
     62 Arduino_DataBus *bus = create_default_Arduino_DataBus();
     63 
     64 /* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
     65 Arduino_GFX *gfx = new Arduino_ILI9341(bus, DF_GFX_RST, 0 /* rotation */, false /* IPS */);
     66 
     67 #endif /* !defined(DISPLAY_DEV_KIT) */
     68 /*******************************************************************************
     69  * End of Arduino_GFX setting
     70  ******************************************************************************/
     71 
     72 /*******************************************************************************
     73  * Please config the touch panel in touch.h
     74  ******************************************************************************/
     75 #include "touch.h"
     76 
     77 /* Change to your screen resolution */
     78 static uint32_t screenWidth;
     79 static uint32_t screenHeight;
     80 static lv_disp_draw_buf_t draw_buf;
     81 static lv_color_t *disp_draw_buf;
     82 static lv_disp_drv_t disp_drv;
     83 static unsigned long last_ms;
     84 
     85 /* Display flushing */
     86 void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
     87 {
     88   uint32_t w = (area->x2 - area->x1 + 1);
     89   uint32_t h = (area->y2 - area->y1 + 1);
     90 
     91 #if (LV_COLOR_16_SWAP != 0)
     92   gfx->draw16bitBeRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
     93 #else
     94   gfx->draw16bitRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
     95 #endif
     96 
     97   lv_disp_flush_ready(disp);
     98 }
     99 
    100 void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
    101 {
    102   if (touch_has_signal())
    103   {
    104     if (touch_touched())
    105     {
    106       data->state = LV_INDEV_STATE_PR;
    107 
    108       /*Set the coordinates*/
    109       data->point.x = touch_last_x;
    110       data->point.y = touch_last_y;
    111     }
    112     else if (touch_released())
    113     {
    114       data->state = LV_INDEV_STATE_REL;
    115     }
    116   }
    117   else
    118   {
    119     data->state = LV_INDEV_STATE_REL;
    120   }
    121 }
    122 
    123 void setup()
    124 {
    125   Serial.begin(115200);
    126   // Serial.setDebugOutput(true);
    127   // while(!Serial);
    128   Serial.println("LVGL Benchmark Demo");
    129 
    130 #ifdef GFX_EXTRA_PRE_INIT
    131   GFX_EXTRA_PRE_INIT();
    132 #endif
    133 
    134   // Init Display
    135   gfx->begin();
    136   gfx->fillScreen(BLACK);
    137 
    138 #ifdef GFX_BL
    139   pinMode(GFX_BL, OUTPUT);
    140   digitalWrite(GFX_BL, HIGH);
    141 #endif
    142 
    143   // Init touch device
    144   touch_init(gfx->width(), gfx->height(), gfx->getRotation());
    145 
    146   lv_init();
    147 
    148   screenWidth = gfx->width();
    149   screenHeight = gfx->height();
    150 #ifdef ESP32
    151   disp_draw_buf = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * screenWidth * 32, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
    152 #else
    153   disp_draw_buf = (lv_color_t *)malloc(sizeof(lv_color_t) * screenWidth * 32);
    154 #endif
    155   if (!disp_draw_buf)
    156   {
    157     Serial.println("LVGL disp_draw_buf allocate failed!");
    158   }
    159   else
    160   {
    161     lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, NULL, screenWidth * 32);
    162 
    163     /* Initialize the display */
    164     lv_disp_drv_init(&disp_drv);
    165     /* Change the following line to your display resolution */
    166     disp_drv.hor_res = screenWidth;
    167     disp_drv.ver_res = screenHeight;
    168     disp_drv.flush_cb = my_disp_flush;
    169     disp_drv.draw_buf = &draw_buf;
    170     lv_disp_drv_register(&disp_drv);
    171 
    172     /* Initialize the (dummy) input device driver */
    173     static lv_indev_drv_t indev_drv;
    174     lv_indev_drv_init(&indev_drv);
    175     indev_drv.type = LV_INDEV_TYPE_POINTER;
    176     indev_drv.read_cb = my_touchpad_read;
    177     lv_indev_drv_register(&indev_drv);
    178 
    179     lv_demo_benchmark();
    180 
    181     Serial.println("Setup done");
    182   }
    183   last_ms = millis();
    184 }
    185 
    186 void loop()
    187 {
    188   lv_timer_handler(); /* let the GUI do its work */
    189   delay(5);
    190 }