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

lv_test_init.c (2510B)

      1 
      2 #if LV_BUILD_TEST
      3 #include "lv_test_init.h"
      4 #include "lv_test_indev.h"
      5 #include <sys/time.h>
      6 #include <stdio.h>
      7 #include <stdlib.h>
      8 
      9 #define HOR_RES 800
     10 #define VER_RES 480
     11 
     12 static void hal_init(void);
     13 static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
     14 
     15 lv_indev_t * lv_test_mouse_indev;
     16 lv_indev_t * lv_test_keypad_indev;
     17 lv_indev_t * lv_test_encoder_indev;
     18 
     19 lv_color_t test_fb[HOR_RES * VER_RES];
     20 static lv_color_t disp_buf1[HOR_RES * VER_RES];
     21 
     22 void lv_test_init(void)
     23 {
     24     lv_init();
     25     hal_init();
     26 }
     27 
     28 void lv_test_deinit(void)
     29 {
     30     lv_mem_deinit();
     31 }
     32 
     33 static void hal_init(void)
     34 {
     35     static lv_disp_draw_buf_t draw_buf;
     36 
     37     lv_disp_draw_buf_init(&draw_buf, disp_buf1, NULL, HOR_RES * VER_RES);
     38 
     39     static lv_disp_drv_t disp_drv;
     40     lv_disp_drv_init(&disp_drv);
     41     disp_drv.draw_buf = &draw_buf;
     42     disp_drv.flush_cb = dummy_flush_cb;
     43     disp_drv.hor_res = HOR_RES;
     44     disp_drv.ver_res = VER_RES;
     45     lv_disp_drv_register(&disp_drv);
     46 
     47     static lv_indev_drv_t indev_mouse_drv;
     48     lv_indev_drv_init(&indev_mouse_drv);
     49     indev_mouse_drv.type = LV_INDEV_TYPE_POINTER;
     50     indev_mouse_drv.read_cb = lv_test_mouse_read_cb;
     51     lv_test_mouse_indev = lv_indev_drv_register(&indev_mouse_drv);
     52 
     53     static lv_indev_drv_t indev_keypad_drv;
     54     lv_indev_drv_init(&indev_keypad_drv);
     55     indev_keypad_drv.type = LV_INDEV_TYPE_KEYPAD;
     56     indev_keypad_drv.read_cb = lv_test_keypad_read_cb;
     57     lv_test_keypad_indev = lv_indev_drv_register(&indev_keypad_drv);
     58 
     59     static lv_indev_drv_t indev_encoder_drv;
     60     lv_indev_drv_init(&indev_encoder_drv);
     61     indev_encoder_drv.type = LV_INDEV_TYPE_ENCODER;
     62     indev_encoder_drv.read_cb = lv_test_encoder_read_cb;
     63     lv_test_encoder_indev = lv_indev_drv_register(&indev_encoder_drv);
     64 }
     65 
     66 static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
     67 {
     68     LV_UNUSED(area);
     69     LV_UNUSED(color_p);
     70 
     71     memcpy(test_fb, color_p, lv_area_get_size(area) * sizeof(lv_color_t));
     72 
     73     lv_disp_flush_ready(disp_drv);
     74 }
     75 
     76 uint32_t custom_tick_get(void)
     77 {
     78     static uint64_t start_ms = 0;
     79     if(start_ms == 0) {
     80         struct timeval tv_start;
     81         gettimeofday(&tv_start, NULL);
     82         start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
     83     }
     84 
     85     struct timeval tv_now;
     86     gettimeofday(&tv_now, NULL);
     87     uint64_t now_ms;
     88     now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;
     89 
     90     uint32_t time_ms = now_ms - start_ms;
     91     return time_ms;
     92 }
     93 
     94 #endif