Added methods and features
Fork of SPI_TFT_ILI9341 by
SPI_TFT_ILI9341.h@9:6d30a225a5c7, 2014-04-07 (annotated)
- Committer:
- wim
- Date:
- Mon Apr 07 20:25:09 2014 +0000
- Revision:
- 9:6d30a225a5c7
- Parent:
- 8:8593d3668153
- Child:
- 10:2d505d14b7eb
Test version 2, LCD functions, I2C lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 2:0a16083193a4 | 1 | /* mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller |
dreschpe | 2:0a16083193a4 | 2 | * Copyright (c) 2013 Peter Drescher - DC2PD |
dreschpe | 0:da1bf437cbc1 | 3 | * |
dreschpe | 0:da1bf437cbc1 | 4 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
dreschpe | 0:da1bf437cbc1 | 5 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
dreschpe | 0:da1bf437cbc1 | 6 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
dreschpe | 0:da1bf437cbc1 | 7 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
dreschpe | 0:da1bf437cbc1 | 8 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dreschpe | 0:da1bf437cbc1 | 9 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
dreschpe | 0:da1bf437cbc1 | 10 | * THE SOFTWARE. |
dreschpe | 0:da1bf437cbc1 | 11 | */ |
dreschpe | 0:da1bf437cbc1 | 12 | |
wim | 9:6d30a225a5c7 | 13 | // PD Change the char position handling, use pixel (x,y) instead of (colum, row) |
wim | 9:6d30a225a5c7 | 14 | // 30.03.14 WH Added some methods & defines, Fixed typos & warnings, General define for SPI_16 selection |
wim | 9:6d30a225a5c7 | 15 | // |
dreschpe | 0:da1bf437cbc1 | 16 | |
dreschpe | 0:da1bf437cbc1 | 17 | #ifndef MBED_SPI_TFT_ILI9341_H |
dreschpe | 0:da1bf437cbc1 | 18 | #define MBED_SPI_TFT_ILI9341_H |
dreschpe | 0:da1bf437cbc1 | 19 | |
dreschpe | 0:da1bf437cbc1 | 20 | #include "mbed.h" |
dreschpe | 0:da1bf437cbc1 | 21 | #include "GraphicsDisplay.h" |
dreschpe | 0:da1bf437cbc1 | 22 | |
wim | 8:8593d3668153 | 23 | /* Enable or disable 16 bit SPI communication */ |
wim | 8:8593d3668153 | 24 | #if defined TARGET_KL25Z |
wim | 8:8593d3668153 | 25 | //Always disable for KL25Z since it does not support 16 bit SPI. |
wim | 9:6d30a225a5c7 | 26 | #define SPI_16 0 |
wim | 8:8593d3668153 | 27 | #else |
wim | 8:8593d3668153 | 28 | //Disable anyhow since 16 bit SPI does not really seem to improve performance.. |
wim | 9:6d30a225a5c7 | 29 | #define SPI_16 0 |
wim | 9:6d30a225a5c7 | 30 | //#define SPI_16 1 |
wim | 8:8593d3668153 | 31 | #endif |
wim | 8:8593d3668153 | 32 | |
wim | 9:6d30a225a5c7 | 33 | /*Enable characters with transparant background color */ |
wim | 9:6d30a225a5c7 | 34 | #define TRANSPARANCY 1 |
wim | 9:6d30a225a5c7 | 35 | |
wim | 8:8593d3668153 | 36 | /* Default Display Dimensions */ |
wim | 8:8593d3668153 | 37 | #define TFT_WIDTH 240 |
wim | 8:8593d3668153 | 38 | #define TFT_HEIGHT 320 |
wim | 9:6d30a225a5c7 | 39 | /* Default Bits per pixel */ |
wim | 9:6d30a225a5c7 | 40 | #define TFT_BPP 16 |
wim | 8:8593d3668153 | 41 | |
wim | 9:6d30a225a5c7 | 42 | /** @def Compute RGB color in 565 format */ |
dreschpe | 0:da1bf437cbc1 | 43 | #define RGB(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue |
dreschpe | 0:da1bf437cbc1 | 44 | |
wim | 9:6d30a225a5c7 | 45 | /** @def swap(type, a, b) |
wim | 9:6d30a225a5c7 | 46 | * @brief Convenience macro to swap two values. |
wim | 9:6d30a225a5c7 | 47 | */ |
wim | 9:6d30a225a5c7 | 48 | #define swap(type, a, b) { type tmp = ( a ); ( a ) = ( b ); ( b ) = tmp; } |
wim | 9:6d30a225a5c7 | 49 | |
wim | 9:6d30a225a5c7 | 50 | //#define POLY_Y(Z) ((int32_t)((Points + Z)->X)) |
wim | 9:6d30a225a5c7 | 51 | //#define POLY_X(Z) ((int32_t)((Points + Z)->Y)) |
wim | 9:6d30a225a5c7 | 52 | // |
wim | 9:6d30a225a5c7 | 53 | //#define max(a,b) (((a)>(b))?(a):(b)) |
wim | 9:6d30a225a5c7 | 54 | //#define min(a,b) (((a)<(b))?(a):(b)) |
wim | 9:6d30a225a5c7 | 55 | //#define ABS(X) ((X) > 0 ? (X) : -(X)) |
wim | 9:6d30a225a5c7 | 56 | |
wim | 8:8593d3668153 | 57 | /* Some RGB color definitions in 888 format */ |
dreschpe | 0:da1bf437cbc1 | 58 | #define Black 0x0000 /* 0, 0, 0 */ |
dreschpe | 0:da1bf437cbc1 | 59 | #define Navy 0x000F /* 0, 0, 128 */ |
dreschpe | 0:da1bf437cbc1 | 60 | #define DarkGreen 0x03E0 /* 0, 128, 0 */ |
dreschpe | 0:da1bf437cbc1 | 61 | #define DarkCyan 0x03EF /* 0, 128, 128 */ |
dreschpe | 0:da1bf437cbc1 | 62 | #define Maroon 0x7800 /* 128, 0, 0 */ |
dreschpe | 0:da1bf437cbc1 | 63 | #define Purple 0x780F /* 128, 0, 128 */ |
dreschpe | 0:da1bf437cbc1 | 64 | #define Olive 0x7BE0 /* 128, 128, 0 */ |
dreschpe | 0:da1bf437cbc1 | 65 | #define LightGrey 0xC618 /* 192, 192, 192 */ |
wim | 9:6d30a225a5c7 | 66 | #define Grey 0xF7DE |
dreschpe | 0:da1bf437cbc1 | 67 | #define DarkGrey 0x7BEF /* 128, 128, 128 */ |
dreschpe | 0:da1bf437cbc1 | 68 | #define Blue 0x001F /* 0, 0, 255 */ |
wim | 9:6d30a225a5c7 | 69 | #define Blue2 0x051F |
dreschpe | 0:da1bf437cbc1 | 70 | #define Green 0x07E0 /* 0, 255, 0 */ |
dreschpe | 0:da1bf437cbc1 | 71 | #define Cyan 0x07FF /* 0, 255, 255 */ |
wim | 9:6d30a225a5c7 | 72 | #define Cyan2 0x7FFF |
dreschpe | 0:da1bf437cbc1 | 73 | #define Red 0xF800 /* 255, 0, 0 */ |
dreschpe | 0:da1bf437cbc1 | 74 | #define Magenta 0xF81F /* 255, 0, 255 */ |
dreschpe | 0:da1bf437cbc1 | 75 | #define Yellow 0xFFE0 /* 255, 255, 0 */ |
dreschpe | 0:da1bf437cbc1 | 76 | #define White 0xFFFF /* 255, 255, 255 */ |
dreschpe | 0:da1bf437cbc1 | 77 | #define Orange 0xFD20 /* 255, 165, 0 */ |
wim | 9:6d30a225a5c7 | 78 | #define Orange2 0x051F |
dreschpe | 0:da1bf437cbc1 | 79 | #define GreenYellow 0xAFE5 /* 173, 255, 47 */ |
dreschpe | 0:da1bf437cbc1 | 80 | |
dreschpe | 0:da1bf437cbc1 | 81 | |
wim | 8:8593d3668153 | 82 | /** |
wim | 8:8593d3668153 | 83 | * @brief ILI9341 Registers |
wim | 8:8593d3668153 | 84 | */ |
wim | 8:8593d3668153 | 85 | #define ILI9341_DISPLAY_RST 0x01 /* SW reset */ |
wim | 9:6d30a225a5c7 | 86 | #define READ_DISPLAY_PIXEL_FORMAT 0x0C |
wim | 8:8593d3668153 | 87 | |
wim | 8:8593d3668153 | 88 | #define ILI9341_SLEEP_OUT 0x11 /* Sleep out register */ |
wim | 9:6d30a225a5c7 | 89 | #define ILI9341_PARTIAL_MODE 0x12 /* Partial Mode register */ |
wim | 9:6d30a225a5c7 | 90 | #define ILI9341_NORMAL_MODE 0x13 /* Normal Mode register */ |
wim | 9:6d30a225a5c7 | 91 | #define ILI9341_DISPLAY_INVERT_OFF 0x21 /* Display inversion off register */ |
wim | 9:6d30a225a5c7 | 92 | #define ILI9341_DISPLAY_INVERT_ON 0x22 /* Display inversion on register */ |
wim | 8:8593d3668153 | 93 | #define ILI9341_GAMMA 0x26 /* Gamma register */ |
wim | 8:8593d3668153 | 94 | #define ILI9341_DISPLAY_OFF 0x28 /* Display off register */ |
wim | 8:8593d3668153 | 95 | #define ILI9341_DISPLAY_ON 0x29 /* Display on register */ |
wim | 8:8593d3668153 | 96 | #define ILI9341_COLUMN_ADDR 0x2A /* Colomn address register */ |
wim | 8:8593d3668153 | 97 | #define ILI9341_PAGE_ADDR 0x2B /* Page address register */ |
wim | 8:8593d3668153 | 98 | #define ILI9341_GRAM 0x2C /* GRAM register */ |
wim | 9:6d30a225a5c7 | 99 | #define READ_MEMORY 0x2E |
wim | 8:8593d3668153 | 100 | // |
wim | 8:8593d3668153 | 101 | // |
wim | 8:8593d3668153 | 102 | #define ILI9341_TEAR_OFF 0x34 /* tearing effect off */ |
wim | 8:8593d3668153 | 103 | #define ILI9341_TEAR_ON 0x35 /* tearing effect on */ |
wim | 8:8593d3668153 | 104 | #define ILI9341_MAC 0x36 /* Memory Access Control register*/ |
wim | 8:8593d3668153 | 105 | #define ILI9341_PIXEL_FORMAT 0x3A /* Pixel Format register */ |
wim | 9:6d30a225a5c7 | 106 | #define READ_MEMORY_CONTINUE 0x3E |
wim | 8:8593d3668153 | 107 | |
wim | 8:8593d3668153 | 108 | #define ILI9341_WDB 0x51 /* Write Brightness Display register */ |
wim | 8:8593d3668153 | 109 | #define ILI9341_WCD 0x53 /* Write Control Display register*/ |
wim | 8:8593d3668153 | 110 | #define ILI9341_RGB_INTERFACE 0xB0 /* RGB Interface Signal Control */ |
wim | 8:8593d3668153 | 111 | #define ILI9341_FRC 0xB1 /* Frame Rate Control register */ |
wim | 8:8593d3668153 | 112 | #define ILI9341_BPC 0xB5 /* Blanking Porch Control register*/ |
wim | 8:8593d3668153 | 113 | #define ILI9341_DFC 0xB6 /* Display Function Control register*/ |
wim | 8:8593d3668153 | 114 | #define ILI9341_ENTRY_MODE 0xB7 /* Display Entry mode register*/ |
wim | 8:8593d3668153 | 115 | // |
wim | 8:8593d3668153 | 116 | #define ILI9341_POWER1 0xC0 /* Power Control 1 register */ |
wim | 8:8593d3668153 | 117 | #define ILI9341_POWER2 0xC1 /* Power Control 2 register */ |
wim | 8:8593d3668153 | 118 | #define ILI9341_VCOM1 0xC5 /* VCOM Control 1 register */ |
wim | 8:8593d3668153 | 119 | #define ILI9341_VCOM2 0xC7 /* VCOM Control 2 register */ |
wim | 8:8593d3668153 | 120 | #define ILI9341_POWERA 0xCB /* Power control A register */ |
wim | 8:8593d3668153 | 121 | #define ILI9341_POWERB 0xCF /* Power control B register */ |
wim | 8:8593d3668153 | 122 | #define ILI9341_PGAMMA 0xE0 /* Positive Gamma Correction register*/ |
wim | 8:8593d3668153 | 123 | #define ILI9341_NGAMMA 0xE1 /* Negative Gamma Correction register*/ |
wim | 8:8593d3668153 | 124 | #define ILI9341_DTCA 0xE8 /* Driver timing control A */ |
wim | 8:8593d3668153 | 125 | #define ILI9341_DTCB 0xEA /* Driver timing control B */ |
wim | 8:8593d3668153 | 126 | #define ILI9341_POWER_SEQ 0xED /* Power on sequence register */ |
wim | 9:6d30a225a5c7 | 127 | #define UNDOCUMENTED_0xEF 0xEF // !@#$ |
wim | 8:8593d3668153 | 128 | #define ILI9341_3GAMMA_EN 0xF2 /* 3 Gamma enable register */ |
wim | 8:8593d3668153 | 129 | #define ILI9341_INTERFACE 0xF6 /* Interface control register */ |
wim | 8:8593d3668153 | 130 | #define ILI9341_PRC 0xF7 /* Pump ratio control register */ |
wim | 8:8593d3668153 | 131 | |
wim | 8:8593d3668153 | 132 | |
dreschpe | 0:da1bf437cbc1 | 133 | /** Display control class, based on GraphicsDisplay and TextDisplay |
dreschpe | 0:da1bf437cbc1 | 134 | * |
dreschpe | 0:da1bf437cbc1 | 135 | * Example: |
dreschpe | 0:da1bf437cbc1 | 136 | * @code |
dreschpe | 0:da1bf437cbc1 | 137 | * #include "stdio.h" |
dreschpe | 0:da1bf437cbc1 | 138 | * #include "mbed.h" |
dreschpe | 0:da1bf437cbc1 | 139 | * #include "SPI_TFT_ILI9341.h" |
dreschpe | 0:da1bf437cbc1 | 140 | * #include "string" |
dreschpe | 0:da1bf437cbc1 | 141 | * #include "Arial12x12.h" |
dreschpe | 0:da1bf437cbc1 | 142 | * #include "Arial24x23.h" |
dreschpe | 0:da1bf437cbc1 | 143 | * |
dreschpe | 0:da1bf437cbc1 | 144 | * |
dreschpe | 0:da1bf437cbc1 | 145 | * |
dreschpe | 2:0a16083193a4 | 146 | * // the TFT is connected to SPI pin 5-7 and IO's 8-10 |
dreschpe | 1:6d6125e88de7 | 147 | * SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc |
dreschpe | 2:0a16083193a4 | 148 | * If your display need a signal for switch the backlight use a aditional IO pin in your program |
dreschpe | 2:0a16083193a4 | 149 | * |
dreschpe | 0:da1bf437cbc1 | 150 | * int main() { |
dreschpe | 0:da1bf437cbc1 | 151 | * TFT.claim(stdout); // send stdout to the TFT display |
dreschpe | 0:da1bf437cbc1 | 152 | * //TFT.claim(stderr); // send stderr to the TFT display |
dreschpe | 0:da1bf437cbc1 | 153 | * |
dreschpe | 0:da1bf437cbc1 | 154 | * TFT.background(Black); // set background to black |
dreschpe | 0:da1bf437cbc1 | 155 | * TFT.foreground(White); // set chars to white |
dreschpe | 0:da1bf437cbc1 | 156 | * TFT.cls(); // clear the screen |
dreschpe | 0:da1bf437cbc1 | 157 | * TFT.set_font((unsigned char*) Arial12x12); // select the font |
dreschpe | 0:da1bf437cbc1 | 158 | * |
dreschpe | 0:da1bf437cbc1 | 159 | * TFT.set_orientation(0); |
dreschpe | 0:da1bf437cbc1 | 160 | * printf(" Hello Mbed 0"); |
dreschpe | 0:da1bf437cbc1 | 161 | * TFT.set_font((unsigned char*) Arial24x23); // select font 2 |
dreschpe | 0:da1bf437cbc1 | 162 | * TFT.locate(48,115); |
dreschpe | 0:da1bf437cbc1 | 163 | * TFT.printf("Bigger Font"); |
dreschpe | 0:da1bf437cbc1 | 164 | * } |
dreschpe | 0:da1bf437cbc1 | 165 | * @endcode |
dreschpe | 0:da1bf437cbc1 | 166 | */ |
dreschpe | 0:da1bf437cbc1 | 167 | class SPI_TFT_ILI9341 : public GraphicsDisplay { |
dreschpe | 0:da1bf437cbc1 | 168 | public: |
dreschpe | 0:da1bf437cbc1 | 169 | |
wim | 8:8593d3668153 | 170 | /** Display origin */ |
wim | 8:8593d3668153 | 171 | enum Origin { |
wim | 8:8593d3668153 | 172 | Origin_LeftTop=0, /**< Left Top of panel is origin */ |
wim | 8:8593d3668153 | 173 | Origin_RightTop, /**< Right Top of panel is origin */ |
wim | 8:8593d3668153 | 174 | Origin_RightBot, /**< Right Bottom of panel is origin */ |
wim | 8:8593d3668153 | 175 | Origin_LeftBot /**< Left Bottom panel is origin */ |
wim | 8:8593d3668153 | 176 | }; |
wim | 8:8593d3668153 | 177 | |
dreschpe | 1:6d6125e88de7 | 178 | /** Create a SPI_TFT object connected to SPI and three pins |
dreschpe | 0:da1bf437cbc1 | 179 | * |
dreschpe | 1:6d6125e88de7 | 180 | * @param mosi pin connected to SDO of display |
dreschpe | 1:6d6125e88de7 | 181 | * @param miso pin connected to SDI of display |
dreschpe | 1:6d6125e88de7 | 182 | * @param sclk pin connected to RS of display |
dreschpe | 0:da1bf437cbc1 | 183 | * @param cs pin connected to CS of display |
dreschpe | 0:da1bf437cbc1 | 184 | * @param reset pin connected to RESET of display |
dreschpe | 1:6d6125e88de7 | 185 | * @param dc pin connected to WR of display |
wim | 8:8593d3668153 | 186 | * The IM pins have to be set to 1110 (3-0). Note: the M24SR board uses 0110 which also works. |
dreschpe | 0:da1bf437cbc1 | 187 | */ |
dreschpe | 0:da1bf437cbc1 | 188 | SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char* name ="TFT"); |
dreschpe | 0:da1bf437cbc1 | 189 | |
wim | 8:8593d3668153 | 190 | /** Get the width of the screen in pixels |
dreschpe | 0:da1bf437cbc1 | 191 | * |
wim | 8:8593d3668153 | 192 | * @returns width of screen in pixels |
dreschpe | 0:da1bf437cbc1 | 193 | * |
dreschpe | 0:da1bf437cbc1 | 194 | */ |
dreschpe | 0:da1bf437cbc1 | 195 | virtual int width(); |
dreschpe | 0:da1bf437cbc1 | 196 | |
wim | 8:8593d3668153 | 197 | /** Get the height of the screen in pixels |
dreschpe | 0:da1bf437cbc1 | 198 | * |
wim | 8:8593d3668153 | 199 | * @returns height of screen in pixels |
dreschpe | 0:da1bf437cbc1 | 200 | * |
dreschpe | 0:da1bf437cbc1 | 201 | */ |
dreschpe | 0:da1bf437cbc1 | 202 | virtual int height(); |
dreschpe | 0:da1bf437cbc1 | 203 | |
dreschpe | 0:da1bf437cbc1 | 204 | /** Draw a pixel at x,y with color |
dreschpe | 0:da1bf437cbc1 | 205 | * |
dreschpe | 0:da1bf437cbc1 | 206 | * @param x horizontal position |
dreschpe | 0:da1bf437cbc1 | 207 | * @param y vertical position |
dreschpe | 0:da1bf437cbc1 | 208 | * @param color 16 bit pixel color |
dreschpe | 0:da1bf437cbc1 | 209 | */ |
wim | 8:8593d3668153 | 210 | virtual void pixel(int x, int y, int colour); |
dreschpe | 0:da1bf437cbc1 | 211 | |
dreschpe | 0:da1bf437cbc1 | 212 | /** draw a circle |
dreschpe | 0:da1bf437cbc1 | 213 | * |
dreschpe | 0:da1bf437cbc1 | 214 | * @param x0,y0 center |
dreschpe | 0:da1bf437cbc1 | 215 | * @param r radius |
dreschpe | 0:da1bf437cbc1 | 216 | * @param color 16 bit color * |
dreschpe | 0:da1bf437cbc1 | 217 | * |
dreschpe | 0:da1bf437cbc1 | 218 | */ |
dreschpe | 0:da1bf437cbc1 | 219 | void circle(int x, int y, int r, int colour); |
dreschpe | 0:da1bf437cbc1 | 220 | |
dreschpe | 0:da1bf437cbc1 | 221 | /** draw a filled circle |
dreschpe | 0:da1bf437cbc1 | 222 | * |
dreschpe | 0:da1bf437cbc1 | 223 | * @param x0,y0 center |
dreschpe | 0:da1bf437cbc1 | 224 | * @param r radius |
dreschpe | 0:da1bf437cbc1 | 225 | * @param color 16 bit color * |
dreschpe | 0:da1bf437cbc1 | 226 | */ |
dreschpe | 0:da1bf437cbc1 | 227 | void fillcircle(int x, int y, int r, int colour); |
dreschpe | 0:da1bf437cbc1 | 228 | |
wim | 9:6d30a225a5c7 | 229 | |
wim | 9:6d30a225a5c7 | 230 | /** draw an oval |
wim | 9:6d30a225a5c7 | 231 | * |
wim | 9:6d30a225a5c7 | 232 | * @param x,y center |
wim | 9:6d30a225a5c7 | 233 | * @param b radius |
wim | 9:6d30a225a5c7 | 234 | * @param aspect hor/ver ratio ( hor. oval < 1.0; circle = 1.0; vert. oval > 1.0 ) |
wim | 9:6d30a225a5c7 | 235 | * @param color 16 bit color * |
wim | 9:6d30a225a5c7 | 236 | * |
wim | 9:6d30a225a5c7 | 237 | */ |
wim | 9:6d30a225a5c7 | 238 | void oval(int x, int y, int b, int color, float aspect=1.0); |
wim | 9:6d30a225a5c7 | 239 | |
wim | 9:6d30a225a5c7 | 240 | |
wim | 9:6d30a225a5c7 | 241 | /** draw a filled oval |
wim | 9:6d30a225a5c7 | 242 | * |
wim | 9:6d30a225a5c7 | 243 | * @param x,y center |
wim | 9:6d30a225a5c7 | 244 | * @param b radius |
wim | 9:6d30a225a5c7 | 245 | * @param aspect hor/ver ratio ( hor. oval < 1.0; circle = 1.0; vert. oval > 1.0 ) |
wim | 9:6d30a225a5c7 | 246 | * @param color 16 bit color * |
wim | 9:6d30a225a5c7 | 247 | * |
wim | 9:6d30a225a5c7 | 248 | */ |
wim | 9:6d30a225a5c7 | 249 | void filloval(int x, int y, int b, int color, float aspect=1.0); |
dreschpe | 0:da1bf437cbc1 | 250 | |
dreschpe | 0:da1bf437cbc1 | 251 | /** draw a 1 pixel line |
dreschpe | 0:da1bf437cbc1 | 252 | * |
dreschpe | 0:da1bf437cbc1 | 253 | * @param x0,y0 start point |
dreschpe | 0:da1bf437cbc1 | 254 | * @param x1,y1 stop point |
dreschpe | 0:da1bf437cbc1 | 255 | * @param color 16 bit color |
dreschpe | 0:da1bf437cbc1 | 256 | * |
dreschpe | 0:da1bf437cbc1 | 257 | */ |
dreschpe | 0:da1bf437cbc1 | 258 | void line(int x0, int y0, int x1, int y1, int colour); |
dreschpe | 0:da1bf437cbc1 | 259 | |
dreschpe | 0:da1bf437cbc1 | 260 | /** draw a rect |
dreschpe | 0:da1bf437cbc1 | 261 | * |
dreschpe | 0:da1bf437cbc1 | 262 | * @param x0,y0 top left corner |
dreschpe | 0:da1bf437cbc1 | 263 | * @param x1,y1 down right corner |
dreschpe | 0:da1bf437cbc1 | 264 | * @param color 16 bit color |
dreschpe | 0:da1bf437cbc1 | 265 | * * |
dreschpe | 0:da1bf437cbc1 | 266 | */ |
dreschpe | 0:da1bf437cbc1 | 267 | void rect(int x0, int y0, int x1, int y1, int colour); |
dreschpe | 0:da1bf437cbc1 | 268 | |
dreschpe | 0:da1bf437cbc1 | 269 | /** draw a filled rect |
dreschpe | 0:da1bf437cbc1 | 270 | * |
dreschpe | 0:da1bf437cbc1 | 271 | * @param x0,y0 top left corner |
dreschpe | 0:da1bf437cbc1 | 272 | * @param x1,y1 down right corner |
dreschpe | 0:da1bf437cbc1 | 273 | * @param color 16 bit color |
dreschpe | 0:da1bf437cbc1 | 274 | * |
dreschpe | 0:da1bf437cbc1 | 275 | */ |
dreschpe | 0:da1bf437cbc1 | 276 | void fillrect(int x0, int y0, int x1, int y1, int colour); |
wim | 9:6d30a225a5c7 | 277 | |
wim | 9:6d30a225a5c7 | 278 | |
wim | 9:6d30a225a5c7 | 279 | |
wim | 9:6d30a225a5c7 | 280 | /** draw a rounded rect |
wim | 9:6d30a225a5c7 | 281 | * |
wim | 9:6d30a225a5c7 | 282 | * @param x0,y0 top left corner |
wim | 9:6d30a225a5c7 | 283 | * @param x1,y1 down right corner |
wim | 9:6d30a225a5c7 | 284 | * @param color 16 bit color |
wim | 9:6d30a225a5c7 | 285 | * * |
wim | 9:6d30a225a5c7 | 286 | */ |
wim | 9:6d30a225a5c7 | 287 | void roundrect( int x0, int y0, int x1, int y1, int color ); |
wim | 9:6d30a225a5c7 | 288 | |
wim | 9:6d30a225a5c7 | 289 | |
wim | 9:6d30a225a5c7 | 290 | /** draw a filled rounded rect |
wim | 9:6d30a225a5c7 | 291 | * |
wim | 9:6d30a225a5c7 | 292 | * @param x0,y0 top left corner |
wim | 9:6d30a225a5c7 | 293 | * @param x1,y1 down right corner |
wim | 9:6d30a225a5c7 | 294 | * @param color 16 bit color |
wim | 9:6d30a225a5c7 | 295 | * |
wim | 9:6d30a225a5c7 | 296 | */ |
wim | 9:6d30a225a5c7 | 297 | void fillroundrect( int x0, int y0, int x1, int y1, int color ); |
dreschpe | 0:da1bf437cbc1 | 298 | |
dreschpe | 0:da1bf437cbc1 | 299 | /** setup cursor position |
dreschpe | 0:da1bf437cbc1 | 300 | * |
dreschpe | 0:da1bf437cbc1 | 301 | * @param x x-position (top left) |
dreschpe | 0:da1bf437cbc1 | 302 | * @param y y-position |
dreschpe | 0:da1bf437cbc1 | 303 | */ |
dreschpe | 0:da1bf437cbc1 | 304 | virtual void locate(int x, int y); |
dreschpe | 0:da1bf437cbc1 | 305 | |
wim | 8:8593d3668153 | 306 | /** Fill the screen with _background color |
wim | 8:8593d3668153 | 307 | * @param none |
wim | 8:8593d3668153 | 308 | * @return none |
wim | 8:8593d3668153 | 309 | */ |
wim | 8:8593d3668153 | 310 | virtual void cls(); |
wim | 8:8593d3668153 | 311 | |
dreschpe | 0:da1bf437cbc1 | 312 | /** calculate the max number of char in a line |
dreschpe | 0:da1bf437cbc1 | 313 | * |
dreschpe | 0:da1bf437cbc1 | 314 | * @returns max columns |
dreschpe | 0:da1bf437cbc1 | 315 | * depends on actual font size |
dreschpe | 0:da1bf437cbc1 | 316 | * |
dreschpe | 0:da1bf437cbc1 | 317 | */ |
dreschpe | 0:da1bf437cbc1 | 318 | virtual int columns(void); |
dreschpe | 0:da1bf437cbc1 | 319 | |
dreschpe | 0:da1bf437cbc1 | 320 | /** calculate the max number of columns |
dreschpe | 0:da1bf437cbc1 | 321 | * |
dreschpe | 0:da1bf437cbc1 | 322 | * @returns max column |
dreschpe | 0:da1bf437cbc1 | 323 | * depends on actual font size |
dreschpe | 0:da1bf437cbc1 | 324 | * |
dreschpe | 0:da1bf437cbc1 | 325 | */ |
dreschpe | 0:da1bf437cbc1 | 326 | virtual int rows(void); |
dreschpe | 0:da1bf437cbc1 | 327 | |
dreschpe | 0:da1bf437cbc1 | 328 | /** put a char on the screen |
dreschpe | 0:da1bf437cbc1 | 329 | * |
dreschpe | 0:da1bf437cbc1 | 330 | * @param value char to print |
dreschpe | 0:da1bf437cbc1 | 331 | * @returns printed char |
dreschpe | 0:da1bf437cbc1 | 332 | * |
dreschpe | 0:da1bf437cbc1 | 333 | */ |
dreschpe | 0:da1bf437cbc1 | 334 | virtual int _putc(int value); |
dreschpe | 0:da1bf437cbc1 | 335 | |
dreschpe | 0:da1bf437cbc1 | 336 | /** draw a character on given position out of the active font to the TFT |
dreschpe | 0:da1bf437cbc1 | 337 | * |
dreschpe | 0:da1bf437cbc1 | 338 | * @param x x-position of char (top left) |
dreschpe | 0:da1bf437cbc1 | 339 | * @param y y-position |
dreschpe | 0:da1bf437cbc1 | 340 | * @param c char to print |
dreschpe | 0:da1bf437cbc1 | 341 | * |
dreschpe | 0:da1bf437cbc1 | 342 | */ |
dreschpe | 0:da1bf437cbc1 | 343 | virtual void character(int x, int y, int c); |
dreschpe | 0:da1bf437cbc1 | 344 | |
dreschpe | 0:da1bf437cbc1 | 345 | /** paint a bitmap on the TFT |
dreschpe | 0:da1bf437cbc1 | 346 | * |
dreschpe | 0:da1bf437cbc1 | 347 | * @param x,y : upper left corner |
dreschpe | 0:da1bf437cbc1 | 348 | * @param w width of bitmap |
wim | 8:8593d3668153 | 349 | * @param h height of bitmap |
dreschpe | 0:da1bf437cbc1 | 350 | * @param *bitmap pointer to the bitmap data |
dreschpe | 0:da1bf437cbc1 | 351 | * |
dreschpe | 0:da1bf437cbc1 | 352 | * bitmap format: 16 bit R5 G6 B5 |
dreschpe | 0:da1bf437cbc1 | 353 | * |
dreschpe | 0:da1bf437cbc1 | 354 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
dreschpe | 0:da1bf437cbc1 | 355 | * use winhex to load this file and mark data stating at offset 0x46 to end |
dreschpe | 0:da1bf437cbc1 | 356 | * use edit -> copy block -> C Source to export C array |
dreschpe | 0:da1bf437cbc1 | 357 | * paste this array into your program |
dreschpe | 0:da1bf437cbc1 | 358 | * |
dreschpe | 0:da1bf437cbc1 | 359 | * define the array as static const unsigned char to put it into flash memory |
dreschpe | 0:da1bf437cbc1 | 360 | * cast the pointer to (unsigned char *) : |
dreschpe | 0:da1bf437cbc1 | 361 | * tft.Bitmap(10,40,309,50,(unsigned char *)scala); |
dreschpe | 0:da1bf437cbc1 | 362 | */ |
wim | 8:8593d3668153 | 363 | void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap); |
dreschpe | 0:da1bf437cbc1 | 364 | |
dreschpe | 0:da1bf437cbc1 | 365 | |
dreschpe | 6:fe07ae8329f7 | 366 | /** paint a 16 bit BMP from filesytem on the TFT (slow) |
dreschpe | 6:fe07ae8329f7 | 367 | * |
dreschpe | 6:fe07ae8329f7 | 368 | * @param x,y : position of upper left corner |
dreschpe | 6:fe07ae8329f7 | 369 | * @param *Name_BMP name of the BMP file with drive: "/local/test.bmp" |
dreschpe | 0:da1bf437cbc1 | 370 | * |
dreschpe | 0:da1bf437cbc1 | 371 | * @returns 1 if bmp file was found and painted |
dreschpe | 6:fe07ae8329f7 | 372 | * @returns 0 if bmp file was found not found |
dreschpe | 6:fe07ae8329f7 | 373 | * @returns -1 if file is no bmp |
dreschpe | 6:fe07ae8329f7 | 374 | * @returns -2 if bmp file is no 16 bit bmp |
dreschpe | 0:da1bf437cbc1 | 375 | * @returns -3 if bmp file is to big for screen |
dreschpe | 0:da1bf437cbc1 | 376 | * @returns -4 if buffer malloc go wrong |
dreschpe | 0:da1bf437cbc1 | 377 | * |
dreschpe | 0:da1bf437cbc1 | 378 | * bitmap format: 16 bit R5 G6 B5 |
dreschpe | 0:da1bf437cbc1 | 379 | * |
dreschpe | 0:da1bf437cbc1 | 380 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
dreschpe | 6:fe07ae8329f7 | 381 | * copy to internal file system or SD card |
dreschpe | 0:da1bf437cbc1 | 382 | */ |
dreschpe | 0:da1bf437cbc1 | 383 | |
dreschpe | 0:da1bf437cbc1 | 384 | int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP); |
dreschpe | 0:da1bf437cbc1 | 385 | |
wim | 8:8593d3668153 | 386 | |
wim | 8:8593d3668153 | 387 | |
wim | 8:8593d3668153 | 388 | /******************************************************************************* |
wim | 8:8593d3668153 | 389 | * Function Name : WriteBMP_FAT |
wim | 8:8593d3668153 | 390 | * @brief Displays a bitmap picture loaded in Flash. |
wim | 8:8593d3668153 | 391 | * @param Xpos: specifies the X position. |
wim | 8:8593d3668153 | 392 | * @param Ypos: specifies the Y position. |
wim | 8:8593d3668153 | 393 | * @param BmpAddress: Bmp picture address in Flash. |
wim | 8:8593d3668153 | 394 | * @return None |
wim | 8:8593d3668153 | 395 | *******************************************************************************/ |
wim | 8:8593d3668153 | 396 | void WriteBMP_FAT(uint16_t Xpos, uint16_t Ypos, const char* BmpName); |
wim | 8:8593d3668153 | 397 | |
dreschpe | 0:da1bf437cbc1 | 398 | |
dreschpe | 0:da1bf437cbc1 | 399 | /** select the font to use |
dreschpe | 0:da1bf437cbc1 | 400 | * |
dreschpe | 0:da1bf437cbc1 | 401 | * @param f pointer to font array |
dreschpe | 0:da1bf437cbc1 | 402 | * |
dreschpe | 0:da1bf437cbc1 | 403 | * font array can created with GLCD Font Creator from http://www.mikroe.com |
dreschpe | 0:da1bf437cbc1 | 404 | * you have to add 4 parameter at the beginning of the font array to use: |
dreschpe | 0:da1bf437cbc1 | 405 | * - the number of byte / char |
dreschpe | 0:da1bf437cbc1 | 406 | * - the vertial size in pixel |
dreschpe | 0:da1bf437cbc1 | 407 | * - the horizontal size in pixel |
dreschpe | 0:da1bf437cbc1 | 408 | * - the number of byte per vertical line |
dreschpe | 0:da1bf437cbc1 | 409 | * you also have to change the array to char[] |
dreschpe | 0:da1bf437cbc1 | 410 | * |
dreschpe | 0:da1bf437cbc1 | 411 | */ |
dreschpe | 0:da1bf437cbc1 | 412 | void set_font(unsigned char* f); |
dreschpe | 0:da1bf437cbc1 | 413 | |
dreschpe | 0:da1bf437cbc1 | 414 | /** Set the orientation of the screen |
dreschpe | 0:da1bf437cbc1 | 415 | * x,y: 0,0 is always top left |
dreschpe | 0:da1bf437cbc1 | 416 | * |
dreschpe | 2:0a16083193a4 | 417 | * @param o direction to use the screen (0-3) |
dreschpe | 0:da1bf437cbc1 | 418 | * |
dreschpe | 0:da1bf437cbc1 | 419 | */ |
wim | 8:8593d3668153 | 420 | //WH void set_orientation(unsigned int o); |
wim | 8:8593d3668153 | 421 | void set_origin(Origin origin); |
wim | 9:6d30a225a5c7 | 422 | |
dreschpe | 6:fe07ae8329f7 | 423 | |
wim | 9:6d30a225a5c7 | 424 | /** Set background transparancy for characters |
wim | 9:6d30a225a5c7 | 425 | * |
wim | 9:6d30a225a5c7 | 426 | * @param state transparancy on/off |
wim | 9:6d30a225a5c7 | 427 | * |
wim | 9:6d30a225a5c7 | 428 | */ |
wim | 9:6d30a225a5c7 | 429 | void set_transparancy(bool state); |
wim | 9:6d30a225a5c7 | 430 | |
wim | 9:6d30a225a5c7 | 431 | /** Enable the ILI9341 display |
wim | 9:6d30a225a5c7 | 432 | * |
wim | 9:6d30a225a5c7 | 433 | * @param on: display On/Off |
wim | 9:6d30a225a5c7 | 434 | * |
wim | 9:6d30a225a5c7 | 435 | */ |
wim | 9:6d30a225a5c7 | 436 | void tft_on(bool on); |
dreschpe | 6:fe07ae8329f7 | 437 | |
dreschpe | 6:fe07ae8329f7 | 438 | /** read out the manufacturer ID of the LCD |
dreschpe | 6:fe07ae8329f7 | 439 | * can used for checking the connection to the display |
dreschpe | 6:fe07ae8329f7 | 440 | * @returns ID |
dreschpe | 6:fe07ae8329f7 | 441 | */ |
dreschpe | 6:fe07ae8329f7 | 442 | int Read_ID(void); |
dreschpe | 6:fe07ae8329f7 | 443 | |
dreschpe | 0:da1bf437cbc1 | 444 | |
dreschpe | 0:da1bf437cbc1 | 445 | protected: |
dreschpe | 0:da1bf437cbc1 | 446 | |
dreschpe | 0:da1bf437cbc1 | 447 | /** draw a horizontal line |
dreschpe | 0:da1bf437cbc1 | 448 | * |
dreschpe | 0:da1bf437cbc1 | 449 | * @param x0 horizontal start |
dreschpe | 0:da1bf437cbc1 | 450 | * @param x1 horizontal stop |
dreschpe | 0:da1bf437cbc1 | 451 | * @param y vertical position |
dreschpe | 0:da1bf437cbc1 | 452 | * @param color 16 bit color |
dreschpe | 0:da1bf437cbc1 | 453 | * |
dreschpe | 0:da1bf437cbc1 | 454 | */ |
dreschpe | 0:da1bf437cbc1 | 455 | void hline(int x0, int x1, int y, int colour); |
dreschpe | 0:da1bf437cbc1 | 456 | |
dreschpe | 0:da1bf437cbc1 | 457 | /** draw a vertical line |
dreschpe | 0:da1bf437cbc1 | 458 | * |
dreschpe | 0:da1bf437cbc1 | 459 | * @param x horizontal position |
dreschpe | 0:da1bf437cbc1 | 460 | * @param y0 vertical start |
dreschpe | 0:da1bf437cbc1 | 461 | * @param y1 vertical stop |
dreschpe | 0:da1bf437cbc1 | 462 | * @param color 16 bit color |
dreschpe | 0:da1bf437cbc1 | 463 | */ |
wim | 9:6d30a225a5c7 | 464 | void vline(int x, int y0, int y1, int colour); |
dreschpe | 0:da1bf437cbc1 | 465 | |
dreschpe | 0:da1bf437cbc1 | 466 | /** Set draw window region |
dreschpe | 0:da1bf437cbc1 | 467 | * |
dreschpe | 0:da1bf437cbc1 | 468 | * @param x horizontal position |
dreschpe | 0:da1bf437cbc1 | 469 | * @param y vertical position |
dreschpe | 0:da1bf437cbc1 | 470 | * @param w window width in pixel |
dreschpe | 0:da1bf437cbc1 | 471 | * @param h window height in pixels |
dreschpe | 0:da1bf437cbc1 | 472 | */ |
dreschpe | 0:da1bf437cbc1 | 473 | virtual void window (unsigned int x,unsigned int y, unsigned int w, unsigned int h); |
dreschpe | 0:da1bf437cbc1 | 474 | |
wim | 9:6d30a225a5c7 | 475 | /** Set draw window region to whole screen |
wim | 9:6d30a225a5c7 | 476 | * |
wim | 9:6d30a225a5c7 | 477 | */ |
wim | 9:6d30a225a5c7 | 478 | void window_max (void); |
dreschpe | 0:da1bf437cbc1 | 479 | |
dreschpe | 0:da1bf437cbc1 | 480 | |
dreschpe | 6:fe07ae8329f7 | 481 | /** Init the ILI9341 controller |
dreschpe | 0:da1bf437cbc1 | 482 | * |
dreschpe | 0:da1bf437cbc1 | 483 | */ |
dreschpe | 0:da1bf437cbc1 | 484 | void tft_reset(); |
wim | 9:6d30a225a5c7 | 485 | |
dreschpe | 0:da1bf437cbc1 | 486 | |
dreschpe | 0:da1bf437cbc1 | 487 | /** Write data to the LCD controller |
dreschpe | 0:da1bf437cbc1 | 488 | * |
dreschpe | 0:da1bf437cbc1 | 489 | * @param dat data written to LCD controller |
dreschpe | 0:da1bf437cbc1 | 490 | * |
dreschpe | 0:da1bf437cbc1 | 491 | */ |
dreschpe | 0:da1bf437cbc1 | 492 | //void wr_dat(unsigned int value); |
dreschpe | 0:da1bf437cbc1 | 493 | void wr_dat(unsigned char value); |
dreschpe | 0:da1bf437cbc1 | 494 | |
dreschpe | 0:da1bf437cbc1 | 495 | /** Write a command the LCD controller |
dreschpe | 0:da1bf437cbc1 | 496 | * |
dreschpe | 0:da1bf437cbc1 | 497 | * @param cmd: command to be written |
dreschpe | 0:da1bf437cbc1 | 498 | * |
dreschpe | 0:da1bf437cbc1 | 499 | */ |
dreschpe | 0:da1bf437cbc1 | 500 | void wr_cmd(unsigned char value); |
dreschpe | 0:da1bf437cbc1 | 501 | |
dreschpe | 0:da1bf437cbc1 | 502 | /** Start data sequence to the LCD controller |
dreschpe | 0:da1bf437cbc1 | 503 | * |
dreschpe | 0:da1bf437cbc1 | 504 | */ |
dreschpe | 0:da1bf437cbc1 | 505 | //void wr_dat_start(); |
dreschpe | 0:da1bf437cbc1 | 506 | |
dreschpe | 0:da1bf437cbc1 | 507 | /** Stop of data writing to the LCD controller |
dreschpe | 0:da1bf437cbc1 | 508 | * |
dreschpe | 0:da1bf437cbc1 | 509 | */ |
dreschpe | 0:da1bf437cbc1 | 510 | //void wr_dat_stop(); |
dreschpe | 0:da1bf437cbc1 | 511 | |
dreschpe | 0:da1bf437cbc1 | 512 | /** write data to the LCD controller |
dreschpe | 0:da1bf437cbc1 | 513 | * |
dreschpe | 0:da1bf437cbc1 | 514 | * @param data to be written |
dreschpe | 0:da1bf437cbc1 | 515 | * * |
dreschpe | 0:da1bf437cbc1 | 516 | */ |
dreschpe | 0:da1bf437cbc1 | 517 | //void wr_dat_only(unsigned short dat); |
dreschpe | 0:da1bf437cbc1 | 518 | |
dreschpe | 6:fe07ae8329f7 | 519 | /** Read byte from the LCD controller |
dreschpe | 0:da1bf437cbc1 | 520 | * |
dreschpe | 6:fe07ae8329f7 | 521 | * @param cmd comand to controller |
dreschpe | 0:da1bf437cbc1 | 522 | * @returns data from LCD controller |
dreschpe | 0:da1bf437cbc1 | 523 | * |
dreschpe | 0:da1bf437cbc1 | 524 | */ |
dreschpe | 6:fe07ae8329f7 | 525 | char rd_byte(unsigned char cmd); |
dreschpe | 6:fe07ae8329f7 | 526 | |
dreschpe | 6:fe07ae8329f7 | 527 | |
dreschpe | 6:fe07ae8329f7 | 528 | int rd_32(unsigned char cmd); |
dreschpe | 6:fe07ae8329f7 | 529 | |
dreschpe | 0:da1bf437cbc1 | 530 | |
dreschpe | 0:da1bf437cbc1 | 531 | /** Write a value to the to a LCD register |
dreschpe | 0:da1bf437cbc1 | 532 | * |
dreschpe | 0:da1bf437cbc1 | 533 | * @param reg register to be written |
dreschpe | 0:da1bf437cbc1 | 534 | * @param val data to be written |
dreschpe | 0:da1bf437cbc1 | 535 | */ |
dreschpe | 0:da1bf437cbc1 | 536 | //void wr_reg (unsigned char reg, unsigned char val); |
dreschpe | 0:da1bf437cbc1 | 537 | |
dreschpe | 0:da1bf437cbc1 | 538 | /** Read a LCD register |
dreschpe | 0:da1bf437cbc1 | 539 | * |
dreschpe | 0:da1bf437cbc1 | 540 | * @param reg register to be read |
dreschpe | 0:da1bf437cbc1 | 541 | * @returns value of the register |
dreschpe | 0:da1bf437cbc1 | 542 | */ |
dreschpe | 0:da1bf437cbc1 | 543 | //unsigned short rd_reg (unsigned char reg); |
dreschpe | 0:da1bf437cbc1 | 544 | |
wim | 8:8593d3668153 | 545 | |
wim | 8:8593d3668153 | 546 | SPI _spi; |
wim | 8:8593d3668153 | 547 | DigitalOut _cs; |
wim | 8:8593d3668153 | 548 | DigitalOut _reset; |
wim | 8:8593d3668153 | 549 | DigitalOut _dc; |
wim | 9:6d30a225a5c7 | 550 | |
wim | 8:8593d3668153 | 551 | unsigned char* _font; |
wim | 9:6d30a225a5c7 | 552 | unsigned int _char_x; |
wim | 9:6d30a225a5c7 | 553 | unsigned int _char_y; |
wim | 9:6d30a225a5c7 | 554 | bool _transparancy; |
wim | 9:6d30a225a5c7 | 555 | |
wim | 9:6d30a225a5c7 | 556 | //WHunsigned int orientation; |
wim | 9:6d30a225a5c7 | 557 | Origin _origin; |
wim | 9:6d30a225a5c7 | 558 | |
dreschpe | 0:da1bf437cbc1 | 559 | }; |
dreschpe | 0:da1bf437cbc1 | 560 | |
dreschpe | 0:da1bf437cbc1 | 561 | #endif |