#include #include #include const int XP = 12, XM = 15, YP = 33, YM = 13; const int TS_LEFT = 167, TS_RT = 927, TS_TOP = 988, TS_BOT = 105; #define MINPRESSURE 1 #define MAXPRESSURE 1000 TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); TSPoint tp; TFT_eSPI tft = TFT_eSPI(); static const uint32_t screenWidth = 480; static const uint32_t screenHeight = 320; static void disp_init(void) { tft.init(); tft.setRotation(1); } /* Display flushing */ static void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) { uint64_t w = (area->x2 - area->x1 + 1); uint64_t h = (area->y2 - area->y1 + 1); tft.startWrite(); tft.setAddrWindow(area->x1, area->y1, w, h); tft.pushColors(&color_p->full, w * h, true); tft.endWrite(); lv_disp_flush_ready(disp); } /*OPTIONAL: GPU INTERFACE*/ #if LV_USE_GPU /*If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color*/ static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width, const lv_area_t * fill_area, lv_color_t color) { /*It's an example code which should be done by your GPU*/ int32_t x, y; dest_buf += dest_width * fill_area->y1; /*Go to the first line*/ for (y = fill_area->y1; y <= fill_area->y2; y++) { for (x = fill_area->x1; x <= fill_area->x2; x++) { dest_buf[x] = color; } dest_buf += dest_width; /*Go to the next line*/ } } #endif /*LV_USE_GPU*/ /*Read the touchpad*/ static void my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) { uint64_t touchX, touchY; tp = ts.getPoint(); pinMode(XM, OUTPUT); pinMode(YP, OUTPUT); if (tp.z > MINPRESSURE && tp.z < MAXPRESSURE) { touchX = map(tp.y, TS_TOP, TS_BOT, 0, tft.width()); touchY = map(tp.x, TS_RT, TS_LEFT, 0, tft.height()); if ((touchX) || (touchY)) { data->state = LV_INDEV_STATE_PR; data->point.x = touchX; data->point.y = touchY; } else { data->point.x = touchX; data->point.y = touchY; data->state = LV_INDEV_STATE_REL; } } } void setup() { // put your setup code here, to run once: Serial.begin(115200); lv_init(); disp_init(); static lv_disp_draw_buf_t draw_buf; static lv_color_t buf[screenWidth * 40]; lv_disp_draw_buf_init(&draw_buf, buf, NULL, screenWidth * 40); /*Initialize the display*/ static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/ lv_disp_drv_init(&disp_drv); /*Basic initialization*/ /*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; #if LV_USE_GPU /*Fill a memory array with a color*/ disp_drv.gpu_fill_cb = gpu_fill; #endif lv_disp_drv_register(&disp_drv); /*Initialize the (dummy) input device driver*/ 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_obj_t * spinner = lv_spinner_create(lv_scr_act(), 5, 50); lv_obj_set_size(spinner, 100, 100); lv_obj_align(spinner, LV_ALIGN_CENTER, 0, 0); } void loop() { // put your main code here, to run repeatedly: lv_timer_handler(); delay(5); }