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 |
LvglHelloNeoPixel.ino (3684B)
1 /******************************************************************************* 2 * LVGL Hello NeoPixel demo 3 * This is a LVGL Hello World with NeoPixel matrix and Unicode text display 4 * 5 * Dependent libraries: 6 * LVGL: https://github.com/lvgl/lvgl.git 7 * Adafruit_NeoPixel: https://github.com/adafruit/Adafruit_NeoPixel.git 8 * 9 * Font: 10 * https://github.com/Warren2060/Chill-Bitmap.git 11 * 12 * LVGL Configuration file: 13 * Copy your_arduino_path/libraries/lvgl/lv_conf_template.h 14 * to your_arduino_path/libraries/lv_conf.h 15 * 16 * In lv_conf.h around line 15, enable config file: 17 * #if 1 // Set it to "1" to enable content 18 * 19 * Then find and set: 20 * #define LV_COLOR_DEPTH 16 21 * #define LV_TICK_CUSTOM 1 22 * #define LV_COLOR_16_SWAP 0 23 ******************************************************************************/ 24 #include <lvgl.h> 25 #include <Arduino_GFX_Library.h> 26 27 // all settings in header file 28 #include "Adafruit_NeoPixel_GFX.h" 29 Arduino_GFX *gfx = new Adafruit_NeoPixel_GFX(); 30 int16_t x; 31 uint16_t w, tw; 32 33 static lv_disp_draw_buf_t draw_buf; 34 static lv_color_t *disp_draw_buf; 35 static lv_disp_drv_t disp_drv; 36 37 /* Display flushing */ 38 void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) 39 { 40 uint32_t w = (area->x2 - area->x1 + 1); 41 uint32_t h = (area->y2 - area->y1 + 1); 42 43 gfx->draw16bitRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h); 44 45 lv_disp_flush_ready(disp); 46 } 47 48 void setup() 49 { 50 Serial.begin(115200); 51 // Serial.setDebugOutput(true); 52 // while(!Serial); 53 Serial.println("LVGL Hello NeoPixel Demo"); 54 55 #ifdef GFX_EXTRA_PRE_INIT 56 GFX_EXTRA_PRE_INIT(); 57 #endif 58 59 // Init Display 60 gfx->begin(); 61 gfx->fillScreen(BLACK); 62 63 #ifdef GFX_BL 64 pinMode(GFX_BL, OUTPUT); 65 digitalWrite(GFX_BL, HIGH); 66 #endif 67 68 lv_init(); 69 70 #ifdef ESP32 71 disp_draw_buf = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * NEOPIXEL_WIDTH * NEOPIXEL_HEIGHT, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); 72 #else 73 disp_draw_buf = (lv_color_t *)malloc(sizeof(lv_color_t) * NEOPIXEL_WIDTH * NEOPIXEL_HEIGHT); 74 #endif 75 if (!disp_draw_buf) 76 { 77 Serial.println("LVGL disp_draw_buf allocate failed!"); 78 } 79 else 80 { 81 lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, NULL, NEOPIXEL_WIDTH * NEOPIXEL_HEIGHT); 82 83 /* Initialize the display */ 84 lv_disp_drv_init(&disp_drv); 85 /* Change the following line to your display resolution */ 86 disp_drv.hor_res = NEOPIXEL_WIDTH; 87 disp_drv.ver_res = NEOPIXEL_HEIGHT; 88 disp_drv.flush_cb = my_disp_flush; 89 disp_drv.draw_buf = &draw_buf; 90 lv_disp_drv_register(&disp_drv); 91 92 /* Initialize the (dummy) input device driver */ 93 static lv_indev_drv_t indev_drv; 94 lv_indev_drv_init(&indev_drv); 95 indev_drv.type = LV_INDEV_TYPE_POINTER; 96 lv_indev_drv_register(&indev_drv); 97 98 /* Set black background */ 99 lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT ); 100 /* Create label */ 101 lv_obj_t *label = lv_label_create(lv_scr_act()); 102 lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); 103 lv_obj_set_width(label, NEOPIXEL_WIDTH); 104 lv_obj_set_style_text_color(label, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT ); 105 lv_label_set_text(label, "LVGL Hello NeoPixel! 《陈亮手痕定律》 点阵屏测试"); 106 /* Set font */ 107 LV_FONT_DECLARE(ui_font_Chill7); 108 lv_obj_set_style_text_font(label, &ui_font_Chill7, LV_PART_MAIN| LV_STATE_DEFAULT); 109 /* Set scrolling */ 110 lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); 111 lv_obj_set_style_anim_speed(label, 10, LV_STATE_DEFAULT); 112 113 Serial.println("Setup done"); 114 } 115 } 116 117 void loop() 118 { 119 lv_timer_handler(); /* let the GUI do its work */ 120 delay(5); 121 }