#ifndef TM_ILI9341_H
#define TM_ILI9341_H 130

#include "lab.h"
#include "main.h"
#include "tm_stm32f4_fonts.h"
#include "img.h"

/* LCD settings */
#define ILI9341_WIDTH        240
#define ILI9341_HEIGHT       320
#define ILI9341_PIXEL        76800

/* Colors */
#define COLOR_WHITE			0xFFFF
#define COLOR_BLACK			0x0000
#define COLOR_RED       0xF800
#define COLOR_GREEN			0x07E0
#define COLOR_GREEN2		0xB723
#define COLOR_BLUE			0x001F
#define COLOR_BLUE2			0x051D
#define COLOR_YELLOW		0xFFE0
#define COLOR_ORANGE		0xFBE4
#define COLOR_CYAN			0x07FF
#define COLOR_MAGENTA		0xA254
#define COLOR_GRAY			0x7BEF
#define COLOR_BROWN			0xBBCA
#define COLOR_BACKGRAUND 0x8F9E

/* Transparent background, only for strings and chars */
#define TRANSPARENT			0x80000000

typedef enum {
	TM_SPI_DataSize_8b, /*!< SPI in 8-bits mode */
	TM_SPI_DataSize_16b /*!< SPI in 16-bits mode */        
} TM_SPI_DataSize_t;

typedef enum {
	TM_ILI9341_Orientation_Portrait_1,  /*!< Portrait orientation mode 1 */
	TM_ILI9341_Orientation_Portrait_2,  /*!< Portrait orientation mode 2 */
	TM_ILI9341_Orientation_Landscape_1, /*!< Landscape orientation mode 1 */
	TM_ILI9341_Orientation_Landscape_2  /*!< Landscape orientation mode 2 */
} TM_ILI9341_Orientation_t;

void TM_ILI9341_Init(void);
void TM_ILI9341_DrawPixel(uint16_t x, uint16_t y, uint32_t color);
void TM_ILI9341_Fill(uint32_t color);
void TM_ILI9341_Rotate(TM_ILI9341_Orientation_t orientation);
void TM_ILI9341_Putc(uint16_t x, uint16_t y, char c, TM_FontDef_t* font, uint32_t foreground, uint32_t background);
void TM_ILI9341_Puts(uint16_t x, uint16_t y, char* str, TM_FontDef_t *font, uint32_t foreground, uint32_t background);
void TM_ILI9341_GetStringSize(char* str, TM_FontDef_t* font, uint16_t* width, uint16_t* height);
void TM_ILI9341_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t color);
void TM_ILI9341_DrawRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t color);
void TM_ILI9341_DrawFilledRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t color);
void TM_ILI9341_DrawCircle(int16_t x0, int16_t y0, int16_t r, uint32_t color);
void TM_ILI9341_DrawFilledCircle(int16_t x0, int16_t y0, int16_t r, uint32_t color);
void TM_ILI9341_DisplayOn(void);
void TM_ILI9341_DisplayOff(void);
void TM_ILI9341_SetSquare(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
uint16_t TM_ILI9341_GetPixel(int16_t x, int16_t y);
void TM_Image(unsigned char const *img);

uint8_t GG_ILI9341_PutImage(uint16_t x, uint16_t y,  GG_ImageDef_t *image );

#ifdef __cplusplus
}
#endif

#endif

