ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts
1.0
ESP8266ILI9341DisplayProject
|
ili9341 driver inspired by Adafruit ili9341 code All code in this file has been rewritten by Mike Gore More...
#include "user_config.h"
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include "display/font.h"
#include "display/ili9341.h"
#include "3rd_party/ili9341_adafruit.h"
Go to the source code of this file.
Macros | |
#define | XYSTACK 64 |
X,Y point stack. More... | |
#define | MAXVEC 24 |
find beginning and end of all non-matching color transitions in a line FIXME: not tested yet More... | |
#define | HSPI_PIX ((HSPI_FIFO_SIZE-2)/3) |
Read Rectangle and return 16bit color array in 565 RGB format We clip the window to the current view Note: TFT Chip Select must be asserted for each block read As soon as chip select goes high the read aborts! We break up the data into chunks with a Memory Read, followed by Memory Read Continue So we use Memory Read and Memory Read Continue. More... | |
#define | USE_OPTIMIZATION_DRAWLINE |
Functions | |
void | tft_Cmd (uint8_t cmd) |
Transmit 8 bit command. More... | |
uint8_t | tft_Data (uint8_t data) |
Transmit 8 bit data amd read 8bit data. More... | |
void | tft_Cmd_Data_TX (uint8_t cmd, uint8_t *data, int bytes) |
Transmit 8 bit command and optionally send data buffer. More... | |
int32_t | tft_abs_window (window *win, int16_t x, int16_t y, int16_t w, int16_t h) |
============================================================= More... | |
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,y,w,y. More... | |
MEMSPACE uint32_t | tft_readRegister (uint8_t command, uint8_t parameter) |
==================================== More... | |
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 that when called the clock speed in reduced. More... | |
void | tft_bit_blit (window *win, uint8_t *ptr, int16_t x, int16_t y, int16_t w, int16_t h) |
BLIT functionsMore... | |
void | tft_fillWin (window *win, uint16_t color) |
Fill functionsMore... | |
void | tft_flood (window *win, int16_t x, int16_t y, uint16_t border, uint16_t fill) |
Flood fill. More... | |
int | tft_push_xy (int16_t x, int16_t y) |
point push More... | |
int | tft_pop_xy (int16_t *x, int16_t *y) |
point push More... | |
int | tft_floodline (window *win, int16_t x, int16_t y, uint16_t border, uint16_t fill) |
Flood using line fill method. More... | |
int | tft_FillPolyLine (window *win, int16_t x, int16_t y, int w, uint16_t color) |
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. More... | |
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. More... | |
void | tft_drawPixel (window *win, int16_t x, int16_t y, int16_t color) |
Pixel functionsMore... | |
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. More... | |
void | tft_readRect (window *win, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t *color) |
void | tft_Vscroll (window *win, int dir) |
Scroll window up by dir lines We start at the top of the window and move down. More... | |
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: Read Memory must be done in a continious write/read operation Chip select can not be deactivated for the transaction. More... | |
MEMSPACE void | tft_setRotation (uint8_t m) |
Set Display rotation, applies to the master window only Set hardware display rotation and memory fill option bits Update software display limits FIXME Work in progress. More... | |
void | tft_565toRGB (uint16_t color, uint8_t *r, uint8_t *g, uint8_t *b) |
Color conversionsMore... | |
MEMSPACE void | tft_invertDisplay (int flag) |
Invert the display. More... | |
MEMSPACE int | tft_window_clip (window *win) |
Clip window structure to TFT limits. More... | |
MEMSPACE void | tft_clip_xy (window *win, int16_t *X, int16_t *Y) |
Clip X,Y to fix inside specifiied window. More... | |
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 More... | |
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. More... | |
MEMSPACE void | tft_setTextColor (window *win, uint16_t fg, uint16_t bg) |
==================================== More... | |
MEMSPACE void | tft_setpos (window *win, int16_t x, int16_t y) |
Set current window text pointer in pixels (per current rotation) More... | |
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. More... | |
MEMSPACE void | tft_set_font (window *win, uint16_t index) |
Set current font size (per current rotation) More... | |
MEMSPACE void | tft_font_fixed (window *win) |
MEMSPACE void | tft_font_var (window *win) |
Set current font type to variable. More... | |
int | tft_get_font_height (window *win) |
Get font height. More... | |
void | tft_drawFastVLine (window *win, int16_t x, int16_t y, int16_t h, uint16_t color) |
Fast virtical line drawing. More... | |
void | tft_drawFastHLine (window *win, int16_t x, int16_t y, int16_t w, uint16_t color) |
Fast virtical line drawing. More... | |
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. More... | |
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, see https://en.wikipedia.org/wiki/Bézier_curve B(t) = (1-t)*(1-t)*S + 2*(1-t)*t*C + t*t*T, 0 <= t <= 1. More... | |
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, see https://en.wikipedia.org/wiki/Bézier_curve B(t) = (1-t)(1-t)*(1-t)*S + 3*(1-t)(1-t)*t*C1 + 3(1-t)*t*t*C2 + t*t*t*T, 0 <= t <= 1. More... | |
MEMSPACE void | tft_cleareol (window *win) |
Character and String functionsMore... | |
MEMSPACE void | tft_clearline (window *win) |
Clear display text line. More... | |
void | tft_putch (window *win, int c) |
put character in current winoow More... | |
Variables | |
window | tftwin |
window * | tft = &tftwin |
struct { | |
int16_t x [XYSTACK+2] | |
int16_t y [XYSTACK+2] | |
int ind | |
} | xy |
ili9341 driver inspired by Adafruit ili9341 code All code in this file has been rewritten by Mike Gore
This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file ili9341.c.
#define HSPI_PIX ((HSPI_FIFO_SIZE-2)/3) |
Read Rectangle and return 16bit color array in 565 RGB format We clip the window to the current view Note: TFT Chip Select must be asserted for each block read As soon as chip select goes high the read aborts! We break up the data into chunks with a Memory Read, followed by Memory Read Continue So we use Memory Read and Memory Read Continue.
[in] | win* | window structure |
[in] | x | X offset |
[in] | y | Y offset |
[in] | w | Width |
[in] | h | Height |
[in] | *color | pixel array in 565 format Number of pixels FIFO can hold We also include the 2 byte Memory Read / Continue opcodes; |
#define MAXVEC 24 |
find beginning and end of all non-matching color transitions in a line FIXME: not tested yet
[in] | win* | window structure |
[in] | x | X position to start scan |
[in] | y | Y line to scan |
[in] | *vec | start and end of transition offsets |
[in] | count | maximum size of transitions to save |
[in] | color | match color @ return true count of saved transitions |
Definition at line 509 of file ili9341.c.
Referenced by tft_FillPolyLine().
#define USE_OPTIMIZATION_DRAWLINE |
#define XYSTACK 64 |
=============================================================
====================================
Set the ili9341 working window by absolute position and size Note: Function clips x,y,w,y
[in] | x | Starting X offset |
[in] | y | Starting Y offset |
[in] | w | Width |
[in] | h | Height |
Definition at line 101 of file ili9341.c.
Referenced by tft_rel_window().
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, see https://en.wikipedia.org/wiki/Bézier_curve B(t) = (1-t)*(1-t)*S + 2*(1-t)*t*C + t*t*T, 0 <= t <= 1.
====================================
The path traced by the function B(t), given points S, C, and T, S = initial points C = control points T = target points
Derivative of the Bézier curve with respect to t B'(t) = 2*(1-t)*(C-S) + 2*t*(T-C)
Second derivative of the Bézier curve with respect to t is B"(t) = 2*(T-2*C+S)
As t increases from 0 to 1, the curve departs from S in the direction of C, then bends to arrive at T from the direction of C. The tangents to the curve at S and T intersect at C.
[in] | *win | Window Structure of active window |
[in] | S | Start |
[in] | C | Control |
[in] | T | Target |
[in] | steps | line segments along curve (1..N) |
[in] | color | Line color |
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, see https://en.wikipedia.org/wiki/Bézier_curve B(t) = (1-t)(1-t)*(1-t)*S + 3*(1-t)(1-t)*t*C1 + 3(1-t)*t*t*C2 + t*t*t*T, 0 <= t <= 1.
The path traced by the function B(t), given points S, C, and T, S = initial points C1 = control point 1 C2 = control point 2 T = target points
Derivative of the Bézier curve with respect to t B'(t) = 3(1-t)*(1-t)*(C1-S) + 6*(1-t)*t*(C2-C1) + 3*t*t*(T-C2)
Second derivative of the Bézier curve with respect to t is B"(t) = 6*(1-t)*(C2-2*C1+S) + 6*t*(T-2*C2+C1)
The curve starts at S and moves toward C1 and on to T from the direction of C2. Points C1 and C2 provide directional information and the distance between them determines "how far" and "how fast" the curve moves towards C1 before turning towards C2.
[in] | *win | Window Structure of active window |
[in] | S | Start |
[in] | C1 | Control 1 |
[in] | C2 | Control 2 |
[in] | T | Target |
[in] | steps | line segments along curve (1..N) |
[in] | color | Line color |
BLIT a bit array to the display
[in] | win* | window structure |
[in] | *ptr | bit array w * h in size |
[in] | x | BLITX offset |
[in] | y | BLIT Y offset |
[in] | w | BLIT Width |
[in] | h | BLIT Height |
Definition at line 234 of file ili9341.c.
Referenced by tft_drawChar().
====================================Clear display to end of line
[in] | win* | window structure return: void, win->x = win->w |
Definition at line 1601 of file ili9341.c.
Referenced by tft_putch(), and user_loop().
void tft_Cmd | ( | uint8_t | cmd | ) |
Transmit 8 bit command.
[in] | cmd | display command return: void status is in data array - bytes in size |
Definition at line 53 of file ili9341.c.
Referenced by tft_bit_blit(), tft_Cmd_Data_TX(), tft_FillPolyLine(), tft_fillRectWH(), tft_invertDisplay(), tft_readPixel(), tft_readRect(), tft_readRegister(), and tft_writeRect().
Transmit 8 bit command and optionally send data buffer.
[in] | cmd | display command |
[in] | *data | data buffer to send after command |
[in] | bytes | data buffer size return: void status is in data array - bytes in size |
Definition at line 72 of file ili9341.c.
Referenced by tft_abs_window(), tft_configRegister(), tft_drawPixel(), and tft_setRotation().
Transmit 8 bit data amd read 8bit data.
[in] | data | display command return: read result |
Definition at line 61 of file ili9341.c.
Referenced by tft_readRegister().
Fast virtical line drawing.
[in] | *win | window structure |
[in] | x | X offset |
[in] | y | Y offset |
[in] | w | Width of line |
[in] | color | Color |
Definition at line 1329 of file ili9341.c.
Referenced by tft_drawRect(), tft_drawRoundRect(), tft_FillPolyLine(), and tft_fillTriangle().
Fast virtical line drawing.
[in] | *win | window structure |
[in] | x | X offset |
[in] | y | Y offset |
[in] | h | Height of line |
[in] | color | Color |
Definition at line 1314 of file ili9341.c.
Referenced by tft_drawRect(), tft_drawRoundRect(), tft_fillCircle(), and tft_fillCircleHelper().
Draw line From my blit test code testit.c 1984 - 1985 Mike Gore.
[in] | win* | window structure |
[in] | x0 | X Start |
[in] | y0 | Y Start |
[in] | x1 | X End |
[in] | y1 | Y End |
[in] | color | color to set |
[in] | win* | window structure |
[in] | x0 | X Start |
[in] | y0 | Y Start |
[in] | x1 | X End |
[in] | y1 | Y End |
[in] | color | color to set |
Definition at line 1389 of file ili9341.c.
Referenced by tft_Bezier2(), tft_Bezier3(), tft_drawFastHLine(), tft_drawTriangle(), and wire_draw().
void tft_drawPixel | ( | window * | win, |
int16_t | x, | ||
int16_t | y, | ||
int16_t | color | ||
) |
====================================Draw one pixel set to color in 16bit 565 RGB format We clip the window to the current view
[in] | win* | window structure |
[in] | x | X Start |
[in] | y | Y Start |
[in] | color | color to set |
Definition at line 717 of file ili9341.c.
Referenced by tft_bit_blit(), tft_drawCircle(), tft_drawCircleHelper(), tft_drawFastHLine(), tft_flood(), tft_floodline(), tft_writeRect(), and user_tests().
Partial window Fill with color We clip the window to the current view.
[in] | win* | window structure |
[in] | x | X Start |
[in] | y | Y Start |
[in] | w | Width |
[in] | h | Height |
[in] | color | Fill color |
Definition at line 627 of file ili9341.c.
Referenced by tft_cleareol(), tft_clearline(), tft_drawChar(), tft_drawFastHLine(), tft_drawFastVLine(), tft_fillRectXY(), tft_fillRoundRect(), tft_fillWin(), tft_putch(), and tft_Vscroll().
Fill rectangle with color We clip the window to the current view.
[in] | win* | window structure |
[in] | x | X Start |
[in] | y | Y Start |
[in] | xl | X End |
[in] | yl | Y End |
[in] | color | Fill color |
Definition at line 690 of file ili9341.c.
Referenced by tft_drawFastHLine().
====================================Fill window
[in] | win* | window structure |
[in] | color | Fill color |
Definition at line 334 of file ili9341.c.
Referenced by test_types(), tft_init(), and tft_putch().
Flood fill.
[in] | win* | window structure |
[in] | border | border color |
[in] | fill | Fill color |
Definition at line 346 of file ili9341.c.
Referenced by tft_flood().
Flood using line fill method.
[in] | win* | window structure |
[in] | x | X position to fill from |
[in] | y | Y position to fill from |
[in] | border | border color |
[in] | fill | Fill color @ return true one success, 0 of stack overflow |
Only works if font is proportional type
[in] | win* | window structure return: void |
Definition at line 1278 of file ili9341.c.
Referenced by user_loop().
Set current font type to variable.
[in] | win* | window structure return: void |
Definition at line 1288 of file ili9341.c.
Referenced by test_types().
int tft_get_font_height | ( | window * | win | ) |
MEMSPACE void tft_invertDisplay | ( | int | flag | ) |
int tft_pop_xy | ( | int16_t * | x, |
int16_t * | y | ||
) |
point push
[in] | x | X |
[in] | y | Y @ return true if data exists, 0 of none |
Definition at line 397 of file ili9341.c.
Referenced by tft_floodline().
int tft_push_xy | ( | int16_t | x, |
int16_t | y | ||
) |
point push
[in] | x | X |
[in] | y | Y @ return true on success, 0 of stack overflow |
Definition at line 380 of file ili9341.c.
Referenced by tft_floodline().
void tft_putch | ( | window * | win, |
int | c | ||
) |
put character in current winoow
[in] | win* | window structure |
[in] | c | character return: void |
Definition at line 1643 of file ili9341.c.
Referenced by _putc_win(), and _putc_win_len().
Read ILI9341 device ID should be 9341 This does not work for really high SPI clock speeds Make sure that when called the clock speed in reduced.
Paramter 0 is unused See Read ID4 Command ( 0xd3 ) for a description of the parameters
Definition at line 206 of file ili9341.c.
Referenced by tft_init().
Read one pixel and return color in 1bit 565 RGB format We clip the window to the current view Note: Read Memory must be done in a continious write/read operation Chip select can not be deactivated for the transaction.
[in] | win* | window structure |
[in] | x | X Start |
[in] | y | Y Start |
Definition at line 952 of file ili9341.c.
Referenced by tft_flood(), tft_floodline(), and user_tests().
Definition at line 837 of file ili9341.c.
Referenced by loop(), and tft_Vscroll().
====================================
====================================================================== SPIRead parameters on SPI bus ILI9341 displays For those displays that do not have the EXTC pin asserted. This undocumented command overrides the restriction for reading command parameters. Notes: SPI configurations See M:[0-3] control bits in ILI9341 documenation
[in] | command | command whose parameters we want to read |
[in] | parameter | parameter number |
Definition at line 166 of file ili9341.c.
Referenced by tft_readId().
Set the ili9341 working window by relative position and size Note: Function clips x,y,w,y.
[in] | win* | window structure |
[in] | x | Starting X offset |
[in] | y | Starting Y offset |
[in] | w | Width |
[in] | h | Height |
Definition at line 140 of file ili9341.c.
Referenced by tft_bit_blit(), tft_drawPixel(), tft_FillPolyLine(), tft_fillRectWH(), tft_readPixel(), tft_readRect(), and tft_writeRect().
Set current font size (per current rotation)
[in] | win* | window structure |
[in] | index | font index (for array of fonts) return: void |
Definition at line 1267 of file ili9341.c.
Referenced by test_types(), and user_loop().
Set current window text pointer in characters (per current rotation) - overall font bounding box.
[in] | win* | window structure |
[in] | x | x offset |
[in] | y | y oofset return: void |
Definition at line 1254 of file ili9341.c.
Referenced by test_types(), and user_loop().
Set Display rotation, applies to the master window only Set hardware display rotation and memory fill option bits Update software display limits FIXME Work in progress.
Definition at line 982 of file ili9341.c.
Referenced by test_types(), tft_init(), and user_tests().
====================================
Set text forground and background color
[in] | win* | window structure |
[in] | fg | forground color |
[in] | bg | background color |
Definition at line 1228 of file ili9341.c.
Referenced by test_types().
void tft_Vscroll | ( | window * | win, |
int | dir | ||
) |
Scroll window up by dir lines We start at the top of the window and move down.
[in] | win* | window structure |
[in] | dir | direction and count TODO +/- scroll direction TODO +/- Horizontal scroll functions |
Definition at line 903 of file ili9341.c.
Referenced by tft_drawChar().
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
[in] | *win | window structure we will use to clip arguments to. |
[in] | *x | X argument offset |
[in] | *y | Y argument offset |
[in] | *w | W argument width |
[in] | *h | H argument height |
Definition at line 1145 of file ili9341.c.
Referenced by tft_abs_window(), tft_bit_blit(), and tft_window_init().
Initialize window structure we default values FIXME check x+w, y+h absolute limits against TFT limuts.
[in] | win* | window structure |
[in] | x | X offset to window start - absolute |
[in] | y | Y offset to window start - absolute |
[in] | w | Window width |
[in] | h | Window Height |
Definition at line 1198 of file ili9341.c.
Referenced by test_types(), and tft_init().
Write a rectangle pixel array.
[in] | win* | window structure |
[in] | x | X offset |
[in] | y | Y offset |
[in] | w | Width |
[in] | h | Height |
[in] | *color | pixel array in 565 format |
Definition at line 745 of file ili9341.c.
Referenced by tft_drawBitmap(), and tft_Vscroll().
int ind |
Definition at line 373 of file ili9341.c.
Referenced by buffer_gets(), dirname(), fatfs_tests(), fgets(), match_headers(), p_ntoa(), posix_tests(), ReadBdf(), tft_Bezier2(), tft_Bezier3(), tft_bit_blit(), tft_FillPolyLine(), tft_fillRectWH(), tft_writeRect(), and user_tests().
int16_t x[XYSTACK+2] |
Definition at line 371 of file ili9341.c.
Referenced by asinCordic(), bitclrxy(), bitsetxy(), bittestxy(), Circular(), ComputeGapSize(), cordit1(), FontAdjustFull(), FontAdjustSmall(), FontPreview(), FontPreviewFull(), FontPreviewProportional(), loop(), main(), ReadBdf(), rotate(), test_types(), tft_clip_xy(), tft_drawCircle(), tft_drawCircleHelper(), tft_fillCircleHelper(), tft_FillPolyLine(), tft_floodline(), tft_push_xy(), tft_setpos(), tft_window_init(), user_tests(), and WriteCharacterBits().
struct { ... } xy |
Referenced by tft_floodline(), tft_pop_xy(), and tft_push_xy().
int16_t y[XYSTACK+2] |
Definition at line 372 of file ili9341.c.
Referenced by asinCordic(), Circular(), ComputeGapSize(), cordit1(), FontAdjustFull(), FontAdjustSmall(), FontPreview(), FontPreviewFull(), FontPreviewProportional(), loop(), main(), rotate(), test_types(), tft_clip_xy(), tft_drawCircle(), tft_drawCircleHelper(), tft_fillCircleHelper(), tft_fillTriangle(), tft_push_xy(), tft_setpos(), tft_window_init(), user_tests(), and WriteCharacterBits().