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.cpp@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 UniGraphic library - Graphics class |
hudakz | 0:fa952828e34c | 2 | * Copyright (c) 2015 Giuliano Dianda |
hudakz | 0:fa952828e34c | 3 | * Released under the MIT License: http://mbed.org/license/mit |
hudakz | 0:fa952828e34c | 4 | * |
hudakz | 0:fa952828e34c | 5 | * Derived work of: |
hudakz | 0:fa952828e34c | 6 | * |
hudakz | 0:fa952828e34c | 7 | * mbed GraphicsDisplay Display Library Base Class |
hudakz | 0:fa952828e34c | 8 | * Copyright (c) 2007-2009 sford |
hudakz | 0:fa952828e34c | 9 | * Released under the MIT License: http://mbed.org/license/mit |
hudakz | 0:fa952828e34c | 10 | * |
hudakz | 0:fa952828e34c | 11 | * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller |
hudakz | 0:fa952828e34c | 12 | * Copyright (c) 2013 Peter Drescher - DC2PD |
hudakz | 0:fa952828e34c | 13 | * |
hudakz | 0:fa952828e34c | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
hudakz | 0:fa952828e34c | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
hudakz | 0:fa952828e34c | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
hudakz | 0:fa952828e34c | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
hudakz | 0:fa952828e34c | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
hudakz | 0:fa952828e34c | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
hudakz | 0:fa952828e34c | 20 | * THE SOFTWARE. |
hudakz | 0:fa952828e34c | 21 | */ |
hudakz | 0:fa952828e34c | 22 | #include "GraphicsDisplay.h" |
hudakz | 0:fa952828e34c | 23 | #define SWAP(a, b) { \ |
hudakz | 0:fa952828e34c | 24 | a ^= b; \ |
hudakz | 0:fa952828e34c | 25 | b ^= a; \ |
hudakz | 0:fa952828e34c | 26 | a ^= b; \ |
hudakz | 0:fa952828e34c | 27 | } |
hudakz | 0:fa952828e34c | 28 | |
hudakz | 0:fa952828e34c | 29 | /** |
hudakz | 0:fa952828e34c | 30 | * @brief |
hudakz | 0:fa952828e34c | 31 | * @note |
hudakz | 0:fa952828e34c | 32 | * @param |
hudakz | 0:fa952828e34c | 33 | * @retval |
hudakz | 0:fa952828e34c | 34 | */ |
hudakz | 0:fa952828e34c | 35 | GraphicsDisplay::GraphicsDisplay(const char* name) : |
hudakz | 0:fa952828e34c | 36 | TextDisplay(name) |
hudakz | 0:fa952828e34c | 37 | { |
hudakz | 0:fa952828e34c | 38 | set_font((unsigned char*)Terminal6x8, 32, 127, true); |
hudakz | 0:fa952828e34c | 39 | |
hudakz | 0:fa952828e34c | 40 | // foreground(0xFFFF); |
hudakz | 0:fa952828e34c | 41 | // background(0x0000); |
hudakz | 0:fa952828e34c | 42 | char_x = 0; |
hudakz | 0:fa952828e34c | 43 | char_y = 0; |
hudakz | 0:fa952828e34c | 44 | oriented_width = 0; |
hudakz | 0:fa952828e34c | 45 | oriented_height = 0; |
hudakz | 0:fa952828e34c | 46 | fontzoomver = 1; |
hudakz | 0:fa952828e34c | 47 | fontzoomhor = 1; |
hudakz | 0:fa952828e34c | 48 | auto_up = true; |
hudakz | 0:fa952828e34c | 49 | } |
hudakz | 0:fa952828e34c | 50 | |
hudakz | 0:fa952828e34c | 51 | /** |
hudakz | 0:fa952828e34c | 52 | * @brief |
hudakz | 0:fa952828e34c | 53 | * @note |
hudakz | 0:fa952828e34c | 54 | * @param |
hudakz | 0:fa952828e34c | 55 | * @retval |
hudakz | 0:fa952828e34c | 56 | */ |
hudakz | 0:fa952828e34c | 57 | void GraphicsDisplay::WindowMax(void) |
hudakz | 0:fa952828e34c | 58 | { |
hudakz | 0:fa952828e34c | 59 | window(0, 0, oriented_width, oriented_height); |
hudakz | 0:fa952828e34c | 60 | } |
hudakz | 0:fa952828e34c | 61 | |
hudakz | 0:fa952828e34c | 62 | /** |
hudakz | 0:fa952828e34c | 63 | * @brief |
hudakz | 0:fa952828e34c | 64 | * @note |
hudakz | 0:fa952828e34c | 65 | * @param |
hudakz | 0:fa952828e34c | 66 | * @retval |
hudakz | 0:fa952828e34c | 67 | */ |
hudakz | 0:fa952828e34c | 68 | void GraphicsDisplay::set_width(int width) |
hudakz | 0:fa952828e34c | 69 | { |
hudakz | 0:fa952828e34c | 70 | oriented_width = width; |
hudakz | 0:fa952828e34c | 71 | } |
hudakz | 0:fa952828e34c | 72 | |
hudakz | 0:fa952828e34c | 73 | /** |
hudakz | 0:fa952828e34c | 74 | * @brief |
hudakz | 0:fa952828e34c | 75 | * @note |
hudakz | 0:fa952828e34c | 76 | * @param |
hudakz | 0:fa952828e34c | 77 | * @retval |
hudakz | 0:fa952828e34c | 78 | */ |
hudakz | 0:fa952828e34c | 79 | void GraphicsDisplay::set_height(int height) |
hudakz | 0:fa952828e34c | 80 | { |
hudakz | 0:fa952828e34c | 81 | oriented_height = height; |
hudakz | 0:fa952828e34c | 82 | } |
hudakz | 0:fa952828e34c | 83 | |
hudakz | 0:fa952828e34c | 84 | /** |
hudakz | 0:fa952828e34c | 85 | * @brief |
hudakz | 0:fa952828e34c | 86 | * @note |
hudakz | 0:fa952828e34c | 87 | * @param |
hudakz | 0:fa952828e34c | 88 | * @retval |
hudakz | 0:fa952828e34c | 89 | */ |
hudakz | 0:fa952828e34c | 90 | int GraphicsDisplay::width() |
hudakz | 0:fa952828e34c | 91 | { |
hudakz | 0:fa952828e34c | 92 | return oriented_width; |
hudakz | 0:fa952828e34c | 93 | } |
hudakz | 0:fa952828e34c | 94 | |
hudakz | 0:fa952828e34c | 95 | /** |
hudakz | 0:fa952828e34c | 96 | * @brief |
hudakz | 0:fa952828e34c | 97 | * @note |
hudakz | 0:fa952828e34c | 98 | * @param |
hudakz | 0:fa952828e34c | 99 | * @retval |
hudakz | 0:fa952828e34c | 100 | */ |
hudakz | 0:fa952828e34c | 101 | int GraphicsDisplay::height() |
hudakz | 0:fa952828e34c | 102 | { |
hudakz | 0:fa952828e34c | 103 | return oriented_height; |
hudakz | 0:fa952828e34c | 104 | } |
hudakz | 0:fa952828e34c | 105 | |
hudakz | 0:fa952828e34c | 106 | /** |
hudakz | 0:fa952828e34c | 107 | * @brief |
hudakz | 0:fa952828e34c | 108 | * @note |
hudakz | 0:fa952828e34c | 109 | * @param |
hudakz | 0:fa952828e34c | 110 | * @retval |
hudakz | 0:fa952828e34c | 111 | */ |
hudakz | 0:fa952828e34c | 112 | void GraphicsDisplay::circle(int x0, int y0, int r, unsigned short color) |
hudakz | 0:fa952828e34c | 113 | { |
hudakz | 0:fa952828e34c | 114 | int x = -r; |
hudakz | 0:fa952828e34c | 115 | int y = 0; |
hudakz | 0:fa952828e34c | 116 | int err = 2 - 2 * r; |
hudakz | 0:fa952828e34c | 117 | int e2; |
hudakz | 0:fa952828e34c | 118 | |
hudakz | 0:fa952828e34c | 119 | do |
hudakz | 0:fa952828e34c | 120 | { |
hudakz | 0:fa952828e34c | 121 | pixel(x0 - x, y0 + y, color); |
hudakz | 0:fa952828e34c | 122 | pixel(x0 + x, y0 + y, color); |
hudakz | 0:fa952828e34c | 123 | pixel(x0 + x, y0 - y, color); |
hudakz | 0:fa952828e34c | 124 | pixel(x0 - x, y0 - y, color); |
hudakz | 0:fa952828e34c | 125 | e2 = err; |
hudakz | 0:fa952828e34c | 126 | if (e2 <= y) { |
hudakz | 0:fa952828e34c | 127 | err += ++y * 2 + 1; |
hudakz | 0:fa952828e34c | 128 | if (-x == y && e2 <= x) |
hudakz | 0:fa952828e34c | 129 | e2 = 0; |
hudakz | 0:fa952828e34c | 130 | } |
hudakz | 0:fa952828e34c | 131 | |
hudakz | 0:fa952828e34c | 132 | if (e2 > x) |
hudakz | 0:fa952828e34c | 133 | err += ++x * 2 + 1; |
hudakz | 0:fa952828e34c | 134 | } while (x <= 0); |
hudakz | 0:fa952828e34c | 135 | if (auto_up) |
hudakz | 0:fa952828e34c | 136 | copy_to_lcd(); |
hudakz | 0:fa952828e34c | 137 | } |
hudakz | 0:fa952828e34c | 138 | |
hudakz | 0:fa952828e34c | 139 | /** |
hudakz | 0:fa952828e34c | 140 | * @brief |
hudakz | 0:fa952828e34c | 141 | * @note |
hudakz | 0:fa952828e34c | 142 | * @param |
hudakz | 0:fa952828e34c | 143 | * @retval |
hudakz | 0:fa952828e34c | 144 | */ |
hudakz | 0:fa952828e34c | 145 | void GraphicsDisplay::fillcircle(int x0, int y0, int r, unsigned short color) |
hudakz | 0:fa952828e34c | 146 | { |
hudakz | 0:fa952828e34c | 147 | bool old_auto_up = auto_up; |
hudakz | 0:fa952828e34c | 148 | if (auto_up) |
hudakz | 0:fa952828e34c | 149 | auto_up = false; |
hudakz | 0:fa952828e34c | 150 | |
hudakz | 0:fa952828e34c | 151 | int x = -r, y = 0, err = 2 - 2 * r, e2; |
hudakz | 0:fa952828e34c | 152 | do |
hudakz | 0:fa952828e34c | 153 | { |
hudakz | 0:fa952828e34c | 154 | vline(x0 - x, y0 - y, y0 + y, color); |
hudakz | 0:fa952828e34c | 155 | vline(x0 + x, y0 - y, y0 + y, color); |
hudakz | 0:fa952828e34c | 156 | e2 = err; |
hudakz | 0:fa952828e34c | 157 | if (e2 <= y) { |
hudakz | 0:fa952828e34c | 158 | err += ++y * 2 + 1; |
hudakz | 0:fa952828e34c | 159 | if (-x == y && e2 <= x) |
hudakz | 0:fa952828e34c | 160 | e2 = 0; |
hudakz | 0:fa952828e34c | 161 | } |
hudakz | 0:fa952828e34c | 162 | |
hudakz | 0:fa952828e34c | 163 | if (e2 > x) |
hudakz | 0:fa952828e34c | 164 | err += ++x * 2 + 1; |
hudakz | 0:fa952828e34c | 165 | } while (x <= 0); |
hudakz | 0:fa952828e34c | 166 | if (old_auto_up) { |
hudakz | 0:fa952828e34c | 167 | auto_up = true; |
hudakz | 0:fa952828e34c | 168 | copy_to_lcd(); |
hudakz | 0:fa952828e34c | 169 | } |
hudakz | 0:fa952828e34c | 170 | } |
hudakz | 0:fa952828e34c | 171 | |
hudakz | 0:fa952828e34c | 172 | /** |
hudakz | 0:fa952828e34c | 173 | * @brief |
hudakz | 0:fa952828e34c | 174 | * @note |
hudakz | 0:fa952828e34c | 175 | * @param |
hudakz | 0:fa952828e34c | 176 | * @retval |
hudakz | 0:fa952828e34c | 177 | */ |
hudakz | 0:fa952828e34c | 178 | void GraphicsDisplay::hline(int x0, int x1, int y, unsigned short color) |
hudakz | 0:fa952828e34c | 179 | { |
hudakz | 0:fa952828e34c | 180 | int len = x1 - x0 + 1; |
hudakz | 0:fa952828e34c | 181 | window(x0, y, len, 1); |
hudakz | 0:fa952828e34c | 182 | |
hudakz | 0:fa952828e34c | 183 | // for (int j=0; j<len; j++) window_pushpixel(color); |
hudakz | 0:fa952828e34c | 184 | window_pushpixel(color, len); |
hudakz | 0:fa952828e34c | 185 | if (auto_up) |
hudakz | 0:fa952828e34c | 186 | copy_to_lcd(); |
hudakz | 0:fa952828e34c | 187 | return; |
hudakz | 0:fa952828e34c | 188 | } |
hudakz | 0:fa952828e34c | 189 | |
hudakz | 0:fa952828e34c | 190 | /** |
hudakz | 0:fa952828e34c | 191 | * @brief |
hudakz | 0:fa952828e34c | 192 | * @note |
hudakz | 0:fa952828e34c | 193 | * @param |
hudakz | 0:fa952828e34c | 194 | * @retval |
hudakz | 0:fa952828e34c | 195 | */ |
hudakz | 0:fa952828e34c | 196 | void GraphicsDisplay::vline(int x, int y0, int y1, unsigned short color) |
hudakz | 0:fa952828e34c | 197 | { |
hudakz | 0:fa952828e34c | 198 | int len = y1 - y0 + 1; |
hudakz | 0:fa952828e34c | 199 | window(x, y0, 1, len); |
hudakz | 0:fa952828e34c | 200 | |
hudakz | 0:fa952828e34c | 201 | // for (int y=0; y<len; y++) window_pushpixel(color); |
hudakz | 0:fa952828e34c | 202 | window_pushpixel(color, len); |
hudakz | 0:fa952828e34c | 203 | if (auto_up) |
hudakz | 0:fa952828e34c | 204 | copy_to_lcd(); |
hudakz | 0:fa952828e34c | 205 | return; |
hudakz | 0:fa952828e34c | 206 | } |
hudakz | 0:fa952828e34c | 207 | |
hudakz | 0:fa952828e34c | 208 | /** |
hudakz | 0:fa952828e34c | 209 | * @brief |
hudakz | 0:fa952828e34c | 210 | * @note |
hudakz | 0:fa952828e34c | 211 | * @param |
hudakz | 0:fa952828e34c | 212 | * @retval |
hudakz | 0:fa952828e34c | 213 | */ |
hudakz | 0:fa952828e34c | 214 | void GraphicsDisplay::line(int x0, int y0, int x1, int y1, unsigned short color) |
hudakz | 0:fa952828e34c | 215 | { |
hudakz | 0:fa952828e34c | 216 | //WindowMax(); |
hudakz | 0:fa952828e34c | 217 | int dx = 0, dy = 0; |
hudakz | 0:fa952828e34c | 218 | int dx_sym = 0, dy_sym = 0; |
hudakz | 0:fa952828e34c | 219 | int dx_x2 = 0, dy_x2 = 0; |
hudakz | 0:fa952828e34c | 220 | int di = 0; |
hudakz | 0:fa952828e34c | 221 | |
hudakz | 0:fa952828e34c | 222 | dx = x1 - x0; |
hudakz | 0:fa952828e34c | 223 | dy = y1 - y0; |
hudakz | 0:fa952828e34c | 224 | |
hudakz | 0:fa952828e34c | 225 | if (dx == 0) { |
hudakz | 0:fa952828e34c | 226 | |
hudakz | 0:fa952828e34c | 227 | /* vertical line */ |
hudakz | 0:fa952828e34c | 228 | if (y1 < y0) |
hudakz | 0:fa952828e34c | 229 | SWAP(y0, y1); |
hudakz | 0:fa952828e34c | 230 | vline(x0, y0, y1, color); |
hudakz | 0:fa952828e34c | 231 | return; |
hudakz | 0:fa952828e34c | 232 | } |
hudakz | 0:fa952828e34c | 233 | |
hudakz | 0:fa952828e34c | 234 | if (dx > 0) { |
hudakz | 0:fa952828e34c | 235 | dx_sym = 1; |
hudakz | 0:fa952828e34c | 236 | } |
hudakz | 0:fa952828e34c | 237 | else { |
hudakz | 0:fa952828e34c | 238 | dx_sym = -1; |
hudakz | 0:fa952828e34c | 239 | } |
hudakz | 0:fa952828e34c | 240 | |
hudakz | 0:fa952828e34c | 241 | if (dy == 0) { |
hudakz | 0:fa952828e34c | 242 | |
hudakz | 0:fa952828e34c | 243 | /* horizontal line */ |
hudakz | 0:fa952828e34c | 244 | if (x1 < x0) |
hudakz | 0:fa952828e34c | 245 | SWAP(x1, x0); |
hudakz | 0:fa952828e34c | 246 | hline(x0, x1, y0, color); |
hudakz | 0:fa952828e34c | 247 | return; |
hudakz | 0:fa952828e34c | 248 | } |
hudakz | 0:fa952828e34c | 249 | |
hudakz | 0:fa952828e34c | 250 | if (dy > 0) { |
hudakz | 0:fa952828e34c | 251 | dy_sym = 1; |
hudakz | 0:fa952828e34c | 252 | } |
hudakz | 0:fa952828e34c | 253 | else { |
hudakz | 0:fa952828e34c | 254 | dy_sym = -1; |
hudakz | 0:fa952828e34c | 255 | } |
hudakz | 0:fa952828e34c | 256 | |
hudakz | 0:fa952828e34c | 257 | dx = dx_sym * dx; |
hudakz | 0:fa952828e34c | 258 | dy = dy_sym * dy; |
hudakz | 0:fa952828e34c | 259 | |
hudakz | 0:fa952828e34c | 260 | dx_x2 = dx * 2; |
hudakz | 0:fa952828e34c | 261 | dy_x2 = dy * 2; |
hudakz | 0:fa952828e34c | 262 | |
hudakz | 0:fa952828e34c | 263 | if (dx >= dy) { |
hudakz | 0:fa952828e34c | 264 | di = dy_x2 - dx; |
hudakz | 0:fa952828e34c | 265 | while (x0 != x1) { |
hudakz | 0:fa952828e34c | 266 | pixel(x0, y0, color); |
hudakz | 0:fa952828e34c | 267 | x0 += dx_sym; |
hudakz | 0:fa952828e34c | 268 | if (di < 0) { |
hudakz | 0:fa952828e34c | 269 | di += dy_x2; |
hudakz | 0:fa952828e34c | 270 | } |
hudakz | 0:fa952828e34c | 271 | else { |
hudakz | 0:fa952828e34c | 272 | di += dy_x2 - dx_x2; |
hudakz | 0:fa952828e34c | 273 | y0 += dy_sym; |
hudakz | 0:fa952828e34c | 274 | } |
hudakz | 0:fa952828e34c | 275 | } |
hudakz | 0:fa952828e34c | 276 | |
hudakz | 0:fa952828e34c | 277 | pixel(x0, y0, color); |
hudakz | 0:fa952828e34c | 278 | } |
hudakz | 0:fa952828e34c | 279 | else { |
hudakz | 0:fa952828e34c | 280 | di = dx_x2 - dy; |
hudakz | 0:fa952828e34c | 281 | while (y0 != y1) { |
hudakz | 0:fa952828e34c | 282 | pixel(x0, y0, color); |
hudakz | 0:fa952828e34c | 283 | y0 += dy_sym; |
hudakz | 0:fa952828e34c | 284 | if (di < 0) { |
hudakz | 0:fa952828e34c | 285 | di += dx_x2; |
hudakz | 0:fa952828e34c | 286 | } |
hudakz | 0:fa952828e34c | 287 | else { |
hudakz | 0:fa952828e34c | 288 | di += dx_x2 - dy_x2; |
hudakz | 0:fa952828e34c | 289 | x0 += dx_sym; |
hudakz | 0:fa952828e34c | 290 | } |
hudakz | 0:fa952828e34c | 291 | } |
hudakz | 0:fa952828e34c | 292 | |
hudakz | 0:fa952828e34c | 293 | pixel(x0, y0, color); |
hudakz | 0:fa952828e34c | 294 | } |
hudakz | 0:fa952828e34c | 295 | |
hudakz | 0:fa952828e34c | 296 | if (auto_up) |
hudakz | 0:fa952828e34c | 297 | copy_to_lcd(); |
hudakz | 0:fa952828e34c | 298 | return; |
hudakz | 0:fa952828e34c | 299 | } |
hudakz | 0:fa952828e34c | 300 | |
hudakz | 0:fa952828e34c | 301 | /** |
hudakz | 0:fa952828e34c | 302 | * @brief |
hudakz | 0:fa952828e34c | 303 | * @note |
hudakz | 0:fa952828e34c | 304 | * @param |
hudakz | 0:fa952828e34c | 305 | * @retval |
hudakz | 0:fa952828e34c | 306 | */ |
hudakz | 0:fa952828e34c | 307 | void GraphicsDisplay::rect(int x0, int y0, int x1, int y1, unsigned short color) |
hudakz | 0:fa952828e34c | 308 | { |
hudakz | 0:fa952828e34c | 309 | bool old_auto_up = auto_up; |
hudakz | 0:fa952828e34c | 310 | if (auto_up) |
hudakz | 0:fa952828e34c | 311 | auto_up = 0; |
hudakz | 0:fa952828e34c | 312 | if (x1 > x0) |
hudakz | 0:fa952828e34c | 313 | hline(x0, x1, y0, color); |
hudakz | 0:fa952828e34c | 314 | else |
hudakz | 0:fa952828e34c | 315 | hline(x1, x0, y0, color); |
hudakz | 0:fa952828e34c | 316 | |
hudakz | 0:fa952828e34c | 317 | if (y1 > y0) |
hudakz | 0:fa952828e34c | 318 | vline(x0, y0, y1, color); |
hudakz | 0:fa952828e34c | 319 | else |
hudakz | 0:fa952828e34c | 320 | vline(x0, y1, y0, color); |
hudakz | 0:fa952828e34c | 321 | |
hudakz | 0:fa952828e34c | 322 | if (x1 > x0) |
hudakz | 0:fa952828e34c | 323 | hline(x0, x1, y1, color); |
hudakz | 0:fa952828e34c | 324 | else |
hudakz | 0:fa952828e34c | 325 | hline(x1, x0, y1, color); |
hudakz | 0:fa952828e34c | 326 | |
hudakz | 0:fa952828e34c | 327 | if (y1 > y0) |
hudakz | 0:fa952828e34c | 328 | vline(x1, y0, y1, color); |
hudakz | 0:fa952828e34c | 329 | else |
hudakz | 0:fa952828e34c | 330 | vline(x1, y1, y0, color); |
hudakz | 0:fa952828e34c | 331 | if (old_auto_up) { |
hudakz | 0:fa952828e34c | 332 | auto_up = true; |
hudakz | 0:fa952828e34c | 333 | copy_to_lcd(); |
hudakz | 0:fa952828e34c | 334 | } |
hudakz | 0:fa952828e34c | 335 | |
hudakz | 0:fa952828e34c | 336 | return; |
hudakz | 0:fa952828e34c | 337 | } |
hudakz | 0:fa952828e34c | 338 | |
hudakz | 0:fa952828e34c | 339 | /** |
hudakz | 0:fa952828e34c | 340 | * @brief |
hudakz | 0:fa952828e34c | 341 | * @note |
hudakz | 0:fa952828e34c | 342 | * @param |
hudakz | 0:fa952828e34c | 343 | * @retval |
hudakz | 0:fa952828e34c | 344 | */ |
hudakz | 0:fa952828e34c | 345 | void GraphicsDisplay::fillrect(int x0, int y0, int x1, int y1, unsigned short color) |
hudakz | 0:fa952828e34c | 346 | { |
hudakz | 0:fa952828e34c | 347 | if (x0 > x1) |
hudakz | 0:fa952828e34c | 348 | SWAP(x0, x1); |
hudakz | 0:fa952828e34c | 349 | if (y0 > y1) |
hudakz | 0:fa952828e34c | 350 | SWAP(y0, y1); |
hudakz | 0:fa952828e34c | 351 | |
hudakz | 0:fa952828e34c | 352 | int h = y1 - y0 + 1; |
hudakz | 0:fa952828e34c | 353 | int w = x1 - x0 + 1; |
hudakz | 0:fa952828e34c | 354 | unsigned int pixels = h * w; |
hudakz | 0:fa952828e34c | 355 | window(x0, y0, w, h); |
hudakz | 0:fa952828e34c | 356 | |
hudakz | 0:fa952828e34c | 357 | // for (unsigned int p=0; p<pixels; p++) window_pushpixel(color); |
hudakz | 0:fa952828e34c | 358 | window_pushpixel(color, pixels); |
hudakz | 0:fa952828e34c | 359 | if (auto_up) |
hudakz | 0:fa952828e34c | 360 | copy_to_lcd(); |
hudakz | 0:fa952828e34c | 361 | return; |
hudakz | 0:fa952828e34c | 362 | } |
hudakz | 0:fa952828e34c | 363 | |
hudakz | 0:fa952828e34c | 364 | /** |
hudakz | 0:fa952828e34c | 365 | * @brief |
hudakz | 0:fa952828e34c | 366 | * @note |
hudakz | 0:fa952828e34c | 367 | * @param |
hudakz | 0:fa952828e34c | 368 | * @retval |
hudakz | 0:fa952828e34c | 369 | */ |
hudakz | 0:fa952828e34c | 370 | void GraphicsDisplay::locate(int x, int y) |
hudakz | 0:fa952828e34c | 371 | { |
hudakz | 0:fa952828e34c | 372 | char_x = x; |
hudakz | 0:fa952828e34c | 373 | char_y = y; |
hudakz | 0:fa952828e34c | 374 | } |
hudakz | 0:fa952828e34c | 375 | |
hudakz | 0:fa952828e34c | 376 | /** |
hudakz | 0:fa952828e34c | 377 | * @brief |
hudakz | 0:fa952828e34c | 378 | * @note |
hudakz | 0:fa952828e34c | 379 | * @param |
hudakz | 0:fa952828e34c | 380 | * @retval |
hudakz | 0:fa952828e34c | 381 | */ |
hudakz | 0:fa952828e34c | 382 | int GraphicsDisplay::columns() |
hudakz | 0:fa952828e34c | 383 | { |
hudakz | 0:fa952828e34c | 384 | return oriented_width / fonthor; |
hudakz | 0:fa952828e34c | 385 | } |
hudakz | 0:fa952828e34c | 386 | |
hudakz | 0:fa952828e34c | 387 | /** |
hudakz | 0:fa952828e34c | 388 | * @brief |
hudakz | 0:fa952828e34c | 389 | * @note |
hudakz | 0:fa952828e34c | 390 | * @param |
hudakz | 0:fa952828e34c | 391 | * @retval |
hudakz | 0:fa952828e34c | 392 | */ |
hudakz | 0:fa952828e34c | 393 | int GraphicsDisplay::rows() |
hudakz | 0:fa952828e34c | 394 | { |
hudakz | 0:fa952828e34c | 395 | return oriented_height / fontvert; |
hudakz | 0:fa952828e34c | 396 | } |
hudakz | 0:fa952828e34c | 397 | |
hudakz | 0:fa952828e34c | 398 | /** |
hudakz | 0:fa952828e34c | 399 | * @brief |
hudakz | 0:fa952828e34c | 400 | * @note |
hudakz | 0:fa952828e34c | 401 | * @param |
hudakz | 0:fa952828e34c | 402 | * @retval |
hudakz | 0:fa952828e34c | 403 | */ |
hudakz | 0:fa952828e34c | 404 | void GraphicsDisplay::set_font(unsigned char* f, unsigned char firstascii, unsigned char lastascii, bool proportional) |
hudakz | 0:fa952828e34c | 405 | { |
hudakz | 0:fa952828e34c | 406 | font = f; |
hudakz | 0:fa952828e34c | 407 | |
hudakz | 0:fa952828e34c | 408 | // read font parameter from start of array |
hudakz | 0:fa952828e34c | 409 | //fontoffset = font[0]; // bytes / char |
hudakz | 0:fa952828e34c | 410 | fonthor = font[1]; // get hor size of font |
hudakz | 0:fa952828e34c | 411 | fontvert = font[2]; // get vert size of font |
hudakz | 0:fa952828e34c | 412 | |
hudakz | 0:fa952828e34c | 413 | //fontbpl = font[3]; // bytes per line |
hudakz | 0:fa952828e34c | 414 | fontbpl = (fontvert + 7) >> 3; //bytes per line, rounded up to multiple of 8 |
hudakz | 0:fa952828e34c | 415 | fontoffset = (fonthor * fontbpl) + 1; |
hudakz | 0:fa952828e34c | 416 | firstch = firstascii; // first ascii code present in font array (usually 32) |
hudakz | 0:fa952828e34c | 417 | lastch = lastascii; // last ascii code present in font array (usually 127) |
hudakz | 0:fa952828e34c | 418 | fontprop = proportional; |
hudakz | 0:fa952828e34c | 419 | set_font_zoom(1, 1); |
hudakz | 0:fa952828e34c | 420 | } |
hudakz | 0:fa952828e34c | 421 | |
hudakz | 0:fa952828e34c | 422 | /** |
hudakz | 0:fa952828e34c | 423 | * @brief |
hudakz | 0:fa952828e34c | 424 | * @note |
hudakz | 0:fa952828e34c | 425 | * @param |
hudakz | 0:fa952828e34c | 426 | * @retval |
hudakz | 0:fa952828e34c | 427 | */ |
hudakz | 0:fa952828e34c | 428 | void GraphicsDisplay::set_font_zoom(unsigned char x_mul, unsigned char y_mul) |
hudakz | 0:fa952828e34c | 429 | { |
hudakz | 0:fa952828e34c | 430 | fontzoomhor = ((x_mul == 0) ? 1 : x_mul); |
hudakz | 0:fa952828e34c | 431 | fontzoomver = ((y_mul == 0) ? 1 : y_mul); |
hudakz | 0:fa952828e34c | 432 | } |
hudakz | 0:fa952828e34c | 433 | |
hudakz | 0:fa952828e34c | 434 | /** |
hudakz | 0:fa952828e34c | 435 | * @brief |
hudakz | 0:fa952828e34c | 436 | * @note |
hudakz | 0:fa952828e34c | 437 | * @param |
hudakz | 0:fa952828e34c | 438 | * @retval |
hudakz | 0:fa952828e34c | 439 | */ |
hudakz | 0:fa952828e34c | 440 | int GraphicsDisplay::_putc(int value) |
hudakz | 0:fa952828e34c | 441 | { |
hudakz | 0:fa952828e34c | 442 | if (value == '\n') { |
hudakz | 0:fa952828e34c | 443 | |
hudakz | 0:fa952828e34c | 444 | // new line |
hudakz | 0:fa952828e34c | 445 | char_x = 0; |
hudakz | 0:fa952828e34c | 446 | char_y = char_y + fontvert * fontzoomver; |
hudakz | 0:fa952828e34c | 447 | if (char_y >= oriented_height - fontvert * fontzoomver) { |
hudakz | 0:fa952828e34c | 448 | char_y = 0; |
hudakz | 0:fa952828e34c | 449 | } |
hudakz | 0:fa952828e34c | 450 | } |
hudakz | 0:fa952828e34c | 451 | else { |
hudakz | 0:fa952828e34c | 452 | character(char_x, char_y, value); |
hudakz | 0:fa952828e34c | 453 | if (auto_up) |
hudakz | 0:fa952828e34c | 454 | copy_to_lcd(); |
hudakz | 0:fa952828e34c | 455 | } |
hudakz | 0:fa952828e34c | 456 | |
hudakz | 0:fa952828e34c | 457 | return value; |
hudakz | 0:fa952828e34c | 458 | } |
hudakz | 0:fa952828e34c | 459 | |
hudakz | 0:fa952828e34c | 460 | /** |
hudakz | 0:fa952828e34c | 461 | * @brief |
hudakz | 0:fa952828e34c | 462 | * @note |
hudakz | 0:fa952828e34c | 463 | * @param |
hudakz | 0:fa952828e34c | 464 | * @retval |
hudakz | 0:fa952828e34c | 465 | */ |
hudakz | 0:fa952828e34c | 466 | void GraphicsDisplay::character(int x, int y, int c) |
hudakz | 0:fa952828e34c | 467 | { |
hudakz | 0:fa952828e34c | 468 | char_x = x; |
hudakz | 0:fa952828e34c | 469 | char_y = y; |
hudakz | 0:fa952828e34c | 470 | |
hudakz | 0:fa952828e34c | 471 | int j, i, b; |
hudakz | 0:fa952828e34c | 472 | unsigned char* zeichen; |
hudakz | 0:fa952828e34c | 473 | unsigned char z, w, v; |
hudakz | 0:fa952828e34c | 474 | |
hudakz | 0:fa952828e34c | 475 | /* // read font parameter from start of array |
hudakz | 0:fa952828e34c | 476 | offset = font[0]; // bytes / char |
hudakz | 0:fa952828e34c | 477 | hor = font[1]; // get hor size of font |
hudakz | 0:fa952828e34c | 478 | vert = font[2]; // get vert size of font |
hudakz | 0:fa952828e34c | 479 | bpl = font[3]; // bytes per line |
hudakz | 0:fa952828e34c | 480 | */ |
hudakz | 0:fa952828e34c | 481 | |
hudakz | 0:fa952828e34c | 482 | if (char_x + fonthor * fontzoomhor > oriented_width) { |
hudakz | 0:fa952828e34c | 483 | char_x = 0; |
hudakz | 0:fa952828e34c | 484 | char_y = char_y + fontvert * fontzoomver; |
hudakz | 0:fa952828e34c | 485 | if (char_y > oriented_height - fontvert * fontzoomver) { |
hudakz | 0:fa952828e34c | 486 | char_y = 0; |
hudakz | 0:fa952828e34c | 487 | } |
hudakz | 0:fa952828e34c | 488 | } |
hudakz | 0:fa952828e34c | 489 | |
hudakz | 0:fa952828e34c | 490 | window(char_x, char_y, fonthor * fontzoomhor, fontvert * fontzoomver); // char box |
hudakz | 0:fa952828e34c | 491 | if ((c < firstch) || (c > lastch)) { |
hudakz | 0:fa952828e34c | 492 | |
hudakz | 0:fa952828e34c | 493 | // test char range - if not exist fill with blank |
hudakz | 0:fa952828e34c | 494 | for (i = 0; i < fonthor * fontvert * fontzoomver; i++) { |
hudakz | 0:fa952828e34c | 495 | window_pushpixel(_background, fontzoomhor); //(color, howmany) |
hudakz | 0:fa952828e34c | 496 | } |
hudakz | 0:fa952828e34c | 497 | } |
hudakz | 0:fa952828e34c | 498 | else { |
hudakz | 0:fa952828e34c | 499 | zeichen = &font[((c - firstch) * fontoffset) + 4]; // start of char bitmap |
hudakz | 0:fa952828e34c | 500 | w = zeichen[0]; // width of actual char |
hudakz | 0:fa952828e34c | 501 | |
hudakz | 0:fa952828e34c | 502 | // construct the char into the buffer |
hudakz | 0:fa952828e34c | 503 | for (j = 0; j < fontvert; j++) { |
hudakz | 0:fa952828e34c | 504 | |
hudakz | 0:fa952828e34c | 505 | // vert line |
hudakz | 0:fa952828e34c | 506 | for (v = 0; v < fontzoomver; v++) { |
hudakz | 0:fa952828e34c | 507 | |
hudakz | 0:fa952828e34c | 508 | // repeat horiz line for vertical zooming |
hudakz | 0:fa952828e34c | 509 | for (i = 0; i < fonthor; i++) { |
hudakz | 0:fa952828e34c | 510 | |
hudakz | 0:fa952828e34c | 511 | // horz line |
hudakz | 0:fa952828e34c | 512 | z = zeichen[(fontbpl * i) + ((j & 0xF8) >> 3) + 1]; |
hudakz | 0:fa952828e34c | 513 | b = 1 << (j & 0x07); |
hudakz | 0:fa952828e34c | 514 | if ((z & b) == 0x00) { |
hudakz | 0:fa952828e34c | 515 | |
hudakz | 0:fa952828e34c | 516 | // pixel(char_x+i,char_y+j,0); |
hudakz | 0:fa952828e34c | 517 | window_pushpixel(_background, fontzoomhor); //(color, howmany) |
hudakz | 0:fa952828e34c | 518 | } |
hudakz | 0:fa952828e34c | 519 | else { |
hudakz | 0:fa952828e34c | 520 | |
hudakz | 0:fa952828e34c | 521 | // pixel(char_x+i,char_y+j,1); |
hudakz | 0:fa952828e34c | 522 | window_pushpixel(_foreground, fontzoomhor); |
hudakz | 0:fa952828e34c | 523 | } |
hudakz | 0:fa952828e34c | 524 | } |
hudakz | 0:fa952828e34c | 525 | } //for each zoomed vert |
hudakz | 0:fa952828e34c | 526 | } |
hudakz | 0:fa952828e34c | 527 | } |
hudakz | 0:fa952828e34c | 528 | |
hudakz | 0:fa952828e34c | 529 | if (fontprop) { |
hudakz | 0:fa952828e34c | 530 | if ((w + 1) < fonthor) |
hudakz | 0:fa952828e34c | 531 | char_x += (w * fontzoomhor) + 1; // put at least 1 blank after variable-width characters, except characters that occupy whole fonthor space like "_" |
hudakz | 0:fa952828e34c | 532 | else |
hudakz | 0:fa952828e34c | 533 | char_x += fonthor * fontzoomhor; |
hudakz | 0:fa952828e34c | 534 | } |
hudakz | 0:fa952828e34c | 535 | else |
hudakz | 0:fa952828e34c | 536 | char_x += fonthor * fontzoomhor; // fixed width |
hudakz | 0:fa952828e34c | 537 | } |
hudakz | 0:fa952828e34c | 538 | |
hudakz | 0:fa952828e34c | 539 | /** |
hudakz | 0:fa952828e34c | 540 | * @brief |
hudakz | 0:fa952828e34c | 541 | * @note |
hudakz | 0:fa952828e34c | 542 | * @param |
hudakz | 0:fa952828e34c | 543 | * @retval |
hudakz | 0:fa952828e34c | 544 | */ |
hudakz | 0:fa952828e34c | 545 | void GraphicsDisplay::Bitmap_BW(Bitmap_s bm, int x, int y) |
hudakz | 0:fa952828e34c | 546 | { |
hudakz | 0:fa952828e34c | 547 | int h, v, b; |
hudakz | 0:fa952828e34c | 548 | |
hudakz | 0:fa952828e34c | 549 | // int cropX; |
hudakz | 0:fa952828e34c | 550 | char d; |
hudakz | 0:fa952828e34c | 551 | if (x < 0) |
hudakz | 0:fa952828e34c | 552 | x = 0; |
hudakz | 0:fa952828e34c | 553 | if (y < 0) |
hudakz | 0:fa952828e34c | 554 | y = 0; |
hudakz | 0:fa952828e34c | 555 | |
hudakz | 0:fa952828e34c | 556 | int cropX = (x + bm.xSize) - oriented_width; |
hudakz | 0:fa952828e34c | 557 | if (cropX < 0) |
hudakz | 0:fa952828e34c | 558 | cropX = 0; |
hudakz | 0:fa952828e34c | 559 | window(x, y, bm.xSize - cropX, bm.ySize); |
hudakz | 0:fa952828e34c | 560 | for (v = 0; v < bm.ySize; v++) { |
hudakz | 0:fa952828e34c | 561 | |
hudakz | 0:fa952828e34c | 562 | // lines |
hudakz | 0:fa952828e34c | 563 | if ((v + y) >= oriented_height) |
hudakz | 0:fa952828e34c | 564 | break; // no need to crop Y |
hudakz | 0:fa952828e34c | 565 | for (h = 0; h < bm.xSize; h++) { |
hudakz | 0:fa952828e34c | 566 | |
hudakz | 0:fa952828e34c | 567 | // pixel |
hudakz | 0:fa952828e34c | 568 | if ((h + x) >= oriented_width) |
hudakz | 0:fa952828e34c | 569 | break; |
hudakz | 0:fa952828e34c | 570 | d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)]; |
hudakz | 0:fa952828e34c | 571 | b = 0x80 >> (h & 0x07); |
hudakz | 0:fa952828e34c | 572 | if ((d & b) == 0) { |
hudakz | 0:fa952828e34c | 573 | window_pushpixel(_background); |
hudakz | 0:fa952828e34c | 574 | } |
hudakz | 0:fa952828e34c | 575 | else { |
hudakz | 0:fa952828e34c | 576 | window_pushpixel(_foreground); |
hudakz | 0:fa952828e34c | 577 | } |
hudakz | 0:fa952828e34c | 578 | } |
hudakz | 0:fa952828e34c | 579 | } |
hudakz | 0:fa952828e34c | 580 | |
hudakz | 0:fa952828e34c | 581 | if (auto_up) |
hudakz | 0:fa952828e34c | 582 | copy_to_lcd(); |
hudakz | 0:fa952828e34c | 583 | } |
hudakz | 0:fa952828e34c | 584 | |
hudakz | 0:fa952828e34c | 585 | /** |
hudakz | 0:fa952828e34c | 586 | * @brief |
hudakz | 0:fa952828e34c | 587 | * @note |
hudakz | 0:fa952828e34c | 588 | * @param |
hudakz | 0:fa952828e34c | 589 | * @retval |
hudakz | 0:fa952828e34c | 590 | */ |
hudakz | 0:fa952828e34c | 591 | void GraphicsDisplay::Bitmap(int x, int y, int w, int h, unsigned char* bitmap) |
hudakz | 0:fa952828e34c | 592 | { |
hudakz | 0:fa952828e34c | 593 | int j; |
hudakz | 0:fa952828e34c | 594 | unsigned char padd; |
hudakz | 0:fa952828e34c | 595 | unsigned short* bitmap_ptr = (unsigned short*)bitmap; |
hudakz | 0:fa952828e34c | 596 | |
hudakz | 0:fa952828e34c | 597 | padd = w % 2; // the lines are padded to multiple of 4 bytes in a bitmap |
hudakz | 0:fa952828e34c | 598 | if (x < 0) |
hudakz | 0:fa952828e34c | 599 | x = 0; |
hudakz | 0:fa952828e34c | 600 | else |
hudakz | 0:fa952828e34c | 601 | if (x >= oriented_width) |
hudakz | 0:fa952828e34c | 602 | return; |
hudakz | 0:fa952828e34c | 603 | if (y < 0) |
hudakz | 0:fa952828e34c | 604 | y = 0; |
hudakz | 0:fa952828e34c | 605 | else |
hudakz | 0:fa952828e34c | 606 | if (y >= oriented_height) |
hudakz | 0:fa952828e34c | 607 | return; |
hudakz | 0:fa952828e34c | 608 | |
hudakz | 0:fa952828e34c | 609 | int cropX = (x + w) - oriented_width; |
hudakz | 0:fa952828e34c | 610 | if (cropX < 0) |
hudakz | 0:fa952828e34c | 611 | cropX = 0; |
hudakz | 0:fa952828e34c | 612 | |
hudakz | 0:fa952828e34c | 613 | int cropY = (y + h) - oriented_height; |
hudakz | 0:fa952828e34c | 614 | if (cropY < 0) |
hudakz | 0:fa952828e34c | 615 | cropY = 0; |
hudakz | 0:fa952828e34c | 616 | window(x, y, w - cropX, h - cropY); |
hudakz | 0:fa952828e34c | 617 | bitmap_ptr += ((h - 1) * (w + padd)); // begin of last line in array (first line of image)(standard bmp scan direction is left->right bottom->top) |
hudakz | 0:fa952828e34c | 618 | for (j = 0; j < h - cropY; j++) { |
hudakz | 0:fa952828e34c | 619 | |
hudakz | 0:fa952828e34c | 620 | //Lines |
hudakz | 0:fa952828e34c | 621 | window_pushpixelbuf(bitmap_ptr, w - cropX); |
hudakz | 0:fa952828e34c | 622 | bitmap_ptr -= w + padd; |
hudakz | 0:fa952828e34c | 623 | } |
hudakz | 0:fa952828e34c | 624 | |
hudakz | 0:fa952828e34c | 625 | if (auto_up) |
hudakz | 0:fa952828e34c | 626 | copy_to_lcd(); |
hudakz | 0:fa952828e34c | 627 | } |
hudakz | 0:fa952828e34c | 628 | |
hudakz | 0:fa952828e34c | 629 | // local filesystem is not implemented in kinetis board , but you can add a SD card |
hudakz | 0:fa952828e34c | 630 | |
hudakz | 0:fa952828e34c | 631 | // fixme this whole functions needs testing and speedup |
hudakz | 0:fa952828e34c | 632 | int GraphicsDisplay::BMP_16(int x, int y, const char* Name_BMP) |
hudakz | 0:fa952828e34c | 633 | { |
hudakz | 0:fa952828e34c | 634 | #define OffsetPixelWidth 18 |
hudakz | 0:fa952828e34c | 635 | #define OffsetPixelHeigh 22 |
hudakz | 0:fa952828e34c | 636 | #define OffsetFileSize 34 |
hudakz | 0:fa952828e34c | 637 | #define OffsetPixData 10 |
hudakz | 0:fa952828e34c | 638 | #define OffsetBPP 28 |
hudakz | 0:fa952828e34c | 639 | char filename[50]; |
hudakz | 0:fa952828e34c | 640 | unsigned char BMP_Header[54]; |
hudakz | 0:fa952828e34c | 641 | unsigned short BPP_t; |
hudakz | 0:fa952828e34c | 642 | unsigned int PixelWidth, PixelHeigh, start_data; |
hudakz | 0:fa952828e34c | 643 | unsigned int i, off; |
hudakz | 0:fa952828e34c | 644 | int padd, j; |
hudakz | 0:fa952828e34c | 645 | unsigned short* line; |
hudakz | 0:fa952828e34c | 646 | |
hudakz | 0:fa952828e34c | 647 | // get the filename |
hudakz | 0:fa952828e34c | 648 | |
hudakz | 0:fa952828e34c | 649 | i = 0; |
hudakz | 0:fa952828e34c | 650 | while (*Name_BMP != '\0') { |
hudakz | 0:fa952828e34c | 651 | filename[i++] = *Name_BMP++; |
hudakz | 0:fa952828e34c | 652 | } |
hudakz | 0:fa952828e34c | 653 | |
hudakz | 0:fa952828e34c | 654 | filename[i] = 0; |
hudakz | 0:fa952828e34c | 655 | |
hudakz | 0:fa952828e34c | 656 | FILE* Image = fopen((const char*) &filename[0], "rb"); // open the bmp file |
hudakz | 0:fa952828e34c | 657 | |
hudakz | 0:fa952828e34c | 658 | if (!Image) { |
hudakz | 0:fa952828e34c | 659 | return(0); // error file not found ! |
hudakz | 0:fa952828e34c | 660 | } |
hudakz | 0:fa952828e34c | 661 | |
hudakz | 0:fa952828e34c | 662 | fread(&BMP_Header[0], 1, 54, Image); // get the BMP Header |
hudakz | 0:fa952828e34c | 663 | if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { |
hudakz | 0:fa952828e34c | 664 | |
hudakz | 0:fa952828e34c | 665 | // check magic byte |
hudakz | 0:fa952828e34c | 666 | fclose(Image); |
hudakz | 0:fa952828e34c | 667 | return(-1); // error no BMP file |
hudakz | 0:fa952828e34c | 668 | } |
hudakz | 0:fa952828e34c | 669 | |
hudakz | 0:fa952828e34c | 670 | BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8); |
hudakz | 0:fa952828e34c | 671 | if (BPP_t != 0x0010) { |
hudakz | 0:fa952828e34c | 672 | fclose(Image); |
hudakz | 0:fa952828e34c | 673 | return(-2); // error no 16 bit BMP |
hudakz | 0:fa952828e34c | 674 | } |
hudakz | 0:fa952828e34c | 675 | |
hudakz | 0:fa952828e34c | 676 | PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24); |
hudakz | 0:fa952828e34c | 677 | PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24); |
hudakz | 0:fa952828e34c | 678 | if (PixelHeigh > oriented_height + y || PixelWidth > oriented_width + x) { |
hudakz | 0:fa952828e34c | 679 | fclose(Image); |
hudakz | 0:fa952828e34c | 680 | return(-3); // to big |
hudakz | 0:fa952828e34c | 681 | } |
hudakz | 0:fa952828e34c | 682 | |
hudakz | 0:fa952828e34c | 683 | start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24); |
hudakz | 0:fa952828e34c | 684 | |
hudakz | 0:fa952828e34c | 685 | line = (unsigned short*)malloc(2 * PixelWidth); // we need a buffer for a line |
hudakz | 0:fa952828e34c | 686 | if (line == NULL) { |
hudakz | 0:fa952828e34c | 687 | return(-4); // error no memory |
hudakz | 0:fa952828e34c | 688 | } |
hudakz | 0:fa952828e34c | 689 | |
hudakz | 0:fa952828e34c | 690 | // the bmp lines are padded to multiple of 4 bytes |
hudakz | 0:fa952828e34c | 691 | padd = -1; |
hudakz | 0:fa952828e34c | 692 | do |
hudakz | 0:fa952828e34c | 693 | { |
hudakz | 0:fa952828e34c | 694 | padd++; |
hudakz | 0:fa952828e34c | 695 | } while ((PixelWidth * 2 + padd) % 4 != 0); |
hudakz | 0:fa952828e34c | 696 | |
hudakz | 0:fa952828e34c | 697 | window(x, y, PixelWidth, PixelHeigh); |
hudakz | 0:fa952828e34c | 698 | |
hudakz | 0:fa952828e34c | 699 | // wr_cmd(0x2C); // send pixel |
hudakz | 0:fa952828e34c | 700 | for (j = PixelHeigh - 1; j >= 0; j--) { |
hudakz | 0:fa952828e34c | 701 | |
hudakz | 0:fa952828e34c | 702 | //Lines bottom up |
hudakz | 0:fa952828e34c | 703 | off = j * (PixelWidth * 2 + padd) + start_data; // start of line |
hudakz | 0:fa952828e34c | 704 | fseek(Image, off, SEEK_SET); |
hudakz | 0:fa952828e34c | 705 | fread(line, 1, PixelWidth * 2, Image); // read a line - slow |
hudakz | 0:fa952828e34c | 706 | |
hudakz | 0:fa952828e34c | 707 | /* for (i = 0; i < PixelWidth; i++) |
hudakz | 0:fa952828e34c | 708 | { // copy pixel data to TFT |
hudakz | 0:fa952828e34c | 709 | // wr_16(line[i]); // one 16 bit pixel |
hudakz | 0:fa952828e34c | 710 | window_pushpixel(line[i]); |
hudakz | 0:fa952828e34c | 711 | |
hudakz | 0:fa952828e34c | 712 | } */ |
hudakz | 0:fa952828e34c | 713 | window_pushpixelbuf(line, PixelWidth); |
hudakz | 0:fa952828e34c | 714 | } |
hudakz | 0:fa952828e34c | 715 | |
hudakz | 0:fa952828e34c | 716 | free(line); |
hudakz | 0:fa952828e34c | 717 | fclose(Image); |
hudakz | 0:fa952828e34c | 718 | if (auto_up) |
hudakz | 0:fa952828e34c | 719 | copy_to_lcd(); |
hudakz | 0:fa952828e34c | 720 | return(1); |
hudakz | 0:fa952828e34c | 721 | } |
hudakz | 0:fa952828e34c | 722 | |
hudakz | 0:fa952828e34c | 723 | /** |
hudakz | 0:fa952828e34c | 724 | * @brief |
hudakz | 0:fa952828e34c | 725 | * @note |
hudakz | 0:fa952828e34c | 726 | * @param |
hudakz | 0:fa952828e34c | 727 | * @retval |
hudakz | 0:fa952828e34c | 728 | */ |
hudakz | 0:fa952828e34c | 729 | void GraphicsDisplay::cls(void) |
hudakz | 0:fa952828e34c | 730 | { |
hudakz | 0:fa952828e34c | 731 | unsigned int pixels = (oriented_width * oriented_height); |
hudakz | 0:fa952828e34c | 732 | WindowMax(); |
hudakz | 0:fa952828e34c | 733 | for (unsigned int i = 0; i < pixels; i++) { |
hudakz | 0:fa952828e34c | 734 | window_pushpixel(_background); |
hudakz | 0:fa952828e34c | 735 | } |
hudakz | 0:fa952828e34c | 736 | } |
hudakz | 0:fa952828e34c | 737 | |
hudakz | 0:fa952828e34c | 738 | /** |
hudakz | 0:fa952828e34c | 739 | * @brief |
hudakz | 0:fa952828e34c | 740 | * @note |
hudakz | 0:fa952828e34c | 741 | * @param |
hudakz | 0:fa952828e34c | 742 | * @retval |
hudakz | 0:fa952828e34c | 743 | */ |
hudakz | 0:fa952828e34c | 744 | void GraphicsDisplay::set_auto_up(bool up) |
hudakz | 0:fa952828e34c | 745 | { |
hudakz | 0:fa952828e34c | 746 | if (up) |
hudakz | 0:fa952828e34c | 747 | auto_up = true; |
hudakz | 0:fa952828e34c | 748 | else |
hudakz | 0:fa952828e34c | 749 | auto_up = false; |
hudakz | 0:fa952828e34c | 750 | } |
hudakz | 0:fa952828e34c | 751 | |
hudakz | 0:fa952828e34c | 752 | /** |
hudakz | 0:fa952828e34c | 753 | * @brief |
hudakz | 0:fa952828e34c | 754 | * @note |
hudakz | 0:fa952828e34c | 755 | * @param |
hudakz | 0:fa952828e34c | 756 | * @retval |
hudakz | 0:fa952828e34c | 757 | */ |
hudakz | 0:fa952828e34c | 758 | bool GraphicsDisplay::get_auto_up(void) |
hudakz | 0:fa952828e34c | 759 | { |
hudakz | 0:fa952828e34c | 760 | return(auto_up); |
hudakz | 0:fa952828e34c | 761 | } |