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