
3.5" inch TFT LCD Display Module 480X320 driven with FSMC.
TFT LCD Display Module 480X320 driven with FSMC
I have recently bought a 3.5" inch TFT LCD Touch Screen Display Module 480X320 with a www.mcufriend.com
label on the back side. The display was equipped with an 8bit parallel interface. First I decided to test it with the UniGraphic library using the BUS_8
protocol. The display was very slow but improved when I switched to the PAR_8
protocol. Because I heard about the possibility to use a Flexible Static Memory Controller (FSMC), built into some STM MCU's, to drive LCD's (read/write to LCD's memory rather than to an external SRAM) I thought it would be a fun to try it out.
Below is the brief story of what I did:
- Created a project for my STM32F407VE board in the STM32CubeIDE
- Set the
Clock Configuration
to match the one used by Mbed for the Seeed Arch Max board:
- Selected
FSMC
in theConnectivity
category and configured it as below: - Let the
STM32CubeIDE
generate the code (files). - Created a new program for the Seeed Arch Max target in the Mbed Online Compiler by selecting a
mbed os blinky
template. - Replaced the
main.cpp
with themain.c
content of theSTM32CubeIDE
project. Copy & Pasted
the other files with codes from theSTM32CubeIDE
project to the online compiler project.- Renamed and modified:
"stm32f4xx_it.h" to "stm32f4xx_it_msp.h"
"stm32f4xx_it.c" to "stm32f4xx_it_msp.c" - Added the UniGraphic library to the online compiler project.
- Extended the
UniGraphic
library with aFSMC_8
protocol and replaced theTFT::set_orientation(int orient)
function with the one used bymcufriend
for arduino. - Modified the
main.cpp
as needed.
![]() | ![]() |
Wiring
STM32F407VE | TFT LCD module |
---|---|
+3.3V | 3V3 |
GND | GND |
PB_12 | LCD_RST |
GND | LCD_CS |
PD_13 (RS) | LCD_RS |
PD_5 (WR) | LCD_WR |
PD_4 (RD) | LCD_RD |
PD_14 (DB00) | LCD_D0 |
PD_15 (DB01) | LCD_D1 |
PD_0 (DB02) | LCD_D2 |
PD_1 (DB03) | LCD_D3 |
PE_7 (DB04) | LCD_D4 |
PE_8 (DB05) | LCD_D5 |
PE_9 (DB06) | LCD_D6 |
PE_10 (DB07) | LCD_D7 |
Results
Execution times | ||
---|---|---|
Used protocol | BUS_8 | FSMC_8 |
Operation \ Time | ms | ms |
Clear | 2283.980 | 38.454 |
Plot | 192.066 | 11.365 |
8bit BMP | 63.805 | 41.338 |
Large Font | 163.872 | 7.895 |
Sparce pixels | 2072.265/1458.051 | 74.107/52.168 |
16bit BMP | 2288.589 | 59.904 |
UniGraphic/Graphics/GraphicsDisplay.h@1:47c996032a9e, 2020-09-25 (annotated)
- Committer:
- hudakz
- Date:
- Fri Sep 25 14:52:27 2020 +0000
- Revision:
- 1:47c996032a9e
- Parent:
- 0:fa952828e34c
3.5" inch TFT LCD Display Module 480X320 driven with FSMC.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:fa952828e34c | 1 | /* mbed GraphicsDisplay Display Library Base Class |
hudakz | 0:fa952828e34c | 2 | * Copyright (c) 2007-2009 sford |
hudakz | 0:fa952828e34c | 3 | * Released under the MIT License: http://mbed.org/license/mit |
hudakz | 0:fa952828e34c | 4 | * |
hudakz | 0:fa952828e34c | 5 | * A library for providing a common base class for Graphics displays |
hudakz | 0:fa952828e34c | 6 | * To port a new display, derive from this class and implement |
hudakz | 0:fa952828e34c | 7 | * the constructor (setup the display), pixel (put a pixel |
hudakz | 0:fa952828e34c | 8 | * at a location), width and height functions. Everything else |
hudakz | 0:fa952828e34c | 9 | * (locate, printf, putc, cls, window, putp, fill, blit, blitbit) |
hudakz | 0:fa952828e34c | 10 | * will come for free. You can also provide a specialised implementation |
hudakz | 0:fa952828e34c | 11 | * of window and putp to speed up the results |
hudakz | 0:fa952828e34c | 12 | */ |
hudakz | 0:fa952828e34c | 13 | |
hudakz | 0:fa952828e34c | 14 | #ifndef MBED_GRAPHICSDISPLAY_H |
hudakz | 0:fa952828e34c | 15 | #define MBED_GRAPHICSDISPLAY_H |
hudakz | 0:fa952828e34c | 16 | |
hudakz | 0:fa952828e34c | 17 | #include "TextDisplay.h" |
hudakz | 0:fa952828e34c | 18 | #include "Terminal6x8.h" |
hudakz | 0:fa952828e34c | 19 | |
hudakz | 0:fa952828e34c | 20 | |
hudakz | 0:fa952828e34c | 21 | |
hudakz | 0:fa952828e34c | 22 | /* some RGB color definitions */ |
hudakz | 0:fa952828e34c | 23 | #define Black 0x0000 /* 0, 0, 0 */ |
hudakz | 0:fa952828e34c | 24 | #define Navy 0x000F /* 0, 0, 128 */ |
hudakz | 0:fa952828e34c | 25 | #define DarkGreen 0x03E0 /* 0, 128, 0 */ |
hudakz | 0:fa952828e34c | 26 | #define DarkCyan 0x03EF /* 0, 128, 128 */ |
hudakz | 0:fa952828e34c | 27 | #define Maroon 0x7800 /* 128, 0, 0 */ |
hudakz | 0:fa952828e34c | 28 | #define Purple 0x780F /* 128, 0, 128 */ |
hudakz | 0:fa952828e34c | 29 | #define Olive 0x7BE0 /* 128, 128, 0 */ |
hudakz | 0:fa952828e34c | 30 | #define LightGrey 0xC618 /* 192, 192, 192 */ |
hudakz | 0:fa952828e34c | 31 | #define DarkGrey 0x7BEF /* 128, 128, 128 */ |
hudakz | 0:fa952828e34c | 32 | #define Blue 0x001F /* 0, 0, 255 */ |
hudakz | 0:fa952828e34c | 33 | #define Green 0x07E0 /* 0, 255, 0 */ |
hudakz | 0:fa952828e34c | 34 | #define Cyan 0x07FF /* 0, 255, 255 */ |
hudakz | 0:fa952828e34c | 35 | #define Red 0xF800 /* 255, 0, 0 */ |
hudakz | 0:fa952828e34c | 36 | #define Magenta 0xF81F /* 255, 0, 255 */ |
hudakz | 0:fa952828e34c | 37 | #define Yellow 0xFFE0 /* 255, 255, 0 */ |
hudakz | 0:fa952828e34c | 38 | #define White 0xFFFF /* 255, 255, 255 */ |
hudakz | 0:fa952828e34c | 39 | #define Orange 0xFD20 /* 255, 165, 0 */ |
hudakz | 0:fa952828e34c | 40 | #define GreenYellow 0xAFE5 /* 173, 255, 47 */ |
hudakz | 0:fa952828e34c | 41 | |
hudakz | 0:fa952828e34c | 42 | /** Bitmap |
hudakz | 0:fa952828e34c | 43 | */ |
hudakz | 0:fa952828e34c | 44 | struct Bitmap_s{ |
hudakz | 0:fa952828e34c | 45 | int xSize; |
hudakz | 0:fa952828e34c | 46 | int ySize; |
hudakz | 0:fa952828e34c | 47 | int Byte_in_Line; |
hudakz | 0:fa952828e34c | 48 | char* data; |
hudakz | 0:fa952828e34c | 49 | }; |
hudakz | 0:fa952828e34c | 50 | |
hudakz | 0:fa952828e34c | 51 | /** A common base class for Graphics displays |
hudakz | 0:fa952828e34c | 52 | */ |
hudakz | 0:fa952828e34c | 53 | class GraphicsDisplay : public TextDisplay { |
hudakz | 0:fa952828e34c | 54 | |
hudakz | 0:fa952828e34c | 55 | public: |
hudakz | 0:fa952828e34c | 56 | |
hudakz | 0:fa952828e34c | 57 | /** Create a GraphicsDisplay interface |
hudakz | 0:fa952828e34c | 58 | * @param name The name used by the parent class to access the interface |
hudakz | 0:fa952828e34c | 59 | */ |
hudakz | 0:fa952828e34c | 60 | GraphicsDisplay(const char* name); |
hudakz | 0:fa952828e34c | 61 | |
hudakz | 0:fa952828e34c | 62 | ////// functions needing implementation in derived implementation class /////////////////////////////////////// |
hudakz | 0:fa952828e34c | 63 | ////// ---------------------------------------------------------------- /////////////////////////////////////// |
hudakz | 0:fa952828e34c | 64 | |
hudakz | 0:fa952828e34c | 65 | /** Draw a pixel in the specified color. |
hudakz | 0:fa952828e34c | 66 | * @note this method must be supported in the derived class. |
hudakz | 0:fa952828e34c | 67 | * @param x is the horizontal offset to this pixel. |
hudakz | 0:fa952828e34c | 68 | * @param y is the vertical offset to this pixel. |
hudakz | 0:fa952828e34c | 69 | * @param color defines the color for the pixel. |
hudakz | 0:fa952828e34c | 70 | */ |
hudakz | 0:fa952828e34c | 71 | virtual void pixel(int x, int y, unsigned short color) = 0; |
hudakz | 0:fa952828e34c | 72 | |
hudakz | 0:fa952828e34c | 73 | /** Set the window, which controls where items are written to the screen. |
hudakz | 0:fa952828e34c | 74 | * When something hits the window width, it wraps back to the left side |
hudakz | 0:fa952828e34c | 75 | * and down a row. If the initial write is outside the window, it will |
hudakz | 0:fa952828e34c | 76 | * be captured into the window when it crosses a boundary. |
hudakz | 0:fa952828e34c | 77 | * @param x is the left edge in pixels. |
hudakz | 0:fa952828e34c | 78 | * @param y is the top edge in pixels. |
hudakz | 0:fa952828e34c | 79 | * @param w is the window width in pixels. |
hudakz | 0:fa952828e34c | 80 | * @param h is the window height in pixels. |
hudakz | 0:fa952828e34c | 81 | * @note this method must be overridden in a derived class. |
hudakz | 0:fa952828e34c | 82 | */ |
hudakz | 0:fa952828e34c | 83 | virtual void window(int x, int y, int w, int h) = 0; |
hudakz | 0:fa952828e34c | 84 | |
hudakz | 0:fa952828e34c | 85 | /** Push a single pixel into the window and increment position. |
hudakz | 0:fa952828e34c | 86 | * You may first call window() then push pixels in loop. |
hudakz | 0:fa952828e34c | 87 | * @param color is the pixel color. |
hudakz | 0:fa952828e34c | 88 | * @note this method must be overridden in a derived class. |
hudakz | 0:fa952828e34c | 89 | */ |
hudakz | 0:fa952828e34c | 90 | virtual void window_pushpixel(unsigned short color) = 0; |
hudakz | 0:fa952828e34c | 91 | |
hudakz | 0:fa952828e34c | 92 | /** Push some pixels of the same color into the window and increment position. |
hudakz | 0:fa952828e34c | 93 | * You must first call window() then push pixels. |
hudakz | 0:fa952828e34c | 94 | * @param color is the pixel color. |
hudakz | 0:fa952828e34c | 95 | * @param count: how many |
hudakz | 0:fa952828e34c | 96 | */ |
hudakz | 0:fa952828e34c | 97 | virtual void window_pushpixel(unsigned short color, unsigned int count) = 0; |
hudakz | 0:fa952828e34c | 98 | |
hudakz | 0:fa952828e34c | 99 | /** Push array of pixel colors into the window and increment position. |
hudakz | 0:fa952828e34c | 100 | * You must first call window() then push pixels. |
hudakz | 0:fa952828e34c | 101 | * @param color is the pixel color. |
hudakz | 0:fa952828e34c | 102 | */ |
hudakz | 0:fa952828e34c | 103 | virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght) = 0; |
hudakz | 0:fa952828e34c | 104 | |
hudakz | 0:fa952828e34c | 105 | /** If framebuffer is used, it needs to be sent to LCD from time to time |
hudakz | 0:fa952828e34c | 106 | @note this method must be overridden in a derived class. |
hudakz | 0:fa952828e34c | 107 | @note real function for LCD, dummy for TFT |
hudakz | 0:fa952828e34c | 108 | */ |
hudakz | 0:fa952828e34c | 109 | virtual void copy_to_lcd() = 0; |
hudakz | 0:fa952828e34c | 110 | |
hudakz | 0:fa952828e34c | 111 | /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// |
hudakz | 0:fa952828e34c | 112 | /////// ----------------------------------------------------/////////////////////////////////////////////////// |
hudakz | 0:fa952828e34c | 113 | |
hudakz | 0:fa952828e34c | 114 | /** Set window to max possible size |
hudakz | 0:fa952828e34c | 115 | * May be overridden in a derived class. |
hudakz | 0:fa952828e34c | 116 | */ |
hudakz | 0:fa952828e34c | 117 | virtual void WindowMax(void); |
hudakz | 0:fa952828e34c | 118 | |
hudakz | 0:fa952828e34c | 119 | /** clear the entire screen |
hudakz | 0:fa952828e34c | 120 | * Basically it sets windomax then fill with background color |
hudakz | 0:fa952828e34c | 121 | * May be overridden in a derived class. |
hudakz | 0:fa952828e34c | 122 | */ |
hudakz | 0:fa952828e34c | 123 | virtual void cls(); |
hudakz | 0:fa952828e34c | 124 | |
hudakz | 0:fa952828e34c | 125 | /** draw a circle |
hudakz | 0:fa952828e34c | 126 | * |
hudakz | 0:fa952828e34c | 127 | * @param x0,y0 center |
hudakz | 0:fa952828e34c | 128 | * @param r radius |
hudakz | 0:fa952828e34c | 129 | * @param color 16 bit color * |
hudakz | 0:fa952828e34c | 130 | * |
hudakz | 0:fa952828e34c | 131 | */ |
hudakz | 0:fa952828e34c | 132 | virtual void circle(int x, int y, int r, unsigned short color); |
hudakz | 0:fa952828e34c | 133 | |
hudakz | 0:fa952828e34c | 134 | /** draw a filled circle |
hudakz | 0:fa952828e34c | 135 | * |
hudakz | 0:fa952828e34c | 136 | * @param x0,y0 center |
hudakz | 0:fa952828e34c | 137 | * @param r radius |
hudakz | 0:fa952828e34c | 138 | * @param color 16 bit color * |
hudakz | 0:fa952828e34c | 139 | */ |
hudakz | 0:fa952828e34c | 140 | virtual void fillcircle(int x, int y, int r, unsigned short color); |
hudakz | 0:fa952828e34c | 141 | |
hudakz | 0:fa952828e34c | 142 | |
hudakz | 0:fa952828e34c | 143 | /** draw a 1 pixel line |
hudakz | 0:fa952828e34c | 144 | * |
hudakz | 0:fa952828e34c | 145 | * @param x0,y0 start point |
hudakz | 0:fa952828e34c | 146 | * @param x1,y1 stop point |
hudakz | 0:fa952828e34c | 147 | * @param color 16 bit color |
hudakz | 0:fa952828e34c | 148 | * |
hudakz | 0:fa952828e34c | 149 | */ |
hudakz | 0:fa952828e34c | 150 | virtual void line(int x0, int y0, int x1, int y1, unsigned short color); |
hudakz | 0:fa952828e34c | 151 | |
hudakz | 0:fa952828e34c | 152 | /** draw a horizontal line |
hudakz | 0:fa952828e34c | 153 | * |
hudakz | 0:fa952828e34c | 154 | * @param x0 horizontal start |
hudakz | 0:fa952828e34c | 155 | * @param x1 horizontal stop |
hudakz | 0:fa952828e34c | 156 | * @param y vertical position |
hudakz | 0:fa952828e34c | 157 | * @param color 16 bit color |
hudakz | 0:fa952828e34c | 158 | * |
hudakz | 0:fa952828e34c | 159 | */ |
hudakz | 0:fa952828e34c | 160 | void hline(int x0, int x1, int y, unsigned short color); |
hudakz | 0:fa952828e34c | 161 | |
hudakz | 0:fa952828e34c | 162 | /** draw a vertical line |
hudakz | 0:fa952828e34c | 163 | * |
hudakz | 0:fa952828e34c | 164 | * @param x horizontal position |
hudakz | 0:fa952828e34c | 165 | * @param y0 vertical start |
hudakz | 0:fa952828e34c | 166 | * @param y1 vertical stop |
hudakz | 0:fa952828e34c | 167 | * @param color 16 bit color |
hudakz | 0:fa952828e34c | 168 | */ |
hudakz | 0:fa952828e34c | 169 | void vline(int y0, int y1, int x, unsigned short color); |
hudakz | 0:fa952828e34c | 170 | |
hudakz | 0:fa952828e34c | 171 | /** draw a rect |
hudakz | 0:fa952828e34c | 172 | * |
hudakz | 0:fa952828e34c | 173 | * @param x0,y0 top left corner |
hudakz | 0:fa952828e34c | 174 | * @param x1,y1 down right corner |
hudakz | 0:fa952828e34c | 175 | * @param color 16 bit color |
hudakz | 0:fa952828e34c | 176 | * * |
hudakz | 0:fa952828e34c | 177 | */ |
hudakz | 0:fa952828e34c | 178 | virtual void rect(int x0, int y0, int x1, int y1, unsigned short color); |
hudakz | 0:fa952828e34c | 179 | |
hudakz | 0:fa952828e34c | 180 | /** draw a filled rect |
hudakz | 0:fa952828e34c | 181 | * |
hudakz | 0:fa952828e34c | 182 | * @param x0,y0 top left corner |
hudakz | 0:fa952828e34c | 183 | * @param x1,y1 down right corner |
hudakz | 0:fa952828e34c | 184 | * @param color 16 bit color |
hudakz | 0:fa952828e34c | 185 | * |
hudakz | 0:fa952828e34c | 186 | */ |
hudakz | 0:fa952828e34c | 187 | virtual void fillrect(int x0, int y0, int x1, int y1, unsigned short color); |
hudakz | 0:fa952828e34c | 188 | |
hudakz | 0:fa952828e34c | 189 | /** setup cursor position for text |
hudakz | 0:fa952828e34c | 190 | * |
hudakz | 0:fa952828e34c | 191 | * @param x x-position (top left) |
hudakz | 0:fa952828e34c | 192 | * @param y y-position |
hudakz | 0:fa952828e34c | 193 | */ |
hudakz | 0:fa952828e34c | 194 | virtual void locate(int x, int y); |
hudakz | 0:fa952828e34c | 195 | |
hudakz | 0:fa952828e34c | 196 | /** put a char on the screen |
hudakz | 0:fa952828e34c | 197 | * |
hudakz | 0:fa952828e34c | 198 | * @param value char to print |
hudakz | 0:fa952828e34c | 199 | * @returns printed char |
hudakz | 0:fa952828e34c | 200 | * |
hudakz | 0:fa952828e34c | 201 | */ |
hudakz | 0:fa952828e34c | 202 | virtual int _putc(int value); |
hudakz | 0:fa952828e34c | 203 | |
hudakz | 0:fa952828e34c | 204 | /** draw a character on given position out of the active font to the TFT |
hudakz | 0:fa952828e34c | 205 | * |
hudakz | 0:fa952828e34c | 206 | * @param x x-position of char (top left) |
hudakz | 0:fa952828e34c | 207 | * @param y y-position |
hudakz | 0:fa952828e34c | 208 | * @param c char to print |
hudakz | 0:fa952828e34c | 209 | * |
hudakz | 0:fa952828e34c | 210 | */ |
hudakz | 0:fa952828e34c | 211 | virtual void character(int x, int y, int c); |
hudakz | 0:fa952828e34c | 212 | |
hudakz | 0:fa952828e34c | 213 | /** paint a bitmap on the TFT |
hudakz | 0:fa952828e34c | 214 | * |
hudakz | 0:fa952828e34c | 215 | * @param x,y : upper left corner |
hudakz | 0:fa952828e34c | 216 | * @param w width of bitmap |
hudakz | 0:fa952828e34c | 217 | * @param h high of bitmap |
hudakz | 0:fa952828e34c | 218 | * @param *bitmap pointer to the bitmap data |
hudakz | 0:fa952828e34c | 219 | * |
hudakz | 0:fa952828e34c | 220 | * bitmap format: 16 bit R5 G6 B5 |
hudakz | 0:fa952828e34c | 221 | * |
hudakz | 0:fa952828e34c | 222 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
hudakz | 0:fa952828e34c | 223 | * use winhex to load this file and mark data stating at offset 0x46 to end |
hudakz | 0:fa952828e34c | 224 | * use edit -> copy block -> C Source to export C array |
hudakz | 0:fa952828e34c | 225 | * paste this array into your program |
hudakz | 0:fa952828e34c | 226 | * |
hudakz | 0:fa952828e34c | 227 | * define the array as static const unsigned char to put it into flash memory |
hudakz | 0:fa952828e34c | 228 | * cast the pointer to (unsigned char *) : |
hudakz | 0:fa952828e34c | 229 | * tft.Bitmap(10,40,309,50,(unsigned char *)scala); |
hudakz | 0:fa952828e34c | 230 | */ |
hudakz | 0:fa952828e34c | 231 | void Bitmap(int x, int y, int w, int h,unsigned char *bitmap); |
hudakz | 0:fa952828e34c | 232 | |
hudakz | 0:fa952828e34c | 233 | /** paint monochrome bitmap to screen |
hudakz | 0:fa952828e34c | 234 | * |
hudakz | 0:fa952828e34c | 235 | * @param bm Bitmap in flash |
hudakz | 0:fa952828e34c | 236 | * @param x x start |
hudakz | 0:fa952828e34c | 237 | * @param y y start |
hudakz | 0:fa952828e34c | 238 | * |
hudakz | 0:fa952828e34c | 239 | */ |
hudakz | 0:fa952828e34c | 240 | void Bitmap_BW(Bitmap_s bm, int x, int y); |
hudakz | 0:fa952828e34c | 241 | |
hudakz | 0:fa952828e34c | 242 | /** paint a 16 bit BMP from filesytem on the TFT (slow) |
hudakz | 0:fa952828e34c | 243 | * |
hudakz | 0:fa952828e34c | 244 | * @param x,y : position of upper left corner |
hudakz | 0:fa952828e34c | 245 | * @param *Name_BMP name of the BMP file with drive: "/local/test.bmp" |
hudakz | 0:fa952828e34c | 246 | * |
hudakz | 0:fa952828e34c | 247 | * @returns 1 if bmp file was found and painted |
hudakz | 0:fa952828e34c | 248 | * @returns 0 if bmp file was found not found |
hudakz | 0:fa952828e34c | 249 | * @returns -1 if file is no bmp |
hudakz | 0:fa952828e34c | 250 | * @returns -2 if bmp file is no 16 bit bmp |
hudakz | 0:fa952828e34c | 251 | * @returns -3 if bmp file is to big for screen |
hudakz | 0:fa952828e34c | 252 | * @returns -4 if buffer malloc go wrong |
hudakz | 0:fa952828e34c | 253 | * |
hudakz | 0:fa952828e34c | 254 | * bitmap format: 16 bit R5 G6 B5 |
hudakz | 0:fa952828e34c | 255 | * |
hudakz | 0:fa952828e34c | 256 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
hudakz | 0:fa952828e34c | 257 | * copy to internal file system or SD card |
hudakz | 0:fa952828e34c | 258 | */ |
hudakz | 0:fa952828e34c | 259 | int BMP_16(int x, int y, const char *Name_BMP); |
hudakz | 0:fa952828e34c | 260 | |
hudakz | 0:fa952828e34c | 261 | |
hudakz | 0:fa952828e34c | 262 | |
hudakz | 0:fa952828e34c | 263 | /** select the font to use |
hudakz | 0:fa952828e34c | 264 | * |
hudakz | 0:fa952828e34c | 265 | * @param f pointer to font array |
hudakz | 0:fa952828e34c | 266 | * @param firstascii first ascii code present in font array, default 32 (space) |
hudakz | 0:fa952828e34c | 267 | * @param lastascii last ascii code present in font array, default 127 (DEL) |
hudakz | 0:fa952828e34c | 268 | * @param proportional enable/disable variable font width (default enabled) |
hudakz | 0:fa952828e34c | 269 | * |
hudakz | 0:fa952828e34c | 270 | * font array can created with GLCD Font Creator from http://www.mikroe.com |
hudakz | 0:fa952828e34c | 271 | * you have to add 4 parameter at the beginning of the font array to use: |
hudakz | 0:fa952828e34c | 272 | * - the number of byte / char (not used in this revision, set to whatever) |
hudakz | 0:fa952828e34c | 273 | * - the vertial size in pixel |
hudakz | 0:fa952828e34c | 274 | * - the horizontal size in pixel |
hudakz | 0:fa952828e34c | 275 | * - the number of byte per vertical line (not used in this revision, set to whatever) |
hudakz | 0:fa952828e34c | 276 | * you also have to change the array to cont unsigned char[] and __align(2) |
hudakz | 0:fa952828e34c | 277 | * |
hudakz | 0:fa952828e34c | 278 | */ |
hudakz | 0:fa952828e34c | 279 | void set_font(unsigned char* f, unsigned char firstascii=32, unsigned char lastascii=127, bool proportional = true); |
hudakz | 0:fa952828e34c | 280 | |
hudakz | 0:fa952828e34c | 281 | /** Zoom fount |
hudakz | 0:fa952828e34c | 282 | * |
hudakz | 0:fa952828e34c | 283 | * @param x_mul horizontal size multiplier |
hudakz | 0:fa952828e34c | 284 | * @param y_mul vertical size multiplier |
hudakz | 0:fa952828e34c | 285 | */ |
hudakz | 0:fa952828e34c | 286 | void set_font_zoom(unsigned char x_mul, unsigned char y_mul); |
hudakz | 0:fa952828e34c | 287 | |
hudakz | 0:fa952828e34c | 288 | /** Get the number of columns based on the currently active font. |
hudakz | 0:fa952828e34c | 289 | * @returns number of columns. |
hudakz | 0:fa952828e34c | 290 | * @note this method may be overridden in a derived class. |
hudakz | 0:fa952828e34c | 291 | */ |
hudakz | 0:fa952828e34c | 292 | virtual int columns(); |
hudakz | 0:fa952828e34c | 293 | |
hudakz | 0:fa952828e34c | 294 | /** Get the number of rows based on the currently active font. |
hudakz | 0:fa952828e34c | 295 | * @returns number of rows. |
hudakz | 0:fa952828e34c | 296 | * @note this method may be overridden in a derived class. |
hudakz | 0:fa952828e34c | 297 | */ |
hudakz | 0:fa952828e34c | 298 | virtual int rows(); |
hudakz | 0:fa952828e34c | 299 | |
hudakz | 0:fa952828e34c | 300 | /** get the current oriented screen width in pixels |
hudakz | 0:fa952828e34c | 301 | * @returns screen width in pixels. |
hudakz | 0:fa952828e34c | 302 | */ |
hudakz | 0:fa952828e34c | 303 | int width(); |
hudakz | 0:fa952828e34c | 304 | |
hudakz | 0:fa952828e34c | 305 | /** get the current oriented screen height in pixels |
hudakz | 0:fa952828e34c | 306 | * @returns screen height in pixels. |
hudakz | 0:fa952828e34c | 307 | */ |
hudakz | 0:fa952828e34c | 308 | int height(); |
hudakz | 0:fa952828e34c | 309 | |
hudakz | 0:fa952828e34c | 310 | /** set the current oriented screen width in pixels |
hudakz | 0:fa952828e34c | 311 | * @param width screen width in pixels. |
hudakz | 0:fa952828e34c | 312 | */ |
hudakz | 0:fa952828e34c | 313 | void set_width(int width); |
hudakz | 0:fa952828e34c | 314 | |
hudakz | 0:fa952828e34c | 315 | /** set the current oriented screen height in pixels |
hudakz | 0:fa952828e34c | 316 | * @param height screen height in pixels. |
hudakz | 0:fa952828e34c | 317 | */ |
hudakz | 0:fa952828e34c | 318 | void set_height(int height); |
hudakz | 0:fa952828e34c | 319 | |
hudakz | 0:fa952828e34c | 320 | /** setup auto update of screen |
hudakz | 0:fa952828e34c | 321 | * |
hudakz | 0:fa952828e34c | 322 | * @param up 1 = on , 0 = off |
hudakz | 0:fa952828e34c | 323 | * if switched off the program has to call copy_to_lcd() |
hudakz | 0:fa952828e34c | 324 | * to update screen from framebuffer |
hudakz | 0:fa952828e34c | 325 | */ |
hudakz | 0:fa952828e34c | 326 | void set_auto_up(bool up); |
hudakz | 0:fa952828e34c | 327 | |
hudakz | 0:fa952828e34c | 328 | /** get status of the auto update function |
hudakz | 0:fa952828e34c | 329 | * |
hudakz | 0:fa952828e34c | 330 | * @returns if auto update is on |
hudakz | 0:fa952828e34c | 331 | */ |
hudakz | 0:fa952828e34c | 332 | bool get_auto_up(void); |
hudakz | 0:fa952828e34c | 333 | |
hudakz | 0:fa952828e34c | 334 | |
hudakz | 0:fa952828e34c | 335 | |
hudakz | 0:fa952828e34c | 336 | private: |
hudakz | 0:fa952828e34c | 337 | |
hudakz | 0:fa952828e34c | 338 | unsigned char* font; |
hudakz | 0:fa952828e34c | 339 | // display width and height related to current orientation |
hudakz | 0:fa952828e34c | 340 | int oriented_width; |
hudakz | 0:fa952828e34c | 341 | int oriented_height; |
hudakz | 0:fa952828e34c | 342 | |
hudakz | 0:fa952828e34c | 343 | // text char location |
hudakz | 0:fa952828e34c | 344 | int char_x; |
hudakz | 0:fa952828e34c | 345 | int char_y; |
hudakz | 0:fa952828e34c | 346 | |
hudakz | 0:fa952828e34c | 347 | int fontoffset;// bytes / char (short) |
hudakz | 0:fa952828e34c | 348 | int fonthor; // hor size of font (char) |
hudakz | 0:fa952828e34c | 349 | int fontvert; // ver size of font (char) |
hudakz | 0:fa952828e34c | 350 | int fontbpl; // bytes per line (char) |
hudakz | 0:fa952828e34c | 351 | int fontzoomver; // size multiplier |
hudakz | 0:fa952828e34c | 352 | int fontzoomhor; // size multiplier |
hudakz | 0:fa952828e34c | 353 | unsigned char firstch; // first ascii code present in font array (usually 32) |
hudakz | 0:fa952828e34c | 354 | unsigned char lastch; // last ascii code present in font array (usually 127) |
hudakz | 0:fa952828e34c | 355 | bool auto_up; // autoupdate flag for LCD |
hudakz | 0:fa952828e34c | 356 | bool fontprop; |
hudakz | 0:fa952828e34c | 357 | |
hudakz | 0:fa952828e34c | 358 | |
hudakz | 0:fa952828e34c | 359 | }; |
hudakz | 0:fa952828e34c | 360 | |
hudakz | 0:fa952828e34c | 361 | #endif |