Added methods and features

Fork of SPI_TFT_ILI9341 by Peter Drescher

Committer:
wim
Date:
Tue Apr 22 19:10:47 2014 +0000
Revision:
11:7aabc3810093
Parent:
10:2d505d14b7eb
Added methods and features

Who changed what in which revision?

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