Uses the same fonts as the SPI_TFT_ILI9341 Library (I have many, and a html/php font editor for that)

Committer:
JackB
Date:
Wed Nov 23 22:42:30 2016 +0000
Revision:
17:b120858d05ff
Parent:
14:a7640e7e9f80
Comment added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JackB 0:cc1fb45bc3ad 1 #ifndef TFT_22_ILI9225_h
JackB 0:cc1fb45bc3ad 2 #define TFT_22_ILI9225_h
JackB 0:cc1fb45bc3ad 3 #include "mbed.h"
JackB 0:cc1fb45bc3ad 4
JackB 0:cc1fb45bc3ad 5 #define FONT_LENGTH 0
JackB 0:cc1fb45bc3ad 6 #define FONT_HORZ 1
JackB 0:cc1fb45bc3ad 7 #define FONT_VERT 2
JackB 0:cc1fb45bc3ad 8 #define FONT_BYTES_VERT 3
JackB 0:cc1fb45bc3ad 9
JackB 0:cc1fb45bc3ad 10 #define ILI9225_CHARS_PER_LINE 36
JackB 0:cc1fb45bc3ad 11
JackB 0:cc1fb45bc3ad 12 /* ILI9225 screen size */
JackB 0:cc1fb45bc3ad 13 #define ILI9225_LCD_WIDTH 176
JackB 0:cc1fb45bc3ad 14 #define ILI9225_LCD_HEIGHT 220
JackB 0:cc1fb45bc3ad 15
JackB 1:8e447a4c8995 16 #define ILI9225_PORTRAIT_L 0 // SD card at the left side
JackB 1:8e447a4c8995 17 #define ILI9225_LANDSCAPE_B 1 // SD card at the bottom side
JackB 1:8e447a4c8995 18 #define ILI9225_PORTRAIT_R 2 // SD card at the right side
JackB 1:8e447a4c8995 19 #define ILI9225_LANDSCAPE_T 3 // SD card at the top side
JackB 0:cc1fb45bc3ad 20
JackB 0:cc1fb45bc3ad 21 /* ILI9225 LCD Registers */
JackB 0:cc1fb45bc3ad 22 #define ILI9225_DRIVER_OUTPUT_CTRL (0x01u) // Driver Output Control
JackB 0:cc1fb45bc3ad 23 #define ILI9225_LCD_AC_DRIVING_CTRL (0x02u) // LCD AC Driving Control
JackB 0:cc1fb45bc3ad 24 #define ILI9225_ENTRY_MODE (0x03u) // Entry Mode
JackB 0:cc1fb45bc3ad 25 #define ILI9225_DISP_CTRL1 (0x07u) // Display Control 1
JackB 0:cc1fb45bc3ad 26 #define ILI9225_BLANK_PERIOD_CTRL1 (0x08u) // Blank Period Control
JackB 0:cc1fb45bc3ad 27 #define ILI9225_FRAME_CYCLE_CTRL (0x0Bu) // Frame Cycle Control
JackB 0:cc1fb45bc3ad 28 #define ILI9225_INTERFACE_CTRL (0x0Cu) // Interface Control
JackB 0:cc1fb45bc3ad 29 #define ILI9225_OSC_CTRL (0x0Fu) // Osc Control
JackB 0:cc1fb45bc3ad 30 #define ILI9225_POWER_CTRL1 (0x10u) // Power Control 1
JackB 0:cc1fb45bc3ad 31 #define ILI9225_POWER_CTRL2 (0x11u) // Power Control 2
JackB 0:cc1fb45bc3ad 32 #define ILI9225_POWER_CTRL3 (0x12u) // Power Control 3
JackB 0:cc1fb45bc3ad 33 #define ILI9225_POWER_CTRL4 (0x13u) // Power Control 4
JackB 0:cc1fb45bc3ad 34 #define ILI9225_POWER_CTRL5 (0x14u) // Power Control 5
JackB 0:cc1fb45bc3ad 35 #define ILI9225_VCI_RECYCLING (0x15u) // VCI Recycling
JackB 0:cc1fb45bc3ad 36 #define ILI9225_RAM_ADDR_SET1 (0x20u) // Horizontal GRAM Address Set
JackB 0:cc1fb45bc3ad 37 #define ILI9225_RAM_ADDR_SET2 (0x21u) // Vertical GRAM Address Set
JackB 0:cc1fb45bc3ad 38 #define ILI9225_GRAM_DATA_REG (0x22u) // GRAM Data Register
JackB 0:cc1fb45bc3ad 39 #define ILI9225_GATE_SCAN_CTRL (0x30u) // Gate Scan Control Register
JackB 0:cc1fb45bc3ad 40 #define ILI9225_VERTICAL_SCROLL_CTRL1 (0x31u) // Vertical Scroll Control 1 Register
JackB 0:cc1fb45bc3ad 41 #define ILI9225_VERTICAL_SCROLL_CTRL2 (0x32u) // Vertical Scroll Control 2 Register
JackB 0:cc1fb45bc3ad 42 #define ILI9225_VERTICAL_SCROLL_CTRL3 (0x33u) // Vertical Scroll Control 3 Register
JackB 0:cc1fb45bc3ad 43 #define ILI9225_PARTIAL_DRIVING_POS1 (0x34u) // Partial Driving Position 1 Register
JackB 0:cc1fb45bc3ad 44 #define ILI9225_PARTIAL_DRIVING_POS2 (0x35u) // Partial Driving Position 2 Register
JackB 0:cc1fb45bc3ad 45 #define ILI9225_HORIZONTAL_WINDOW_ADDR1 (0x36u) // Horizontal Address Start Position
JackB 0:cc1fb45bc3ad 46 #define ILI9225_HORIZONTAL_WINDOW_ADDR2 (0x37u) // Horizontal Address End Position
JackB 0:cc1fb45bc3ad 47 #define ILI9225_VERTICAL_WINDOW_ADDR1 (0x38u) // Vertical Address Start Position
JackB 0:cc1fb45bc3ad 48 #define ILI9225_VERTICAL_WINDOW_ADDR2 (0x39u) // Vertical Address End Position
JackB 0:cc1fb45bc3ad 49 #define ILI9225_GAMMA_CTRL1 (0x50u) // Gamma Control 1
JackB 0:cc1fb45bc3ad 50 #define ILI9225_GAMMA_CTRL2 (0x51u) // Gamma Control 2
JackB 0:cc1fb45bc3ad 51 #define ILI9225_GAMMA_CTRL3 (0x52u) // Gamma Control 3
JackB 0:cc1fb45bc3ad 52 #define ILI9225_GAMMA_CTRL4 (0x53u) // Gamma Control 4
JackB 0:cc1fb45bc3ad 53 #define ILI9225_GAMMA_CTRL5 (0x54u) // Gamma Control 5
JackB 0:cc1fb45bc3ad 54 #define ILI9225_GAMMA_CTRL6 (0x55u) // Gamma Control 6
JackB 0:cc1fb45bc3ad 55 #define ILI9225_GAMMA_CTRL7 (0x56u) // Gamma Control 7
JackB 0:cc1fb45bc3ad 56 #define ILI9225_GAMMA_CTRL8 (0x57u) // Gamma Control 8
JackB 0:cc1fb45bc3ad 57 #define ILI9225_GAMMA_CTRL9 (0x58u) // Gamma Control 9
JackB 0:cc1fb45bc3ad 58 #define ILI9225_GAMMA_CTRL10 (0x59u) // Gamma Control 10
JackB 0:cc1fb45bc3ad 59
JackB 0:cc1fb45bc3ad 60 #define ILI9225C_INVOFF 0x20
JackB 0:cc1fb45bc3ad 61 #define ILI9225C_INVON 0x21
JackB 0:cc1fb45bc3ad 62
JackB 0:cc1fb45bc3ad 63
JackB 0:cc1fb45bc3ad 64 /* RGB 24-bits color table definition (RGB888). */
JackB 0:cc1fb45bc3ad 65 #define RGB888_RGB565(color) ((((color) >> 19) & 0x1f) << 11) | ((((color) >> 10) & 0x3f) << 5) | (((color) >> 3) & 0x1f)
JackB 0:cc1fb45bc3ad 66
JackB 0:cc1fb45bc3ad 67 #define COLOR_BLACK RGB888_RGB565(0x000000u)
JackB 0:cc1fb45bc3ad 68 #define COLOR_WHITE RGB888_RGB565(0xFFFFFFu)
JackB 0:cc1fb45bc3ad 69 #define COLOR_BLUE RGB888_RGB565(0x0000FFu)
JackB 0:cc1fb45bc3ad 70 #define COLOR_GREEN RGB888_RGB565(0x00FF00u)
JackB 0:cc1fb45bc3ad 71 #define COLOR_RED RGB888_RGB565(0xFF0000u)
JackB 0:cc1fb45bc3ad 72 #define COLOR_NAVY RGB888_RGB565(0x000080u)
JackB 0:cc1fb45bc3ad 73 #define COLOR_DARKBLUE RGB888_RGB565(0x00008Bu)
JackB 0:cc1fb45bc3ad 74 #define COLOR_DARKGREEN RGB888_RGB565(0x006400u)
JackB 0:cc1fb45bc3ad 75 #define COLOR_DARKCYAN RGB888_RGB565(0x008B8Bu)
JackB 0:cc1fb45bc3ad 76 #define COLOR_CYAN RGB888_RGB565(0x00FFFFu)
JackB 0:cc1fb45bc3ad 77 #define COLOR_TURQUOISE RGB888_RGB565(0x40E0D0u)
JackB 0:cc1fb45bc3ad 78 #define COLOR_INDIGO RGB888_RGB565(0x4B0082u)
JackB 0:cc1fb45bc3ad 79 #define COLOR_DARKRED RGB888_RGB565(0x800000u)
JackB 0:cc1fb45bc3ad 80 #define COLOR_OLIVE RGB888_RGB565(0x808000u)
JackB 0:cc1fb45bc3ad 81 #define COLOR_GRAY RGB888_RGB565(0x808080u)
JackB 0:cc1fb45bc3ad 82 #define COLOR_SKYBLUE RGB888_RGB565(0x87CEEBu)
JackB 0:cc1fb45bc3ad 83 #define COLOR_BLUEVIOLET RGB888_RGB565(0x8A2BE2u)
JackB 0:cc1fb45bc3ad 84 #define COLOR_LIGHTGREEN RGB888_RGB565(0x90EE90u)
JackB 0:cc1fb45bc3ad 85 #define COLOR_DARKVIOLET RGB888_RGB565(0x9400D3u)
JackB 0:cc1fb45bc3ad 86 #define COLOR_YELLOWGREEN RGB888_RGB565(0x9ACD32u)
JackB 0:cc1fb45bc3ad 87 #define COLOR_BROWN RGB888_RGB565(0xA52A2Au)
JackB 0:cc1fb45bc3ad 88 #define COLOR_DARKGRAY RGB888_RGB565(0xA9A9A9u)
JackB 0:cc1fb45bc3ad 89 #define COLOR_SIENNA RGB888_RGB565(0xA0522Du)
JackB 0:cc1fb45bc3ad 90 #define COLOR_LIGHTBLUE RGB888_RGB565(0xADD8E6u)
JackB 0:cc1fb45bc3ad 91 #define COLOR_GREENYELLOW RGB888_RGB565(0xADFF2Fu)
JackB 0:cc1fb45bc3ad 92 #define COLOR_SILVER RGB888_RGB565(0xC0C0C0u)
JackB 0:cc1fb45bc3ad 93 #define COLOR_LIGHTGREY RGB888_RGB565(0xD3D3D3u)
JackB 0:cc1fb45bc3ad 94 #define COLOR_LIGHTCYAN RGB888_RGB565(0xE0FFFFu)
JackB 0:cc1fb45bc3ad 95 #define COLOR_VIOLET RGB888_RGB565(0xEE82EEu)
JackB 0:cc1fb45bc3ad 96 #define COLOR_AZUR RGB888_RGB565(0xF0FFFFu)
JackB 0:cc1fb45bc3ad 97 #define COLOR_BEIGE RGB888_RGB565(0xF5F5DCu)
JackB 0:cc1fb45bc3ad 98 #define COLOR_MAGENTA RGB888_RGB565(0xFF00FFu)
JackB 0:cc1fb45bc3ad 99 #define COLOR_TOMATO RGB888_RGB565(0xFF6347u)
JackB 0:cc1fb45bc3ad 100 #define COLOR_GOLD RGB888_RGB565(0xFFD700u)
JackB 0:cc1fb45bc3ad 101 #define COLOR_ORANGE RGB888_RGB565(0xFFA500u)
JackB 0:cc1fb45bc3ad 102 #define COLOR_SNOW RGB888_RGB565(0xFFFAFAu)
JackB 0:cc1fb45bc3ad 103 #define COLOR_YELLOW RGB888_RGB565(0xFFFF00u)
JackB 0:cc1fb45bc3ad 104
JackB 0:cc1fb45bc3ad 105 /// Main and core class
JackB 13:9e6589dc8864 106 class TFT_22_ILI9225 : public Stream
JackB 13:9e6589dc8864 107 {
JackB 0:cc1fb45bc3ad 108
JackB 0:cc1fb45bc3ad 109 public:
JackB 0:cc1fb45bc3ad 110
JackB 10:a640680b5309 111 /** Constructor
JackB 10:a640680b5309 112 *
JackB 10:a640680b5309 113 */
JackB 0:cc1fb45bc3ad 114 TFT_22_ILI9225(PinName sdi, PinName clk, PinName cs, PinName rs, PinName rst, PinName led, const char *name);
JackB 0:cc1fb45bc3ad 115
JackB 10:a640680b5309 116 /** Initialization
JackB 10:a640680b5309 117 *
JackB 10:a640680b5309 118 */
JackB 0:cc1fb45bc3ad 119 void init(void);
JackB 0:cc1fb45bc3ad 120
JackB 10:a640680b5309 121 /** Clear the screen
JackB 10:a640680b5309 122 *
JackB 10:a640680b5309 123 */
JackB 0:cc1fb45bc3ad 124 void cls(void);
JackB 0:cc1fb45bc3ad 125
JackB 10:a640680b5309 126 /** Fill the screen with color
JackB 10:a640680b5309 127 *
JackB 10:a640680b5309 128 * @param color
JackB 10:a640680b5309 129 *
JackB 10:a640680b5309 130 */
JackB 0:cc1fb45bc3ad 131 void fill(uint16_t color);
JackB 0:cc1fb45bc3ad 132
JackB 10:a640680b5309 133 /** Invert screen
JackB 10:a640680b5309 134 *
JackB 10:a640680b5309 135 * @param flag true to invert, false for normal screen
JackB 10:a640680b5309 136 *
JackB 10:a640680b5309 137 */
JackB 0:cc1fb45bc3ad 138 void invert(bool flag);
JackB 0:cc1fb45bc3ad 139
JackB 10:a640680b5309 140 /** Set backlight brightness
JackB 10:a640680b5309 141 *
JackB 10:a640680b5309 142 * @param brightness
JackB 10:a640680b5309 143 *
JackB 10:a640680b5309 144 */
JackB 10:a640680b5309 145 void setBacklight(double brightness);
JackB 0:cc1fb45bc3ad 146
JackB 10:a640680b5309 147 /** Switch backlight off
JackB 10:a640680b5309 148 *
JackB 10:a640680b5309 149 */
JackB 0:cc1fb45bc3ad 150 void setBacklightOff(void);
JackB 0:cc1fb45bc3ad 151
JackB 10:a640680b5309 152 /** Switch backlight on
JackB 10:a640680b5309 153 *
JackB 10:a640680b5309 154 */
JackB 0:cc1fb45bc3ad 155 void setBacklightOn(void);
JackB 0:cc1fb45bc3ad 156
JackB 10:a640680b5309 157 /** Switch display on or off
JackB 10:a640680b5309 158 *
JackB 10:a640680b5309 159 * @param flag true=on, false=off
JackB 10:a640680b5309 160 *
JackB 10:a640680b5309 161 */
JackB 0:cc1fb45bc3ad 162 void setDisplay(bool flag);
JackB 0:cc1fb45bc3ad 163
JackB 10:a640680b5309 164 /** Set orientation
JackB 10:a640680b5309 165 *
JackB 10:a640680b5309 166 * @param orientation orientation:
JackB 10:a640680b5309 167 * 0=ILI9225_PORTRAIT_L : SD card at the left side
JackB 10:a640680b5309 168 * 1=ILI9225_LANDSCAPE_B : SD card at the bottom side
JackB 10:a640680b5309 169 * 2=ILI9225_PORTRAIT_R : SD card at the right side
JackB 10:a640680b5309 170 * 3=ILI9225_LANDSCAPE_T : SD card at the top side
JackB 10:a640680b5309 171 *
JackB 10:a640680b5309 172 */
JackB 0:cc1fb45bc3ad 173 void setOrientation(uint8_t orientation);
JackB 0:cc1fb45bc3ad 174
JackB 10:a640680b5309 175 /** Get orientation
JackB 10:a640680b5309 176 *
JackB 10:a640680b5309 177 * @return orientation orientation, 0=portrait, 1=right rotated landscape, 2=reverse portrait, 3=left rotated landscape
JackB 10:a640680b5309 178 *
JackB 10:a640680b5309 179 */
JackB 0:cc1fb45bc3ad 180 uint8_t getOrientation(void);
JackB 0:cc1fb45bc3ad 181
JackB 0:cc1fb45bc3ad 182
JackB 6:0f26c28b9bc0 183 // Graphics functions
JackB 0:cc1fb45bc3ad 184
JackB 10:a640680b5309 185 /** Draw pixel
JackB 10:a640680b5309 186 *
JackB 10:a640680b5309 187 * @param x1 point coordinate, x-axis
JackB 10:a640680b5309 188 * @param y1 point coordinate, y-axis
JackB 10:a640680b5309 189 * @param color 16-bit color
JackB 10:a640680b5309 190 *
JackB 10:a640680b5309 191 */
JackB 6:0f26c28b9bc0 192 void pixel(uint16_t x1, uint16_t y1, uint16_t color);
JackB 0:cc1fb45bc3ad 193
JackB 10:a640680b5309 194 /** Draw line, rectangle coordinates
JackB 10:a640680b5309 195 *
JackB 10:a640680b5309 196 * @param x1 top left coordinate, x-axis
JackB 10:a640680b5309 197 * @param y1 top left coordinate, y-axis
JackB 10:a640680b5309 198 * @param x2 bottom right coordinate, x-axis
JackB 10:a640680b5309 199 * @param y2 bottom right coordinate, y-axis
JackB 10:a640680b5309 200 * @param color 16-bit color
JackB 10:a640680b5309 201 *
JackB 10:a640680b5309 202 */
JackB 5:dad648238df3 203 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
JackB 0:cc1fb45bc3ad 204
JackB 10:a640680b5309 205 /** Draw hline, rectangle coordinates
JackB 10:a640680b5309 206 *
JackB 10:a640680b5309 207 * @param x1 top left coordinate, x-axis
JackB 10:a640680b5309 208 * @param x2 bottom right coordinate, x-axis
JackB 10:a640680b5309 209 * @param y bottom right coordinate, y-axis
JackB 10:a640680b5309 210 * @param color 16-bit color
JackB 10:a640680b5309 211 *
JackB 10:a640680b5309 212 */
JackB 9:680f6c9940b3 213 void hline(uint16_t x1, uint16_t x2, uint16_t y, uint16_t color);
JackB 7:2616ae4dd315 214
JackB 10:a640680b5309 215 /** Draw vline, rectangle coordinates
JackB 10:a640680b5309 216 *
JackB 10:a640680b5309 217 * @param x top left coordinate, x-axis
JackB 10:a640680b5309 218 * @param y1 top left coordinate, y-axis
JackB 10:a640680b5309 219 * @param y2 bottom right coordinate, y-axis
JackB 10:a640680b5309 220 * @param color 16-bit color
JackB 10:a640680b5309 221 *
JackB 10:a640680b5309 222 */
JackB 9:680f6c9940b3 223 void vline(uint16_t x, uint16_t y1, uint16_t y2, uint16_t color);
JackB 7:2616ae4dd315 224
JackB 10:a640680b5309 225 /** Draw rectangle, rectangle coordinates
JackB 10:a640680b5309 226 *
JackB 10:a640680b5309 227 * @param x1 top left coordinate, x-axis
JackB 10:a640680b5309 228 * @param y1 top left coordinate, y-axis
JackB 10:a640680b5309 229 * @param x2 bottom right coordinate, x-axis
JackB 10:a640680b5309 230 * @param y2 bottom right coordinate, y-axis
JackB 10:a640680b5309 231 * @param color 16-bit color
JackB 10:a640680b5309 232 *
JackB 10:a640680b5309 233 */
JackB 5:dad648238df3 234 void rect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
JackB 0:cc1fb45bc3ad 235
JackB 10:a640680b5309 236 /** Draw solid rectangle, rectangle coordinates
JackB 10:a640680b5309 237 *
JackB 10:a640680b5309 238 * @param x1 top left coordinate, x-axis
JackB 10:a640680b5309 239 * @param y1 top left coordinate, y-axis
JackB 10:a640680b5309 240 * @param x2 bottom right coordinate, x-axis
JackB 10:a640680b5309 241 * @param y2 bottom right coordinate, y-axis
JackB 10:a640680b5309 242 * @param color 16-bit color
JackB 10:a640680b5309 243 *
JackB 10:a640680b5309 244 */
JackB 5:dad648238df3 245 void fillrect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
JackB 0:cc1fb45bc3ad 246
JackB 10:a640680b5309 247 /** Draw circle
JackB 10:a640680b5309 248 *
JackB 10:a640680b5309 249 * @param x0 center, point coordinate, x-axis
JackB 10:a640680b5309 250 * @param y0 center, point coordinate, y-axis
JackB 10:a640680b5309 251 * @param radius radius
JackB 10:a640680b5309 252 * @param color 16-bit color
JackB 10:a640680b5309 253 *
JackB 10:a640680b5309 254 */
JackB 6:0f26c28b9bc0 255 void circle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color);
JackB 0:cc1fb45bc3ad 256
JackB 10:a640680b5309 257 /** Draw solid circle
JackB 10:a640680b5309 258 *
JackB 10:a640680b5309 259 * @param x0 center, point coordinate, x-axis
JackB 10:a640680b5309 260 * @param y0 center, point coordinate, y-axis
JackB 10:a640680b5309 261 * @param radius radius
JackB 10:a640680b5309 262 * @param color 16-bit color
JackB 10:a640680b5309 263 *
JackB 10:a640680b5309 264 */
JackB 6:0f26c28b9bc0 265 void fillcircle(uint8_t x0, uint8_t y0, uint8_t radius, uint16_t color);
JackB 0:cc1fb45bc3ad 266
JackB 10:a640680b5309 267 /** Draw triangle, triangle coordinates
JackB 10:a640680b5309 268 *
JackB 10:a640680b5309 269 * @param x1 corner 1 coordinate, x-axis
JackB 10:a640680b5309 270 * @param y1 corner 1 coordinate, y-axis
JackB 10:a640680b5309 271 * @param x2 corner 2 coordinate, x-axis
JackB 10:a640680b5309 272 * @param y2 corner 2 coordinate, y-axis
JackB 10:a640680b5309 273 * @param x3 corner 3 coordinate, x-axis
JackB 10:a640680b5309 274 * @param y3 corner 3 coordinate, y-axis
JackB 10:a640680b5309 275 * @param color 16-bit color
JackB 10:a640680b5309 276 *
JackB 10:a640680b5309 277 */
JackB 5:dad648238df3 278 void triangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color);
JackB 0:cc1fb45bc3ad 279
JackB 10:a640680b5309 280 /** Draw solid triangle, triangle coordinates
JackB 10:a640680b5309 281 *
JackB 10:a640680b5309 282 * @param x1 corner 1 coordinate, x-axis
JackB 10:a640680b5309 283 * @param y1 corner 1 coordinate, y-axis
JackB 10:a640680b5309 284 * @param x2 corner 2 coordinate, x-axis
JackB 10:a640680b5309 285 * @param y2 corner 2 coordinate, y-axis
JackB 10:a640680b5309 286 * @param x3 corner 3 coordinate, x-axis
JackB 10:a640680b5309 287 * @param y3 corner 3 coordinate, y-axis
JackB 10:a640680b5309 288 * @param color 16-bit color
JackB 10:a640680b5309 289 *
JackB 10:a640680b5309 290 */
JackB 5:dad648238df3 291 void filltriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color);
JackB 0:cc1fb45bc3ad 292
JackB 10:a640680b5309 293 /** Draw line/filled rectangle, rectangle coordinates
JackB 10:a640680b5309 294 *
JackB 10:a640680b5309 295 * @param x1 top left coordinate, x-axis
JackB 10:a640680b5309 296 * @param y1 top left coordinate, y-axis
JackB 10:a640680b5309 297 * @param x2 bottom right coordinate, x-axis
JackB 10:a640680b5309 298 * @param y2 bottom right coordinate, y-axis
JackB 10:a640680b5309 299 * @param rad defines the redius of the circle
JackB 10:a640680b5309 300 * @param fill fill yes or no
JackB 10:a640680b5309 301 * @param color 16-bit color
JackB 10:a640680b5309 302 *
JackB 10:a640680b5309 303 */
JackB 8:a569bc50b552 304 void roundrect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t rad, bool fill, uint16_t color);
JackB 8:a569bc50b552 305
JackB 13:9e6589dc8864 306 /** Screen size, x-axis
JackB 13:9e6589dc8864 307 *
JackB 13:9e6589dc8864 308 * @return horizontal size of the screen, in pixels
JackB 13:9e6589dc8864 309 * @note 219 means 0..219 coordinates (decimal)
JackB 13:9e6589dc8864 310 *
JackB 13:9e6589dc8864 311 */
JackB 13:9e6589dc8864 312 uint16_t maxX(void);
JackB 13:9e6589dc8864 313
JackB 13:9e6589dc8864 314 /** Screen size, y-axis
JackB 13:9e6589dc8864 315 *
JackB 13:9e6589dc8864 316 * @return vertical size of the screen, in pixels
JackB 13:9e6589dc8864 317 * @note 175 means 0..175 coordinates (decimal)
JackB 13:9e6589dc8864 318 *
JackB 13:9e6589dc8864 319 */
JackB 13:9e6589dc8864 320 uint16_t maxY(void);
JackB 13:9e6589dc8864 321
JackB 13:9e6589dc8864 322 /** Screen size, x-axis
JackB 13:9e6589dc8864 323 *
JackB 13:9e6589dc8864 324 * @return horizontal size of the screen, in pixels
JackB 13:9e6589dc8864 325 * @note 220 means 220 pixels and thus 0..219 coordinates (decimal)
JackB 13:9e6589dc8864 326 *
JackB 13:9e6589dc8864 327 */
JackB 13:9e6589dc8864 328 uint16_t width(void);
JackB 13:9e6589dc8864 329
JackB 13:9e6589dc8864 330 /** Screen size, y-axis
JackB 13:9e6589dc8864 331 *
JackB 13:9e6589dc8864 332 * @return vertical size of the screen, in pixels
JackB 13:9e6589dc8864 333 * @note 176 means 176 pixels and thus 0..175 coordinates (decimal)
JackB 13:9e6589dc8864 334 *
JackB 13:9e6589dc8864 335 */
JackB 13:9e6589dc8864 336 uint16_t height(void);
JackB 13:9e6589dc8864 337
JackB 10:a640680b5309 338 /** Calculate 16-bit color from 8-bit Red-Green-Blue components
JackB 10:a640680b5309 339 *
JackB 10:a640680b5309 340 * @param red red component, 0x00..0xff
JackB 10:a640680b5309 341 * @param green green component, 0x00..0xff
JackB 10:a640680b5309 342 * @param blue blue component, 0x00..0xff
JackB 10:a640680b5309 343 * @return 16-bit color
JackB 10:a640680b5309 344 *
JackB 10:a640680b5309 345 */
JackB 6:0f26c28b9bc0 346 uint16_t setColor(uint8_t red, uint8_t green, uint8_t blue);
JackB 6:0f26c28b9bc0 347
JackB 10:a640680b5309 348 /** Calculate 8-bit Red-Green-Blue components from 16-bit color
JackB 10:a640680b5309 349 *
JackB 10:a640680b5309 350 * @param rgb 16-bit color
JackB 10:a640680b5309 351 * @param red red component, 0x00..0xff
JackB 10:a640680b5309 352 * @param green green component, 0x00..0xff
JackB 10:a640680b5309 353 * @param blue blue component, 0x00..0xff
JackB 10:a640680b5309 354 *
JackB 10:a640680b5309 355 */
JackB 6:0f26c28b9bc0 356 void splitColor(uint16_t rgb, uint8_t &red, uint8_t &green, uint8_t &blue);
JackB 6:0f26c28b9bc0 357
JackB 13:9e6589dc8864 358
JackB 13:9e6589dc8864 359 // Text functions
JackB 13:9e6589dc8864 360
JackB 10:a640680b5309 361 /** Set current font
JackB 10:a640680b5309 362 *
JackB 10:a640680b5309 363 * @param font Font name
JackB 10:a640680b5309 364 *
JackB 10:a640680b5309 365 */
JackB 0:cc1fb45bc3ad 366 void setFont(uint8_t* font);
JackB 0:cc1fb45bc3ad 367
JackB 13:9e6589dc8864 368 /** Font size, x-axis
JackB 13:9e6589dc8864 369 *
JackB 13:9e6589dc8864 370 * @return horizontal size of current font, in pixels
JackB 13:9e6589dc8864 371 *
JackB 13:9e6589dc8864 372 */
JackB 13:9e6589dc8864 373 uint8_t fontX(void);
JackB 13:9e6589dc8864 374
JackB 13:9e6589dc8864 375 /** Font size, y-axis
JackB 13:9e6589dc8864 376 *
JackB 13:9e6589dc8864 377 * @return vertical size of current font, in pixels
JackB 13:9e6589dc8864 378 *
JackB 13:9e6589dc8864 379 */
JackB 13:9e6589dc8864 380 uint8_t fontY(void);
JackB 13:9e6589dc8864 381
JackB 6:0f26c28b9bc0 382 /** put a char on the screen
JackB 6:0f26c28b9bc0 383 *
JackB 6:0f26c28b9bc0 384 * @param value char to print
JackB 6:0f26c28b9bc0 385 * @returns printed char
JackB 6:0f26c28b9bc0 386 *
JackB 6:0f26c28b9bc0 387 */
JackB 6:0f26c28b9bc0 388 virtual int putc(int value);
JackB 0:cc1fb45bc3ad 389
JackB 6:0f26c28b9bc0 390 /** draw a character on given position out of the active font to the TFT
JackB 6:0f26c28b9bc0 391 *
JackB 6:0f26c28b9bc0 392 * @param x x-position of char (top left)
JackB 6:0f26c28b9bc0 393 * @param y y-position
JackB 6:0f26c28b9bc0 394 * @param c char to print
JackB 6:0f26c28b9bc0 395 *
JackB 6:0f26c28b9bc0 396 */
JackB 0:cc1fb45bc3ad 397 void character(int x, int y, int c);
JackB 0:cc1fb45bc3ad 398
JackB 14:a7640e7e9f80 399 /** get string width
JackB 14:a7640e7e9f80 400 *
JackB 14:a7640e7e9f80 401 * @param string
JackB 14:a7640e7e9f80 402 * @return string width in pixels
JackB 14:a7640e7e9f80 403 *
JackB 14:a7640e7e9f80 404 */
JackB 14:a7640e7e9f80 405 uint16_t getStringWidth(char * s);
JackB 14:a7640e7e9f80 406
JackB 10:a640680b5309 407 /** Set text foreground color
JackB 10:a640680b5309 408 *
JackB 10:a640680b5309 409 * @param color
JackB 10:a640680b5309 410 *
JackB 10:a640680b5309 411 */
JackB 10:a640680b5309 412 void foreground(uint16_t color);
JackB 10:a640680b5309 413
JackB 10:a640680b5309 414 /** Set text background color
JackB 10:a640680b5309 415 *
JackB 10:a640680b5309 416 * @param color
JackB 10:a640680b5309 417 *
JackB 10:a640680b5309 418 */
JackB 10:a640680b5309 419 void background(uint16_t color);
JackB 0:cc1fb45bc3ad 420
JackB 10:a640680b5309 421 /** Set grapical cursor position
JackB 10:a640680b5309 422 *
JackB 10:a640680b5309 423 * @param x
JackB 10:a640680b5309 424 * @param y
JackB 10:a640680b5309 425 *
JackB 10:a640680b5309 426 */
JackB 0:cc1fb45bc3ad 427 void locate(int x, int y);
JackB 10:a640680b5309 428
JackB 10:a640680b5309 429 /** Set text cursor position
JackB 10:a640680b5309 430 *
JackB 10:a640680b5309 431 * @param x
JackB 10:a640680b5309 432 * @param y
JackB 10:a640680b5309 433 *
JackB 10:a640680b5309 434 */
JackB 0:cc1fb45bc3ad 435 void gotoxy(int x, int y);
JackB 10:a640680b5309 436
JackB 10:a640680b5309 437 /** Set text cursor at 0,0
JackB 10:a640680b5309 438 *
JackB 10:a640680b5309 439 */
JackB 0:cc1fb45bc3ad 440 void home(void);
JackB 10:a640680b5309 441
JackB 10:a640680b5309 442 /** Set spacing in pixels between text lines
JackB 10:a640680b5309 443 *
JackB 10:a640680b5309 444 * @param line_spacing spacing in pixels between text lines
JackB 10:a640680b5309 445 *
JackB 10:a640680b5309 446 */
JackB 0:cc1fb45bc3ad 447 void linespacing(int line_spacing);
JackB 0:cc1fb45bc3ad 448
JackB 0:cc1fb45bc3ad 449 /** calculate the max number of char in a line
JackB 0:cc1fb45bc3ad 450 *
JackB 0:cc1fb45bc3ad 451 * @returns max columns
JackB 0:cc1fb45bc3ad 452 * depends on actual font size
JackB 0:cc1fb45bc3ad 453 *
JackB 0:cc1fb45bc3ad 454 */
JackB 0:cc1fb45bc3ad 455 virtual int columns(void);
JackB 0:cc1fb45bc3ad 456
JackB 0:cc1fb45bc3ad 457 /** calculate the max number of columns
JackB 0:cc1fb45bc3ad 458 *
JackB 0:cc1fb45bc3ad 459 * @returns max column
JackB 0:cc1fb45bc3ad 460 * depends on actual font size
JackB 0:cc1fb45bc3ad 461 *
JackB 0:cc1fb45bc3ad 462 */
JackB 0:cc1fb45bc3ad 463 virtual int rows(void);
JackB 0:cc1fb45bc3ad 464
JackB 10:a640680b5309 465 /** Make an ascii string from an unicode string
JackB 10:a640680b5309 466 *
JackB 10:a640680b5309 467 * @param uni_str
JackB 10:a640680b5309 468 * @param ascii_str
JackB 10:a640680b5309 469 *
JackB 10:a640680b5309 470 */
JackB 0:cc1fb45bc3ad 471 void unicode2ascii(char *uni_str, char *ascii_str);
JackB 0:cc1fb45bc3ad 472
JackB 13:9e6589dc8864 473 /** Claim standard output
JackB 13:9e6589dc8864 474 *
JackB 13:9e6589dc8864 475 */
JackB 13:9e6589dc8864 476 virtual bool claim (FILE *stream);
JackB 0:cc1fb45bc3ad 477
JackB 0:cc1fb45bc3ad 478
JackB 0:cc1fb45bc3ad 479 private:
JackB 13:9e6589dc8864 480
JackB 13:9e6589dc8864 481 SPI _spi;
JackB 13:9e6589dc8864 482 DigitalOut _rst;
JackB 13:9e6589dc8864 483 DigitalOut _rs;
JackB 13:9e6589dc8864 484 DigitalOut _cs;
JackB 13:9e6589dc8864 485 PwmOut _led;
JackB 13:9e6589dc8864 486
JackB 13:9e6589dc8864 487 float _brightness;
JackB 13:9e6589dc8864 488 uint16_t _entryMode;
JackB 13:9e6589dc8864 489 uint16_t _maxX, _maxY;
JackB 13:9e6589dc8864 490 uint8_t _orientation;
JackB 13:9e6589dc8864 491
JackB 13:9e6589dc8864 492 // for claim
JackB 13:9e6589dc8864 493 uint16_t _column;
JackB 13:9e6589dc8864 494 uint16_t _row;
JackB 13:9e6589dc8864 495 char *_path;
JackB 0:cc1fb45bc3ad 496
JackB 0:cc1fb45bc3ad 497 unsigned char* font;
JackB 0:cc1fb45bc3ad 498 unsigned int char_x;
JackB 0:cc1fb45bc3ad 499 unsigned int char_y;
JackB 0:cc1fb45bc3ad 500 unsigned int char_line_spacing;
JackB 0:cc1fb45bc3ad 501
JackB 13:9e6589dc8864 502 // colors
JackB 0:cc1fb45bc3ad 503 uint16_t _foreground;
JackB 0:cc1fb45bc3ad 504 uint16_t _background;
JackB 0:cc1fb45bc3ad 505
JackB 13:9e6589dc8864 506
JackB 13:9e6589dc8864 507 // Private functions
JackB 13:9e6589dc8864 508
JackB 10:a640680b5309 509 /** Swap two values
JackB 10:a640680b5309 510 *
JackB 10:a640680b5309 511 * @param a b
JackB 10:a640680b5309 512 * @param a b
JackB 10:a640680b5309 513 *
JackB 10:a640680b5309 514 */
JackB 0:cc1fb45bc3ad 515 void _swap(uint16_t &a, uint16_t &b);
JackB 10:a640680b5309 516
JackB 10:a640680b5309 517 /** Set window
JackB 10:a640680b5309 518 *
JackB 10:a640680b5309 519 * @param x0
JackB 10:a640680b5309 520 * @param y0
JackB 10:a640680b5309 521 * @param x1
JackB 10:a640680b5309 522 * @param y1
JackB 10:a640680b5309 523 *
JackB 10:a640680b5309 524 */
JackB 0:cc1fb45bc3ad 525 void _setWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
JackB 10:a640680b5309 526
JackB 13:9e6589dc8864 527 /** Maximize window to entire screen
JackB 13:9e6589dc8864 528 *
JackB 13:9e6589dc8864 529 */
JackB 13:9e6589dc8864 530 void _setWindowMax(void);
JackB 13:9e6589dc8864 531
JackB 10:a640680b5309 532 /** Set coordinates
JackB 10:a640680b5309 533 *
JackB 10:a640680b5309 534 * @param x
JackB 10:a640680b5309 535 * @param y
JackB 10:a640680b5309 536 *
JackB 10:a640680b5309 537 */
JackB 10:a640680b5309 538 void _orientCoordinates(uint16_t &x, uint16_t &y);
JackB 10:a640680b5309 539
JackB 10:a640680b5309 540 /** Write register
JackB 10:a640680b5309 541 *
JackB 10:a640680b5309 542 * @param uint16_t register
JackB 10:a640680b5309 543 * @param uint16_t data
JackB 10:a640680b5309 544 *
JackB 10:a640680b5309 545 */
JackB 0:cc1fb45bc3ad 546 void _writeRegister(uint16_t reg, uint16_t data);
JackB 0:cc1fb45bc3ad 547
JackB 10:a640680b5309 548 /** Write a command
JackB 10:a640680b5309 549 *
JackB 10:a640680b5309 550 * @param HI
JackB 10:a640680b5309 551 * @param LO
JackB 10:a640680b5309 552 *
JackB 10:a640680b5309 553 */
JackB 0:cc1fb45bc3ad 554 void _writeCommand(uint8_t HI, uint8_t LO);
JackB 0:cc1fb45bc3ad 555
JackB 13:9e6589dc8864 556 /** Start writing data
JackB 13:9e6589dc8864 557 *
JackB 13:9e6589dc8864 558 */
JackB 13:9e6589dc8864 559 void _startData(void);
JackB 0:cc1fb45bc3ad 560
JackB 13:9e6589dc8864 561 /** Write data
JackB 13:9e6589dc8864 562 *
JackB 13:9e6589dc8864 563 * @param uint16_t data
JackB 13:9e6589dc8864 564 *
JackB 13:9e6589dc8864 565 */
JackB 13:9e6589dc8864 566 void _writeData(uint16_t data);
JackB 0:cc1fb45bc3ad 567
JackB 13:9e6589dc8864 568 /** End writing data
JackB 13:9e6589dc8864 569 *
JackB 13:9e6589dc8864 570 */
JackB 13:9e6589dc8864 571 void _endData(void);
JackB 0:cc1fb45bc3ad 572
JackB 0:cc1fb45bc3ad 573
JackB 0:cc1fb45bc3ad 574 protected:
JackB 13:9e6589dc8864 575
JackB 0:cc1fb45bc3ad 576 //used by printf - supply a new _putc virtual function for the new device
JackB 0:cc1fb45bc3ad 577 virtual int _putc(int c) {
JackB 0:cc1fb45bc3ad 578 putc(c); //your new LCD put to print an ASCII character on LCD
JackB 0:cc1fb45bc3ad 579 return 0;
JackB 0:cc1fb45bc3ad 580 };
JackB 13:9e6589dc8864 581 //assuming no reads from LCD
JackB 0:cc1fb45bc3ad 582 virtual int _getc() {
JackB 0:cc1fb45bc3ad 583 return -1;
JackB 0:cc1fb45bc3ad 584 }
JackB 0:cc1fb45bc3ad 585
JackB 0:cc1fb45bc3ad 586 };
JackB 0:cc1fb45bc3ad 587
JackB 0:cc1fb45bc3ad 588 #endif