discoverpixy
Macros | Functions
TFT

Macros

#define RGB(r, g, b)   ((((r) & 0xF8) << 8) | (((g) & 0xFC) << 3) | (((b) & 0xF8) >> 3))
 
#define RED   RGB(255,0,0)
 
#define GREEN   RGB(0,255,0)
 
#define BLUE   RGB(0,0,255)
 
#define WHITE   0xF7BE
 
#define BLACK   RGB(0,0,0)
 
#define HEX(h)   (RGB(((h)>>16),((h)>>8),(h)))
 
#define TRANSPARENT   ((uint16_t)0x80C2)
 

Functions

bool tft_init ()
 
void tft_clear (uint16_t color)
 
void tft_draw_line (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
 
void tft_draw_pixel (uint16_t x, uint16_t y, uint16_t color)
 
void tft_draw_rectangle (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
 
void tft_fill_rectangle (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
 
void tft_draw_bitmap_unscaled (uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat)
 
bool tft_draw_bitmap_file_unscaled (uint16_t x, uint16_t y, const char *filename)
 
void tft_draw_circle (uint16_t x, uint16_t y, uint16_t r, uint16_t color)
 
uint8_t tft_num_fonts ()
 
uint8_t tft_font_height (uint8_t fontnum)
 
uint8_t tft_font_width (uint8_t fontnum)
 
void tft_print_line (uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char *text)
 
void tft_print_formatted (uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char *format,...)
 

Detailed Description

The TFT Modul provides access to the display

Macro Definition Documentation

#define BLACK   RGB(0,0,0)

Definition at line 54 of file tft.h.

#define BLUE   RGB(0,0,255)

Definition at line 52 of file tft.h.

#define GREEN   RGB(0,255,0)

Definition at line 51 of file tft.h.

#define HEX (   h)    (RGB(((h)>>16),((h)>>8),(h)))

Creates a 16bit color from a 24bit hex rgb color code

Returns

Definition at line 60 of file tft.h.

#define RED   RGB(255,0,0)

Definition at line 50 of file tft.h.

#define RGB (   r,
  g,
 
)    ((((r) & 0xF8) << 8) | (((g) & 0xFC) << 3) | (((b) & 0xF8) >> 3))

Creates a 16bit color from 8bit * 3 colors (r,g,b)

Returns

Definition at line 48 of file tft.h.

#define TRANSPARENT   ((uint16_t)0x80C2)

Transparent color

Returns

Definition at line 66 of file tft.h.

#define WHITE   0xF7BE

Definition at line 53 of file tft.h.

Function Documentation

void tft_clear ( uint16_t  color)

Clears the entire display with the given color. Overpaints everything which was there before.

Parameters
colorThe 16-bit color to clear the display with.

Definition at line 45 of file tft.c.

46 {
47  ll_tft_clear(color);
48 }
void ll_tft_clear(uint16_t color)

Here is the call graph for this function:

Here is the caller graph for this function:

bool tft_draw_bitmap_file_unscaled ( uint16_t  x,
uint16_t  y,
const char *  filename 
)

Draws a bitmap from the filesystem onto the display without scaling/cropping The bitmap must be saved in the windows bitmap format (.bmp) without compression and with 24 (b,g,r) or 32 (a,r,g,b) bits per pixel

Parameters
xThe x-coordinate of the top-left corner to draw the bitmap at
yThe y-coordinate of the top-left corner to draw the bitmap at
filenameThe absolute path to the .bmp file
Returns
true on success

Definition at line 123 of file tft.c.

124 {
125  //This method reads a .bmp file from the filesystem and tries to draw it.
126  //Note: The bmp implementation is not complete, it has some limitations and it makes assumptions. See doxygen comment for this method.
127  //Source Copied and adapted from: http://stackoverflow.com/a/17040962/2606757
128 
129  FILE_HANDLE* file = filesystem_file_open(filename); //try to open the file
130 
131  if (file == NULL) { //file opening failed
132  return false;
133  }
134 
135  unsigned char info[54];
136 
137  if (filesystem_file_read(file, info, 54) != F_OK) { //try to read the 54 byte header
138  filesystem_file_close(file);
139  return false; //reading the header failed
140  }
141 
142  // extract image height and width from header
143  uint32_t width = *(uint32_t*)&info[18]; //width in pixel
144  uint32_t height = *(uint32_t*)&info[22]; //height in pixel
145  uint16_t depth = *(uint16_t*)&info[28]; //bit's per pixel (color depth)
146  depth /= 8; //we want the number of bytes per pixel
147 
148  filesystem_file_seek(file, *(uint32_t*)&info[10]); //seek to the place where img data begins
149 
150  uint32_t row_padded = (width * depth + 3) & (~3); //row size must be aligned to 4 bytes
151 
152  unsigned char data [row_padded]; //allocate space for one row (incl. padding)
153 
154  for (int i = 0; i < height; i++) { //for each row
155  filesystem_file_read(file, data, row_padded); //read row into buffer
156 
157  for (int j = 0; j < width * depth; j += depth) { //for each pixel
158  unsigned char a, r, g, b;
159 
160  if (depth == 4) { //a,r,g,b 8bit each
161  a = data[j];
162  r = data[j + 1];
163  g = data[j + 2];
164  b = data[j + 3];
165  } else if (depth == 3) { // b,g,r, 8bit each
166  a = 255;
167  r = data[j + 2];
168  g = data[j + 1];
169  b = data[j];
170  }
171 
172  if (a != 0) {
173  //bmp's are stored "bottom-up", so we start drawing at the bottom
174  tft_draw_pixel(x + j / depth, y + height - 1 - i, RGB(r, g, b));
175  }
176  }
177  }
178 
179  filesystem_file_close(file);
180 
181  return true;
182 
183 }
FILE_STATUS filesystem_file_seek(FILE_HANDLE *handle, uint32_t offset)
Definition: filesystem.c:43
#define RGB(r, g, b)
Definition: tft.h:48
uint16_t y
Definition: pixy.h:81
FILE_HANDLE * filesystem_file_open(const char *filename)
Definition: filesystem.c:33
void filesystem_file_close(FILE_HANDLE *handle)
Definition: filesystem.c:38
void tft_draw_pixel(uint16_t x, uint16_t y, uint16_t color)
Definition: tft.c:56
uint16_t height
Definition: pixy.h:83
uint16_t width
Definition: pixy.h:82
Everything ok.
Definition: filesystem.h:91
uint16_t x
Definition: pixy.h:80
FILE_STATUS filesystem_file_read(FILE_HANDLE *handle, uint8_t *buf, uint32_t size)
Definition: filesystem.c:48

Here is the call graph for this function:

Here is the caller graph for this function:

void tft_draw_bitmap_unscaled ( uint16_t  x,
uint16_t  y,
uint16_t  width,
uint16_t  height,
const uint16_t *  dat 
)

Draws a bitmap onto the display without scaling/cropping. The bitmap must be provided as an array of 16-bit colors

Parameters
xThe x-coordinate of the top-left corner to draw the bitmap at
yThe y-coordinate of the top-left corner to draw the bitmap at
widthThe width of the bitmap in pixels
heightThe height of the bitmap in pixels
datA pointer to a uint16_t array containing the colors for each pixel. Starting in the topleft and going from left to right, line by line.

Definition at line 72 of file tft.c.

73 {
75 }
uint16_t y
Definition: pixy.h:81
uint16_t height
Definition: pixy.h:83
uint16_t width
Definition: pixy.h:82
uint16_t x
Definition: pixy.h:80
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat)

Here is the call graph for this function:

Here is the caller graph for this function:

void tft_draw_circle ( uint16_t  x,
uint16_t  y,
uint16_t  r,
uint16_t  color 
)

Draws the outline of a circle onto the display

Parameters
xThe x-Coordinate of the center point
yThe y-Coordinate of the center point
rThe Radius in Pixels
colorThe 16-Bit color to draw the circle with

Definition at line 77 of file tft.c.

78 {
79  ll_tft_draw_circle(x, y, r, color);
80 }
void ll_tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color)
uint16_t y
Definition: pixy.h:81
uint16_t x
Definition: pixy.h:80

Here is the call graph for this function:

Here is the caller graph for this function:

void tft_draw_line ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
uint16_t  color 
)

Draws a line onto the display. The pixels specified by start/end point are inclusive!

Parameters
x1The x-Coordinate of the start-point
y1The y-Coordinate of the start-point
x2The x-Coordinate of the end-point
y2The y-Coordinate of the end-point
colorThe 16-bit color to draw the line with

Definition at line 50 of file tft.c.

51 {
52  ll_tft_draw_line(x1, y1, x2, y2, color);
53 }
void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)

Here is the call graph for this function:

Here is the caller graph for this function:

void tft_draw_pixel ( uint16_t  x,
uint16_t  y,
uint16_t  color 
)

Draws a pixel onto the display.

Parameters
xThe x-Coordinate of the pixel
yThe y-Coordinate of the pixel
colorThe 16-bit color to draw the pixel with

Definition at line 56 of file tft.c.

57 {
58  ll_tft_draw_pixel(x, y, color);
59 }
uint16_t y
Definition: pixy.h:81
void ll_tft_draw_pixel(uint16_t x, uint16_t y, uint16_t color)
uint16_t x
Definition: pixy.h:80

Here is the call graph for this function:

Here is the caller graph for this function:

void tft_draw_rectangle ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
uint16_t  color 
)

Draws the outline of a rectangle onto the display. The outline is one pixel wide and goes through the specified start and endpoint.

Parameters
x1The x-Coordinate of the start-point
y1The y-Coordinate of the start-point
x2The x-Coordinate of the end-point
y2The y-Coordinate of the end-point
colorThe 16-bit color to draw the pixel with

Definition at line 61 of file tft.c.

62 {
63  //could be implemented with 4 lines instead of introducing a ll func
64  ll_tft_draw_rectangle(x1, y1, x2, y2, color);
65 }
void ll_tft_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)

Here is the call graph for this function:

Here is the caller graph for this function:

void tft_fill_rectangle ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
uint16_t  color 
)

Draws a filled rectangle onto the display. The start,end points are inclusive

Parameters
x1The x-Coordinate of the start-point
y1The y-Coordinate of the start-point
x2The x-Coordinate of the end-point
y2The y-Coordinate of the end-point
colorThe 16-bit color to draw the pixel with

Definition at line 67 of file tft.c.

68 {
69  ll_tft_fill_rectangle(x1, y1, x2, y2, color);
70 }
void ll_tft_fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t tft_font_height ( uint8_t  fontnum)

Get the height of a font

Parameters
fontnumThe number of the font, from 0 .. (num_fonts -1)
Returns
The height in pixel

Definition at line 87 of file tft.c.

88 {
89  return ll_tft_font_height(fontnum);
90 }
uint8_t ll_tft_font_height(uint8_t fontnum)

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t tft_font_width ( uint8_t  fontnum)

Get the width of a font

Parameters
fontnumThe number of the font, from 0 .. (num_fonts -1)
Returns
The width in pixel

Definition at line 92 of file tft.c.

93 {
94  return ll_tft_font_width(fontnum);
95 }
uint8_t ll_tft_font_width(uint8_t fontnum)

Here is the call graph for this function:

Here is the caller graph for this function:

bool tft_init ( )

Initializes the display. Call this method before using any tft_* functions

Returns
true on success

Definition at line 39 of file tft.c.

40 {
41  return ll_tft_init();
42 
43 }
bool ll_tft_init()

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t tft_num_fonts ( )

Queries the number of available fonts

Returns

Definition at line 82 of file tft.c.

83 {
84  return ll_tft_num_fonts();
85 }
uint8_t ll_tft_num_fonts()

Here is the call graph for this function:

void tft_print_formatted ( uint16_t  x,
uint16_t  y,
uint16_t  color,
uint16_t  bgcolor,
uint8_t  font,
const char *  format,
  ... 
)

Prints a formatted text (like printf) onto the display

Parameters
xThe x-Coordinate of the Top-Left corner where the text should be drawn
yThe y-Coordinate of the Top-Left corner where the text should be drawn
colorThe 16-bit foreground color of the text
bgcolorThe 16-bit background color of the text. You may pass TRANSPARENT as Color
fontThe Fontnum to use for drawing
formatThe format string (like printf)
...The arguments to format (like printf)

Definition at line 111 of file tft.c.

112 {
113  static char buffer[128]; //buffer to save the formatted text into
114 
115  //Since we have variable arguments, we need to forward them. We have to use vsprintf instead of sprintf for that.
116  va_list args;
117  va_start(args, format); //start the varg-list
118  vsprintf(buffer, format, args); //let vsprintf render the formatted string
119  tft_print_line(x, y, color, bgcolor, font, buffer); //print the string as normal text
120  va_end(args); //end the varg-list
121 }
void tft_print_line(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char *text)
Definition: tft.c:98
uint16_t y
Definition: pixy.h:81
uint16_t x
Definition: pixy.h:80

Here is the call graph for this function:

Here is the caller graph for this function:

void tft_print_line ( uint16_t  x,
uint16_t  y,
uint16_t  color,
uint16_t  bgcolor,
uint8_t  font,
const char *  text 
)

Prints a unformatted/preformatted string onto the display

Parameters
xThe x-Coordinate of the Top-Left corner where the text should be drawn
yThe y-Coordinate of the Top-Left corner where the text should be drawn
colorThe 16-bit foreground color of the text
bgcolorThe 16-bit background color of the text. You may pass TRANSPARENT as Color
fontThe Fontnum to use for drawing
textThe text to draw

Definition at line 98 of file tft.c.

99 {
100  if (font >= ll_tft_num_fonts()) {
101  return; //invalid font index
102  }
103 
104  for (int i = 0; i < strlen(text); i++) { //for each char in the line
105  ll_tft_draw_char(x, y, color, bgcolor, font, text[i]); //draw the char
106  x += ll_tft_font_width(font); //and increase the x position
107  }
108 }
uint16_t y
Definition: pixy.h:81
uint8_t ll_tft_font_width(uint8_t fontnum)
uint8_t ll_tft_num_fonts()
void ll_tft_draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, char c)
uint16_t x
Definition: pixy.h:80

Here is the call graph for this function:

Here is the caller graph for this function: