#ifndef __LCD_2INCH_H
#define __LCD_2INCH_H

#include <SPI.h>
#include <Wire.h>
#include <Arduino.h>

#define LCD_W   240 
#define LCD_H   320 

#define LCD_SCK  48
#define LCD_MOSI 47
#define MISO_PIN -1 

#define LCD_CS   14
#define LCD_DC   13
#define LCD_RST  12
#define LCD_BL   38

#define TP_SCL   4
#define TP_SDA   5
#define TP_RST   6
#define TP_INT   7

#define LCD_CS_0    digitalWrite(LCD_CS, LOW)
#define LCD_CS_1    digitalWrite(LCD_CS, HIGH)

#define LCD_RST_0   digitalWrite(LCD_RST, LOW)
#define LCD_RST_1   digitalWrite(LCD_RST, HIGH)

#define LCD_DC_0    digitalWrite(LCD_DC, LOW)
#define LCD_DC_1    digitalWrite(LCD_DC, HIGH)

#define LCD_BL_0    digitalWrite(LCD_BL, LOW)
#define LCD_BL_1    digitalWrite(LCD_BL, HIGH)

// Common color definitions in RGB565 format
#define WHITE            0xFFFF
#define BLACK            0x0000
#define BLUE             0x001F
#define BRED             0XF81F
#define GRED             0XFFE0
#define GBLUE            0X07FF
#define RED              0xF800
#define MAGENTA          0xF81F
#define GREEN            0x07E0
#define CYAN             0x7FFF
#define YELLOW           0xFFE0
#define BROWN            0XBC40
#define BRRED            0XFC07
#define GRAY             0X8430

#define BACKGROUND_COLOR   WHITE

// LCD device structure
typedef struct
{
    uint16_t width;
    uint16_t height;
    uint16_t id;
    uint8_t  dir;
    uint16_t wramcmd;  // Write RAM command
    uint16_t setxcmd;  // Set X coordinate command
    uint16_t setycmd;  // Set Y coordinate command
} _lcd_dev;

extern _lcd_dev lcddev;

void Lcd_Init(void);
void LCD_Clear(uint16_t color);
void LCD_Set_Cursor(uint16_t x, uint16_t y);
void Draw_Point(uint16_t x, uint16_t y, uint16_t color);
void Lcd_Gpio_Init(void);
void Spi_write_cmd(uint8_t data);
void Spi_write_data(uint8_t data);
void Spi_write_word(uint16_t data);
void Gui_fill_color(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
void LCD_ShowFullScreenImage(const unsigned char *img);
#endif