#include "lcd_2inch.h"
#include "lcd_touch.h"
#include "lcd_gui.h"
#include "image.h"
/*************************************
 * LCD_SCK     --> 48
 * LCD_MOSI    --> 47
 * LCD_RST     --> 12
 * LCD_DC      --> 13  
 * LCD_CS      --> 14 
 * LCD_BL      --> 38
 * TP_RST      --> 6 
 * TP_SCL      --> 4 
 * TP_SDA      --> 5
 * TP_INT      --> 7  

**************************************/
/******************************
 * 1------------> x (1~320) 
 * |
 * |
 * |
 * |
 * y (1~240)
 * */

void setup()
{
    Serial.begin(115200);
    Serial.println("ESP32-S3 LCD Touch Test...");

    // Hardware initialization
    SPI.begin(LCD_SCK, MISO_PIN, LCD_MOSI, LCD_CS);
    SPI.beginTransaction(SPISettings(60000000, MSBFIRST, SPI_MODE0));
    SPI.endTransaction(); 

    Lcd_Init(); 
    LCD_Clear(RED);
    delay(1000);
    LCD_Clear(GREEN);
    delay(1000);
    LCD_Clear(BLUE);
    delay(1000);
    LCD_Clear(WHITE);
    LCD_ShowFullScreenImage(gImage_cat);
    delay(1000);
    LCD_Clear(WHITE);
    Gui_draw_point(30, 20, YELLOW, 18);
    Gui_draw_point(30, 20, BRED, 18);
    Gui_draw_line(10, 120, 320, 120, RED, 2, SOLID);
    Gui_draw_line(160, 1, 160, 240, GRAY, 2, SOLID);
    Gui_draw_rectangle(170, 160, 200, 200, BLUE, 1, EMPTY);
    Gui_draw_rectangle(200, 180, 270, 220, MAGENTA, 1, FULL);
    Gui_draw_circle(80, 80, 20, GBLUE,1, EMPTY);
    Gui_draw_circle(40, 160, 15, GREEN,1, FULL);
    delay(1000);
    LCD_Clear(WHITE);
    Gui_draw_str(10, 10, "9876543210", &Font24, BLACK, WHITE);
    Gui_draw_str(10, 40, "seengreat!", &Font24, BLUE, WHITE);
    Gui_draw_str(10, 70, "SEENGREAT!", &Font24, RED, WHITE);
    delay(1000);

    TP_Init();  // Initialize touch
    Load_Draw_Board();
}

void loop()
{
    TP_Test();
}