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

LvglHelloWorld.ino (5862B)

      1 /*******************************************************************************
      2  * LVGL Hello World
      3  * This is a simple example 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 #include <lvgl.h>
     25 
     26 /*******************************************************************************
     27  * Start of Arduino_GFX setting
     28  *
     29  * Arduino_GFX try to find the settings depends on selected board in Arduino IDE
     30  * Or you can define the display dev kit not in the board list
     31  * Defalult pin list for non display dev kit:
     32  * Arduino Nano, Micro and more: CS:  9, DC:  8, RST:  7, BL:  6, SCK: 13, MOSI: 11, MISO: 12
     33  * ESP32 various dev board     : CS:  5, DC: 27, RST: 33, BL: 22, SCK: 18, MOSI: 23, MISO: nil
     34  * ESP32-C3 various dev board  : CS:  7, DC:  2, RST:  1, BL:  3, SCK:  4, MOSI:  6, MISO: nil
     35  * ESP32-S2 various dev board  : CS: 34, DC: 38, RST: 33, BL: 21, SCK: 36, MOSI: 35, MISO: nil
     36  * ESP32-S3 various dev board  : CS: 40, DC: 41, RST: 42, BL: 48, SCK: 36, MOSI: 35, MISO: nil
     37  * ESP8266 various dev board   : CS: 15, DC:  4, RST:  2, BL:  5, SCK: 14, MOSI: 13, MISO: 12
     38  * Raspberry Pi Pico dev board : CS: 17, DC: 27, RST: 26, BL: 28, SCK: 18, MOSI: 19, MISO: 16
     39  * RTL8720 BW16 old patch core : CS: 18, DC: 17, RST:  2, BL: 23, SCK: 19, MOSI: 21, MISO: 20
     40  * RTL8720_BW16 Official core  : CS:  9, DC:  8, RST:  6, BL:  3, SCK: 10, MOSI: 12, MISO: 11
     41  * RTL8722 dev board           : CS: 18, DC: 17, RST: 22, BL: 23, SCK: 13, MOSI: 11, MISO: 12
     42  * RTL8722_mini dev board      : CS: 12, DC: 14, RST: 15, BL: 13, SCK: 11, MOSI:  9, MISO: 10
     43  * Seeeduino XIAO dev board    : CS:  3, DC:  2, RST:  1, BL:  0, SCK:  8, MOSI: 10, MISO:  9
     44  * Teensy 4.1 dev board        : CS: 39, DC: 41, RST: 40, BL: 22, SCK: 13, MOSI: 11, MISO: 12
     45  ******************************************************************************/
     46 #include <Arduino_GFX_Library.h>
     47 
     48 #define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
     49 
     50 /* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */
     51 #if defined(DISPLAY_DEV_KIT)
     52 Arduino_GFX *gfx = create_default_Arduino_GFX();
     53 #else /* !defined(DISPLAY_DEV_KIT) */
     54 
     55 /* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
     56 Arduino_DataBus *bus = create_default_Arduino_DataBus();
     57 
     58 /* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
     59 Arduino_GFX *gfx = new Arduino_ILI9341(bus, DF_GFX_RST, 0 /* rotation */, false /* IPS */);
     60 
     61 #endif /* !defined(DISPLAY_DEV_KIT) */
     62 /*******************************************************************************
     63  * End of Arduino_GFX setting
     64  ******************************************************************************/
     65 
     66 /* Change to your screen resolution */
     67 static uint32_t screenWidth;
     68 static uint32_t screenHeight;
     69 static lv_disp_draw_buf_t draw_buf;
     70 static lv_color_t *disp_draw_buf;
     71 static lv_disp_drv_t disp_drv;
     72 
     73 /* Display flushing */
     74 void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
     75 {
     76   uint32_t w = (area->x2 - area->x1 + 1);
     77   uint32_t h = (area->y2 - area->y1 + 1);
     78 
     79 #if (LV_COLOR_16_SWAP != 0)
     80   gfx->draw16bitBeRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
     81 #else
     82   gfx->draw16bitRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
     83 #endif
     84 
     85   lv_disp_flush_ready(disp);
     86 }
     87 
     88 void setup()
     89 {
     90   Serial.begin(115200);
     91   // Serial.setDebugOutput(true);
     92   // while(!Serial);
     93   Serial.println("LVGL Hello World Demo");
     94 
     95 #ifdef GFX_EXTRA_PRE_INIT
     96   GFX_EXTRA_PRE_INIT();
     97 #endif
     98 
     99   // Init Display
    100   gfx->begin();
    101   gfx->fillScreen(BLACK);
    102 
    103 #ifdef GFX_BL
    104   pinMode(GFX_BL, OUTPUT);
    105   digitalWrite(GFX_BL, HIGH);
    106 #endif
    107 
    108   lv_init();
    109 
    110   screenWidth = gfx->width();
    111   screenHeight = gfx->height();
    112 #ifdef ESP32
    113   disp_draw_buf = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * screenWidth * 32, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
    114 #else
    115   disp_draw_buf = (lv_color_t *)malloc(sizeof(lv_color_t) * screenWidth * 32);
    116 #endif
    117   if (!disp_draw_buf)
    118   {
    119     Serial.println("LVGL disp_draw_buf allocate failed!");
    120   }
    121   else
    122   {
    123     lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, NULL, screenWidth * 32);
    124 
    125     /* Initialize the display */
    126     lv_disp_drv_init(&disp_drv);
    127     /* Change the following line to your display resolution */
    128     disp_drv.hor_res = screenWidth;
    129     disp_drv.ver_res = screenHeight;
    130     disp_drv.flush_cb = my_disp_flush;
    131     disp_drv.draw_buf = &draw_buf;
    132     lv_disp_drv_register(&disp_drv);
    133 
    134     /* Initialize the (dummy) input device driver */
    135     static lv_indev_drv_t indev_drv;
    136     lv_indev_drv_init(&indev_drv);
    137     indev_drv.type = LV_INDEV_TYPE_POINTER;
    138     lv_indev_drv_register(&indev_drv);
    139 
    140     /* Create simple label */
    141     lv_obj_t *label = lv_label_create(lv_scr_act());
    142     lv_label_set_text(label, "Hello Arduino! (V" GFX_STR(LVGL_VERSION_MAJOR) "." GFX_STR(LVGL_VERSION_MINOR) "." GFX_STR(LVGL_VERSION_PATCH) ")");
    143     lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
    144 
    145     Serial.println("Setup done");
    146   }
    147 }
    148 
    149 void loop()
    150 {
    151   lv_timer_handler(); /* let the GUI do its work */
    152   delay(5);
    153 }