Advertisement
Guest User

Untitled

a guest
Jan 31st, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.05 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "ZLVSetup.h"
  4. #include "ZLVTouch.h"
  5. #include <Arduino.h>
  6. #include <lvgl.h>
  7. #include <TFT_eSPI.h>
  8.  
  9. static void ReadTouch(lv_indev_drv_t* indev_driver, lv_indev_data_t* data);
  10. static void FlushDisplay(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p);
  11.  
  12. static lv_disp_draw_buf_t draw_buffer;
  13. static lv_color_t buffer[width * 10];
  14.  
  15. String LVGL_Version;
  16.  
  17. TFT_eSPI tft = TFT_eSPI(width, height);
  18.  
  19. void ZLVFlushDisplay(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p)
  20. {
  21.     uint32_t w = ( area->x2 - area->x1 + 1 );
  22.     uint32_t h = ( area->y2 - area->y1 + 1 );
  23.  
  24.     tft.startWrite();
  25.     tft.setAddrWindow(area->x1, area->y1, w, h );
  26.     tft.pushColors((uint16_t*) &color_p->full, w * h, true);
  27.     tft.endWrite();
  28.  
  29.     lv_disp_flush_ready(disp);
  30. }
  31.  
  32. void ZLVCreatePanel()
  33. {
  34.     LVGL_Version += "LVGL " + String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
  35.  
  36.     lv_init();
  37.  
  38.     tft.begin();/* TFT init */
  39.     //tft.setRotation( 3 ); /* Landscape orientation, flipped */
  40.     /*
  41.     The rotation parameter can be 0, 1, 2 or 3.
  42.     For displays that are part of an Arduino shield, rotation value 0 sets the display to a portrait (tall) mode.
  43.     Rotation value 2 is also a portrait mode. Rotation 1 is landscape (wide) mode, while rotation 3 is also landscape.
  44.     */
  45.     tft.setRotation( 0 );
  46.  
  47.     lv_disp_draw_buf_init(&draw_buffer, buffer, NULL, width * 10);
  48.  
  49.     /*Initialize the display*/
  50.     static lv_disp_drv_t disp_drv;
  51.     lv_disp_drv_init( &disp_drv );
  52.  
  53.     /*Change the following line to your display resolution*/
  54.     disp_drv.hor_res = width;
  55.     disp_drv.ver_res = height;
  56.     disp_drv.flush_cb = ZLVFlushDisplay;
  57.     disp_drv.draw_buf = &draw_buffer;
  58.     lv_disp_drv_register( &disp_drv );
  59.  
  60.     /*Initialize the (dummy) input device driver*/
  61.     static lv_indev_drv_t indev_drv;
  62.     lv_indev_drv_init( &indev_drv );
  63.     indev_drv.type = LV_INDEV_TYPE_POINTER;
  64.     indev_drv.read_cb = ZLVReadTouch;
  65.     lv_indev_drv_register( &indev_drv );
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement