Sensorian  1.0
C API Reference Guide Library
TFT.h
Go to the documentation of this file.
1 
8 #ifndef __TFT_H__
9 #define __TFT_H__
10 
21 #include "bcm2835.h"
22 
23 #define NOP 0x00
24 #define SWRESET 0x01
25 #define RDDID 0x04 //4 arguments
26 #define RDDST 0x09
27 #define RDDPM 0x0A
28 #define RDDMADCTL 0x0B // Read Display MADCTL
29 #define RDDCOLMOD 0x0C // Read Display Pixel Format
30 #define RDDIM 0x0D // Read Display Image Mode
31 #define RDDSM 0x0E // Read Display Signal Mode
32 #define RDDSDR 0x0F // Read Display Self-Diagnostic Result
33 #define SLEEP_IN 0x10
34 #define SLEEP_OUT 0x11
35 #define PTLON 0x12 // Partial Display Mode On
36 #define NORON 0x13 // Normal Display Mode On
37 #define INVOFF 0x20
38 #define INVON 0x21 // Display Inversion On
39 #define GAMSET 0x26 // Gamma Set
40 #define DISPOFF 0x28
41 #define DISPON 0x29
42 #define CASET 0x2A
43 #define RASET 0x2B
44 #define RAMWR 0x2C
45 #define RGBSET 0x2D //Color set
46 #define RAMRD 0x2E
47 #define PTLAR 0x30
48 #define SCRLAR 0x33 // Scroll Area Set
49 #define TEOFF 0x34
50 #define TEON 0x35
51 #define MADCTL 0x36
52 #define VSCSAD 0x37 // Vertical Scroll Start Address of RAM
53 #define IDLE_MODE_OFF 0x38
54 #define IDLE_MODE_ON 0x39
55 #define COLMOD 0x3A // Interface Pixel Format
56 #define RDID1 0xDA
57 #define RDID2 0xDB
58 #define RDID3 0xDC // Read ID3 Value
59 
60 #define FRMCTR1 0xB1 // Frame Rate Control (In normal mode/ Full colors)
61 #define FRMCTR2 0xB2 // Frame Rate Control (In Idle mode/ 8-colors)
62 #define FRMCTR3 0xB3 // Frame Rate Control (In Partial mode/ full colors)
63 #define INVCTR 0xB4 // Display Inversion Control
64 #define DISSET5 0xB6
65 #define PWCTR1 0xC0
66 #define PWCTR2 0xC1
67 #define PWCTR3 0xC2
68 #define PWCTR4 0xC3
69 #define PWCTR5 0xC4
70 #define VMCTR1 0xC5
71 #define VMOFCTR 0xC7
72 #define WRID2 0xD1
73 #define WRID3 0xD2
74 #define NVFCTR1 0xD9 // NVM Control Status
75 #define NVFCTR2 0xDE
76 #define NVFCTR3 0xDF
77 #define GMCTRP1 0xE0 // Gamma (‘+’polarity) Correction Characteristics Setting .
78 #define GMCTRN1 0xE1 // Gamma ‘-’polarity Correction Characteristics Setting
79 #define GCV 0xFC // Gate Pump Clock Frequency Variable
80 
81 #define DUMMY 0xff
82 
83 /******************************************************************************/
84 
85 #define MADCTL_MY 0x80
86 #define MADCTL_MX 0x40
87 #define MADCTL_MV 0x20
88 #define MADCTL_ML 0x10
89 #define MADCTL_MH 0x04
90 
91 /*
92  * B5 is increment direction when 0 page incement is horizontal when 1 vertical
93  */
94 #define MADCTL_M1 0x00
95 #define MADCTL_M2 0b10000000
96 #define MADCTL_M3 0b01000000
97 #define MADCTL_M4 0b11000000
98 #define MADCTL_M5 0b00100000
99 #define MADCTL_M6 0b10100000
100 #define MADCTL_M7 0b01100000
101 #define MADCTL_M8 0b11100000
102 
103 #define MADCTL_RGB 0x00
104 #define MADCTL_BGR 0x08
105 
106 /******************************************************************************/
107 #define WIDTH 0x7F
108 #define HEIGHT 0x9F
110 /******************************Colors******************************************/
111 #define RED 0xf800
112 #define GREEN 0x07e0
113 #define BLUE 0x001f
114 #define WHITE 0xffff
115 #define BLACK 0x0000
116 #define YELLOW 0xFFE0
117 #define GRAY0 0xEF7D
118 #define GRAY1 0x8410
119 #define GRAY2 0x4208
120 #define BLACK 0x0000
121 #define MAROON 0x8000
122 #define OLIVE 0x8400
123 #define NAVY 0x0010
124 #define PURPLE 0x8010
125 /******************************************************************************/
126 
127 #define CS_OUTPUT() bcm2835_gpio_fsel(RPI_V2_GPIO_P1_24,BCM2835_GPIO_FSEL_OUTP); //Set GPIO24 as output
128 #define CS_LOW() bcm2835_gpio_write(RPI_V2_GPIO_P1_24, LOW);
129 #define CS_HIGH() bcm2835_gpio_write(RPI_V2_GPIO_P1_24, HIGH);
130 
131 #define DC_OUTPUT() bcm2835_gpio_fsel(RPI_V2_GPIO_P1_22,BCM2835_GPIO_FSEL_OUTP); //Set
132 #define DC_LOW() bcm2835_gpio_write(RPI_V2_GPIO_P1_22, LOW);
133 #define DC_HIGH() bcm2835_gpio_write(RPI_V2_GPIO_P1_22, HIGH);
134 
135 #define RST_OUTPUT() bcm2835_gpio_fsel(RPI_V2_GPIO_P1_16,BCM2835_GPIO_FSEL_OUTP); //Set GPIO23 as output
136 #define RST_LOW() bcm2835_gpio_write(RPI_V2_GPIO_P1_16, LOW);
137 #define RST_HIGH() bcm2835_gpio_write(RPI_V2_GPIO_P1_16, HIGH);
138 
139 
143 typedef enum { PORTRAIT=0,
151 } orientation_t;
156 typedef struct _Image
157 {
158  unsigned int *picture;
159  unsigned char width;
160  unsigned char height;
161 }Image_t;
162 
163 void TFT_Initialize(void);
164 void TFT_WriteCommand(unsigned char command);
165 void TFT_WriteData(unsigned char datab);
166 void TFT_WriteDataWord(int wdata);
167 void TFT_RamAdress(void);
168 
169 void TFT_SetPixel(unsigned char x_start,unsigned char y_start,unsigned int color);
170 void TFT_Sleep(void);
171 void TFT_WakeUp(void);
172 void TFT_TurnOffDisplay(void);
173 void TFT_TurnOnDisplay(void);
175 
176 void TFT_InvertDisplay(void);
177 void TFT_InvertDisplayOff(void);
178 void TFT_Background(int color);
179 
180 void TFT_ShowPic(unsigned int picture[],unsigned char width, unsigned char height, unsigned int x, unsigned int y);
181 void TFT_DisplayImage(Image_t *image, unsigned char x, unsigned char y);
182 unsigned int TFT_Color565(unsigned char r, unsigned char g, unsigned char b);
183 
184 void TFT_ASCII(char x, char y, int color, int background, char letter, char size);
185 void TFT_PrintString(char x, char y, int color, int background, char * message, char size);
186 void TFT_PrintInteger(char x, char y, int color, int background,int integer, char size);
187 #endif
void TFT_SetOrientation(orientation_t mode)
Sets the display text orientation. Mirrored modes are also supported on top of portrait and landscape...
Definition: TFT.c:269
void TFT_Background(int color)
This function paints the display background a specific color.
Definition: TFT.c:324
void TFT_InvertDisplayOff(void)
Disables color inversion on the display.
Definition: TFT.c:314
void TFT_TurnOnDisplay(void)
This function turns on the display from idle mode.
Definition: TFT.c:258
unsigned char width
Definition: TFT.h:159
void TFT_WriteCommand(unsigned char command)
This function writes a command byte to the display controller.
Definition: TFT.c:144
unsigned int * picture
Definition: TFT.h:158
void TFT_ShowPic(unsigned int picture[], unsigned char width, unsigned char height, unsigned int x, unsigned int y)
This function paints an image with a specific heigh and width on the display at a specific coordinate...
Definition: TFT.c:342
void TFT_Sleep(void)
Puts the display in a low power mode.
Definition: TFT.c:229
Definition: TFT.h:143
void TFT_WakeUp(void)
Wakes the display from sleep mode.
Definition: TFT.c:239
void TFT_SetPixel(unsigned char x_start, unsigned char y_start, unsigned int color)
This functions sets a specific pixel on the TFT display.
Definition: TFT.c:206
void TFT_InvertDisplay(void)
Enables color inversion on the display.
Definition: TFT.c:305
void TFT_WriteData(unsigned char datab)
This function is used to write data to the TFT controller.
Definition: TFT.c:157
orientation_t
Orientation type. Specific orientation modes of the device.
Definition: TFT.h:143
void TFT_PrintString(char x, char y, int color, int background, char *message, char size)
Orint a colored string at coordinates x,y with a specific font size.
Definition: TFT.c:440
Definition: TFT.h:147
void TFT_TurnOffDisplay(void)
Blanks out the display.
Definition: TFT.c:249
struct _Image Image_t
Image type. Contains image array with height and width dimensions.
void TFT_DisplayImage(Image_t *image, unsigned char x, unsigned char y)
This function displays an image of type Image_t on screen.
Definition: TFT.c:363
void TFT_WriteDataWord(int wdata)
This function writes a 16 bit word on the display controller registers.
Definition: TFT.c:170
unsigned int TFT_Color565(unsigned char r, unsigned char g, unsigned char b)
Pass 8-bit (each) R,G,B, get back 16-bit packed color.
Definition: TFT.c:384
void TFT_ASCII(char x, char y, int color, int background, char letter, char size)
Plot an ASCII char on the display. A specific font is used.
Definition: TFT.c:399
unsigned char height
Definition: TFT.h:160
void TFT_PrintInteger(char x, char y, int color, int background, int integer, char size)
Prints an integer at coordinates x,y with a specific color on a specific background. The integer font size is deterined bu var size.
Definition: TFT.c:465
Image type. Contains image array with height and width dimensions.
Definition: TFT.h:156
void TFT_Initialize(void)
This function intializes the display controller and prepares it for any subsequent operations...
Definition: TFT.c:24
void TFT_RamAdress(void)
Definition: TFT.c:183