/*************************************
 * SCK     --> D13
 * MOSI    --> D11
 * LCD_RST     --> D8
 * LCD_DC      --> D9  
 * LCD_CS      --> D10 
 * LCD_BL      --> D6
 * TP_RST      --> D4 
 * TP_SCL      --> A5 
 * TP_SDA      --> A4
 * TP_INT      --> D2 

**************************************/
/******************************
when set DFT_SCAN_DIR to U2D_R2L:
 * 1------------> x (1~320) 
 * |
 * |
 * |
 * |
 * y (1~240)
 * */

#include <SPI.h>
#include <Wire.h>
#include "lcd_2inch.h"
#include "lcd_touch.h"
#include "lcd_gui.h"
#include "fonts.h"

void setup()
{
    Serial.begin(115200);
    Serial.println(F("2Inch LCD System Init...")); 

    Serial.println(F("Lcd Init..."));
    Lcd_Gpio_Init();

    Serial.println(F("Touch Init..."));
    TP_Init();
    
    Serial.println(F("LCD Init...")); 
    Lcd_Init();

    LCD_Display_Dir(5); 
    LCD_Clear(WHITE);

    Serial.println(F("Drawing Demo..."));

    Gui_draw_line(10, 5, 10, 235, RED, 2, SOLID);
    Gui_draw_line(20, 5, 20, 235, ORANGE, 2, SOLID);
    Gui_draw_line(30, 5, 30, 235, YELLOW, 2, SOLID);
    Gui_draw_line(40, 5, 40, 235, GREEN, 2, SOLID);

    Gui_draw_line(60, 10, 310, 10, BLUE, 2, SOLID);
    Gui_draw_line(60, 25, 310, 25, PURPLE, 2, DOTTED);

    Gui_draw_rectangle(60, 50, 100, 90, RED, 1, EMPTY);
    Gui_draw_rectangle(110, 50, 150, 90, GREEN, 1, EMPTY);
    Gui_draw_rectangle(160, 50, 200, 90, BLUE, 1, EMPTY);

    Gui_fill_color(60, 100, 100, 140, RED);
    Gui_fill_color(110, 100, 150, 140, GREEN);
    Gui_fill_color(160, 100, 200, 140, BLUE);

    Gui_draw_circle(260, 95, 20, MAGENTA, 1, FULL); // Filled circle
    Gui_draw_circle(260, 95, 30, BLACK, 1, EMPTY);  // Hollow circle

    Gui_draw_str(60, 160, "SEENGREAT", &Font24, BLACK, WHITE);
    Gui_draw_str(60, 195, "2.0 inch LCD", &Font16, RED, WHITE);
    Gui_draw_str(200, 195, "Touch Test", &Font16, BLUE, WHITE);

    delay(2000); 
    LCD_Clear(WHITE); 
    Load_Touch_Draw(); 
    Serial.println(F("Start Touch Loop..."));
}

void loop()
{
    TP_test();
}
