125 lines
3.1 KiB
Arduino
125 lines
3.1 KiB
Arduino
|
|
//Arduino-TFT_eSPI board-template main routine. There's a TFT_eSPI create+flush driver already in LVGL-9.1 but we create our own here for more control (like e.g. 16-bit color swap).
|
||
|
|
|
||
|
|
#define DWIDTH 128
|
||
|
|
#define DHEIGHT 160
|
||
|
|
|
||
|
|
#define SCREENBUFFERSIZE DWIDTH*DHEIGHT
|
||
|
|
|
||
|
|
#include <lvgl.h>
|
||
|
|
#include <TFT_eSPI.h>
|
||
|
|
#include <ui.h>
|
||
|
|
|
||
|
|
TFT_eSPI tft = TFT_eSPI();
|
||
|
|
|
||
|
|
uint16_t *buf = (uint16_t*)calloc(SCREENBUFFERSIZE * 3, sizeof(uint16_t));
|
||
|
|
|
||
|
|
#if LV_USE_LOG != 0
|
||
|
|
/* Serial debugging */
|
||
|
|
void my_print(const char * buf)
|
||
|
|
{
|
||
|
|
Serial.printf(buf);
|
||
|
|
Serial.flush();
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
/* Display flushing */
|
||
|
|
void my_disp_flush (lv_display_t *disp, const lv_area_t *area, uint8_t *pixelmap)
|
||
|
|
{
|
||
|
|
lv_draw_sw_rgb565_swap( pixelmap, SCREENBUFFERSIZE );
|
||
|
|
tft.pushImageDMA(0, 0, DHEIGHT, DWIDTH, (uint16_t*)pixelmap); // sprPtr
|
||
|
|
lv_disp_flush_ready( disp );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/*Read the touchpad*/
|
||
|
|
void my_touchpad_read (lv_indev_t * indev_driver, lv_indev_data_t * data)
|
||
|
|
{
|
||
|
|
uint16_t touchX = 0, touchY = 0;
|
||
|
|
|
||
|
|
bool touched = false;//tft.getTouch( &touchX, &touchY, 600 );
|
||
|
|
|
||
|
|
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 );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/*Set tick routine needed for LVGL internal timings*/
|
||
|
|
static uint32_t my_tick_get_cb (void) { return millis(); }
|
||
|
|
|
||
|
|
|
||
|
|
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" );
|
||
|
|
|
||
|
|
lv_init();
|
||
|
|
|
||
|
|
#if LV_USE_LOG != 0
|
||
|
|
lv_log_register_print_cb( my_print ); /* register print function for debugging */
|
||
|
|
#endif
|
||
|
|
|
||
|
|
tft.begin();
|
||
|
|
tft.initDMA();
|
||
|
|
tft.setRotation( 3 ); /* Landscape orientation, flipped */
|
||
|
|
|
||
|
|
//sprPtr = (uint16_t*)spr.createSprite(DWIDTH, DHEIGHT);
|
||
|
|
//spr.setViewport(-128,-160, DWIDTH, DHEIGHT);
|
||
|
|
|
||
|
|
static lv_disp_t* disp;
|
||
|
|
disp = lv_display_create( DHEIGHT, DWIDTH );
|
||
|
|
|
||
|
|
lv_display_set_buffers( disp, buf, NULL, SCREENBUFFERSIZE*sizeof(uint16_t)*3, LV_DISPLAY_RENDER_MODE_FULL );
|
||
|
|
|
||
|
|
lv_display_set_flush_cb( disp, my_disp_flush );
|
||
|
|
|
||
|
|
static lv_indev_t* indev;
|
||
|
|
indev = lv_indev_create();
|
||
|
|
lv_indev_set_type( indev, LV_INDEV_TYPE_POINTER );
|
||
|
|
lv_indev_set_read_cb( indev, my_touchpad_read );
|
||
|
|
|
||
|
|
lv_tick_set_cb( my_tick_get_cb );
|
||
|
|
|
||
|
|
ui_init();
|
||
|
|
|
||
|
|
tft.startWrite();
|
||
|
|
|
||
|
|
Serial.println( "Setup done" );
|
||
|
|
}
|
||
|
|
|
||
|
|
int counter = 0;
|
||
|
|
|
||
|
|
void loop ()
|
||
|
|
{
|
||
|
|
|
||
|
|
if(counter == 500) lv_screen_load_anim(ui_Screen2, LV_SCR_LOAD_ANIM_MOVE_LEFT, 100, 1000, false);
|
||
|
|
if(counter == 1000) lv_screen_load_anim(ui_Screen3, LV_SCR_LOAD_ANIM_MOVE_LEFT, 100, 1000, false);
|
||
|
|
if(counter == 1500) lv_screen_load_anim(ui_Screen1, LV_SCR_LOAD_ANIM_MOVE_LEFT, 100, 1000, false);
|
||
|
|
|
||
|
|
if(counter == 1500) counter = 0;
|
||
|
|
|
||
|
|
counter++;
|
||
|
|
|
||
|
|
lv_timer_handler(); /* let the GUI do its work */
|
||
|
|
delay(5);
|
||
|
|
}
|