آموزش lvgl
درباره دوره
جلسه اول
معرفی و پیش نیازها و راه اندازی اولیه و کانفیگ ها: آموزش کامل LVGL: طراحی رابط کاربری حرفهای برای میکروکنترلر بهترین رابط گرافیکی برای آردوینو و میکروکنترلر ها قدم به قدم با آموزش LVGL 
LVGL چیست؟
LVGL (مخفف Light and Versatile Graphics Library) یک کتابخانه گرافیکی متنباز و قدرتمند است که بهطور خاص برای طراحی رابطهای کاربری (UI) در سیستمهای تعبیهشده (Embedded Systems) توسعه یافته است. این کتابخانه با عملکرد بهینه و کممصرف بودن، برای نمایشگرهایی با منابع سختافزاری محدود، مانند میکروکنترلرها، ایدهآل است.
ویژگیهای کلیدی LVGL:
طراحی رابطهای کاربری مدرن و تعاملی. پشتیبانی از انواع ویجتها مثل دکمهها، نمودارها، اسلایدرها و لیبلها. قابلیت شخصیسازی بالا برای هماهنگی با نیازهای خاص پروژه. پشتیبانی از چندین پلتفرم و سیستمعامل. بهینه برای اجرا روی سیستمهایی با منابع محدود. LVGL با چه پلتفرمهایی کار میکند؟ یکی از بزرگترین مزایای LVGL، انعطافپذیری آن برای اجرا روی طیف گستردهای از سختافزارها و پلتفرمها است.
پلتفرمهای پشتیبانیشده:
میکروکنترلرها: STM32، ESP32، NXP، و بسیاری دیگر. بردهای توسعه: Arduino، Raspberry Pi، و Teensy. سیستمعاملها: FreeRTOS، Zephyr، و سایر سیستمعاملهای بلادرنگ. شبیهسازها و سیستمهای دسکتاپ: اجرای کد در محیطهای دسکتاپ برای تست و توسعه آسانتر. سیستمهای لینوکسی و ویندوزی: برای برنامههای پیشرفتهتر روی نمایشگرهای صنعتی یا دستگاههای هوشمند. پیشنیازهای شروع کار با LVGL برای دانشجویان برای شروع یادگیری و استفاده از LVGL، به دانش پایهای و ابزارهای زیر نیاز دارید:
مهارتهای برنامهنویسی:
C یا ++C: کتابخانه LVGL به زبان C نوشته شده، بنابراین آشنایی با مفاهیم برنامهنویسی در این زبان ضروری است. مفاهیم پایه گرافیک کامپیوتری: مانند مختصات پیکسلی و نحوه رسم اشکال ساده. دانش سختافزاری: آشنایی با میکروکنترلرها و نحوه برنامهریزی آنها (مانند STM32، ESP32، یا Arduino). آشنایی با اصول ارتباط میکروکنترلر با نمایشگرها (مانند LCD یا TFT). ابزارهای موردنیاز: سختافزار: یک میکروکنترلر مانند Arduino یا ESP32. نمایشگر مناسب (مانند TFT LCD با رزولوشن 320×240 یا بالاتر). نرمافزار: نصب IDE مناسب (مانند Arduino IDE، PlatformIO، یا STM32CubeIDE). کتابخانه LVGL و ابزارهای مرتبط با آن. مفاهیم الکترونیکی: نحوه اتصال نمایشگر به میکروکنترلر. اصول کار با پینها و منابع تغذیه میکروکنترلر. چرا دانشجویان باید LVGL یاد بگیرند؟ پروژههای دانشگاهی: برای طراحی پروژههایی با رابط گرافیکی زیبا و کاربردی. کاربردهای صنعتی: بسیاری از محصولات تعبیهشده مدرن از رابطهای گرافیکی استفاده میکنند. یادگیری تکنولوژیهای پرکاربرد: مهارت در LVGL فرصتهای شغلی در زمینه طراحی سیستمهای تعبیهشده را افزایش میدهد. 
شروع آموزش LVGL
قطعات مورد نیاز:
ESP32 میکروکنترلر
ILI9488 نمایشگر
SD CARD برای ذخیره و دریافت اطلاعات
راه اندازی کتابخانه گرافیکی LVGL با LOVYAN GFX در این آموزش، با مقدمات استفاده از LVGL همراه با کتابخانه Lovyan GFX برای نمایشگرهای گرافیکی آشنا میشوید. LVGL برای راه اندازی نیاز به یک کتابخانه راه اندازی گرافیکی دارد.که برای آن ما از Lovyan استفاده کردیم.میتوان از TFT_eSPI هم استفاده کرد ولی Lovyan سرعت بیشتری نسبت به آن دارد. چرا Lovyan GFX؟ Lovyan GFX یک کتابخانه عالی برای مدیریت نمایشگرهای گرافیکی است که برای میکروکنترلرهایی مثل ESP32 توسعه داده شده است. این کتابخانه به دلیل سازگاری با LVGL و کارایی بالای خود، انتخابی مناسب برای پروژههای شماست. قدم اول: نصب کتابخانهها برای شروع، ابتدا باید دو کتابخانه LVGL و Lovyan GFX را به پروژه خود اضافه کنید. این کار را میتوانید از طریق Arduino IDE یا PlatformIO انجام دهید. نصب LVGL: کتابخانه lvgl و lovyan-gfx در قسمت پایین این صفحه قرار داده شده. پس از دانلود فایل ها آن ها در پوشه کتابخانه آردوینو قرار دهید: \Documents\Arduino\libraries
تمامی تنظیمات و آپشن های مختلف در این دو کتابخانه به خوبی تنظیم شده و نیازی به تغییرات نیست. برای انتخاب نوع ال سی دی و میکروکنترلر مربوطه میتوانید در آردوینو آن ها را تغییر دهید که قدم به قدم جلو میرویم. بعد از دانلود فایل ها، برای شروع ابتدا کتابخانه LOVYAN GFX راه اندازی میکنیم:
کتابخانه گرافیکی LOVYAN GFX:
ابتدا در خط اول، کتابخانه lovyan را وارد کرده و سپس پایه های نمایشگر را معرفی میکنیم. نمایشگر انتخابی در این دوره از آموزش، ILI9488 و میکروکنترلر انتخابی نیز esp32 می باشد. برنامه راه اندازی ال سی دی ili9488 با lovyanGfx arduino lovyanGfx & ili9488
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 |
#define LGFX_USE_V1 #include <LovyanGFX.hpp> #include <algorithm> #include <lgfx/v1/platforms/esp32s3/Panel_RGB.hpp> #include <lgfx/v1/platforms/esp32s3/Bus_RGB.hpp> //انتخاب مدل ال سی دی class LGFX : public lgfx::LGFX_Device { //lgfx::Panel_GC9A01 _panel_instance; //lgfx::Panel_GDEW0154M09 _panel_instance; //lgfx::Panel_HX8357B _panel_instance; //lgfx::Panel_HX8357D _panel_instance; //lgfx::Panel_ILI9163 _panel_instance; // lgfx::Panel_ILI9341 _panel_instance; //lgfx::Panel_ILI9342 _panel_instance; //lgfx::Panel_ILI9481 _panel_instance; //lgfx::Panel_ILI9486 _panel_instance; lgfx::Panel_ILI9488 _panel_instance; //ال سی دی استفاده شده در این پروژه //lgfx::Panel_IT8951 _panel_instance; //lgfx::Panel_RA8875 _panel_instance; //lgfx::Panel_SH110x _panel_instance; // SH1106, SH1107 //lgfx::Panel_SSD1306 _panel_instance; //lgfx::Panel_SSD1327 _panel_instance; //lgfx::Panel_SSD1331 _panel_instance; //lgfx::Panel_SSD1351 _panel_instance; // SSD1351, SSD1357 //lgfx::Panel_SSD1963 _panel_instance; //lgfx::Panel_ST7735 _panel_instance; //lgfx::Panel_ST7735S _panel_instance; //lgfx::Panel_ST7789 _panel_instance; //lgfx::Panel_ST7796 _panel_instance; //انتخاب پروتکل راه اندازی ال سی دی //lgfx::Bus_Parallel16 _bus_instance; lgfx::Light_PWM _light_instance; lgfx::Bus_SPI _bus_instance; //انتخاب درایور تاچ اسکرین // touch driver //lgfx::Touch_CST816S _touch_instance; // lgfx::Touch_FT5x06 _touch_instance; // FT5206, FT5306, FT5406, FT6206, FT6236, FT6336, FT6436 //lgfx::Touch_GSL1680E_800x480 _touch_instance; // GSL_1680E, 1688E, 2681B, 2682B //lgfx::Touch_GSL1680F_800x480 _touch_instance; //lgfx::Touch_GSL1680F_480x272 _touch_instance; //lgfx::Touch_GSLx680_320x320 _touch_instance; //lgfx::Touch_GT911 _touch_instance; //lgfx::Touch_STMPE610 _touch_instance; //lgfx::Touch_TT21xxx _touch_instance; // TT21100 lgfx::Touch_XPT2046 _touch_instance; // تاچ مورد استفاده public: LGFX(void) { { auto cfg = _bus_instance.config(); // انتخاب پروتکل مربوط به میکر وکنترلر //پروتکل انتخابی برای میکروکنترلر esp32 cfg.spi_host = VSPI_HOST; // ESP32-S2,C3,S3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST / انتخاب مدل spi cfg.spi_mode = 0; cfg.freq_write = 40000000; cfg.freq_read = 16000000; cfg.spi_3wire = true; cfg.use_lock = true; cfg.dma_channel = SPI_DMA_CH_AUTO; cfg.pin_sclk = 12; // SPI-CLK cfg.pin_mosi = 11; // SPI-MOSI cfg.pin_miso = 13; // SPI-MISO(-1 = disable) cfg.pin_dc = 6; // SPI-D/C(-1 = disable) _bus_instance.config(cfg); _panel_instance.setBus(&_bus_instance); } { // 表示パネル制御の設定を行います。 auto cfg = _panel_instance.config(); cfg.pin_cs = 4; // CS cfg.pin_rst = -1; // RST cfg.pin_busy = -1; // BUSY cfg.panel_width = 320; cfg.panel_height = 480; cfg.offset_x = 0; cfg.offset_y = 0; cfg.offset_rotation = 0; cfg.dummy_read_pixel = 8; cfg.dummy_read_bits = 1; cfg.readable = true; cfg.invert = false; cfg.rgb_order = false; cfg.dlen_16bit = false; // 16bit cfg.bus_shared = true; // SDカードとバスを共有している場合 trueに設定(drawJpg cfg.memory_width = 320; cfg.memory_height = 480; _panel_instance.config(cfg); } { // کانفیک ماژول تاچ auto cfg = _touch_instance.config(); cfg.x_min = 0; cfg.x_max = 319; cfg.y_min = 0; cfg.y_max = 479; cfg.pin_int = -1; cfg.bus_shared = true; cfg.offset_rotation = 0; cfg.spi_host = SPI2_HOST; cfg.freq = 1000000; cfg.pin_sclk = 12; // SCLK cfg.pin_mosi = 11; // MOSI cfg.pin_miso = 13; // MISO cfg.pin_cs = 5; // CS _touch_instance.config(cfg); _panel_instance.setTouch(&_touch_instance); } setPanel(&_panel_instance); } }; LGFX tft; unsigned long total = 0; unsigned long tn = 0; void setup() { Serial.begin(115200); Serial.println(""); Serial.println(""); Serial.println("Lovyan's LovyanGFX library Test!"); tft.init(); tft.setRotation(0); tft.startWrite(); tft.fillScreen(TFT_BLACK); } void loop(void) { Serial.println(F("Benchmark Time (microseconds)")); uint32_t usecHaD = testHaD(); Serial.print(F("HaD pushColor ")); Serial.println(usecHaD); delay(100); uint32_t usecFillScreen = testFillScreen(); Serial.print(F("Screen fill ")); Serial.println(usecFillScreen); delay(100); uint32_t usecText = testText(); Serial.print(F("Text ")); Serial.println(usecText); delay(100); uint32_t usecPixels = testPixels(); Serial.print(F("Pixels ")); Serial.println(usecPixels); delay(100); uint32_t usecLines = testLines(TFT_BLUE); Serial.print(F("Lines ")); Serial.println(usecLines); delay(100); uint32_t usecFastLines = testFastLines(TFT_RED, TFT_BLUE); Serial.print(F("Horiz/Vert Lines ")); Serial.println(usecFastLines); delay(100); uint32_t usecRects = testRects(TFT_GREEN); Serial.print(F("Rectangles (outline) ")); Serial.println(usecRects); delay(100); uint32_t usecFilledRects = testFilledRects(TFT_YELLOW, TFT_MAGENTA); Serial.print(F("Rectangles (filled) ")); Serial.println(usecFilledRects); delay(100); uint32_t usecFilledCircles = testFilledCircles(10, TFT_MAGENTA); Serial.print(F("Circles (filled) ")); Serial.println(usecFilledCircles); delay(100); uint32_t usecCircles = testCircles(10, TFT_WHITE); Serial.print(F("Circles (outline) ")); Serial.println(usecCircles); delay(100); uint32_t usecTriangles = testTriangles(); Serial.print(F("Triangles (outline) ")); Serial.println(usecTriangles); delay(100); uint32_t usecFilledTrangles = testFilledTriangles(); Serial.print(F("Triangles (filled) ")); Serial.println(usecFilledTrangles); delay(100); uint32_t usecRoundRects = testRoundRects(); Serial.print(F("Rounded rects (outline) ")); Serial.println(usecRoundRects); delay(100); uint32_t usedFilledRoundRects = testFilledRoundRects(); Serial.print(F("Rounded rects (filled) ")); Serial.println(usedFilledRoundRects); delay(100); Serial.println(F("Done!")); uint16_t c = 4; int8_t d = 1; for (int32_t i = 0; i < tft.height(); i++) { tft.drawFastHLine(0, i, tft.width(), c); c += d; if (c <= 4 || c >= 11) d = -d; } tft.setCursor(0, 0); tft.setTextColor(TFT_MAGENTA); tft.setTextSize(2); tft.println(F(" LovyanGFX test")); tft.setTextSize(1); tft.setTextColor(TFT_WHITE); tft.println(F("")); tft.setTextSize(1); tft.println(F("")); tft.setTextColor(tft.color565(0x80, 0x80, 0x80)); tft.println(F("")); tft.setTextColor(TFT_GREEN); tft.println(F(" Benchmark microseconds")); tft.println(F("")); tft.setTextColor(TFT_YELLOW); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("HaD pushColor ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecHaD); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Screen fill ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecFillScreen); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Text ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecText); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Pixels ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecPixels); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Lines ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecLines); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Horiz/Vert Lines ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecFastLines); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Rectangles ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecRects); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Rectangles-filled ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecFilledRects); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Circles ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecCircles); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Circles-filled ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecFilledCircles); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Triangles ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecTriangles); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Triangles-filled ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecFilledTrangles); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Rounded rects ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usecRoundRects); tft.setTextColor(TFT_CYAN); tft.setTextSize(1); tft.print(F("Rounded rects-fill ")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); printnice(usedFilledRoundRects); tft.setTextSize(1); tft.println(F("")); tft.setTextColor(TFT_GREEN); tft.setTextSize(2); tft.print(F("Benchmark Complete!")); delay(60 * 1000L); } void printnice(int32_t v) { char str[32] = { 0 }; sprintf(str, "%d", v); for (char *p = (str+strlen(str))-3; p > str; p -= 3) { memmove(p+1, p, strlen(p)+1); *p = ','; } while (strlen(str) < 10) { memmove(str+1, str, strlen(str)+1); *str = ' '; } tft.println(str); } static inline uint32_t micros_start() __attribute__ ((always_inline)); static inline uint32_t micros_start() { uint8_t oms = millis(); while ((uint8_t)millis() == oms) ; return micros(); } uint32_t testHaD() { // pseudo-code for cheesy RLE // start with color1 // while more input data remaining // count = 0nnnnnnn = 1 byte or 1nnnnnnn nnnnnnnn 2 bytes (0 - 32767) // repeat color count times // toggle color1/color2 static const uint8_t HaD_240x320[] PROGMEM = { 0xb9, 0x50, 0x0e, 0x80, 0x93, 0x0e, 0x41, 0x11, 0x80, 0x8d, 0x11, 0x42, 0x12, 0x80, 0x89, 0x12, 0x45, 0x12, 0x80, 0x85, 0x12, 0x48, 0x12, 0x80, 0x83, 0x12, 0x4a, 0x13, 0x7f, 0x13, 0x4c, 0x13, 0x7d, 0x13, 0x4e, 0x13, 0x7b, 0x13, 0x50, 0x13, 0x79, 0x13, 0x52, 0x13, 0x77, 0x13, 0x54, 0x13, 0x75, 0x13, 0x57, 0x11, 0x75, 0x11, 0x5a, 0x11, 0x73, 0x11, 0x5c, 0x11, 0x71, 0x11, 0x5e, 0x10, 0x71, 0x10, 0x60, 0x10, 0x6f, 0x10, 0x61, 0x10, 0x6f, 0x10, 0x60, 0x11, 0x6f, 0x11, 0x5e, 0x13, 0x6d, 0x13, 0x5c, 0x14, 0x6d, 0x14, 0x5a, 0x15, 0x6d, 0x15, 0x58, 0x17, 0x6b, 0x17, 0x37, 0x01, 0x1f, 0x17, 0x6b, 0x17, 0x1f, 0x01, 0x17, 0x02, 0x1d, 0x18, 0x6b, 0x18, 0x1d, 0x02, 0x17, 0x03, 0x1b, 0x19, 0x6b, 0x19, 0x1b, 0x03, 0x17, 0x05, 0x18, 0x1a, 0x6b, 0x1a, 0x18, 0x05, 0x17, 0x06, 0x16, 0x1b, 0x6b, 0x1b, 0x16, 0x06, 0x17, 0x07, 0x14, 0x1c, 0x6b, 0x1c, 0x14, 0x07, 0x17, 0x08, 0x12, 0x1d, 0x6b, 0x1d, 0x12, 0x08, 0x17, 0x09, 0x10, 0x1e, 0x6b, 0x1e, 0x10, 0x09, 0x17, 0x0a, 0x0e, 0x1f, 0x6b, 0x1f, 0x0e, 0x0a, 0x17, 0x0b, 0x0c, 0x20, 0x6b, 0x20, 0x0c, 0x0b, 0x17, 0x0c, 0x0b, 0x21, 0x69, 0x21, 0x0b, 0x0c, 0x18, 0x0d, 0x08, 0x23, 0x67, 0x23, 0x08, 0x0d, 0x19, 0x0e, 0x06, 0x26, 0x63, 0x26, 0x06, 0x0e, 0x19, 0x0f, 0x04, 0x28, 0x61, 0x28, 0x04, 0x0f, 0x19, 0x10, 0x02, 0x2a, 0x5f, 0x2a, 0x02, 0x10, 0x1a, 0x3c, 0x5d, 0x3c, 0x1b, 0x3d, 0x5b, 0x3d, 0x1c, 0x3d, 0x59, 0x3d, 0x1d, 0x3e, 0x57, 0x3e, 0x1e, 0x3e, 0x55, 0x3e, 0x1f, 0x40, 0x51, 0x40, 0x20, 0x40, 0x4f, 0x40, 0x22, 0x40, 0x22, 0x09, 0x22, 0x40, 0x24, 0x40, 0x1a, 0x17, 0x1a, 0x40, 0x26, 0x40, 0x16, 0x1d, 0x16, 0x40, 0x28, 0x40, 0x12, 0x23, 0x12, 0x40, 0x2a, 0x40, 0x0f, 0x27, 0x0f, 0x40, 0x2c, 0x41, 0x0b, 0x2b, 0x0b, 0x41, 0x2f, 0x3f, 0x09, 0x2f, 0x09, 0x3f, 0x32, 0x3d, 0x08, 0x33, 0x08, 0x3d, 0x35, 0x3a, 0x08, 0x35, 0x08, 0x3a, 0x3a, 0x36, 0x07, 0x39, 0x07, 0x36, 0x41, 0x09, 0x05, 0x23, 0x07, 0x3b, 0x07, 0x23, 0x05, 0x09, 0x54, 0x21, 0x07, 0x3d, 0x07, 0x21, 0x64, 0x1f, 0x06, 0x41, 0x06, 0x1f, 0x66, 0x1d, 0x06, 0x43, 0x06, 0x1d, 0x68, 0x1b, 0x06, 0x45, 0x06, 0x1b, 0x6b, 0x18, 0x06, 0x47, 0x06, 0x18, 0x6e, 0x16, 0x06, 0x49, 0x06, 0x16, 0x70, 0x14, 0x06, 0x4b, 0x06, 0x14, 0x72, 0x13, 0x06, 0x4b, 0x06, 0x13, 0x74, 0x11, 0x06, 0x4d, 0x06, 0x11, 0x76, 0x0f, 0x06, 0x4f, 0x06, 0x0f, 0x78, 0x0e, 0x05, 0x51, 0x05, 0x0e, 0x7a, 0x0c, 0x06, 0x51, 0x06, 0x0c, 0x7d, 0x09, 0x06, 0x53, 0x06, 0x09, 0x80, 0x80, 0x08, 0x05, 0x55, 0x05, 0x08, 0x80, 0x82, 0x06, 0x05, 0x57, 0x05, 0x06, 0x80, 0x84, 0x05, 0x05, 0x57, 0x05, 0x05, 0x80, 0x86, 0x03, 0x05, 0x59, 0x05, 0x03, 0x80, 0x88, 0x02, 0x05, 0x59, 0x05, 0x02, 0x80, 0x8f, 0x5b, 0x80, 0x95, 0x5b, 0x80, 0x94, 0x5d, 0x80, 0x93, 0x5d, 0x80, 0x92, 0x5e, 0x80, 0x92, 0x5f, 0x80, 0x91, 0x5f, 0x80, 0x90, 0x61, 0x80, 0x8f, 0x61, 0x80, 0x8f, 0x61, 0x80, 0x8e, 0x63, 0x80, 0x8d, 0x63, 0x80, 0x8d, 0x63, 0x80, 0x8d, 0x63, 0x80, 0x8c, 0x19, 0x07, 0x25, 0x07, 0x19, 0x80, 0x8b, 0x16, 0x0d, 0x1f, 0x0d, 0x16, 0x80, 0x8b, 0x14, 0x11, 0x1b, 0x11, 0x14, 0x80, 0x8b, 0x13, 0x13, 0x19, 0x13, 0x13, 0x80, 0x8b, 0x12, 0x15, 0x17, 0x15, 0x12, 0x80, 0x8a, 0x12, 0x17, 0x15, 0x17, 0x12, 0x80, 0x89, 0x11, 0x19, 0x13, 0x19, 0x11, 0x80, 0x89, 0x11, 0x19, 0x13, 0x19, 0x11, 0x80, 0x89, 0x10, 0x1b, 0x11, 0x1b, 0x10, 0x80, 0x89, 0x0f, 0x1c, 0x11, 0x1c, 0x0f, 0x80, 0x89, 0x0f, 0x1c, 0x11, 0x1c, 0x0f, 0x80, 0x89, 0x0f, 0x1c, 0x11, 0x1c, 0x0f, 0x80, 0x89, 0x0e, 0x1d, 0x11, 0x1d, 0x0e, 0x80, 0x89, 0x0e, 0x1c, 0x13, 0x1c, 0x0e, 0x80, 0x89, 0x0e, 0x1b, 0x15, 0x1b, 0x0e, 0x80, 0x89, 0x0e, 0x1b, 0x15, 0x1b, 0x0e, 0x80, 0x89, 0x0e, 0x1a, 0x17, 0x1a, 0x0e, 0x80, 0x89, 0x0e, 0x18, 0x1b, 0x18, 0x0e, 0x80, 0x89, 0x0e, 0x16, 0x1f, 0x16, 0x0e, 0x80, 0x89, 0x0e, 0x14, 0x23, 0x14, 0x0e, 0x80, 0x89, 0x0f, 0x11, 0x27, 0x11, 0x0f, 0x80, 0x89, 0x0f, 0x0e, 0x2d, 0x0e, 0x0f, 0x80, 0x89, 0x0f, 0x0c, 0x31, 0x0c, 0x0f, 0x80, 0x89, 0x0f, 0x0b, 0x33, 0x0b, 0x0f, 0x80, 0x8a, 0x0f, 0x09, 0x35, 0x09, 0x0f, 0x80, 0x8b, 0x10, 0x08, 0x35, 0x08, 0x10, 0x80, 0x8b, 0x10, 0x07, 0x37, 0x07, 0x10, 0x80, 0x8b, 0x11, 0x06, 0x37, 0x06, 0x11, 0x80, 0x8b, 0x12, 0x05, 0x37, 0x05, 0x12, 0x80, 0x8c, 0x13, 0x03, 0x1b, 0x01, 0x1b, 0x03, 0x13, 0x80, 0x8d, 0x30, 0x03, 0x30, 0x80, 0x8d, 0x30, 0x04, 0x2f, 0x80, 0x8d, 0x2f, 0x05, 0x2f, 0x80, 0x8e, 0x2e, 0x06, 0x2d, 0x80, 0x8f, 0x2d, 0x07, 0x2d, 0x80, 0x8f, 0x2d, 0x07, 0x2d, 0x80, 0x90, 0x2c, 0x08, 0x2b, 0x80, 0x91, 0x2b, 0x09, 0x2b, 0x80, 0x8c, 0x01, 0x05, 0x2a, 0x09, 0x2a, 0x05, 0x01, 0x80, 0x85, 0x03, 0x05, 0x2a, 0x09, 0x2a, 0x05, 0x03, 0x80, 0x82, 0x04, 0x05, 0x2a, 0x09, 0x2a, 0x04, 0x05, 0x80, 0x80, 0x06, 0x05, 0x29, 0x04, 0x02, 0x03, 0x29, 0x05, 0x06, 0x7e, 0x07, 0x05, 0x29, 0x03, 0x03, 0x03, 0x29, 0x05, 0x07, 0x7c, 0x09, 0x05, 0x28, 0x02, 0x05, 0x02, 0x28, 0x05, 0x09, 0x7a, 0x0a, 0x05, 0x28, 0x02, 0x05, 0x02, 0x28, 0x05, 0x0a, 0x78, 0x0c, 0x05, 0x27, 0x02, 0x05, 0x02, 0x27, 0x05, 0x0c, 0x76, 0x0d, 0x06, 0x26, 0x01, 0x07, 0x01, 0x26, 0x06, 0x0d, 0x73, 0x10, 0x05, 0x55, 0x05, 0x10, 0x70, 0x12, 0x05, 0x53, 0x05, 0x12, 0x6e, 0x13, 0x06, 0x51, 0x06, 0x13, 0x6c, 0x15, 0x05, 0x51, 0x05, 0x15, 0x6a, 0x16, 0x06, 0x4f, 0x06, 0x16, 0x68, 0x18, 0x06, 0x4d, 0x06, 0x18, 0x66, 0x1a, 0x06, 0x4b, 0x06, 0x1a, 0x64, 0x1c, 0x06, 0x49, 0x06, 0x1c, 0x55, 0x07, 0x05, 0x1e, 0x06, 0x49, 0x06, 0x1e, 0x05, 0x07, 0x42, 0x30, 0x06, 0x47, 0x06, 0x30, 0x3a, 0x34, 0x06, 0x45, 0x06, 0x34, 0x35, 0x37, 0x06, 0x43, 0x06, 0x37, 0x32, 0x39, 0x07, 0x3f, 0x07, 0x39, 0x2f, 0x3c, 0x07, 0x3d, 0x07, 0x3c, 0x2c, 0x3e, 0x07, 0x3b, 0x07, 0x3e, 0x2a, 0x40, 0x06, 0x3b, 0x06, 0x40, 0x28, 0x40, 0x06, 0x3c, 0x07, 0x40, 0x26, 0x3f, 0x08, 0x3d, 0x08, 0x3f, 0x24, 0x3f, 0x09, 0x3d, 0x09, 0x3f, 0x22, 0x3f, 0x0a, 0x14, 0x01, 0x13, 0x02, 0x13, 0x0a, 0x3f, 0x20, 0x3f, 0x0b, 0x14, 0x01, 0x13, 0x02, 0x13, 0x0b, 0x3f, 0x1f, 0x3e, 0x0c, 0x14, 0x01, 0x13, 0x02, 0x13, 0x0c, 0x3e, 0x1e, 0x3e, 0x0d, 0x13, 0x02, 0x13, 0x02, 0x13, 0x0d, 0x3e, 0x1d, 0x3d, 0x0e, 0x13, 0x02, 0x13, 0x02, 0x13, 0x0e, 0x3d, 0x1c, 0x3c, 0x11, 0x11, 0x04, 0x11, 0x04, 0x11, 0x11, 0x3c, 0x1b, 0x10, 0x01, 0x2a, 0x12, 0x11, 0x04, 0x11, 0x04, 0x11, 0x12, 0x2a, 0x01, 0x10, 0x1a, 0x0f, 0x04, 0x28, 0x14, 0x0f, 0x06, 0x0f, 0x06, 0x0f, 0x14, 0x28, 0x04, 0x0f, 0x19, 0x0e, 0x06, 0x26, 0x16, 0x0d, 0x08, 0x0d, 0x08, 0x0d, 0x16, 0x26, 0x06, 0x0e, 0x19, 0x0d, 0x07, 0x25, 0x18, 0x0b, 0x0a, 0x0b, 0x0a, 0x0b, 0x18, 0x25, 0x07, 0x0d, 0x19, 0x0c, 0x09, 0x23, 0x1c, 0x06, 0x0f, 0x05, 0x10, 0x05, 0x1c, 0x23, 0x09, 0x0c, 0x18, 0x0c, 0x0b, 0x21, 0x69, 0x21, 0x0b, 0x0c, 0x17, 0x0b, 0x0d, 0x1f, 0x6b, 0x1f, 0x0d, 0x0b, 0x17, 0x0a, 0x0f, 0x1e, 0x6b, 0x1e, 0x0f, 0x0a, 0x17, 0x09, 0x11, 0x1d, 0x6b, 0x1d, 0x11, 0x09, 0x17, 0x07, 0x14, 0x1c, 0x6b, 0x1c, 0x14, 0x07, 0x17, 0x06, 0x16, 0x1b, 0x6b, 0x1b, 0x16, 0x06, 0x17, 0x05, 0x18, 0x1a, 0x6b, 0x1a, 0x18, 0x05, 0x17, 0x04, 0x1a, 0x19, 0x6b, 0x19, 0x1a, 0x04, 0x17, 0x03, 0x1b, 0x19, 0x6b, 0x19, 0x1b, 0x03, 0x17, 0x02, 0x1d, 0x18, 0x6b, 0x18, 0x1d, 0x02, 0x37, 0x17, 0x6b, 0x17, 0x58, 0x16, 0x6b, 0x16, 0x5a, 0x14, 0x6d, 0x14, 0x5c, 0x13, 0x6d, 0x13, 0x5e, 0x12, 0x6d, 0x12, 0x60, 0x10, 0x6f, 0x10, 0x61, 0x10, 0x6f, 0x10, 0x60, 0x11, 0x6f, 0x11, 0x5e, 0x11, 0x71, 0x11, 0x5c, 0x12, 0x71, 0x12, 0x5a, 0x12, 0x73, 0x12, 0x58, 0x12, 0x75, 0x12, 0x56, 0x13, 0x75, 0x13, 0x54, 0x13, 0x77, 0x13, 0x51, 0x14, 0x79, 0x14, 0x4e, 0x14, 0x7b, 0x14, 0x4c, 0x14, 0x7d, 0x14, 0x4a, 0x14, 0x7f, 0x14, 0x48, 0x13, 0x80, 0x83, 0x13, 0x46, 0x13, 0x80, 0x85, 0x13, 0x44, 0x12, 0x80, 0x89, 0x12, 0x42, 0x11, 0x80, 0x8d, 0x11, 0x40, 0x0f, 0x80, 0x93, 0x0f, 0x45, 0x04, 0x80, 0x9d, 0x04, 0xb9, 0x56, }; tft.fillScreen(TFT_BLACK); uint32_t start = micros_start(); for (int i = 0; i < 0x10; i++) { tft.setAddrWindow(0, 0, 240, 320); uint16_t cnt = 0; uint16_t color = tft.color565((i << 4) | i, (i << 4) | i, (i << 4) | i); uint16_t curcolor = 0; const uint8_t *cmp = &HaD_240x320[0]; tft.startWrite(); while (cmp < &HaD_240x320[sizeof(HaD_240x320)]) { cnt = pgm_read_byte(cmp++); if (cnt & 0x80) cnt = ((cnt & 0x7f) << 8) | pgm_read_byte(cmp++); tft.pushColor(curcolor, cnt); // PDQ_GFX has count curcolor ^= color; } tft.endWrite(); } uint32_t t = micros() - start; tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); tft.setCursor(8, 285); tft.print(F("http://hackaday.io/")); tft.setCursor(96, 302); tft.print(F("Xark")); delay(3 * 1000L); return t; } uint32_t testFillScreen() { uint32_t start = micros_start(); // Shortened this tedious test! tft.fillScreen(TFT_WHITE); tft.fillScreen(TFT_RED); tft.fillScreen(TFT_GREEN); tft.fillScreen(TFT_BLUE); tft.fillScreen(TFT_BLACK); return (micros() - start)/5; } uint32_t testText() { tft.fillScreen(TFT_BLACK); uint32_t start = micros_start(); tft.setCursor(0, 0); tft.setTextColor(TFT_WHITE,TFT_BLACK); tft.setTextSize(1); tft.println(F("Hello World!")); tft.setTextSize(2); tft.setTextColor(tft.color565(0xff, 0x00, 0x00)); tft.print(F("RED ")); tft.setTextColor(tft.color565(0x00, 0xff, 0x00)); tft.print(F("GREEN ")); tft.setTextColor(tft.color565(0x00, 0x00, 0xff)); tft.println(F("BLUE")); tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); tft.println(1234.56); tft.setTextColor(TFT_RED); tft.setTextSize(3); tft.println(0xDEADBEEF, HEX); tft.println(); tft.setTextColor(TFT_GREEN); tft.setTextSize(5); tft.println(F("Groop")); tft.setTextSize(2); tft.println(F("I implore thee,")); tft.setTextColor(TFT_GREEN); tft.setTextSize(1); tft.println(F("my foonting turlingdromes.")); tft.println(F("And hooptiously drangle me")); tft.println(F("with crinkly bindlewurdles,")); tft.println(F("Or I will rend thee")); tft.println(F("in the gobberwarts")); tft.println(F("with my blurglecruncheon,")); tft.println(F("see if I don't!")); tft.println(F("")); tft.println(F("")); tft.setTextColor(TFT_MAGENTA); tft.setTextSize(6); tft.println(F("Woot!")); uint32_t t = micros() - start; delay(1000); return t; } uint32_t testPixels() { int32_t w = tft.width(); int32_t h = tft.height(); uint32_t start = micros_start(); tft.startWrite(); for (uint16_t y = 0; y < h; y++) { for (uint16_t x = 0; x < w; x++) { tft.drawPixel(x, y, tft.color565(x<<3, y<<3, x*y)); } } tft.endWrite(); return micros() - start; } uint32_t testLines(uint16_t color) { uint32_t start, t; int32_t x1, y1, x2, y2; int32_t w = tft.width(); int32_t h = tft.height(); tft.fillScreen(TFT_BLACK); x1 = y1 = 0; y2 = h - 1; start = micros_start(); for (x2 = 0; x2 < w; x2 += 6) { tft.drawLine(x1, y1, x2, y2, color); } x2 = w - 1; for (y2 = 0; y2 < h; y2 += 6) { tft.drawLine(x1, y1, x2, y2, color); } t = micros() - start; // fillScreen doesn't count against timing tft.fillScreen(TFT_BLACK); x1 = w - 1; y1 = 0; y2 = h - 1; start = micros_start(); for (x2 = 0; x2 < w; x2 += 6) { tft.drawLine(x1, y1, x2, y2, color); } x2 = 0; for (y2 = 0; y2 < h; y2 += 6) { tft.drawLine(x1, y1, x2, y2, color); } t += micros() - start; tft.fillScreen(TFT_BLACK); x1 = 0; y1 = h - 1; y2 = 0; start = micros_start(); for (x2 = 0; x2 < w; x2 += 6) { tft.drawLine(x1, y1, x2, y2, color); } x2 = w - 1; for (y2 = 0; y2 < h; y2 += 6) { tft.drawLine(x1, y1, x2, y2, color); } t += micros() - start; tft.fillScreen(TFT_BLACK); x1 = w - 1; y1 = h - 1; y2 = 0; start = micros_start(); for (x2 = 0; x2 < w; x2 += 6) { tft.drawLine(x1, y1, x2, y2, color); } x2 = 0; for (y2 = 0; y2 < h; y2 += 6) { tft.drawLine(x1, y1, x2, y2, color); } t += micros() - start; return t; } uint32_t testFastLines(uint16_t color1, uint16_t color2) { uint32_t start; int32_t x, y; int32_t w = tft.width(); int32_t h = tft.height(); tft.fillScreen(TFT_BLACK); start = micros_start(); for (y = 0; y < h; y += 5) tft.drawFastHLine(0, y, w, color1); for (x = 0; x < w; x += 5) tft.drawFastVLine(x, 0, h, color2); return micros() - start; } uint32_t testRects(uint16_t color) { uint32_t start; int32_t n, i, i2; int32_t cx = tft.width() / 2; int32_t cy = tft.height() / 2; tft.fillScreen(TFT_BLACK); n = std::min(tft.width(), tft.height()); start = micros_start(); for (i = 2; i < n; i += 6) { i2 = i / 2; tft.drawRect(cx-i2, cy-i2, i, i, color); } return micros() - start; } uint32_t testFilledRects(uint16_t color1, uint16_t color2) { uint32_t start, t = 0; int32_t n, i, i2; int32_t cx = tft.width() / 2 - 1; int32_t cy = tft.height() / 2 - 1; tft.fillScreen(TFT_BLACK); n = std::min(tft.width(), tft.height()); for (i = n; i > 0; i -= 6) { i2 = i / 2; start = micros_start(); tft.fillRect(cx-i2, cy-i2, i, i, color1); t += micros() - start; // Outlines are not included in timing results tft.drawRect(cx-i2, cy-i2, i, i, color2); } return t; } uint32_t testFilledCircles(uint8_t radius, uint16_t color) { uint32_t start; int32_t x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; tft.fillScreen(TFT_BLACK); start = micros_start(); for (x = radius; x < w; x += r2) { for (y = radius; y < h; y += r2) { tft.fillCircle(x, y, radius, color); } } return micros() - start; } uint32_t testCircles(uint8_t radius, uint16_t color) { uint32_t start; int32_t x, y, r2 = radius * 2; int32_t w = tft.width() + radius; int32_t h = tft.height() + radius; // Screen is not cleared for this one -- this is // intentional and does not affect the reported time. start = micros_start(); for (x = 0; x < w; x += r2) { for (y = 0; y < h; y += r2) { tft.drawCircle(x, y, radius, color); } } return micros() - start; } uint32_t testTriangles() { uint32_t start; int32_t n, i; int32_t cx = tft.width()/ 2 - 1; int32_t cy = tft.height() / 2 - 1; tft.fillScreen(TFT_BLACK); n = std::min(cx, cy); start = micros_start(); for (i = 0; i < n; i += 5) { tft.drawTriangle( cx , cy - i, // peak cx - i, cy + i, // bottom left cx + i, cy + i, // bottom right tft.color565(0, 0, i)); } return micros() - start; } uint32_t testFilledTriangles() { uint32_t start, t = 0; int32_t i; int32_t cx = tft.width() / 2 - 1; int32_t cy = tft.height() / 2 - 1; tft.fillScreen(TFT_BLACK); start = micros_start(); for (i = std::min(cx,cy); i > 10; i -= 5) { start = micros_start(); tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, tft.color565(0, i, i)); t += micros() - start; tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, tft.color565(i, i, 0)); } return t; } uint32_t testRoundRects() { uint32_t start; int32_t w, i, i2; int32_t cx = tft.width() / 2 - 1; int32_t cy = tft.height() / 2 - 1; tft.fillScreen(TFT_BLACK); w = std::min(tft.width(), tft.height()); start = micros_start(); for (i = 0; i < w; i += 6) { i2 = i / 2; tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0)); } return micros() - start; } uint32_t testFilledRoundRects() { uint32_t start; int32_t i, i2; int32_t cx = tft.width() / 2 - 1; int32_t cy = tft.height() / 2 - 1; tft.fillScreen(TFT_BLACK); start = micros_start(); for (i = std::min(tft.width(), tft.height()); i > 20; i -= 6) { i2 = i / 2; tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); } return micros() - start; } |
فیلم راه اندازی lovyan-gfx Arduino
انتخاب پروتکل spi بستگی به نوع میکروکنترلر دارد: esp32: cfg.spi_host =VSPI_HOST برای esp32-s3: cfg.spi_host = SPI2_HOST برای برای سرعت بیشتر، از spi سخت افزاری استفاده کردیم. این برنامه برای راه اندازی اولیه نمایشر ili9488 می باشد.بعد از راه اندازی ال سی دی باید این کتابخانه را به lvgl متصل کنیم و برای کانفیگ اولیه آماده کنیم. کتابخانه LVGL نیاز به یک کتابخانه راه اندازی ال سی دی دارد تا برنامه ها را اجرا کند. برای راه اندازی اولیه کتابخانه lvgl ابتدا برنامه زیر را آپلود کنید و در ادامه توضیحات، اعداد خروجی را برای کالیبره تاچ اسکرین ذخیره کنید.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
#define LGFX_USE_V1 #include <LovyanGFX.hpp> #include <algorithm> #include <lgfx/v1/platforms/esp32s3/Panel_RGB.hpp> #include <lgfx/v1/platforms/esp32s3/Bus_RGB.hpp> class LGFX : public lgfx::LGFX_Device { //lgfx::Panel_GC9A01 _panel_instance; //lgfx::Panel_GDEW0154M09 _panel_instance; //lgfx::Panel_HX8357B _panel_instance; //lgfx::Panel_HX8357D _panel_instance; //lgfx::Panel_ILI9163 _panel_instance; // lgfx::Panel_ILI9341 _panel_instance; //lgfx::Panel_ILI9342 _panel_instance; //lgfx::Panel_ILI9481 _panel_instance; //lgfx::Panel_ILI9486 _panel_instance; lgfx::Panel_ILI9488 _panel_instance; //lgfx::Panel_IT8951 _panel_instance; //lgfx::Panel_RA8875 _panel_instance; //lgfx::Panel_SH110x _panel_instance; // SH1106, SH1107 //lgfx::Panel_SSD1306 _panel_instance; //lgfx::Panel_SSD1327 _panel_instance; //lgfx::Panel_SSD1331 _panel_instance; //lgfx::Panel_SSD1351 _panel_instance; // SSD1351, SSD1357 //lgfx::Panel_SSD1963 _panel_instance; //lgfx::Panel_ST7735 _panel_instance; //lgfx::Panel_ST7735S _panel_instance; //lgfx::Panel_ST7789 _panel_instance; //lgfx::Panel_ST7796 _panel_instance; //lgfx::Bus_Parallel16 _bus_instance; lgfx::Light_PWM _light_instance; lgfx::Bus_SPI _bus_instance; // touch driver //lgfx::Touch_CST816S _touch_instance; // lgfx::Touch_FT5x06 _touch_instance; // FT5206, FT5306, FT5406, FT6206, FT6236, FT6336, FT6436 //lgfx::Touch_GSL1680E_800x480 _touch_instance; // GSL_1680E, 1688E, 2681B, 2682B //lgfx::Touch_GSL1680F_800x480 _touch_instance; //lgfx::Touch_GSL1680F_480x272 _touch_instance; //lgfx::Touch_GSLx680_320x320 _touch_instance; //lgfx::Touch_GT911 _touch_instance; //lgfx::Touch_STMPE610 _touch_instance; //lgfx::Touch_TT21xxx _touch_instance; // TT21100 lgfx::Touch_XPT2046 _touch_instance; public: LGFX(void) { { auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。 // SPIバスの設定 cfg.spi_host = VSPI_HOST; // 使用するSPIを選択 ESP32-S2,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST // ※ ESP-IDFバージョンアップに伴い、VSPI_HOST , HSPI_HOSTの記述は非推奨になるため、エラーが出る場合は代わりにSPI2_HOST , SPI3_HOSTを使用してください。 cfg.spi_mode = 0; // SPI通信モードを設定 (0 ~ 3) cfg.freq_write = 40000000; // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます) cfg.freq_read = 16000000; // 受信時のSPIクロック cfg.spi_3wire = true; // 受信をMOSIピンで行う場合はtrueを設定 cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定 cfg.dma_channel = SPI_DMA_CH_AUTO; // 使用するDMAチャンネルを設定 (0=DMA不使用 / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=自動設定) // ※ ESP-IDFバージョンアップに伴い、DMAチャンネルはSPI_DMA_CH_AUTO(自動設定)が推奨になりました。1ch,2chの指定は非推奨になります。 cfg.pin_sclk = 12; // SPIのSCLKピン番号を設定 cfg.pin_mosi = 11; // SPIのMOSIピン番号を設定 cfg.pin_miso = 13; // SPIのMISOピン番号を設定 (-1 = disable) cfg.pin_dc = 6; // SPIのD/Cピン番号を設定 (-1 = disable) _bus_instance.config(cfg); // 設定値をバスに反映します。 _panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。 } { // 表示パネル制御の設定を行います。 auto cfg = _panel_instance.config(); cfg.pin_cs = 4; // CS cfg.pin_rst = -1; // RST cfg.pin_busy = -1; // BUSY cfg.panel_width = 320; cfg.panel_height = 480; cfg.offset_x = 0; cfg.offset_y = 0; cfg.offset_rotation = 0; cfg.dummy_read_pixel = 8; cfg.dummy_read_bits = 1; cfg.readable = true; cfg.invert = false; cfg.rgb_order = false; cfg.dlen_16bit = false; // 16bit cfg.bus_shared = true; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います) cfg.memory_width = 320; cfg.memory_height = 480; _panel_instance.config(cfg); } { auto cfg = _touch_instance.config(); cfg.x_min = 0; cfg.x_max = 319; cfg.y_min = 0; cfg.y_max = 479; cfg.pin_int = -1; cfg.bus_shared = true; cfg.offset_rotation = 0; cfg.spi_host = SPI2_HOST; cfg.freq = 1000000; cfg.pin_sclk = 12; // SCLK cfg.pin_mosi = 11; // MOSI cfg.pin_miso = 13; // MISO cfg.pin_cs = 5; // CS _touch_instance.config(cfg); _panel_instance.setTouch(&_touch_instance); } setPanel(&_panel_instance); } }; LGFX display; unsigned long total = 0; unsigned long tn = 0; void setup() { Serial.begin(115200); display.init(); display.setTextSize((std::max(display.width(), display.height()) + 255) >> 8); if (display.touch()) { if (display.width() < display.height()) display.setRotation(display.getRotation() ^ 1); display.setTextDatum(textdatum_t::middle_center); display.drawString("touch the arrow marker.", display.width()>>1, display.height() >> 1); display.setTextDatum(textdatum_t::top_left); std::uint16_t fg = TFT_WHITE; std::uint16_t bg = TFT_BLACK; if (display.isEPD()) std::swap(fg, bg); uint16_t calibrationData[8]; display.calibrateTouch(calibrationData, fg, bg, std::max(display.width(), display.height()) >> 3); for(int i=0; i<8 ; i++){ Serial.println(calibrationData[i]); Serial.print(", "); } } display.fillScreen(TFT_BLACK); } uint32_t count = ~0; void loop(void) { display.startWrite(); display.setRotation(++count & 7); display.setColorDepth((count & 8) ? 16 : 24); display.setTextColor(TFT_WHITE); display.drawNumber(display.getRotation(), 16, 0); display.setTextColor(0xFF0000U); display.drawString("R", 30, 16); display.setTextColor(0x00FF00U); display.drawString("G", 40, 16); display.setTextColor(0x0000FFU); display.drawString("B", 50, 16); display.drawRect(30,30,display.width()-60,display.height()-60,count*7); display.drawFastHLine(0, 0, 10); display.endWrite(); int32_t x, y; if (display.getTouch(&x, &y)) { display.fillRect(x-2, y-2, 5, 5, count*7); } } |
بعد از آپلود برنامه، ابتدا چهار گوشه تصویر را لمس کرده تا اعداد خروجی در ترمینال آردوینو ظاهر شوند. این اعداد را ذخیره کرده تا برای راه اندازی اولین برنامه lvgl از آنها استفاده کنیم.برای مثال این اعداد:
|
1 |
3773 |
|
1 |
, 3804 |
|
1 |
, 3785 |
|
1 |
, 421 |
|
1 |
, 286 |
|
1 |
, 3808 |
|
1 |
, 548 |
|
1 |
, 270 |
بعد از دریافت این اعداد برنامه زیر را آپلود کرده و در قسمت caldata اعداد نمایشگر خود را وارد کنید.توجه داشته باشید که برای هر نمایشگر این اعداد متفاوت می باشد. اعداد بدست آمده را در برنامه زیر وارد کنید: قسمت SETUP آردوینو برای کتابخانه LVGL
اولین پروژه راه اندازی LVGL button lvgl در این برنامه یک دکمه در وسط صفحه ایجاد کردیم و در صورت انتخاب دکمه متغیر شروع به افزایش میکند.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
#include <Arduino.h> #include <lvgl.h> #define LGFX_USE_V1 #include <LovyanGFX.hpp> class LGFX : public lgfx::LGFX_Device { //lgfx::Panel_GC9A01 _panel_instance; //lgfx::Panel_GDEW0154M09 _panel_instance; //lgfx::Panel_HX8357B _panel_instance; //lgfx::Panel_HX8357D _panel_instance; //lgfx::Panel_ILI9163 _panel_instance; // lgfx::Panel_ILI9341 _panel_instance; //lgfx::Panel_ILI9342 _panel_instance; //lgfx::Panel_ILI9481 _panel_instance; //lgfx::Panel_ILI9486 _panel_instance; lgfx::Panel_ILI9488 _panel_instance; //lgfx::Panel_IT8951 _panel_instance; //lgfx::Panel_RA8875 _panel_instance; //lgfx::Panel_SH110x _panel_instance; // SH1106, SH1107 //lgfx::Panel_SSD1306 _panel_instance; //lgfx::Panel_SSD1327 _panel_instance; //lgfx::Panel_SSD1331 _panel_instance; //lgfx::Panel_SSD1351 _panel_instance; // SSD1351, SSD1357 //lgfx::Panel_SSD1963 _panel_instance; //lgfx::Panel_ST7735 _panel_instance; //lgfx::Panel_ST7735S _panel_instance; //lgfx::Panel_ST7789 _panel_instance; //lgfx::Panel_ST7796 _panel_instance; //lgfx::Bus_Parallel16 _bus_instance; lgfx::Light_PWM _light_instance; lgfx::Bus_SPI _bus_instance; // touch driver //lgfx::Touch_CST816S _touch_instance; // lgfx::Touch_FT5x06 _touch_instance; // FT5206, FT5306, FT5406, FT6206, FT6236, FT6336, FT6436 //lgfx::Touch_GSL1680E_800x480 _touch_instance; // GSL_1680E, 1688E, 2681B, 2682B //lgfx::Touch_GSL1680F_800x480 _touch_instance; //lgfx::Touch_GSL1680F_480x272 _touch_instance; //lgfx::Touch_GSLx680_320x320 _touch_instance; //lgfx::Touch_GT911 _touch_instance; //lgfx::Touch_STMPE610 _touch_instance; //lgfx::Touch_TT21xxx _touch_instance; // TT21100 lgfx::Touch_XPT2046 _touch_instance; public: LGFX(void) { { auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。 // SPIバスの設定 cfg.spi_host = VSPI_HOST; // 使用するSPIを選択 ESP32-S2,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST // ※ ESP-IDFバージョンアップに伴い、VSPI_HOST , HSPI_HOSTの記述は非推奨になるため、エラーが出る場合は代わりにSPI2_HOST , SPI3_HOSTを使用してください。 cfg.spi_mode = 0; // SPI通信モードを設定 (0 ~ 3) cfg.freq_write = 40000000; // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます) cfg.freq_read = 16000000; // 受信時のSPIクロック cfg.spi_3wire = true; // 受信をMOSIピンで行う場合はtrueを設定 cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定 cfg.dma_channel = SPI_DMA_CH_AUTO; // 使用するDMAチャンネルを設定 (0=DMA不使用 / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=自動設定) // ※ ESP-IDFバージョンアップに伴い、DMAチャンネルはSPI_DMA_CH_AUTO(自動設定)が推奨になりました。1ch,2chの指定は非推奨になります。 cfg.pin_sclk = 12; // SPIのSCLKピン番号を設定 cfg.pin_mosi = 11; // SPIのMOSIピン番号を設定 cfg.pin_miso = 13; // SPIのMISOピン番号を設定 (-1 = disable) cfg.pin_dc = 6; // SPIのD/Cピン番号を設定 (-1 = disable) _bus_instance.config(cfg); // 設定値をバスに反映します。 _panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。 } { // 表示パネル制御の設定を行います。 auto cfg = _panel_instance.config(); cfg.pin_cs = 4; // CS cfg.pin_rst = -1; // RST cfg.pin_busy = -1; // BUSY cfg.panel_width = 320; cfg.panel_height = 480; cfg.offset_x = 0; cfg.offset_y = 0; cfg.offset_rotation = 0; cfg.dummy_read_pixel = 8; cfg.dummy_read_bits = 1; cfg.readable = true; cfg.invert = false; cfg.rgb_order = false; cfg.dlen_16bit = false; // 16bit cfg.bus_shared = true; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います) cfg.memory_width = 320; cfg.memory_height = 480; _panel_instance.config(cfg); } { auto cfg = _touch_instance.config(); cfg.x_min = 0; cfg.x_max = 319; cfg.y_min = 0; cfg.y_max = 479; cfg.pin_int = -1; cfg.bus_shared = true; cfg.offset_rotation = 0; cfg.spi_host = SPI2_HOST; cfg.freq = 1000000; cfg.pin_sclk = 12; // SCLK cfg.pin_mosi = 11; // MOSI cfg.pin_miso = 13; // MISO cfg.pin_cs = 5; // CS _touch_instance.config(cfg); _panel_instance.setTouch(&_touch_instance); } setPanel(&_panel_instance); } }; LGFX tft; /*Change to your screen resolution*/ static const uint16_t screenWidth = 480; static const uint16_t screenHeight = 320; static lv_disp_draw_buf_t draw_buf; static lv_color_t buf[screenWidth * screenHeight / 10]; /* Display flushing */ void my_disp_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p) { uint32_t w = (area->x2 - area->x1 + 1); uint32_t h = (area->y2 - area->y1 + 1); tft.startWrite(); tft.setAddrWindow(area->x1, area->y1, w, h); //tft.pushColors((uint16_t *)&color_p->full, w * h, true); tft.writePixels((lgfx::rgb565_t *)&color_p->full, w * h); tft.endWrite(); lv_disp_flush_ready(disp_drv); } /*Read the touchpad*/ void my_touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data) { uint16_t touchX, touchY; bool touched = tft.getTouch(&touchX, &touchY); if (!touched) { data->state = LV_INDEV_STATE_REL; } else { data->state = LV_INDEV_STATE_PR; /*Set the coordinates*/ data->point.x = touchX; data->point.y = touchY; Serial.print("Data x "); Serial.println(touchX); Serial.print("Data y "); Serial.println(touchY); } } void setup() { Serial.begin(115200); /* prepare for possible serial debug */ String LVGL_Arduino = "Hello Arduino! "; LVGL_Arduino += String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch(); Serial.println(LVGL_Arduino); Serial.println("I am LVGL_Arduino"); tft.begin(); /* TFT init */ tft.setRotation(3); /* Landscape orientation, flipped */ uint16_t calData[] = { 3779, 3907, 3839, 304, 318, 3879, 329, 283 }; tft.setTouchCalibrate(calData); lv_init(); lv_disp_draw_buf_init(&draw_buf, buf, NULL, screenWidth * screenHeight / 10); /*Initialize the display*/ static lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); /*Change the following line to your display resolution*/ disp_drv.hor_res = screenWidth; disp_drv.ver_res = screenHeight; disp_drv.flush_cb = my_disp_flush; disp_drv.draw_buf = &draw_buf; lv_disp_drv_register(&disp_drv); /*Initialize the (dummy) input device driver*/ static lv_indev_drv_t indev_drv; lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_POINTER; indev_drv.read_cb = my_touchpad_read; lv_indev_drv_register(&indev_drv); lv_example_get_started_1(); } void loop() { lv_timer_handler(); /* let the GUI do its work */ delay(5); } static void btn_event_cb(lv_event_t *e) { lv_event_code_t code = lv_event_get_code(e); lv_obj_t *btn = lv_event_get_target(e); if (code == LV_EVENT_CLICKED) { static uint8_t cnt = 0; cnt++; /*Get the first child of the button which is the label and change its text*/ lv_obj_t *label = lv_obj_get_child(btn, 0); lv_label_set_text_fmt(label, "Button: %d", cnt); } } /** * Create a button with a label and react on click event. */ void lv_example_get_started_1(void) { lv_obj_t *btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/ //lv_obj_set_pos(btn, 10, 10); /*Set its position*/ lv_obj_set_size(btn, 120, 50); /*Set its size*/ lv_obj_align(btn,LV_ALIGN_CENTER,0,0); lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/ lv_obj_t *label = lv_label_create(btn); /*Add a label to the button*/ lv_label_set_text(label, "Button"); /*Set the labels text*/ lv_obj_center(label); } |
اولین پروژه راه اندازی lvgl ساخت دکمه با lvgl توضیح برنامه: ————————————————————————————————————————————————————————
تابع اول:
|
1 2 3 4 5 6 7 8 9 10 11 |
/* Display flushing */ void my_disp_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p) { uint32_t w = (area->x2 - area->x1 + 1); uint32_t h = (area->y2 - area->y1 + 1); tft.startWrite(); tft.setAddrWindow(area->x1, area->y1, w, h); //tft.pushColors((uint16_t *)&color_p->full, w * h, true); tft.writePixels((lgfx::rgb565_t *)&color_p->full, w * h); tft.endWrite(); lv_disp_flush_ready(disp_drv); } |
تابع دوم:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/*Read the touchpad*/ void my_touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data) { uint16_t touchX, touchY; bool touched = tft.getTouch(&touchX, &touchY); if (!touched) { data->state = LV_INDEV_STATE_REL; } else { data->state = LV_INDEV_STATE_PR; /*Set the coordinates*/ data->point.x = touchX; data->point.y = touchY; Serial.print("Data x "); Serial.println(touchX); Serial.print("Data y "); Serial.println(touchY); } } |
برای خواندن ورودی تاچ می باشد ————————————————————————————————————————————————————————
|
1 2 3 4 5 6 7 8 9 10 |
void lv_example_get_started_1(void) { lv_obj_t *btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/ //lv_obj_set_pos(btn, 10, 10); /*Set its position*/ lv_obj_set_size(btn, 120, 50); /*Set its size*/ lv_obj_align(btn,LV_ALIGN_CENTER,0,0); lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/ lv_obj_t *label = lv_label_create(btn); /*Add a label to the button*/ lv_label_set_text(label, "Button"); /*Set the labels text*/ lv_obj_center(label); } |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
static void btn_event_cb(lv_event_t *e) { lv_event_code_t code = lv_event_get_code(e); lv_obj_t *btn = lv_event_get_target(e); if (code == LV_EVENT_CLICKED) { static uint8_t cnt = 0; cnt++; /*Get the first child of the button which is the label and change its text*/ lv_obj_t *label = lv_obj_get_child(btn, 0); lv_label_set_text_fmt(label, "Button: %d", cnt); } } |
این تابع برای اجرای فرمان لمس دکمه می باشد که در صورت لمس دکمه به متغیر اضافه میشود.
ادامه آموزش(جلسه دوم)
دانلود فایل ها»
دانلود کتابخانه Lovyan-gfx
دانلود کتابخانه LVGL (ورژن 8.3.11)
مشاهده محصولات شرکت پاوان

ردیاب خودرو

کنترل هوشمند پمپ آب

ردیاب جیبی
