189 #if ILI9341_DEBUG & 1 273 for (yy=0; yy < h; ++yy)
275 for (xx=0;xx < w; ++xx)
282 buf[ind++] = color >> 8;
283 buf[ind++] = color & 0xff;
285 if(ind >=
sizeof(buf))
308 for (yy=0; yy < h; ++yy)
310 for (xx=0;xx < w; ++xx)
350 if(x < 0 || x >= win->
w)
352 if(y < 0 || y >= win->
h)
356 if(current == border || current == fill)
418 int lineAbove, lineBelow;
425 if(x < 0 || x >= win->
w)
427 printf(
"tft_floodline: X out of range\n");
430 if(y < 0 || y >= win->
h)
432 printf(
"tft_floodline: Y out of range\n");
442 while(
tft_pop_xy((int16_t *)&x, (int16_t *)&y))
444 if(x < 0 || x >= win->
w)
446 printf(
"tft_floodline: X out of range\n");
449 if(y < 0 || y >= win->
h)
451 printf(
"tft_floodline: Y out of range\n");
459 lineAbove = lineBelow = 0;
471 if(!lineAbove && y > 0 &&
tft_readPixel(win,xoff,y-1) != border)
478 else if(lineAbove && y > 0 &&
tft_readPixel(win,xoff,y-1) == border )
482 if(!lineBelow && y < (win->
h-1) &&
tft_readPixel(win,xoff,y+1) != border )
489 else if(lineBelow && y < (win->
h-1) &&
tft_readPixel(win,xoff,y+1) == border)
527 printf(
"FillPoly: w(%d) != pixels(%d)\n", (
int) w, pixels);
601 printf(
"count[%d] @ line %d\n", count, y);
603 printf(
"%d \n", (
int)vec[j]);
653 if(colors >
sizeof(buf)/2)
654 colors =
sizeof(buf)/2;
661 while(ind <
sizeof(buf) && ind < colors*2)
663 buf[ind++] = color >> 8;
664 buf[ind++] = color & 0xff;
722 if(x < 0 || x >= win->
w)
724 if(y < 0 || y >= win->
h)
777 buf[ind++]=pixel >> 8;
778 buf[ind++]=pixel & 0xff;
779 if(ind >=
sizeof(buf))
802 for (yy=0; yy < h; ++yy)
804 for (xx=0;xx < w; ++xx)
835 #define HSPI_PIX ((HSPI_FIFO_SIZE-2)/3) 862 if(pixels >
sizeof(data)/3)
863 rem =
sizeof(data)/3;
922 for(i=0; i < win->
h;++i)
929 if(yfrom >= (win->
h-1))
1035 *r = ((0xf800 & color)>>8);
1036 *g = ((0x7e0 & color)>>3);
1037 *b = (0x1f & color) << 3;
1069 if(win->
x > (tft->
x + tft->
w - 1))
1071 win->
x = (tft->
x + tft->
w - 1);
1082 if(win->
y > (tft->
y + tft->
h - 1))
1084 win->
y = (tft->
y + tft->
h - 1);
1091 if( (win->
x + win->
w - 1 ) > (tft->
x + tft->
w - 1) )
1093 win->
w = (tft->
x + tft->
w ) - win->
x;
1098 if( (win->
y + win->
h - 1 ) > (tft->
y + tft->
h - 1) )
1100 win->
h = (tft->
y + tft->
h ) - win->
y;
1122 if(X1 > (win->
x + win->
w - 1))
1123 X1 = (win->
x + win->
w - 1);
1127 if(Y1 > (win->
y + win->
w - 1))
1128 Y1 = (win->
y + win->
w - 1);
1155 if(*x > (win->
x + win->
w - 1))
1157 *x = (win->
x + win->
w - 1);
1167 if(*y > (win->
y + win->
h - 1))
1169 *y = (win->
y + win->
h - 1);
1174 if( (*x + *w - 1 ) > (win->
x + win->
w - 1) )
1176 *w = (win->
x + win->
w ) - *x;
1181 if( (*y + *h - 1 ) > (win->
y + win->
h - 1) )
1183 *h = (win->
y + win->
h ) - *y;
1349 int npts, i, delx, dely, xi, yi, diff;
1351 delx = (x1-x0); xi = SIGN(delx); delx =
ABS(delx);
1352 dely = (y1-y0); yi = SIGN(dely); dely =
ABS(dely);
1354 npts = MAX(delx,dely);
1356 for(i=0;i<=npts;++i)
1361 diff -= dely; x0 += xi;
1364 diff +=delx; y0 +=yi;
1369 diff += delx; y0 += yi;
1372 diff -= dely; x0 += xi;
1392 #define USE_OPTIMIZATION_DRAWLINE 1394 int16_t dx =
ABS(x1 - x0);
1395 int16_t dy = -
ABS(y1 - y0);
1398 int16_t err = dx + dy;
1401 #ifdef USE_OPTIMIZATION_DRAWLINE 1408 #ifdef USE_OPTIMIZATION_DRAWLINE 1410 if ((startX != x0) && (startY != y0))
1424 if (x0 == x1)
break;
1430 if (y0 == y1)
break;
1435 #ifdef USE_OPTIMIZATION_DRAWLINE 1476 float t, tinc, t1,p1,p2,p3;
1489 tinc = 1.0 / (float) steps;
1493 for (i = 0; i < steps; ++i)
1502 Point.
X = (int16_t) (p1 * (
float)S.
X + p2 * (float)C.
X + p3 * (
float)T.
X);
1503 Point.
Y = (int16_t) (p1 * (
float)S.
Y + p2 * (float)C.
Y + p3 * (
float)T.
Y);
1505 if(Last.
X == Point.
X && Last.
Y == Point.
Y)
1547 float t, tinc, c0, t1,t2,p1,p2,p3,p4;
1562 tinc = 1.0 / (float) steps;
1566 for (i = 0; i < steps; ++i)
1579 Point.
X = (int16_t) (p1 * (
float)S.
X + p2 * (float)C1.
X + p3 * (
float) C2.
X + p4 * (float)T.
X);
1580 Point.
Y = (int16_t) (p3 * (
float)S.
Y + p2 * (float)C1.
Y + p3 * (
float) C2.
Y + p4 * (float)T.
Y);
1583 if(Last.
X == X && Last.
Y == Y)
1608 rem = (win->
w - 1 - win->
xpos);
1628 rem = (win->
w - 1 - win->
xpos);
1651 if(c < 0 || c > 0x7e)
1692 if(win->
xpos + count > win->
w)
1694 count = (win->
xpos + count) - win->
w -1;
int16_t sy(float scale, int16_t yoff, int16_t Y)
MEMSPACE void tft_setRotation(uint8_t m)
Set Display rotation, applies to the master window only Set hardware display rotation and memory fill...
int tft_get_font_height(window *win)
Get font height.
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...
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...
MEMSPACE uint32_t tft_readRegister(uint8_t command, uint8_t parameter)
====================================
void tft_drawFastHLine(window *win, int16_t x, int16_t y, int16_t w, uint16_t color)
Fast virtical line drawing.
void tft_spi_begin(void)
Obtain SPI bus for TFT display, assert chip select return: void.
void tft_bit_blit(window *win, uint8_t *ptr, int16_t x, int16_t y, int16_t w, int16_t h)
BLIT functions
Master include file for project Includes all project includes and defines here.
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.
void tft_Cmd(uint8_t cmd)
Transmit 8 bit command.
#define MAXVEC
find beginning and end of all non-matching color transitions in a line FIXME: not tested yet ...
int tft_floodline(window *win, int16_t x, int16_t y, uint16_t border, uint16_t fill)
Flood using line fill method.
void tft_flood(window *win, int16_t x, int16_t y, uint16_t border, uint16_t fill)
Flood fill.
MEMSPACE void tft_setTextColor(window *win, uint16_t fg, uint16_t bg)
====================================
Cordic_T X
Main Cordic routine - used for basic trig and vector rotations We use fixed point numbers...
uint8_t tft_Data(uint8_t data)
Transmit 8 bit data amd read 8bit data.
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.
MEMSPACE void tft_set_font(window *win, uint16_t index)
Set current font size (per current rotation)
MEMSPACE int tft_window_clip(window *win)
Clip window structure to TFT limits.
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...
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...
int tft_push_xy(int16_t x, int16_t y)
point push
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.
void optimistic_yield(uint32_t interval_us)
void tft_drawChar(window *win, uint8_t c)
Display a character and optionally wrap the graphic cursor.
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 ...
void ets_uart_printf(char *fmt,...)
#define XYSTACK
X,Y point stack.
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...
#define tft_RGBto565(r, g, b)
Pass 8-bit (each) R,G,B, get back 16-bit packed color ILI9341 defaults to MSB/LSB data so we have to ...
int32_t tft_abs_window(window *win, int16_t x, int16_t y, int16_t w, int16_t h)
=============================================================
MEMSPACE void tft_clip_xy(window *win, int16_t *X, int16_t *Y)
Clip X,Y to fix inside specifiied window.
void tft_drawFastVLine(window *win, int16_t x, int16_t y, int16_t h, uint16_t color)
Fast virtical line drawing.
int16_t sx(float scale, int16_t xoff, int16_t X)
MEMSPACE void tft_clearline(window *win)
Clear display text line.
void tft_spi_TXRX(uint8_t *data, int bytes, uint8_t command)
Transmit and read 8 bit data array.
MEMSPACE void tft_font_fixed(window *win)
void tft_drawPixel(window *win, int16_t x, int16_t y, int16_t color)
Pixel functions
int bittestv(unsigned char *ptr, int off)
Test bit in byte array.
2D display point - display coordinates are int16
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.
int tft_FillPolyLine(window *win, int16_t x, int16_t y, int w, uint16_t color)
int font_W(int font)
Get font Width used for character to character spacing.
MEMSPACE void tft_font_var(window *win)
Set current font type to variable.
void tft_spi_end(void)
Release SPI bus from TFT display, deassert chip select return: void.
void tft_565toRGB(uint16_t color, uint8_t *r, uint8_t *g, uint8_t *b)
Color conversions
MEMSPACE void tft_setpos(window *win, int16_t x, int16_t y)
Set current window text pointer in pixels (per current rotation)
void tft_Vscroll(window *win, int dir)
Scroll window up by dir lines We start at the top of the window and move down.
void tft_fillWin(window *win, uint16_t color)
Fill functions
void tft_readRect(window *win, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t *color)
MEMSPACE int printf(const char *format,...)
MEMSPACE void tft_cleareol(window *win)
Character and String functions
void tft_Cmd_Data_TX(uint8_t cmd, uint8_t *data, int bytes)
Transmit 8 bit command and optionally send data buffer.
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...
void tft_spi_TX(uint8_t *data, int bytes, uint8_t command)
Transmit 8 bit data array.
MEMSPACE void tft_invertDisplay(int flag)
Invert the display.
ili9341 driver inspired by Adafruit ili9341 code All code in this file has been rewritten by Mike Gor...
int font_attr(window *win, int c, _fontc *f)
Get font attributes for a font.
int font_H(int font)
Get font height used for line to line spacing.
void tft_spi_RX(uint8_t *data, int bytes, uint8_t command)
read 8 bit data array
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...
void tft_putch(window *win, int c)
put character in current winoow
int tft_pop_xy(int16_t *x, int16_t *y)
point push