// Use only core 1 for demo purposes #if CONFIG_FREERTOS_UNICORE static const BaseType_t app_cpu = 0; #else static const BaseType_t app_cpu = 1; #endif #include #include #include // Pin Interface RA8875 (SPI Bus cannot be combined with other, refer to the product information.) #define RA8875_WAIT 3 // Busy Pin #define RA8875_SCLK 2 // RA8875 SCLK #define RA8875_MISO 8 // RA8875 MISO #define RA8875_MOSI 9 // RA8875 MOSI #define RA8875_CS 10 // RA8875 Chip Selector #define RA8875_INT 18 // RA8875 Touch Interrupt #define RA8875_RST 19 // RA8875 Reset Panel TFT_RA8875 tft(RA8875_WAIT, RA8875_SCLK, RA8875_MISO, RA8875_MOSI, RA8875_CS, RA8875_INT, RA8875_RST); /*Change to your screen resolution*/ static const uint16_t screenWidth = 800; static const uint16_t screenHeight = 480; static lv_disp_draw_buf_t draw_buf; static lv_color_t buf[ screenWidth * 40 ]; static lv_color_t buf2[ screenWidth * 40 ]; // FreeRTOS Setting with Binary Semaphore static SemaphoreHandle_t display_sem; // Timer const unsigned long eventInterval = 1000; unsigned long previousTime = 0; /* Display buffer to TFT */ void my_disp_flush( lv_disp_drv_t *disp, 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.drawPixels(area->x1, area->y1, ( uint16_t * )&color_p->full, w * h); int32_t row_count = (area->x2 - area->x1 + 1); uint16_t color_row[screenWidth]; for (int y = area->y1; y <= area->y2; y++) { for (int x=0; xfull; } tft.drawPixels(area->x1, y, color_row, row_count); } lv_disp_flush_ready( disp ); } /*Read the touchpad*/ void my_touchpad_read( lv_indev_drv_t * indev_driver, lv_indev_data_t * data ) { uint16_t touchX, touchY; tft.readTouch(&touchX, &touchY); if(!tft.isTouched()) { data->state = LV_INDEV_STATE_REL; } else { data->state = LV_INDEV_STATE_PR; /*Set the coordinates*/ data->point.x = touchX; data->point.y = touchY; printf( "Data (x, y) = (%d, %d)\n", touchX, touchY); } } void setup() { Serial.begin(115200); delay(200); // Init display first - default screen is 800x480, change in the RA8875_SPI.h if (!tft.init()) { printf("RA8875 not found!\n"); while(1); } tft.displayOn(); tft.enableGPIOX(); tft.enablePWM1(RA8875_PWM_CLK_DIV4096); tft.setPWM1DutyCycle(255); tft.enableTouch(); display_sem = xSemaphoreCreateBinary(); xSemaphoreGive(display_sem); BaseType_t guiTask = xTaskCreatePinnedToCore( guiFunction, "Handle LVGL", 80000, NULL, 1, NULL, app_cpu); } void loop() { vTaskDelay(100/portTICK_PERIOD_MS); } void guiFunction(void* parameter) { lv_init(); lv_disp_draw_buf_init( &draw_buf, buf, buf2, screenWidth * 40 ); /*Initialize the display*/ static lv_disp_drv_t disp_drv; lv_disp_drv_init( &disp_drv ); 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_demo_widgets(); // lv_demo_music(); lv_demo_stress(); for(;;){ vTaskDelay(pdMS_TO_TICKS(10)); /* Try to take the semaphore, call lvgl related function on success */ if (pdTRUE == xSemaphoreTake(display_sem, portMAX_DELAY)) { lv_task_handler(); xSemaphoreGive(display_sem); } } }