Added methods and features
Fork of SPI_TFT_ILI9341 by
SPI_TFT_ILI9341.h@8:8593d3668153, 2014-04-02 (annotated)
- Committer:
- wim
- Date:
- Wed Apr 02 19:20:09 2014 +0000
- Revision:
- 8:8593d3668153
- Parent:
- 6:fe07ae8329f7
- Child:
- 9:6d30a225a5c7
test van updates op SPI van Peter, werkt
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 | |
dreschpe | 0:da1bf437cbc1 | 13 | /* change the char position handling |
dreschpe | 0:da1bf437cbc1 | 14 | * use pixel (x,y) instadt of colum row */ |
dreschpe | 0:da1bf437cbc1 | 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 | 8:8593d3668153 | 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 | 8:8593d3668153 | 29 | #define SPI_16 0 |
wim | 8:8593d3668153 | 30 | //#define SPI_16 1 |
wim | 8:8593d3668153 | 31 | #endif |
wim | 8:8593d3668153 | 32 | |
wim | 8:8593d3668153 | 33 | /* Default Display Dimensions */ |
wim | 8:8593d3668153 | 34 | #define TFT_WIDTH 240 |
wim | 8:8593d3668153 | 35 | #define TFT_HEIGHT 320 |
wim | 8:8593d3668153 | 36 | |
wim | 8:8593d3668153 | 37 | /* Compute RGB color in 565 format */ |
dreschpe | 0:da1bf437cbc1 | 38 | #define RGB(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue |
dreschpe | 0:da1bf437cbc1 | 39 | |
wim | 8:8593d3668153 | 40 | /* Some RGB color definitions in 888 format */ |
dreschpe | 0:da1bf437cbc1 | 41 | #define Black 0x0000 /* 0, 0, 0 */ |
dreschpe | 0:da1bf437cbc1 | 42 | #define Navy 0x000F /* 0, 0, 128 */ |
dreschpe | 0:da1bf437cbc1 | 43 | #define DarkGreen 0x03E0 /* 0, 128, 0 */ |
dreschpe | 0:da1bf437cbc1 | 44 | #define DarkCyan 0x03EF /* 0, 128, 128 */ |
dreschpe | 0:da1bf437cbc1 | 45 | #define Maroon 0x7800 /* 128, 0, 0 */ |
dreschpe | 0:da1bf437cbc1 | 46 | #define Purple 0x780F /* 128, 0, 128 */ |
dreschpe | 0:da1bf437cbc1 | 47 | #define Olive 0x7BE0 /* 128, 128, 0 */ |
dreschpe | 0:da1bf437cbc1 | 48 | #define LightGrey 0xC618 /* 192, 192, 192 */ |
dreschpe | 0:da1bf437cbc1 | 49 | #define DarkGrey 0x7BEF /* 128, 128, 128 */ |
dreschpe | 0:da1bf437cbc1 | 50 | #define Blue 0x001F /* 0, 0, 255 */ |
dreschpe | 0:da1bf437cbc1 | 51 | #define Green 0x07E0 /* 0, 255, 0 */ |
dreschpe | 0:da1bf437cbc1 | 52 | #define Cyan 0x07FF /* 0, 255, 255 */ |
dreschpe | 0:da1bf437cbc1 | 53 | #define Red 0xF800 /* 255, 0, 0 */ |
dreschpe | 0:da1bf437cbc1 | 54 | #define Magenta 0xF81F /* 255, 0, 255 */ |
dreschpe | 0:da1bf437cbc1 | 55 | #define Yellow 0xFFE0 /* 255, 255, 0 */ |
dreschpe | 0:da1bf437cbc1 | 56 | #define White 0xFFFF /* 255, 255, 255 */ |
dreschpe | 0:da1bf437cbc1 | 57 | #define Orange 0xFD20 /* 255, 165, 0 */ |
dreschpe | 0:da1bf437cbc1 | 58 | #define GreenYellow 0xAFE5 /* 173, 255, 47 */ |
dreschpe | 0:da1bf437cbc1 | 59 | |
dreschpe | 0:da1bf437cbc1 | 60 | |
wim | 8:8593d3668153 | 61 | /** |
wim | 8:8593d3668153 | 62 | * @brief ILI9341 Registers |
wim | 8:8593d3668153 | 63 | */ |
wim | 8:8593d3668153 | 64 | #define ILI9341_DISPLAY_RST 0x01 /* SW reset */ |
wim | 8:8593d3668153 | 65 | |
wim | 8:8593d3668153 | 66 | #define ILI9341_SLEEP_OUT 0x11 /* Sleep out register */ |
wim | 8:8593d3668153 | 67 | #define ILI9341_GAMMA 0x26 /* Gamma register */ |
wim | 8:8593d3668153 | 68 | #define ILI9341_DISPLAY_OFF 0x28 /* Display off register */ |
wim | 8:8593d3668153 | 69 | #define ILI9341_DISPLAY_ON 0x29 /* Display on register */ |
wim | 8:8593d3668153 | 70 | #define ILI9341_COLUMN_ADDR 0x2A /* Colomn address register */ |
wim | 8:8593d3668153 | 71 | #define ILI9341_PAGE_ADDR 0x2B /* Page address register */ |
wim | 8:8593d3668153 | 72 | #define ILI9341_GRAM 0x2C /* GRAM register */ |
wim | 8:8593d3668153 | 73 | // |
wim | 8:8593d3668153 | 74 | // |
wim | 8:8593d3668153 | 75 | #define ILI9341_TEAR_OFF 0x34 /* tearing effect off */ |
wim | 8:8593d3668153 | 76 | #define ILI9341_TEAR_ON 0x35 /* tearing effect on */ |
wim | 8:8593d3668153 | 77 | |
wim | 8:8593d3668153 | 78 | #define ILI9341_MAC 0x36 /* Memory Access Control register*/ |
wim | 8:8593d3668153 | 79 | #define ILI9341_PIXEL_FORMAT 0x3A /* Pixel Format register */ |
wim | 8:8593d3668153 | 80 | |
wim | 8:8593d3668153 | 81 | #define ILI9341_WDB 0x51 /* Write Brightness Display register */ |
wim | 8:8593d3668153 | 82 | #define ILI9341_WCD 0x53 /* Write Control Display register*/ |
wim | 8:8593d3668153 | 83 | #define ILI9341_RGB_INTERFACE 0xB0 /* RGB Interface Signal Control */ |
wim | 8:8593d3668153 | 84 | #define ILI9341_FRC 0xB1 /* Frame Rate Control register */ |
wim | 8:8593d3668153 | 85 | #define ILI9341_BPC 0xB5 /* Blanking Porch Control register*/ |
wim | 8:8593d3668153 | 86 | #define ILI9341_DFC 0xB6 /* Display Function Control register*/ |
wim | 8:8593d3668153 | 87 | #define ILI9341_ENTRY_MODE 0xB7 /* Display Entry mode register*/ |
wim | 8:8593d3668153 | 88 | // |
wim | 8:8593d3668153 | 89 | #define ILI9341_POWER1 0xC0 /* Power Control 1 register */ |
wim | 8:8593d3668153 | 90 | #define ILI9341_POWER2 0xC1 /* Power Control 2 register */ |
wim | 8:8593d3668153 | 91 | #define ILI9341_VCOM1 0xC5 /* VCOM Control 1 register */ |
wim | 8:8593d3668153 | 92 | #define ILI9341_VCOM2 0xC7 /* VCOM Control 2 register */ |
wim | 8:8593d3668153 | 93 | #define ILI9341_POWERA 0xCB /* Power control A register */ |
wim | 8:8593d3668153 | 94 | #define ILI9341_POWERB 0xCF /* Power control B register */ |
wim | 8:8593d3668153 | 95 | #define ILI9341_PGAMMA 0xE0 /* Positive Gamma Correction register*/ |
wim | 8:8593d3668153 | 96 | #define ILI9341_NGAMMA 0xE1 /* Negative Gamma Correction register*/ |
wim | 8:8593d3668153 | 97 | #define ILI9341_DTCA 0xE8 /* Driver timing control A */ |
wim | 8:8593d3668153 | 98 | #define ILI9341_DTCB 0xEA /* Driver timing control B */ |
wim | 8:8593d3668153 | 99 | #define ILI9341_POWER_SEQ 0xED /* Power on sequence register */ |
wim | 8:8593d3668153 | 100 | #define ILI9341_3GAMMA_EN 0xF2 /* 3 Gamma enable register */ |
wim | 8:8593d3668153 | 101 | #define ILI9341_INTERFACE 0xF6 /* Interface control register */ |
wim | 8:8593d3668153 | 102 | #define ILI9341_PRC 0xF7 /* Pump ratio control register */ |
wim | 8:8593d3668153 | 103 | |
wim | 8:8593d3668153 | 104 | |
dreschpe | 0:da1bf437cbc1 | 105 | /** Display control class, based on GraphicsDisplay and TextDisplay |
dreschpe | 0:da1bf437cbc1 | 106 | * |
dreschpe | 0:da1bf437cbc1 | 107 | * Example: |
dreschpe | 0:da1bf437cbc1 | 108 | * @code |
dreschpe | 0:da1bf437cbc1 | 109 | * #include "stdio.h" |
dreschpe | 0:da1bf437cbc1 | 110 | * #include "mbed.h" |
dreschpe | 0:da1bf437cbc1 | 111 | * #include "SPI_TFT_ILI9341.h" |
dreschpe | 0:da1bf437cbc1 | 112 | * #include "string" |
dreschpe | 0:da1bf437cbc1 | 113 | * #include "Arial12x12.h" |
dreschpe | 0:da1bf437cbc1 | 114 | * #include "Arial24x23.h" |
dreschpe | 0:da1bf437cbc1 | 115 | * |
dreschpe | 0:da1bf437cbc1 | 116 | * |
dreschpe | 0:da1bf437cbc1 | 117 | * |
dreschpe | 2:0a16083193a4 | 118 | * // the TFT is connected to SPI pin 5-7 and IO's 8-10 |
dreschpe | 1:6d6125e88de7 | 119 | * SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc |
dreschpe | 2:0a16083193a4 | 120 | * If your display need a signal for switch the backlight use a aditional IO pin in your program |
dreschpe | 2:0a16083193a4 | 121 | * |
dreschpe | 0:da1bf437cbc1 | 122 | * int main() { |
dreschpe | 0:da1bf437cbc1 | 123 | * TFT.claim(stdout); // send stdout to the TFT display |
dreschpe | 0:da1bf437cbc1 | 124 | * //TFT.claim(stderr); // send stderr to the TFT display |
dreschpe | 0:da1bf437cbc1 | 125 | * |
dreschpe | 0:da1bf437cbc1 | 126 | * TFT.background(Black); // set background to black |
dreschpe | 0:da1bf437cbc1 | 127 | * TFT.foreground(White); // set chars to white |
dreschpe | 0:da1bf437cbc1 | 128 | * TFT.cls(); // clear the screen |
dreschpe | 0:da1bf437cbc1 | 129 | * TFT.set_font((unsigned char*) Arial12x12); // select the font |
dreschpe | 0:da1bf437cbc1 | 130 | * |
dreschpe | 0:da1bf437cbc1 | 131 | * TFT.set_orientation(0); |
dreschpe | 0:da1bf437cbc1 | 132 | * printf(" Hello Mbed 0"); |
dreschpe | 0:da1bf437cbc1 | 133 | * TFT.set_font((unsigned char*) Arial24x23); // select font 2 |
dreschpe | 0:da1bf437cbc1 | 134 | * TFT.locate(48,115); |
dreschpe | 0:da1bf437cbc1 | 135 | * TFT.printf("Bigger Font"); |
dreschpe | 0:da1bf437cbc1 | 136 | * } |
dreschpe | 0:da1bf437cbc1 | 137 | * @endcode |
dreschpe | 0:da1bf437cbc1 | 138 | */ |
dreschpe | 0:da1bf437cbc1 | 139 | class SPI_TFT_ILI9341 : public GraphicsDisplay { |
dreschpe | 0:da1bf437cbc1 | 140 | public: |
dreschpe | 0:da1bf437cbc1 | 141 | |
wim | 8:8593d3668153 | 142 | /** Display origin */ |
wim | 8:8593d3668153 | 143 | enum Origin { |
wim | 8:8593d3668153 | 144 | Origin_LeftTop=0, /**< Left Top of panel is origin */ |
wim | 8:8593d3668153 | 145 | Origin_RightTop, /**< Right Top of panel is origin */ |
wim | 8:8593d3668153 | 146 | Origin_RightBot, /**< Right Bottom of panel is origin */ |
wim | 8:8593d3668153 | 147 | Origin_LeftBot /**< Left Bottom panel is origin */ |
wim | 8:8593d3668153 | 148 | }; |
wim | 8:8593d3668153 | 149 | |
dreschpe | 1:6d6125e88de7 | 150 | /** Create a SPI_TFT object connected to SPI and three pins |
dreschpe | 0:da1bf437cbc1 | 151 | * |
dreschpe | 1:6d6125e88de7 | 152 | * @param mosi pin connected to SDO of display |
dreschpe | 1:6d6125e88de7 | 153 | * @param miso pin connected to SDI of display |
dreschpe | 1:6d6125e88de7 | 154 | * @param sclk pin connected to RS of display |
dreschpe | 0:da1bf437cbc1 | 155 | * @param cs pin connected to CS of display |
dreschpe | 0:da1bf437cbc1 | 156 | * @param reset pin connected to RESET of display |
dreschpe | 1:6d6125e88de7 | 157 | * @param dc pin connected to WR of display |
wim | 8:8593d3668153 | 158 | * The IM pins have to be set to 1110 (3-0). Note: the M24SR board uses 0110 which also works. |
dreschpe | 0:da1bf437cbc1 | 159 | */ |
dreschpe | 0:da1bf437cbc1 | 160 | SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char* name ="TFT"); |
dreschpe | 0:da1bf437cbc1 | 161 | |
wim | 8:8593d3668153 | 162 | /** Get the width of the screen in pixels |
dreschpe | 0:da1bf437cbc1 | 163 | * |
wim | 8:8593d3668153 | 164 | * @returns width of screen in pixels |
dreschpe | 0:da1bf437cbc1 | 165 | * |
dreschpe | 0:da1bf437cbc1 | 166 | */ |
dreschpe | 0:da1bf437cbc1 | 167 | virtual int width(); |
dreschpe | 0:da1bf437cbc1 | 168 | |
wim | 8:8593d3668153 | 169 | /** Get the height of the screen in pixels |
dreschpe | 0:da1bf437cbc1 | 170 | * |
wim | 8:8593d3668153 | 171 | * @returns height of screen in pixels |
dreschpe | 0:da1bf437cbc1 | 172 | * |
dreschpe | 0:da1bf437cbc1 | 173 | */ |
dreschpe | 0:da1bf437cbc1 | 174 | virtual int height(); |
dreschpe | 0:da1bf437cbc1 | 175 | |
dreschpe | 0:da1bf437cbc1 | 176 | /** Draw a pixel at x,y with color |
dreschpe | 0:da1bf437cbc1 | 177 | * |
dreschpe | 0:da1bf437cbc1 | 178 | * @param x horizontal position |
dreschpe | 0:da1bf437cbc1 | 179 | * @param y vertical position |
dreschpe | 0:da1bf437cbc1 | 180 | * @param color 16 bit pixel color |
dreschpe | 0:da1bf437cbc1 | 181 | */ |
wim | 8:8593d3668153 | 182 | virtual void pixel(int x, int y, int colour); |
dreschpe | 0:da1bf437cbc1 | 183 | |
dreschpe | 0:da1bf437cbc1 | 184 | /** draw a circle |
dreschpe | 0:da1bf437cbc1 | 185 | * |
dreschpe | 0:da1bf437cbc1 | 186 | * @param x0,y0 center |
dreschpe | 0:da1bf437cbc1 | 187 | * @param r radius |
dreschpe | 0:da1bf437cbc1 | 188 | * @param color 16 bit color * |
dreschpe | 0:da1bf437cbc1 | 189 | * |
dreschpe | 0:da1bf437cbc1 | 190 | */ |
dreschpe | 0:da1bf437cbc1 | 191 | void circle(int x, int y, int r, int colour); |
dreschpe | 0:da1bf437cbc1 | 192 | |
dreschpe | 0:da1bf437cbc1 | 193 | /** draw a filled circle |
dreschpe | 0:da1bf437cbc1 | 194 | * |
dreschpe | 0:da1bf437cbc1 | 195 | * @param x0,y0 center |
dreschpe | 0:da1bf437cbc1 | 196 | * @param r radius |
dreschpe | 0:da1bf437cbc1 | 197 | * @param color 16 bit color * |
dreschpe | 0:da1bf437cbc1 | 198 | */ |
dreschpe | 0:da1bf437cbc1 | 199 | void fillcircle(int x, int y, int r, int colour); |
dreschpe | 0:da1bf437cbc1 | 200 | |
dreschpe | 0:da1bf437cbc1 | 201 | |
dreschpe | 0:da1bf437cbc1 | 202 | /** draw a 1 pixel line |
dreschpe | 0:da1bf437cbc1 | 203 | * |
dreschpe | 0:da1bf437cbc1 | 204 | * @param x0,y0 start point |
dreschpe | 0:da1bf437cbc1 | 205 | * @param x1,y1 stop point |
dreschpe | 0:da1bf437cbc1 | 206 | * @param color 16 bit color |
dreschpe | 0:da1bf437cbc1 | 207 | * |
dreschpe | 0:da1bf437cbc1 | 208 | */ |
dreschpe | 0:da1bf437cbc1 | 209 | void line(int x0, int y0, int x1, int y1, int colour); |
dreschpe | 0:da1bf437cbc1 | 210 | |
dreschpe | 0:da1bf437cbc1 | 211 | /** draw a rect |
dreschpe | 0:da1bf437cbc1 | 212 | * |
dreschpe | 0:da1bf437cbc1 | 213 | * @param x0,y0 top left corner |
dreschpe | 0:da1bf437cbc1 | 214 | * @param x1,y1 down right corner |
dreschpe | 0:da1bf437cbc1 | 215 | * @param color 16 bit color |
dreschpe | 0:da1bf437cbc1 | 216 | * * |
dreschpe | 0:da1bf437cbc1 | 217 | */ |
dreschpe | 0:da1bf437cbc1 | 218 | void rect(int x0, int y0, int x1, int y1, int colour); |
dreschpe | 0:da1bf437cbc1 | 219 | |
dreschpe | 0:da1bf437cbc1 | 220 | /** draw a filled rect |
dreschpe | 0:da1bf437cbc1 | 221 | * |
dreschpe | 0:da1bf437cbc1 | 222 | * @param x0,y0 top left corner |
dreschpe | 0:da1bf437cbc1 | 223 | * @param x1,y1 down right corner |
dreschpe | 0:da1bf437cbc1 | 224 | * @param color 16 bit color |
dreschpe | 0:da1bf437cbc1 | 225 | * |
dreschpe | 0:da1bf437cbc1 | 226 | */ |
dreschpe | 0:da1bf437cbc1 | 227 | void fillrect(int x0, int y0, int x1, int y1, int colour); |
dreschpe | 0:da1bf437cbc1 | 228 | |
dreschpe | 0:da1bf437cbc1 | 229 | /** setup cursor position |
dreschpe | 0:da1bf437cbc1 | 230 | * |
dreschpe | 0:da1bf437cbc1 | 231 | * @param x x-position (top left) |
dreschpe | 0:da1bf437cbc1 | 232 | * @param y y-position |
dreschpe | 0:da1bf437cbc1 | 233 | */ |
dreschpe | 0:da1bf437cbc1 | 234 | virtual void locate(int x, int y); |
dreschpe | 0:da1bf437cbc1 | 235 | |
wim | 8:8593d3668153 | 236 | /** Fill the screen with _background color |
wim | 8:8593d3668153 | 237 | * @param none |
wim | 8:8593d3668153 | 238 | * @return none |
wim | 8:8593d3668153 | 239 | */ |
wim | 8:8593d3668153 | 240 | virtual void cls(); |
wim | 8:8593d3668153 | 241 | |
dreschpe | 0:da1bf437cbc1 | 242 | /** calculate the max number of char in a line |
dreschpe | 0:da1bf437cbc1 | 243 | * |
dreschpe | 0:da1bf437cbc1 | 244 | * @returns max columns |
dreschpe | 0:da1bf437cbc1 | 245 | * depends on actual font size |
dreschpe | 0:da1bf437cbc1 | 246 | * |
dreschpe | 0:da1bf437cbc1 | 247 | */ |
dreschpe | 0:da1bf437cbc1 | 248 | virtual int columns(void); |
dreschpe | 0:da1bf437cbc1 | 249 | |
dreschpe | 0:da1bf437cbc1 | 250 | /** calculate the max number of columns |
dreschpe | 0:da1bf437cbc1 | 251 | * |
dreschpe | 0:da1bf437cbc1 | 252 | * @returns max column |
dreschpe | 0:da1bf437cbc1 | 253 | * depends on actual font size |
dreschpe | 0:da1bf437cbc1 | 254 | * |
dreschpe | 0:da1bf437cbc1 | 255 | */ |
dreschpe | 0:da1bf437cbc1 | 256 | virtual int rows(void); |
dreschpe | 0:da1bf437cbc1 | 257 | |
dreschpe | 0:da1bf437cbc1 | 258 | /** put a char on the screen |
dreschpe | 0:da1bf437cbc1 | 259 | * |
dreschpe | 0:da1bf437cbc1 | 260 | * @param value char to print |
dreschpe | 0:da1bf437cbc1 | 261 | * @returns printed char |
dreschpe | 0:da1bf437cbc1 | 262 | * |
dreschpe | 0:da1bf437cbc1 | 263 | */ |
dreschpe | 0:da1bf437cbc1 | 264 | virtual int _putc(int value); |
dreschpe | 0:da1bf437cbc1 | 265 | |
dreschpe | 0:da1bf437cbc1 | 266 | /** draw a character on given position out of the active font to the TFT |
dreschpe | 0:da1bf437cbc1 | 267 | * |
dreschpe | 0:da1bf437cbc1 | 268 | * @param x x-position of char (top left) |
dreschpe | 0:da1bf437cbc1 | 269 | * @param y y-position |
dreschpe | 0:da1bf437cbc1 | 270 | * @param c char to print |
dreschpe | 0:da1bf437cbc1 | 271 | * |
dreschpe | 0:da1bf437cbc1 | 272 | */ |
dreschpe | 0:da1bf437cbc1 | 273 | virtual void character(int x, int y, int c); |
dreschpe | 0:da1bf437cbc1 | 274 | |
dreschpe | 0:da1bf437cbc1 | 275 | /** paint a bitmap on the TFT |
dreschpe | 0:da1bf437cbc1 | 276 | * |
dreschpe | 0:da1bf437cbc1 | 277 | * @param x,y : upper left corner |
dreschpe | 0:da1bf437cbc1 | 278 | * @param w width of bitmap |
wim | 8:8593d3668153 | 279 | * @param h height of bitmap |
dreschpe | 0:da1bf437cbc1 | 280 | * @param *bitmap pointer to the bitmap data |
dreschpe | 0:da1bf437cbc1 | 281 | * |
dreschpe | 0:da1bf437cbc1 | 282 | * bitmap format: 16 bit R5 G6 B5 |
dreschpe | 0:da1bf437cbc1 | 283 | * |
dreschpe | 0:da1bf437cbc1 | 284 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
dreschpe | 0:da1bf437cbc1 | 285 | * use winhex to load this file and mark data stating at offset 0x46 to end |
dreschpe | 0:da1bf437cbc1 | 286 | * use edit -> copy block -> C Source to export C array |
dreschpe | 0:da1bf437cbc1 | 287 | * paste this array into your program |
dreschpe | 0:da1bf437cbc1 | 288 | * |
dreschpe | 0:da1bf437cbc1 | 289 | * define the array as static const unsigned char to put it into flash memory |
dreschpe | 0:da1bf437cbc1 | 290 | * cast the pointer to (unsigned char *) : |
dreschpe | 0:da1bf437cbc1 | 291 | * tft.Bitmap(10,40,309,50,(unsigned char *)scala); |
dreschpe | 0:da1bf437cbc1 | 292 | */ |
wim | 8:8593d3668153 | 293 | void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap); |
dreschpe | 0:da1bf437cbc1 | 294 | |
dreschpe | 0:da1bf437cbc1 | 295 | |
dreschpe | 6:fe07ae8329f7 | 296 | /** paint a 16 bit BMP from filesytem on the TFT (slow) |
dreschpe | 6:fe07ae8329f7 | 297 | * |
dreschpe | 6:fe07ae8329f7 | 298 | * @param x,y : position of upper left corner |
dreschpe | 6:fe07ae8329f7 | 299 | * @param *Name_BMP name of the BMP file with drive: "/local/test.bmp" |
dreschpe | 0:da1bf437cbc1 | 300 | * |
dreschpe | 0:da1bf437cbc1 | 301 | * @returns 1 if bmp file was found and painted |
dreschpe | 6:fe07ae8329f7 | 302 | * @returns 0 if bmp file was found not found |
dreschpe | 6:fe07ae8329f7 | 303 | * @returns -1 if file is no bmp |
dreschpe | 6:fe07ae8329f7 | 304 | * @returns -2 if bmp file is no 16 bit bmp |
dreschpe | 0:da1bf437cbc1 | 305 | * @returns -3 if bmp file is to big for screen |
dreschpe | 0:da1bf437cbc1 | 306 | * @returns -4 if buffer malloc go wrong |
dreschpe | 0:da1bf437cbc1 | 307 | * |
dreschpe | 0:da1bf437cbc1 | 308 | * bitmap format: 16 bit R5 G6 B5 |
dreschpe | 0:da1bf437cbc1 | 309 | * |
dreschpe | 0:da1bf437cbc1 | 310 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
dreschpe | 6:fe07ae8329f7 | 311 | * copy to internal file system or SD card |
dreschpe | 0:da1bf437cbc1 | 312 | */ |
dreschpe | 0:da1bf437cbc1 | 313 | |
dreschpe | 0:da1bf437cbc1 | 314 | int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP); |
dreschpe | 0:da1bf437cbc1 | 315 | |
wim | 8:8593d3668153 | 316 | |
wim | 8:8593d3668153 | 317 | |
wim | 8:8593d3668153 | 318 | /******************************************************************************* |
wim | 8:8593d3668153 | 319 | * Function Name : WriteBMP_FAT |
wim | 8:8593d3668153 | 320 | * @brief Displays a bitmap picture loaded in Flash. |
wim | 8:8593d3668153 | 321 | * @param Xpos: specifies the X position. |
wim | 8:8593d3668153 | 322 | * @param Ypos: specifies the Y position. |
wim | 8:8593d3668153 | 323 | * @param BmpAddress: Bmp picture address in Flash. |
wim | 8:8593d3668153 | 324 | * @return None |
wim | 8:8593d3668153 | 325 | *******************************************************************************/ |
wim | 8:8593d3668153 | 326 | void WriteBMP_FAT(uint16_t Xpos, uint16_t Ypos, const char* BmpName); |
wim | 8:8593d3668153 | 327 | |
dreschpe | 0:da1bf437cbc1 | 328 | |
dreschpe | 0:da1bf437cbc1 | 329 | /** select the font to use |
dreschpe | 0:da1bf437cbc1 | 330 | * |
dreschpe | 0:da1bf437cbc1 | 331 | * @param f pointer to font array |
dreschpe | 0:da1bf437cbc1 | 332 | * |
dreschpe | 0:da1bf437cbc1 | 333 | * font array can created with GLCD Font Creator from http://www.mikroe.com |
dreschpe | 0:da1bf437cbc1 | 334 | * you have to add 4 parameter at the beginning of the font array to use: |
dreschpe | 0:da1bf437cbc1 | 335 | * - the number of byte / char |
dreschpe | 0:da1bf437cbc1 | 336 | * - the vertial size in pixel |
dreschpe | 0:da1bf437cbc1 | 337 | * - the horizontal size in pixel |
dreschpe | 0:da1bf437cbc1 | 338 | * - the number of byte per vertical line |
dreschpe | 0:da1bf437cbc1 | 339 | * you also have to change the array to char[] |
dreschpe | 0:da1bf437cbc1 | 340 | * |
dreschpe | 0:da1bf437cbc1 | 341 | */ |
dreschpe | 0:da1bf437cbc1 | 342 | void set_font(unsigned char* f); |
dreschpe | 0:da1bf437cbc1 | 343 | |
dreschpe | 0:da1bf437cbc1 | 344 | /** Set the orientation of the screen |
dreschpe | 0:da1bf437cbc1 | 345 | * x,y: 0,0 is always top left |
dreschpe | 0:da1bf437cbc1 | 346 | * |
dreschpe | 2:0a16083193a4 | 347 | * @param o direction to use the screen (0-3) |
dreschpe | 0:da1bf437cbc1 | 348 | * |
dreschpe | 0:da1bf437cbc1 | 349 | */ |
wim | 8:8593d3668153 | 350 | //WH void set_orientation(unsigned int o); |
wim | 8:8593d3668153 | 351 | void set_origin(Origin origin); |
dreschpe | 6:fe07ae8329f7 | 352 | |
dreschpe | 6:fe07ae8329f7 | 353 | |
dreschpe | 6:fe07ae8329f7 | 354 | /** read out the manufacturer ID of the LCD |
dreschpe | 6:fe07ae8329f7 | 355 | * can used for checking the connection to the display |
dreschpe | 6:fe07ae8329f7 | 356 | * @returns ID |
dreschpe | 6:fe07ae8329f7 | 357 | */ |
dreschpe | 6:fe07ae8329f7 | 358 | int Read_ID(void); |
dreschpe | 6:fe07ae8329f7 | 359 | |
dreschpe | 6:fe07ae8329f7 | 360 | |
wim | 8:8593d3668153 | 361 | //These should move to protected section |
wim | 8:8593d3668153 | 362 | // SPI _spi; |
wim | 8:8593d3668153 | 363 | // DigitalOut _cs; |
wim | 8:8593d3668153 | 364 | // DigitalOut _reset; |
wim | 8:8593d3668153 | 365 | // DigitalOut _dc; |
wim | 8:8593d3668153 | 366 | // unsigned char* font; |
dreschpe | 0:da1bf437cbc1 | 367 | |
dreschpe | 0:da1bf437cbc1 | 368 | |
dreschpe | 0:da1bf437cbc1 | 369 | protected: |
dreschpe | 0:da1bf437cbc1 | 370 | |
dreschpe | 0:da1bf437cbc1 | 371 | /** Set draw window region to whole screen |
dreschpe | 0:da1bf437cbc1 | 372 | * |
dreschpe | 0:da1bf437cbc1 | 373 | */ |
wim | 8:8593d3668153 | 374 | void window_max (void); |
dreschpe | 0:da1bf437cbc1 | 375 | |
dreschpe | 0:da1bf437cbc1 | 376 | |
dreschpe | 0:da1bf437cbc1 | 377 | /** draw a horizontal line |
dreschpe | 0:da1bf437cbc1 | 378 | * |
dreschpe | 0:da1bf437cbc1 | 379 | * @param x0 horizontal start |
dreschpe | 0:da1bf437cbc1 | 380 | * @param x1 horizontal stop |
dreschpe | 0:da1bf437cbc1 | 381 | * @param y vertical position |
dreschpe | 0:da1bf437cbc1 | 382 | * @param color 16 bit color |
dreschpe | 0:da1bf437cbc1 | 383 | * |
dreschpe | 0:da1bf437cbc1 | 384 | */ |
dreschpe | 0:da1bf437cbc1 | 385 | void hline(int x0, int x1, int y, int colour); |
dreschpe | 0:da1bf437cbc1 | 386 | |
dreschpe | 0:da1bf437cbc1 | 387 | /** draw a vertical line |
dreschpe | 0:da1bf437cbc1 | 388 | * |
dreschpe | 0:da1bf437cbc1 | 389 | * @param x horizontal position |
dreschpe | 0:da1bf437cbc1 | 390 | * @param y0 vertical start |
dreschpe | 0:da1bf437cbc1 | 391 | * @param y1 vertical stop |
dreschpe | 0:da1bf437cbc1 | 392 | * @param color 16 bit color |
dreschpe | 0:da1bf437cbc1 | 393 | */ |
dreschpe | 0:da1bf437cbc1 | 394 | void vline(int y0, int y1, int x, int colour); |
dreschpe | 0:da1bf437cbc1 | 395 | |
dreschpe | 0:da1bf437cbc1 | 396 | /** Set draw window region |
dreschpe | 0:da1bf437cbc1 | 397 | * |
dreschpe | 0:da1bf437cbc1 | 398 | * @param x horizontal position |
dreschpe | 0:da1bf437cbc1 | 399 | * @param y vertical position |
dreschpe | 0:da1bf437cbc1 | 400 | * @param w window width in pixel |
dreschpe | 0:da1bf437cbc1 | 401 | * @param h window height in pixels |
dreschpe | 0:da1bf437cbc1 | 402 | */ |
dreschpe | 0:da1bf437cbc1 | 403 | virtual void window (unsigned int x,unsigned int y, unsigned int w, unsigned int h); |
dreschpe | 0:da1bf437cbc1 | 404 | |
dreschpe | 0:da1bf437cbc1 | 405 | |
dreschpe | 0:da1bf437cbc1 | 406 | |
dreschpe | 6:fe07ae8329f7 | 407 | /** Init the ILI9341 controller |
dreschpe | 0:da1bf437cbc1 | 408 | * |
dreschpe | 0:da1bf437cbc1 | 409 | */ |
dreschpe | 0:da1bf437cbc1 | 410 | void tft_reset(); |
dreschpe | 0:da1bf437cbc1 | 411 | |
dreschpe | 0:da1bf437cbc1 | 412 | /** Write data to the LCD controller |
dreschpe | 0:da1bf437cbc1 | 413 | * |
dreschpe | 0:da1bf437cbc1 | 414 | * @param dat data written to LCD controller |
dreschpe | 0:da1bf437cbc1 | 415 | * |
dreschpe | 0:da1bf437cbc1 | 416 | */ |
dreschpe | 0:da1bf437cbc1 | 417 | //void wr_dat(unsigned int value); |
dreschpe | 0:da1bf437cbc1 | 418 | void wr_dat(unsigned char value); |
dreschpe | 0:da1bf437cbc1 | 419 | |
dreschpe | 0:da1bf437cbc1 | 420 | /** Write a command the LCD controller |
dreschpe | 0:da1bf437cbc1 | 421 | * |
dreschpe | 0:da1bf437cbc1 | 422 | * @param cmd: command to be written |
dreschpe | 0:da1bf437cbc1 | 423 | * |
dreschpe | 0:da1bf437cbc1 | 424 | */ |
dreschpe | 0:da1bf437cbc1 | 425 | void wr_cmd(unsigned char value); |
dreschpe | 0:da1bf437cbc1 | 426 | |
dreschpe | 0:da1bf437cbc1 | 427 | /** Start data sequence to the LCD controller |
dreschpe | 0:da1bf437cbc1 | 428 | * |
dreschpe | 0:da1bf437cbc1 | 429 | */ |
dreschpe | 0:da1bf437cbc1 | 430 | //void wr_dat_start(); |
dreschpe | 0:da1bf437cbc1 | 431 | |
dreschpe | 0:da1bf437cbc1 | 432 | /** Stop of data writing to the LCD controller |
dreschpe | 0:da1bf437cbc1 | 433 | * |
dreschpe | 0:da1bf437cbc1 | 434 | */ |
dreschpe | 0:da1bf437cbc1 | 435 | //void wr_dat_stop(); |
dreschpe | 0:da1bf437cbc1 | 436 | |
dreschpe | 0:da1bf437cbc1 | 437 | /** write data to the LCD controller |
dreschpe | 0:da1bf437cbc1 | 438 | * |
dreschpe | 0:da1bf437cbc1 | 439 | * @param data to be written |
dreschpe | 0:da1bf437cbc1 | 440 | * * |
dreschpe | 0:da1bf437cbc1 | 441 | */ |
dreschpe | 0:da1bf437cbc1 | 442 | //void wr_dat_only(unsigned short dat); |
dreschpe | 0:da1bf437cbc1 | 443 | |
dreschpe | 6:fe07ae8329f7 | 444 | /** Read byte from the LCD controller |
dreschpe | 0:da1bf437cbc1 | 445 | * |
dreschpe | 6:fe07ae8329f7 | 446 | * @param cmd comand to controller |
dreschpe | 0:da1bf437cbc1 | 447 | * @returns data from LCD controller |
dreschpe | 0:da1bf437cbc1 | 448 | * |
dreschpe | 0:da1bf437cbc1 | 449 | */ |
dreschpe | 6:fe07ae8329f7 | 450 | char rd_byte(unsigned char cmd); |
dreschpe | 6:fe07ae8329f7 | 451 | |
dreschpe | 6:fe07ae8329f7 | 452 | |
dreschpe | 6:fe07ae8329f7 | 453 | int rd_32(unsigned char cmd); |
dreschpe | 6:fe07ae8329f7 | 454 | |
dreschpe | 0:da1bf437cbc1 | 455 | |
dreschpe | 0:da1bf437cbc1 | 456 | /** Write a value to the to a LCD register |
dreschpe | 0:da1bf437cbc1 | 457 | * |
dreschpe | 0:da1bf437cbc1 | 458 | * @param reg register to be written |
dreschpe | 0:da1bf437cbc1 | 459 | * @param val data to be written |
dreschpe | 0:da1bf437cbc1 | 460 | */ |
dreschpe | 0:da1bf437cbc1 | 461 | //void wr_reg (unsigned char reg, unsigned char val); |
dreschpe | 0:da1bf437cbc1 | 462 | |
dreschpe | 0:da1bf437cbc1 | 463 | /** Read a LCD register |
dreschpe | 0:da1bf437cbc1 | 464 | * |
dreschpe | 0:da1bf437cbc1 | 465 | * @param reg register to be read |
dreschpe | 0:da1bf437cbc1 | 466 | * @returns value of the register |
dreschpe | 0:da1bf437cbc1 | 467 | */ |
dreschpe | 0:da1bf437cbc1 | 468 | //unsigned short rd_reg (unsigned char reg); |
dreschpe | 0:da1bf437cbc1 | 469 | |
wim | 8:8593d3668153 | 470 | //WH unsigned char spi_port; |
wim | 8:8593d3668153 | 471 | //WHunsigned int orientation; |
wim | 8:8593d3668153 | 472 | Origin _origin; |
dreschpe | 0:da1bf437cbc1 | 473 | unsigned int char_x; |
dreschpe | 0:da1bf437cbc1 | 474 | unsigned int char_y; |
wim | 8:8593d3668153 | 475 | // PinName clk; |
wim | 8:8593d3668153 | 476 | |
wim | 8:8593d3668153 | 477 | |
wim | 8:8593d3668153 | 478 | SPI _spi; |
wim | 8:8593d3668153 | 479 | DigitalOut _cs; |
wim | 8:8593d3668153 | 480 | DigitalOut _reset; |
wim | 8:8593d3668153 | 481 | DigitalOut _dc; |
wim | 8:8593d3668153 | 482 | unsigned char* _font; |
wim | 8:8593d3668153 | 483 | |
dreschpe | 0:da1bf437cbc1 | 484 | }; |
dreschpe | 0:da1bf437cbc1 | 485 | |
dreschpe | 0:da1bf437cbc1 | 486 | #endif |