ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
ili9341.h
Go to the documentation of this file.
1 
31 #ifndef _ILI9341_H_
32 #define _ILI9341_H_
33 
34 typedef struct
35 {
36  int16_t xpos; // x pos
37  int16_t ypos; // y pos
38  int16_t x;
39  int16_t y;
40  int16_t w;
41  int16_t h;
42  uint16_t font; // font index
43  uint16_t flags;// font fixed == 1, var == 0
48 } window;
49 
51 typedef struct {
52  int16_t X;
53  int16_t Y;
54 } p2_int16_t;
55 
57 typedef struct {
58  int16_t X;
59  int16_t Y;
60  int16_t Z;
61 } p3_int16_t;
62 
63 
64 // Named address space
65 #ifndef MEMSPACE
66 #define MEMSPACE
67 #endif
68 
69 // Weak attribute
70 #ifndef WEAK_ATR
71 #define WEAK_ATR __attribute__((weak))
72 #endif
73 
74 #include "font.h"
75 #include "ili9341_adafruit.h"
76 
77 // FIXED font is default
78 #define FONT_VAR 1
79 #define WRAP_H 2
80 #define WRAP_V 4
81 #define WRAP (WRAP_H | WRAP_V)
82 
83 #define TFT_W (MAX_TFT_X-MIN_TFT_X+1)
84 #define TFT_H (MAX_TFT_Y-MIN_TFT_Y+1)
85 #define TFT_XOFF (MIN_TFT_X)
86 #define TFT_YOFF (MIN_TFT_Y)
87 
93 #define tft_RGBto565(r, g, b) ((uint16_t) (((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >>3))
94 
95 #define SWAP(a, b) do { a ^= b; b ^= a; a ^= b; } while(0)
96 #define ABS(x) ((x)<0 ? -(x) : (x))
97 
98 // ============================================================
99 
100 /* font.c */
101 int font_max ( void );
102 int font_H ( int font );
103 int font_W ( int font );
104 int font_attr ( window *win , int c , _fontc *f );
105 
106 // ============================================================
107 /* vfont.c */
108 int16_t sx ( float scale , int16_t xoff , int16_t X );
109 int16_t sy ( float scale , int16_t yoff , int16_t Y );
110 void drawSVG ( window *win , int16_t x , int16_t y , int16_t c , float scale , uint16_t color, int16_t fill );
111 
112 // ============================================================
113 
114 /* ili9341.c */
115 void tft_Cmd ( uint8_t cmd );
116 uint8_t tft_Data ( uint8_t data );
117 void tft_Cmd_Data_TX ( uint8_t cmd , uint8_t *data , int bytes );
118 int32_t tft_abs_window ( window *win , int16_t x , int16_t y , int16_t w , int16_t h );
119 int32_t tft_rel_window ( window *win , int16_t x , int16_t y , int16_t w , int16_t h );
120 MEMSPACE uint32_t tft_readRegister ( uint8_t command , uint8_t parameter );
121 MEMSPACE uint32_t tft_readId ( void );
122 void tft_bit_blit ( window *win , uint8_t *ptr , int16_t x , int16_t y , int16_t w , int16_t h );
123 void tft_fillWin ( window *win , uint16_t color );
124 void tft_flood ( window *win , int16_t x , int16_t y , uint16_t border , uint16_t fill );
125 int tft_push_xy ( int16_t x , int16_t y );
126 int tft_pop_xy ( int16_t *x , int16_t *y );
127 int tft_floodline ( window *win , int16_t x , int16_t y , uint16_t border , uint16_t fill );
128 int tft_FillPolyLine ( window *win , int16_t x , int16_t y , int w , uint16_t color );
129 void tft_fillRectWH ( window *win , int16_t x , int16_t y , int16_t w , int16_t h , uint16_t color );
130 void tft_fillRectXY ( window *win , int16_t x , int16_t y , int16_t xl , int16_t yl , uint16_t color );
131 void tft_drawPixel ( window *win , int16_t x , int16_t y , int16_t color );
132 void tft_writeRect ( window *win , int16_t x , int16_t y , int16_t w , int16_t h , uint16_t *color );
133 void tft_readRect ( window *win , int16_t x , int16_t y , int16_t w , int16_t h , uint16_t *color );
134 void tft_Vscroll ( window *win , int dir );
135 uint16_t tft_readPixel ( window *win , int16_t x , int16_t y );
136 MEMSPACE void tft_setRotation ( uint8_t m );
137 void tft_565toRGB ( uint16_t color , uint8_t *r , uint8_t *g , uint8_t *b );
138 MEMSPACE void tft_invertDisplay ( int flag );
139 MEMSPACE int tft_window_clip ( window *win );
140 MEMSPACE void tft_clip_xy ( window *win , int16_t *X , int16_t *Y );
141 MEMSPACE int tft_window_clip_args ( window *win , int16_t *x , int16_t *y , int16_t *w , int16_t *h );
142 MEMSPACE void tft_window_init ( window *win , int16_t x , int16_t y , int16_t w , int16_t h );
143 MEMSPACE void tft_setTextColor ( window *win , uint16_t fg , uint16_t bg );
144 MEMSPACE void tft_setpos ( window *win , int16_t x , int16_t y );
145 MEMSPACE void tft_set_textpos ( window *win , int16_t x , int16_t y );
146 MEMSPACE void tft_set_font ( window *win , uint16_t index );
147 MEMSPACE void tft_font_fixed ( window *win );
148 MEMSPACE void tft_font_var ( window *win );
149 int tft_get_font_height ( window *win );
150 void tft_drawFastVLine ( window *win , int16_t x , int16_t y , int16_t h , uint16_t color );
151 void tft_drawFastHLine ( window *win , int16_t x , int16_t y , int16_t w , uint16_t color );
152 void tft_drawLine ( window *win , int16_t x0 , int16_t y0 , int16_t x1 , int16_t y1 , uint16_t color );
153 int tft_Bezier2 ( window *win , p2_int16_t S , p2_int16_t C , p2_int16_t T , int steps , uint16_t color );
154 int tft_Bezier3 ( window *win , p2_int16_t S , p2_int16_t C1 , p2_int16_t C2 , p2_int16_t T , int steps , uint16_t color );
155 MEMSPACE void tft_cleareol ( window *win );
156 MEMSPACE void tft_clearline ( window *win );
157 void tft_putch ( window *win , int c );
158 
159 // ============================================================
160 /* ili9341_hal.c */
161 void tft_spi_init ( uint32_t prescale );
162 void tft_spi_begin ( void );
163 void tft_spi_end ( void );
164 void tft_reset_init ( void );
165 void tft_reset_enable ( void );
166 void tft_addr_init ( void );
167 void tft_reset_disable ( void );
168 void tft_spi_TX ( uint8_t *data , int bytes , uint8_t command );
169 void tft_spi_TXRX ( uint8_t *data , int bytes , uint8_t command );
170 void tft_spi_RX ( uint8_t *data , int bytes , uint8_t command );
171 MEMSPACE window *tft_init ( void );
172 
173 #endif // _ILI9341_SUP_H_
int16_t w
Definition: ili9341.h:40
int16_t sy(float scale, int16_t yoff, int16_t Y)
void tft_Cmd_Data_TX(uint8_t cmd, uint8_t *data, int bytes)
Transmit 8 bit command and optionally send data buffer.
Definition: ili9341.c:72
void tft_drawFastHLine(window *win, int16_t x, int16_t y, int16_t w, uint16_t color)
Fast virtical line drawing.
Definition: ili9341.c:1329
int int32_t
MEMSPACE void tft_window_init(window *win, int16_t x, int16_t y, int16_t w, int16_t h)
Initialize window structure we default values FIXME check x+w, y+h absolute limits against TFT limuts...
Definition: ili9341.c:1198
void tft_bit_blit(window *win, uint8_t *ptr, int16_t x, int16_t y, int16_t w, int16_t h)
BLIT functions
Definition: ili9341.c:234
MEMSPACE void tft_set_font(window *win, uint16_t index)
Set current font size (per current rotation)
Definition: ili9341.c:1267
void tft_drawLine(window *win, int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Draw line From my blit test code testit.c 1984 - 1985 Mike Gore.
Definition: ili9341.c:1389
void tft_spi_begin(void)
Obtain SPI bus for TFT display, assert chip select return: void.
Definition: ili9341_hal.c:80
int16_t h
Definition: ili9341.h:41
MEMSPACE void tft_set_textpos(window *win, int16_t x, int16_t y)
Set current window text pointer in characters (per current rotation) - overall font bounding box...
Definition: ili9341.c:1254
unsigned short uint16_t
Definition: send.c:18
int16_t X
Definition: ili9341.h:58
void tft_fillRectXY(window *win, int16_t x, int16_t y, int16_t xl, int16_t yl, uint16_t color)
Fill rectangle with color We clip the window to the current view.
Definition: ili9341.c:690
uint16_t flags
Definition: ili9341.h:43
uint16_t bg
Definition: ili9341.h:45
Cordic_T X
Main Cordic routine - used for basic trig and vector rotations We use fixed point numbers...
Definition: cordic.c:102
void drawSVG(window *win, int16_t x, int16_t y, int16_t c, float scale, uint16_t color, int16_t fill)
int16_t xpos
Definition: ili9341.h:36
uint8_t rotation
Definition: ili9341.h:46
int16_t Y
Definition: ili9341.h:59
int16_t y[XYSTACK+2]
Definition: ili9341.c:372
void tft_flood(window *win, int16_t x, int16_t y, uint16_t border, uint16_t fill)
Flood fill.
Definition: ili9341.c:346
MEMSPACE void tft_setRotation(uint8_t m)
Set Display rotation, applies to the master window only Set hardware display rotation and memory fill...
Definition: ili9341.c:982
unsigned int uint32_t
Definition: send.c:19
int16_t Z
Definition: ili9341.h:60
uint8_t tft_Data(uint8_t data)
Transmit 8 bit data amd read 8bit data.
Definition: ili9341.c:61
MEMSPACE void tft_clip_xy(window *win, int16_t *X, int16_t *Y)
Clip X,Y to fix inside specifiied window.
Definition: ili9341.c:1114
Cordic_T Y
Definition: cordic.c:102
void tft_drawFastVLine(window *win, int16_t x, int16_t y, int16_t h, uint16_t color)
Fast virtical line drawing.
Definition: ili9341.c:1314
int font_attr(window *win, int c, _fontc *f)
Get font attributes for a font.
Definition: font.c:94
void tft_writeRect(window *win, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t *color)
Write a rectangle pixel array.
Definition: ili9341.c:745
3D display point - display coordinates are int16
Definition: ili9341.h:57
void tft_spi_init(uint32_t prescale)
int font_W(int font)
Get font Width used for character to character spacing.
Definition: font.c:80
MEMSPACE int tft_window_clip(window *win)
Clip window structure to TFT limits.
Definition: ili9341.c:1059
int32_t tft_abs_window(window *win, int16_t x, int16_t y, int16_t w, int16_t h)
=============================================================
Definition: ili9341.c:101
int font_max(void)
Definition: font.c:59
void tft_fillRectWH(window *win, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Partial window Fill with color We clip the window to the current view.
Definition: ili9341.c:627
void tft_drawPixel(window *win, int16_t x, int16_t y, int16_t color)
Pixel functions
Definition: ili9341.c:717
void tft_reset_disable(void)
disnable ILI9341 reset return: void
Definition: ili9341_hal.c:120
int tft_floodline(window *win, int16_t x, int16_t y, uint16_t border, uint16_t fill)
Flood using line fill method.
Definition: ili9341.c:416
MEMSPACE void tft_clearline(window *win)
Clear display text line.
Definition: ili9341.c:1621
int16_t x[XYSTACK+2]
Definition: ili9341.c:371
int tft_get_font_height(window *win)
Get font height.
Definition: ili9341.c:1296
int tft_Bezier2(window *win, p2_int16_t S, p2_int16_t C, p2_int16_t T, int steps, uint16_t color)
Draw lines between points along Quadratic Bézier curve Quadratic Bézier with respect to t...
Definition: ili9341.c:1474
void tft_565toRGB(uint16_t color, uint8_t *r, uint8_t *g, uint8_t *b)
Color conversions
Definition: ili9341.c:1033
MEMSPACE void tft_setpos(window *win, int16_t x, int16_t y)
Set current window text pointer in pixels (per current rotation)
Definition: ili9341.c:1241
int32_t tft_rel_window(window *win, int16_t x, int16_t y, int16_t w, int16_t h)
Set the ili9341 working window by relative position and size Note: Function clips x...
Definition: ili9341.c:140
int font_H(int font)
Get font height used for line to line spacing.
Definition: font.c:70
int16_t sx(float scale, int16_t xoff, int16_t X)
int tft_FillPolyLine(window *win, int16_t x, int16_t y, int w, uint16_t color)
Definition: ili9341.c:510
MEMSPACE void tft_font_var(window *win)
Set current font type to variable.
Definition: ili9341.c:1288
void tft_spi_TXRX(uint8_t *data, int bytes, uint8_t command)
Transmit and read 8 bit data array.
Definition: ili9341_hal.c:149
int16_t y
Definition: ili9341.h:39
MEMSPACE void tft_setTextColor(window *win, uint16_t fg, uint16_t bg)
====================================
Definition: ili9341.c:1228
int tft_Bezier3(window *win, p2_int16_t S, p2_int16_t C1, p2_int16_t C2, p2_int16_t T, int steps, uint16_t color)
Draw lines between points along Cubic Bézier curve Quadratic Bézier with respect to t...
Definition: ili9341.c:1545
MEMSPACE void tft_invertDisplay(int flag)
Invert the display.
Definition: ili9341.c:1045
void tft_readRect(window *win, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t *color)
Definition: ili9341.c:837
2D display point - display coordinates are int16
Definition: ili9341.h:51
uint16_t font
Definition: ili9341.h:42
MEMSPACE uint32_t tft_readId(void)
Read ILI9341 device ID should be 9341 This does not work for really high SPI clock speeds Make sure t...
Definition: ili9341.c:206
int16_t ypos
Definition: ili9341.h:37
MEMSPACE int tft_window_clip_args(window *win, int16_t *x, int16_t *y, int16_t *w, int16_t *h)
clip arguments to window limits Arguments position x,y width w and height h to be clipped ...
Definition: ili9341.c:1145
int16_t X
Definition: ili9341.h:52
void tft_spi_end(void)
Release SPI bus from TFT display, deassert chip select return: void.
Definition: ili9341_hal.c:87
uint16_t fg
Definition: ili9341.h:44
_font font
void tft_addr_init(void)
Initialize ILI9341 command/data GPIO return: void.
Definition: ili9341_hal.c:112
void tft_Cmd(uint8_t cmd)
Transmit 8 bit command.
Definition: ili9341.c:53
int16_t x
Definition: ili9341.h:38
void tft_putch(window *win, int c)
put character in current winoow
Definition: ili9341.c:1643
Definition: ili9341.h:34
int tft_pop_xy(int16_t *x, int16_t *y)
point push
Definition: ili9341.c:397
void tft_Vscroll(window *win, int dir)
Scroll window up by dir lines We start at the top of the window and move down.
Definition: ili9341.c:903
void tft_reset_enable(void)
enable ILI9341 reset return: void
Definition: ili9341_hal.c:103
uint16_t tft_readPixel(window *win, int16_t x, int16_t y)
Read one pixel and return color in 1bit 565 RGB format We clip the window to the current view Note: R...
Definition: ili9341.c:952
void tft_fillWin(window *win, uint16_t color)
Fill functions
Definition: ili9341.c:334
#define MEMSPACE
Definition: ili9341.h:66
void tft_spi_TX(uint8_t *data, int bytes, uint8_t command)
Transmit 8 bit data array.
Definition: ili9341_hal.c:134
void tft_reset_init(void)
Initialize ILI9341 reset GPIO return: void.
Definition: ili9341_hal.c:94
int16_t Y
Definition: ili9341.h:53
MEMSPACE void tft_cleareol(window *win)
Character and String functions
Definition: ili9341.c:1601
uint8_t tabstop
Definition: ili9341.h:47
unsigned char uint8_t
Definition: send.c:17
MEMSPACE uint32_t tft_readRegister(uint8_t command, uint8_t parameter)
====================================
Definition: ili9341.c:166
Definition: font.h:89
MEMSPACE window * tft_init(void)
Initialize TFT.
Definition: ili9341_hal.c:178
int tft_push_xy(int16_t x, int16_t y)
point push
Definition: ili9341.c:380
MEMSPACE void tft_font_fixed(window *win)
Definition: ili9341.c:1278
void tft_spi_RX(uint8_t *data, int bytes, uint8_t command)
read 8 bit data array
Definition: ili9341_hal.c:165