Library to drive an ILI9225 2.2" SPI TFT.
Dependents: ILI9225_TFT_Sample
ILI9225 SPI TFT Library
This library works with the ILI9225 based 2.2" 176x220 TFT LCD shields commonly found on eBay. Note that there is a commonly available 2.2" 240x320 TFT module very similar in appearance but using the ILI9341 driver. (Only the main Buffer IC and I/O pins are different)
Wiring guide :
mbed board | LCD board |
---|---|
+ 3,3V or +5V | VCC |
GND | GND |
GPIO_PIN | RST (Reset pin) |
GPIO_PIN | RS [Command (RS=0)/ Parameter (RS=1)] |
GPIO_PIN or GND | CS (Chip selection pin) |
SPI_MOSI | SDI (Serial data input ) |
SPI_SCK | CLK (Reference clock) |
GPIO_PIN or PWM or VCC | LED (Backlit) |
TFT_22_ILI9225.h@0:e97881aef140, 2015-08-31 (annotated)
- Committer:
- Arman92
- Date:
- Mon Aug 31 05:05:09 2015 +0000
- Revision:
- 0:e97881aef140
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Arman92 | 0:e97881aef140 | 1 | #ifndef TFT_22_ILI9225_h |
Arman92 | 0:e97881aef140 | 2 | #define TFT_22_ILI9225_h |
Arman92 | 0:e97881aef140 | 3 | #include "mbed.h" |
Arman92 | 0:e97881aef140 | 4 | #include "FAmap.h" |
Arman92 | 0:e97881aef140 | 5 | #include "EN_FA_font.h" |
Arman92 | 0:e97881aef140 | 6 | |
Arman92 | 0:e97881aef140 | 7 | // Other libraries |
Arman92 | 0:e97881aef140 | 8 | #include "SPI.h" |
Arman92 | 0:e97881aef140 | 9 | |
Arman92 | 0:e97881aef140 | 10 | /* ILI9225 screen size */ |
Arman92 | 0:e97881aef140 | 11 | #define ILI9225_LCD_WIDTH 176 |
Arman92 | 0:e97881aef140 | 12 | #define ILI9225_LCD_HEIGHT 220 |
Arman92 | 0:e97881aef140 | 13 | |
Arman92 | 0:e97881aef140 | 14 | /* ILI9225 LCD Registers */ |
Arman92 | 0:e97881aef140 | 15 | #define ILI9225_DRIVER_OUTPUT_CTRL (0x01u) // Driver Output Control |
Arman92 | 0:e97881aef140 | 16 | #define ILI9225_LCD_AC_DRIVING_CTRL (0x02u) // LCD AC Driving Control |
Arman92 | 0:e97881aef140 | 17 | #define ILI9225_ENTRY_MODE (0x03u) // Entry Mode |
Arman92 | 0:e97881aef140 | 18 | #define ILI9225_DISP_CTRL1 (0x07u) // Display Control 1 |
Arman92 | 0:e97881aef140 | 19 | #define ILI9225_BLANK_PERIOD_CTRL1 (0x08u) // Blank Period Control |
Arman92 | 0:e97881aef140 | 20 | #define ILI9225_FRAME_CYCLE_CTRL (0x0Bu) // Frame Cycle Control |
Arman92 | 0:e97881aef140 | 21 | #define ILI9225_INTERFACE_CTRL (0x0Cu) // Interface Control |
Arman92 | 0:e97881aef140 | 22 | #define ILI9225_OSC_CTRL (0x0Fu) // Osc Control |
Arman92 | 0:e97881aef140 | 23 | #define ILI9225_POWER_CTRL1 (0x10u) // Power Control 1 |
Arman92 | 0:e97881aef140 | 24 | #define ILI9225_POWER_CTRL2 (0x11u) // Power Control 2 |
Arman92 | 0:e97881aef140 | 25 | #define ILI9225_POWER_CTRL3 (0x12u) // Power Control 3 |
Arman92 | 0:e97881aef140 | 26 | #define ILI9225_POWER_CTRL4 (0x13u) // Power Control 4 |
Arman92 | 0:e97881aef140 | 27 | #define ILI9225_POWER_CTRL5 (0x14u) // Power Control 5 |
Arman92 | 0:e97881aef140 | 28 | #define ILI9225_VCI_RECYCLING (0x15u) // VCI Recycling |
Arman92 | 0:e97881aef140 | 29 | #define ILI9225_RAM_ADDR_SET1 (0x20u) // Horizontal GRAM Address Set |
Arman92 | 0:e97881aef140 | 30 | #define ILI9225_RAM_ADDR_SET2 (0x21u) // Vertical GRAM Address Set |
Arman92 | 0:e97881aef140 | 31 | #define ILI9225_GRAM_DATA_REG (0x22u) // GRAM Data Register |
Arman92 | 0:e97881aef140 | 32 | #define ILI9225_GATE_SCAN_CTRL (0x30u) // Gate Scan Control Register |
Arman92 | 0:e97881aef140 | 33 | #define ILI9225_VERTICAL_SCROLL_CTRL1 (0x31u) // Vertical Scroll Control 1 Register |
Arman92 | 0:e97881aef140 | 34 | #define ILI9225_VERTICAL_SCROLL_CTRL2 (0x32u) // Vertical Scroll Control 2 Register |
Arman92 | 0:e97881aef140 | 35 | #define ILI9225_VERTICAL_SCROLL_CTRL3 (0x33u) // Vertical Scroll Control 3 Register |
Arman92 | 0:e97881aef140 | 36 | #define ILI9225_PARTIAL_DRIVING_POS1 (0x34u) // Partial Driving Position 1 Register |
Arman92 | 0:e97881aef140 | 37 | #define ILI9225_PARTIAL_DRIVING_POS2 (0x35u) // Partial Driving Position 2 Register |
Arman92 | 0:e97881aef140 | 38 | #define ILI9225_HORIZONTAL_WINDOW_ADDR1 (0x36u) // Horizontal Address Start Position |
Arman92 | 0:e97881aef140 | 39 | #define ILI9225_HORIZONTAL_WINDOW_ADDR2 (0x37u) // Horizontal Address End Position |
Arman92 | 0:e97881aef140 | 40 | #define ILI9225_VERTICAL_WINDOW_ADDR1 (0x38u) // Vertical Address Start Position |
Arman92 | 0:e97881aef140 | 41 | #define ILI9225_VERTICAL_WINDOW_ADDR2 (0x39u) // Vertical Address End Position |
Arman92 | 0:e97881aef140 | 42 | #define ILI9225_GAMMA_CTRL1 (0x50u) // Gamma Control 1 |
Arman92 | 0:e97881aef140 | 43 | #define ILI9225_GAMMA_CTRL2 (0x51u) // Gamma Control 2 |
Arman92 | 0:e97881aef140 | 44 | #define ILI9225_GAMMA_CTRL3 (0x52u) // Gamma Control 3 |
Arman92 | 0:e97881aef140 | 45 | #define ILI9225_GAMMA_CTRL4 (0x53u) // Gamma Control 4 |
Arman92 | 0:e97881aef140 | 46 | #define ILI9225_GAMMA_CTRL5 (0x54u) // Gamma Control 5 |
Arman92 | 0:e97881aef140 | 47 | #define ILI9225_GAMMA_CTRL6 (0x55u) // Gamma Control 6 |
Arman92 | 0:e97881aef140 | 48 | #define ILI9225_GAMMA_CTRL7 (0x56u) // Gamma Control 7 |
Arman92 | 0:e97881aef140 | 49 | #define ILI9225_GAMMA_CTRL8 (0x57u) // Gamma Control 8 |
Arman92 | 0:e97881aef140 | 50 | #define ILI9225_GAMMA_CTRL9 (0x58u) // Gamma Control 9 |
Arman92 | 0:e97881aef140 | 51 | #define ILI9225_GAMMA_CTRL10 (0x59u) // Gamma Control 10 |
Arman92 | 0:e97881aef140 | 52 | |
Arman92 | 0:e97881aef140 | 53 | #define ILI9225C_INVOFF 0x20 |
Arman92 | 0:e97881aef140 | 54 | #define ILI9225C_INVON 0x21 |
Arman92 | 0:e97881aef140 | 55 | |
Arman92 | 0:e97881aef140 | 56 | |
Arman92 | 0:e97881aef140 | 57 | /* RGB 24-bits color table definition (RGB888). */ |
Arman92 | 0:e97881aef140 | 58 | #define RGB888_RGB565(color) ((((color) >> 19) & 0x1f) << 11) | ((((color) >> 10) & 0x3f) << 5) | (((color) >> 3) & 0x1f) |
Arman92 | 0:e97881aef140 | 59 | |
Arman92 | 0:e97881aef140 | 60 | #define COLOR_BLACK RGB888_RGB565(0x000000u) |
Arman92 | 0:e97881aef140 | 61 | #define COLOR_WHITE RGB888_RGB565(0xFFFFFFu) |
Arman92 | 0:e97881aef140 | 62 | #define COLOR_BLUE RGB888_RGB565(0x0000FFu) |
Arman92 | 0:e97881aef140 | 63 | #define COLOR_GREEN RGB888_RGB565(0x00FF00u) |
Arman92 | 0:e97881aef140 | 64 | #define COLOR_RED RGB888_RGB565(0xFF0000u) |
Arman92 | 0:e97881aef140 | 65 | #define COLOR_NAVY RGB888_RGB565(0x000080u) |
Arman92 | 0:e97881aef140 | 66 | #define COLOR_DARKBLUE RGB888_RGB565(0x00008Bu) |
Arman92 | 0:e97881aef140 | 67 | #define COLOR_DARKGREEN RGB888_RGB565(0x006400u) |
Arman92 | 0:e97881aef140 | 68 | #define COLOR_DARKCYAN RGB888_RGB565(0x008B8Bu) |
Arman92 | 0:e97881aef140 | 69 | #define COLOR_CYAN RGB888_RGB565(0x00FFFFu) |
Arman92 | 0:e97881aef140 | 70 | #define COLOR_TURQUOISE RGB888_RGB565(0x40E0D0u) |
Arman92 | 0:e97881aef140 | 71 | #define COLOR_INDIGO RGB888_RGB565(0x4B0082u) |
Arman92 | 0:e97881aef140 | 72 | #define COLOR_DARKRED RGB888_RGB565(0x800000u) |
Arman92 | 0:e97881aef140 | 73 | #define COLOR_OLIVE RGB888_RGB565(0x808000u) |
Arman92 | 0:e97881aef140 | 74 | #define COLOR_GRAY RGB888_RGB565(0x808080u) |
Arman92 | 0:e97881aef140 | 75 | #define COLOR_SKYBLUE RGB888_RGB565(0x87CEEBu) |
Arman92 | 0:e97881aef140 | 76 | #define COLOR_BLUEVIOLET RGB888_RGB565(0x8A2BE2u) |
Arman92 | 0:e97881aef140 | 77 | #define COLOR_LIGHTGREEN RGB888_RGB565(0x90EE90u) |
Arman92 | 0:e97881aef140 | 78 | #define COLOR_DARKVIOLET RGB888_RGB565(0x9400D3u) |
Arman92 | 0:e97881aef140 | 79 | #define COLOR_YELLOWGREEN RGB888_RGB565(0x9ACD32u) |
Arman92 | 0:e97881aef140 | 80 | #define COLOR_BROWN RGB888_RGB565(0xA52A2Au) |
Arman92 | 0:e97881aef140 | 81 | #define COLOR_DARKGRAY RGB888_RGB565(0xA9A9A9u) |
Arman92 | 0:e97881aef140 | 82 | #define COLOR_SIENNA RGB888_RGB565(0xA0522Du) |
Arman92 | 0:e97881aef140 | 83 | #define COLOR_LIGHTBLUE RGB888_RGB565(0xADD8E6u) |
Arman92 | 0:e97881aef140 | 84 | #define COLOR_GREENYELLOW RGB888_RGB565(0xADFF2Fu) |
Arman92 | 0:e97881aef140 | 85 | #define COLOR_SILVER RGB888_RGB565(0xC0C0C0u) |
Arman92 | 0:e97881aef140 | 86 | #define COLOR_LIGHTGREY RGB888_RGB565(0xD3D3D3u) |
Arman92 | 0:e97881aef140 | 87 | #define COLOR_LIGHTCYAN RGB888_RGB565(0xE0FFFFu) |
Arman92 | 0:e97881aef140 | 88 | #define COLOR_VIOLET RGB888_RGB565(0xEE82EEu) |
Arman92 | 0:e97881aef140 | 89 | #define COLOR_AZUR RGB888_RGB565(0xF0FFFFu) |
Arman92 | 0:e97881aef140 | 90 | #define COLOR_BEIGE RGB888_RGB565(0xF5F5DCu) |
Arman92 | 0:e97881aef140 | 91 | #define COLOR_MAGENTA RGB888_RGB565(0xFF00FFu) |
Arman92 | 0:e97881aef140 | 92 | #define COLOR_TOMATO RGB888_RGB565(0xFF6347u) |
Arman92 | 0:e97881aef140 | 93 | #define COLOR_GOLD RGB888_RGB565(0xFFD700u) |
Arman92 | 0:e97881aef140 | 94 | #define COLOR_ORANGE RGB888_RGB565(0xFFA500u) |
Arman92 | 0:e97881aef140 | 95 | #define COLOR_SNOW RGB888_RGB565(0xFFFAFAu) |
Arman92 | 0:e97881aef140 | 96 | #define COLOR_YELLOW RGB888_RGB565(0xFFFF00u) |
Arman92 | 0:e97881aef140 | 97 | |
Arman92 | 0:e97881aef140 | 98 | /* Font defines */ |
Arman92 | 0:e97881aef140 | 99 | #define FONT_HEADER_SIZE 4 // 1: pixel width of 1 font character, 2: pixel height, |
Arman92 | 0:e97881aef140 | 100 | #define readFontByte(x) pgm_read_byte(&cfont.font[x]) |
Arman92 | 0:e97881aef140 | 101 | |
Arman92 | 0:e97881aef140 | 102 | extern uint8_t Terminal6x8[]; |
Arman92 | 0:e97881aef140 | 103 | extern uint8_t Terminal11x16[]; |
Arman92 | 0:e97881aef140 | 104 | extern uint8_t Terminal12x16[]; |
Arman92 | 0:e97881aef140 | 105 | extern uint8_t Trebuchet_MS16x21[]; |
Arman92 | 0:e97881aef140 | 106 | |
Arman92 | 0:e97881aef140 | 107 | struct _currentFont |
Arman92 | 0:e97881aef140 | 108 | { |
Arman92 | 0:e97881aef140 | 109 | uint8_t* font; |
Arman92 | 0:e97881aef140 | 110 | uint8_t width; |
Arman92 | 0:e97881aef140 | 111 | uint8_t height; |
Arman92 | 0:e97881aef140 | 112 | uint8_t offset; |
Arman92 | 0:e97881aef140 | 113 | uint8_t numchars; |
Arman92 | 0:e97881aef140 | 114 | uint8_t nbrows; |
Arman92 | 0:e97881aef140 | 115 | }; |
Arman92 | 0:e97881aef140 | 116 | |
Arman92 | 0:e97881aef140 | 117 | /// Main and core class |
Arman92 | 0:e97881aef140 | 118 | class TFT_22_ILI9225 { |
Arman92 | 0:e97881aef140 | 119 | |
Arman92 | 0:e97881aef140 | 120 | public: |
Arman92 | 0:e97881aef140 | 121 | |
Arman92 | 0:e97881aef140 | 122 | TFT_22_ILI9225(PinName RST, PinName RS, PinName CS, PinName SDI, PinName CLK, PinName LED); |
Arman92 | 0:e97881aef140 | 123 | //TFT_22_ILI9225(PinName RST, PinName RS, PinName CS, PinName LED); |
Arman92 | 0:e97881aef140 | 124 | |
Arman92 | 0:e97881aef140 | 125 | |
Arman92 | 0:e97881aef140 | 126 | /// Initialization |
Arman92 | 0:e97881aef140 | 127 | void begin(void); |
Arman92 | 0:e97881aef140 | 128 | |
Arman92 | 0:e97881aef140 | 129 | /// Clear the screen |
Arman92 | 0:e97881aef140 | 130 | void clear(void); |
Arman92 | 0:e97881aef140 | 131 | |
Arman92 | 0:e97881aef140 | 132 | /// fill the screen with color: |
Arman92 | 0:e97881aef140 | 133 | void fill(uint16_t color); |
Arman92 | 0:e97881aef140 | 134 | |
Arman92 | 0:e97881aef140 | 135 | /// Invert screen |
Arman92 | 0:e97881aef140 | 136 | /// @param flag true to invert, false for normal screen |
Arman92 | 0:e97881aef140 | 137 | void invert(bool flag); |
Arman92 | 0:e97881aef140 | 138 | |
Arman92 | 0:e97881aef140 | 139 | /// Switch backlight on or off |
Arman92 | 0:e97881aef140 | 140 | /// @param flag true=on, false=off |
Arman92 | 0:e97881aef140 | 141 | void setBacklight(bool flag); |
Arman92 | 0:e97881aef140 | 142 | |
Arman92 | 0:e97881aef140 | 143 | /// Switch display on or off |
Arman92 | 0:e97881aef140 | 144 | /// @param flag true=on, false=off |
Arman92 | 0:e97881aef140 | 145 | void setDisplay(bool flag); |
Arman92 | 0:e97881aef140 | 146 | |
Arman92 | 0:e97881aef140 | 147 | /// Set orientation |
Arman92 | 0:e97881aef140 | 148 | /// @param orientation orientation, 0=portrait, 1=right rotated landscape, 2=reverse portrait, 3=left rotated landscape |
Arman92 | 0:e97881aef140 | 149 | void setOrientation(uint8_t orientation); |
Arman92 | 0:e97881aef140 | 150 | |
Arman92 | 0:e97881aef140 | 151 | /// Get orientation |
Arman92 | 0:e97881aef140 | 152 | /// @return orientation orientation, 0=portrait, 1=right rotated landscape, 2=reverse portrait, 3=left rotated landscape |
Arman92 | 0:e97881aef140 | 153 | uint8_t getOrientation(void); |
Arman92 | 0:e97881aef140 | 154 | |
Arman92 | 0:e97881aef140 | 155 | /// Font size, x-axis |
Arman92 | 0:e97881aef140 | 156 | /// @return horizontal size of current font, in pixels |
Arman92 | 0:e97881aef140 | 157 | uint8_t fontX(void); |
Arman92 | 0:e97881aef140 | 158 | |
Arman92 | 0:e97881aef140 | 159 | /// Font size, y-axis |
Arman92 | 0:e97881aef140 | 160 | /// @return vertical size of current font, in pixels |
Arman92 | 0:e97881aef140 | 161 | uint8_t fontY(void); |
Arman92 | 0:e97881aef140 | 162 | |
Arman92 | 0:e97881aef140 | 163 | /// Screen size, x-axis |
Arman92 | 0:e97881aef140 | 164 | /// @return horizontal size of the screen, in pixels |
Arman92 | 0:e97881aef140 | 165 | /// @note 240 means 240 pixels and thus 0..239 coordinates (decimal) |
Arman92 | 0:e97881aef140 | 166 | uint16_t maxX(void); |
Arman92 | 0:e97881aef140 | 167 | |
Arman92 | 0:e97881aef140 | 168 | /// Screen size, y-axis |
Arman92 | 0:e97881aef140 | 169 | /// @return vertical size of the screen, in pixels |
Arman92 | 0:e97881aef140 | 170 | /// @note 220 means 220 pixels and thus 0..219 coordinates (decimal) |
Arman92 | 0:e97881aef140 | 171 | uint16_t maxY(void); |
Arman92 | 0:e97881aef140 | 172 | |
Arman92 | 0:e97881aef140 | 173 | /// Draw circle |
Arman92 | 0:e97881aef140 | 174 | /// @param x0 center, point coordinate, x-axis |
Arman92 | 0:e97881aef140 | 175 | /// @param y0 center, point coordinate, y-axis |
Arman92 | 0:e97881aef140 | 176 | /// @param radius radius |
Arman92 | 0:e97881aef140 | 177 | /// @param color 16-bit color |
Arman92 | 0:e97881aef140 | 178 | void drawCircle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color); |
Arman92 | 0:e97881aef140 | 179 | |
Arman92 | 0:e97881aef140 | 180 | /// Draw solid circle |
Arman92 | 0:e97881aef140 | 181 | /// @param x0 center, point coordinate, x-axis |
Arman92 | 0:e97881aef140 | 182 | /// @param y0 center, point coordinate, y-axis |
Arman92 | 0:e97881aef140 | 183 | /// @param radius radius |
Arman92 | 0:e97881aef140 | 184 | /// @param color 16-bit color |
Arman92 | 0:e97881aef140 | 185 | void fillCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint16_t color); |
Arman92 | 0:e97881aef140 | 186 | |
Arman92 | 0:e97881aef140 | 187 | /// Set background color |
Arman92 | 0:e97881aef140 | 188 | /// @param color background color, default=black |
Arman92 | 0:e97881aef140 | 189 | void setBackgroundColor(uint16_t color = COLOR_BLACK); |
Arman92 | 0:e97881aef140 | 190 | |
Arman92 | 0:e97881aef140 | 191 | /// Draw line, rectangle coordinates |
Arman92 | 0:e97881aef140 | 192 | /// @param x1 top left coordinate, x-axis |
Arman92 | 0:e97881aef140 | 193 | /// @param y1 top left coordinate, y-axis |
Arman92 | 0:e97881aef140 | 194 | /// @param x2 bottom right coordinate, x-axis |
Arman92 | 0:e97881aef140 | 195 | /// @param y2 bottom right coordinate, y-axis |
Arman92 | 0:e97881aef140 | 196 | /// @param color 16-bit color |
Arman92 | 0:e97881aef140 | 197 | void drawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); |
Arman92 | 0:e97881aef140 | 198 | |
Arman92 | 0:e97881aef140 | 199 | /// Draw rectangle, rectangle coordinates |
Arman92 | 0:e97881aef140 | 200 | /// @param x1 top left coordinate, x-axis |
Arman92 | 0:e97881aef140 | 201 | /// @param y1 top left coordinate, y-axis |
Arman92 | 0:e97881aef140 | 202 | /// @param x2 bottom right coordinate, x-axis |
Arman92 | 0:e97881aef140 | 203 | /// @param y2 bottom right coordinate, y-axis |
Arman92 | 0:e97881aef140 | 204 | /// @param color 16-bit color |
Arman92 | 0:e97881aef140 | 205 | void drawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); |
Arman92 | 0:e97881aef140 | 206 | |
Arman92 | 0:e97881aef140 | 207 | /// Draw solid rectangle, rectangle coordinates |
Arman92 | 0:e97881aef140 | 208 | /// @param x1 top left coordinate, x-axis |
Arman92 | 0:e97881aef140 | 209 | /// @param y1 top left coordinate, y-axis |
Arman92 | 0:e97881aef140 | 210 | /// @param x2 bottom right coordinate, x-axis |
Arman92 | 0:e97881aef140 | 211 | /// @param y2 bottom right coordinate, y-axis |
Arman92 | 0:e97881aef140 | 212 | /// @param color 16-bit color |
Arman92 | 0:e97881aef140 | 213 | void fillRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); |
Arman92 | 0:e97881aef140 | 214 | |
Arman92 | 0:e97881aef140 | 215 | /// Draw pixel |
Arman92 | 0:e97881aef140 | 216 | /// @param x1 point coordinate, x-axis |
Arman92 | 0:e97881aef140 | 217 | /// @param y1 point coordinate, y-axis |
Arman92 | 0:e97881aef140 | 218 | /// @param color 16-bit color |
Arman92 | 0:e97881aef140 | 219 | void drawPixel(uint16_t x1, uint16_t y1, uint16_t color); |
Arman92 | 0:e97881aef140 | 220 | |
Arman92 | 0:e97881aef140 | 221 | /// Draw ASCII Text (pixel coordinates) |
Arman92 | 0:e97881aef140 | 222 | /// @param x point coordinate, x-axis |
Arman92 | 0:e97881aef140 | 223 | /// @param y point coordinate, y-axis |
Arman92 | 0:e97881aef140 | 224 | /// @param s text string |
Arman92 | 0:e97881aef140 | 225 | /// @param color 16-bit color, default=white |
Arman92 | 0:e97881aef140 | 226 | void drawText(uint16_t x, uint16_t y, char *s, uint16_t color = COLOR_WHITE); |
Arman92 | 0:e97881aef140 | 227 | |
Arman92 | 0:e97881aef140 | 228 | /// Calculate 16-bit color from 8-bit Red-Green-Blue components |
Arman92 | 0:e97881aef140 | 229 | /// @param red red component, 0x00..0xff |
Arman92 | 0:e97881aef140 | 230 | /// @param green green component, 0x00..0xff |
Arman92 | 0:e97881aef140 | 231 | /// @param blue blue component, 0x00..0xff |
Arman92 | 0:e97881aef140 | 232 | /// @return 16-bit color |
Arman92 | 0:e97881aef140 | 233 | uint16_t setColor(uint8_t red, uint8_t green, uint8_t blue); |
Arman92 | 0:e97881aef140 | 234 | |
Arman92 | 0:e97881aef140 | 235 | /// Calculate 8-bit Red-Green-Blue components from 16-bit color |
Arman92 | 0:e97881aef140 | 236 | /// @param rgb 16-bit color |
Arman92 | 0:e97881aef140 | 237 | /// @param red red component, 0x00..0xff |
Arman92 | 0:e97881aef140 | 238 | /// @param green green component, 0x00..0xff |
Arman92 | 0:e97881aef140 | 239 | /// @param blue blue component, 0x00..0xff |
Arman92 | 0:e97881aef140 | 240 | void splitColor(uint16_t rgb, uint8_t &red, uint8_t &green, uint8_t &blue); |
Arman92 | 0:e97881aef140 | 241 | |
Arman92 | 0:e97881aef140 | 242 | /// Draw triangle, triangle coordinates |
Arman92 | 0:e97881aef140 | 243 | /// @param x1 corner 1 coordinate, x-axis |
Arman92 | 0:e97881aef140 | 244 | /// @param y1 corner 1 coordinate, y-axis |
Arman92 | 0:e97881aef140 | 245 | /// @param x2 corner 2 coordinate, x-axis |
Arman92 | 0:e97881aef140 | 246 | /// @param y2 corner 2 coordinate, y-axis |
Arman92 | 0:e97881aef140 | 247 | /// @param x3 corner 3 coordinate, x-axis |
Arman92 | 0:e97881aef140 | 248 | /// @param y3 corner 3 coordinate, y-axis |
Arman92 | 0:e97881aef140 | 249 | /// @param color 16-bit color |
Arman92 | 0:e97881aef140 | 250 | void drawTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color); |
Arman92 | 0:e97881aef140 | 251 | |
Arman92 | 0:e97881aef140 | 252 | /// Draw solid triangle, triangle coordinates |
Arman92 | 0:e97881aef140 | 253 | /// @param x1 corner 1 coordinate, x-axis |
Arman92 | 0:e97881aef140 | 254 | /// @param y1 corner 1 coordinate, y-axis |
Arman92 | 0:e97881aef140 | 255 | /// @param x2 corner 2 coordinate, x-axis |
Arman92 | 0:e97881aef140 | 256 | /// @param y2 corner 2 coordinate, y-axis |
Arman92 | 0:e97881aef140 | 257 | /// @param x3 corner 3 coordinate, x-axis |
Arman92 | 0:e97881aef140 | 258 | /// @param y3 corner 3 coordinate, y-axis |
Arman92 | 0:e97881aef140 | 259 | /// @param color 16-bit color |
Arman92 | 0:e97881aef140 | 260 | void fillTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color); |
Arman92 | 0:e97881aef140 | 261 | |
Arman92 | 0:e97881aef140 | 262 | /// Set current font |
Arman92 | 0:e97881aef140 | 263 | /// @param font Font name |
Arman92 | 0:e97881aef140 | 264 | void setFont(uint8_t* font); |
Arman92 | 0:e97881aef140 | 265 | |
Arman92 | 0:e97881aef140 | 266 | /// Draw single character (pixel coordinates) |
Arman92 | 0:e97881aef140 | 267 | /// @param x point coordinate, x-axis |
Arman92 | 0:e97881aef140 | 268 | /// @param y point coordinate, y-axis |
Arman92 | 0:e97881aef140 | 269 | /// @param ch ASCII character |
Arman92 | 0:e97881aef140 | 270 | /// @param color 16-bit color, default=white |
Arman92 | 0:e97881aef140 | 271 | uint16_t drawChar(uint16_t x, uint16_t y, uint16_t ch, uint16_t color = COLOR_WHITE); |
Arman92 | 0:e97881aef140 | 272 | |
Arman92 | 0:e97881aef140 | 273 | void setFontColor(int color); |
Arman92 | 0:e97881aef140 | 274 | void setNumberFormatToFa(void); |
Arman92 | 0:e97881aef140 | 275 | void setNumberFormatToEn(void); |
Arman92 | 0:e97881aef140 | 276 | void setFontEffect(int ef); |
Arman92 | 0:e97881aef140 | 277 | void setItalicOn(void); |
Arman92 | 0:e97881aef140 | 278 | void setItalicOff(void); |
Arman92 | 0:e97881aef140 | 279 | void putChar(char character); |
Arman92 | 0:e97881aef140 | 280 | void putBoldChar(char character, int size); |
Arman92 | 0:e97881aef140 | 281 | void goToXY(int x, int y); |
Arman92 | 0:e97881aef140 | 282 | void setTextHighlightOn(void); |
Arman92 | 0:e97881aef140 | 283 | void setTextHighlightOff(void); |
Arman92 | 0:e97881aef140 | 284 | void setTextHighlightColor(unsigned int color); |
Arman92 | 0:e97881aef140 | 285 | void putMixedEnAndFaString(const unsigned char *string, int size); |
Arman92 | 0:e97881aef140 | 286 | void unicode2ascii(char *uni_str, char *ascii_str); |
Arman92 | 0:e97881aef140 | 287 | void roundRectangle(int x0, int y0, int x1, int y1, int rad, bool fill, int color); |
Arman92 | 0:e97881aef140 | 288 | |
Arman92 | 0:e97881aef140 | 289 | |
Arman92 | 0:e97881aef140 | 290 | private: |
Arman92 | 0:e97881aef140 | 291 | SPI spi; |
Arman92 | 0:e97881aef140 | 292 | |
Arman92 | 0:e97881aef140 | 293 | void _swap(uint16_t &a, uint16_t &b), |
Arman92 | 0:e97881aef140 | 294 | _setWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1), |
Arman92 | 0:e97881aef140 | 295 | _orientCoordinates(uint16_t &x1, uint16_t &y1), |
Arman92 | 0:e97881aef140 | 296 | _writeRegister(uint16_t reg, uint16_t data), |
Arman92 | 0:e97881aef140 | 297 | _writeData(uint8_t HI, uint8_t LO), |
Arman92 | 0:e97881aef140 | 298 | _writeCommand(uint8_t HI, uint8_t LO); |
Arman92 | 0:e97881aef140 | 299 | |
Arman92 | 0:e97881aef140 | 300 | uint16_t _maxX, _maxY, _bgColor; |
Arman92 | 0:e97881aef140 | 301 | |
Arman92 | 0:e97881aef140 | 302 | PinName _rst, _rs, _cs, _sdi, _clk, _led; |
Arman92 | 0:e97881aef140 | 303 | DigitalInOut _rsInOut; |
Arman92 | 0:e97881aef140 | 304 | DigitalInOut _csInOut; |
Arman92 | 0:e97881aef140 | 305 | DigitalInOut _rstInOut; |
Arman92 | 0:e97881aef140 | 306 | DigitalInOut _ledInOut; |
Arman92 | 0:e97881aef140 | 307 | uint8_t _orientation; |
Arman92 | 0:e97881aef140 | 308 | |
Arman92 | 0:e97881aef140 | 309 | |
Arman92 | 0:e97881aef140 | 310 | bool hwSPI; |
Arman92 | 0:e97881aef140 | 311 | |
Arman92 | 0:e97881aef140 | 312 | _currentFont cfont; |
Arman92 | 0:e97881aef140 | 313 | |
Arman92 | 0:e97881aef140 | 314 | }; |
Arman92 | 0:e97881aef140 | 315 | |
Arman92 | 0:e97881aef140 | 316 | #endif |