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