older Version without DMA
Fork of SPI_TFT by
SPI_TFT.h@12:b2dd49f04d5d, 2012-04-07 (annotated)
- Committer:
- dreschpe
- Date:
- Sat Apr 07 16:05:39 2012 +0000
- Revision:
- 12:b2dd49f04d5d
- Parent:
- 8:e1f5232d93a0
Use DMA and direct access to SPI register to speed up to 6 times.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:cccc5726bdf3 | 1 | /* mbed library for 240*320 pixel display TFT based on HX8347D LCD Controller |
dreschpe | 0:cccc5726bdf3 | 2 | * Copyright (c) 2011 Peter Drescher - DC2PD |
dreschpe | 0:cccc5726bdf3 | 3 | * |
dreschpe | 0:cccc5726bdf3 | 4 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
dreschpe | 0:cccc5726bdf3 | 5 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
dreschpe | 0:cccc5726bdf3 | 6 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
dreschpe | 0:cccc5726bdf3 | 7 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
dreschpe | 0:cccc5726bdf3 | 8 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dreschpe | 0:cccc5726bdf3 | 9 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
dreschpe | 0:cccc5726bdf3 | 10 | * THE SOFTWARE. |
dreschpe | 0:cccc5726bdf3 | 11 | */ |
dreschpe | 6:fc33e4a5713e | 12 | |
dreschpe | 6:fc33e4a5713e | 13 | /* change the char position handling |
dreschpe | 6:fc33e4a5713e | 14 | * use pixel (x,y) instadt of colum row */ |
dreschpe | 6:fc33e4a5713e | 15 | |
dreschpe | 0:cccc5726bdf3 | 16 | |
dreschpe | 0:cccc5726bdf3 | 17 | #ifndef MBED_SPI_TFT_H |
dreschpe | 0:cccc5726bdf3 | 18 | #define MBED_SPI_TFT_H |
dreschpe | 0:cccc5726bdf3 | 19 | |
dreschpe | 3:5be1edd3a543 | 20 | |
dreschpe | 3:5be1edd3a543 | 21 | #include "mbed.h" |
dreschpe | 3:5be1edd3a543 | 22 | #include "GraphicsDisplay.h" |
dreschpe | 3:5be1edd3a543 | 23 | |
dreschpe | 3:5be1edd3a543 | 24 | #define RGB(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue |
dreschpe | 3:5be1edd3a543 | 25 | |
dreschpe | 3:5be1edd3a543 | 26 | #define SPI_START (0x70) /* Start byte for SPI transfer */ |
dreschpe | 3:5be1edd3a543 | 27 | #define SPI_RD (0x01) /* WR bit 1 within start */ |
dreschpe | 3:5be1edd3a543 | 28 | #define SPI_WR (0x00) /* WR bit 0 within start */ |
dreschpe | 3:5be1edd3a543 | 29 | #define SPI_DATA (0x02) /* RS bit 1 within start byte */ |
dreschpe | 3:5be1edd3a543 | 30 | #define SPI_INDEX (0x00) /* RS bit 0 within start byte */ |
dreschpe | 3:5be1edd3a543 | 31 | |
dreschpe | 3:5be1edd3a543 | 32 | |
dreschpe | 3:5be1edd3a543 | 33 | /* some RGB color definitions */ |
dreschpe | 3:5be1edd3a543 | 34 | #define Black 0x0000 /* 0, 0, 0 */ |
dreschpe | 3:5be1edd3a543 | 35 | #define Navy 0x000F /* 0, 0, 128 */ |
dreschpe | 3:5be1edd3a543 | 36 | #define DarkGreen 0x03E0 /* 0, 128, 0 */ |
dreschpe | 3:5be1edd3a543 | 37 | #define DarkCyan 0x03EF /* 0, 128, 128 */ |
dreschpe | 3:5be1edd3a543 | 38 | #define Maroon 0x7800 /* 128, 0, 0 */ |
dreschpe | 3:5be1edd3a543 | 39 | #define Purple 0x780F /* 128, 0, 128 */ |
dreschpe | 3:5be1edd3a543 | 40 | #define Olive 0x7BE0 /* 128, 128, 0 */ |
dreschpe | 3:5be1edd3a543 | 41 | #define LightGrey 0xC618 /* 192, 192, 192 */ |
dreschpe | 3:5be1edd3a543 | 42 | #define DarkGrey 0x7BEF /* 128, 128, 128 */ |
dreschpe | 3:5be1edd3a543 | 43 | #define Blue 0x001F /* 0, 0, 255 */ |
dreschpe | 3:5be1edd3a543 | 44 | #define Green 0x07E0 /* 0, 255, 0 */ |
dreschpe | 3:5be1edd3a543 | 45 | #define Cyan 0x07FF /* 0, 255, 255 */ |
dreschpe | 3:5be1edd3a543 | 46 | #define Red 0xF800 /* 255, 0, 0 */ |
dreschpe | 3:5be1edd3a543 | 47 | #define Magenta 0xF81F /* 255, 0, 255 */ |
dreschpe | 6:fc33e4a5713e | 48 | #define Yellow 0xFFE0 /* 255, 255, 0 */ |
dreschpe | 3:5be1edd3a543 | 49 | #define White 0xFFFF /* 255, 255, 255 */ |
dreschpe | 6:fc33e4a5713e | 50 | #define Orange 0xFD20 /* 255, 165, 0 */ |
dreschpe | 6:fc33e4a5713e | 51 | #define GreenYellow 0xAFE5 /* 173, 255, 47 */ |
dreschpe | 6:fc33e4a5713e | 52 | |
dreschpe | 3:5be1edd3a543 | 53 | |
dreschpe | 12:b2dd49f04d5d | 54 | // some defines for the DMA use |
dreschpe | 12:b2dd49f04d5d | 55 | #define DMA_CHANNEL_ENABLE 1 |
dreschpe | 12:b2dd49f04d5d | 56 | #define DMA_TRANSFER_TYPE_M2P (1UL << 11) |
dreschpe | 12:b2dd49f04d5d | 57 | #define DMA_CHANNEL_TCIE (1UL << 31) |
dreschpe | 12:b2dd49f04d5d | 58 | #define DMA_CHANNEL_SRC_INC (1UL << 26) |
dreschpe | 12:b2dd49f04d5d | 59 | #define DMA_MASK_IE (1UL << 14) |
dreschpe | 12:b2dd49f04d5d | 60 | #define DMA_MASK_ITC (1UL << 15) |
dreschpe | 12:b2dd49f04d5d | 61 | #define DMA_SSP1_TX (1UL << 2) |
dreschpe | 12:b2dd49f04d5d | 62 | #define DMA_SSP0_TX (0) |
dreschpe | 12:b2dd49f04d5d | 63 | |
dreschpe | 12:b2dd49f04d5d | 64 | |
dreschpe | 1:aa3356b16080 | 65 | /** Display control class, based on GraphicsDisplay and TextDisplay |
dreschpe | 1:aa3356b16080 | 66 | * |
dreschpe | 1:aa3356b16080 | 67 | * Example: |
dreschpe | 1:aa3356b16080 | 68 | * @code |
dreschpe | 1:aa3356b16080 | 69 | * #include "stdio.h" |
dreschpe | 1:aa3356b16080 | 70 | * #include "mbed.h" |
dreschpe | 1:aa3356b16080 | 71 | * #include "SPI_TFT.h" |
dreschpe | 1:aa3356b16080 | 72 | * #include "string" |
dreschpe | 1:aa3356b16080 | 73 | * #include "Arial12x12.h" |
dreschpe | 1:aa3356b16080 | 74 | * #include "Arial24x23.h" |
dreschpe | 1:aa3356b16080 | 75 | * |
dreschpe | 1:aa3356b16080 | 76 | * |
dreschpe | 1:aa3356b16080 | 77 | * |
dreschpe | 1:aa3356b16080 | 78 | * // the TFT is connected to SPI pin 5-7 |
dreschpe | 1:aa3356b16080 | 79 | * SPI_TFT TFT(p5, p6, p7, p8, p15,"TFT"); // mosi, miso, sclk, cs, reset |
dreschpe | 1:aa3356b16080 | 80 | * |
dreschpe | 1:aa3356b16080 | 81 | * int main() { |
dreschpe | 1:aa3356b16080 | 82 | * TFT.claim(stdout); // send stdout to the TFT display |
dreschpe | 1:aa3356b16080 | 83 | * //TFT.claim(stderr); // send stderr to the TFT display |
dreschpe | 1:aa3356b16080 | 84 | * |
dreschpe | 1:aa3356b16080 | 85 | * TFT.background(Black); // set background to black |
dreschpe | 1:aa3356b16080 | 86 | * TFT.foreground(White); // set chars to white |
dreschpe | 1:aa3356b16080 | 87 | * TFT.cls(); // clear the screen |
dreschpe | 1:aa3356b16080 | 88 | * TFT.set_font((unsigned char*) Arial12x12); // select the font |
dreschpe | 1:aa3356b16080 | 89 | * |
dreschpe | 1:aa3356b16080 | 90 | * TFT.set_orientation(0); |
dreschpe | 1:aa3356b16080 | 91 | * TFT.locate(0,0); |
dreschpe | 1:aa3356b16080 | 92 | * printf(" Hello Mbed 0"); |
dreschpe | 1:aa3356b16080 | 93 | * TFT.set_font((unsigned char*) Arial24x23); // select font 2 |
dreschpe | 6:fc33e4a5713e | 94 | * TFT.locate(48,115); |
dreschpe | 1:aa3356b16080 | 95 | * TFT.printf("Bigger Font"); |
dreschpe | 1:aa3356b16080 | 96 | * } |
dreschpe | 1:aa3356b16080 | 97 | * @endcode |
dreschpe | 1:aa3356b16080 | 98 | */ |
dreschpe | 3:5be1edd3a543 | 99 | class SPI_TFT : public GraphicsDisplay { |
dreschpe | 3:5be1edd3a543 | 100 | public: |
dreschpe | 1:aa3356b16080 | 101 | |
dreschpe | 2:0cc880f230ad | 102 | /** Create a SPI_TFT object connected to SPI and two pins |
dreschpe | 2:0cc880f230ad | 103 | * |
dreschpe | 2:0cc880f230ad | 104 | * @param mosi,miso,sclk SPI |
dreschpe | 2:0cc880f230ad | 105 | * @param cs pin connected to CS of display |
dreschpe | 2:0cc880f230ad | 106 | * @param reset pin connected to RESET of display |
dreschpe | 2:0cc880f230ad | 107 | * |
dreschpe | 2:0cc880f230ad | 108 | */ |
dreschpe | 2:0cc880f230ad | 109 | SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset,const char* name ="TFT"); |
dreschpe | 1:aa3356b16080 | 110 | |
dreschpe | 2:0cc880f230ad | 111 | /** Get the width of the screen in pixel |
dreschpe | 2:0cc880f230ad | 112 | * |
dreschpe | 2:0cc880f230ad | 113 | * @param |
dreschpe | 2:0cc880f230ad | 114 | * @returns width of screen in pixel |
dreschpe | 2:0cc880f230ad | 115 | * |
dreschpe | 2:0cc880f230ad | 116 | */ |
dreschpe | 2:0cc880f230ad | 117 | virtual int width(); |
dreschpe | 1:aa3356b16080 | 118 | |
dreschpe | 2:0cc880f230ad | 119 | /** Get the height of the screen in pixel |
dreschpe | 2:0cc880f230ad | 120 | * |
dreschpe | 2:0cc880f230ad | 121 | * @returns height of screen in pixel |
dreschpe | 2:0cc880f230ad | 122 | * |
dreschpe | 2:0cc880f230ad | 123 | */ |
dreschpe | 2:0cc880f230ad | 124 | virtual int height(); |
dreschpe | 1:aa3356b16080 | 125 | |
dreschpe | 2:0cc880f230ad | 126 | /** Draw a pixel at x,y with color |
dreschpe | 2:0cc880f230ad | 127 | * |
dreschpe | 2:0cc880f230ad | 128 | * @param x horizontal position |
dreschpe | 2:0cc880f230ad | 129 | * @param y vertical position |
dreschpe | 2:0cc880f230ad | 130 | * @param color 16 bit pixel color |
dreschpe | 2:0cc880f230ad | 131 | */ |
dreschpe | 12:b2dd49f04d5d | 132 | virtual void pixel(int x, int y,int colour); |
dreschpe | 1:aa3356b16080 | 133 | |
dreschpe | 2:0cc880f230ad | 134 | /** draw a circle |
dreschpe | 2:0cc880f230ad | 135 | * |
dreschpe | 2:0cc880f230ad | 136 | * @param x0,y0 center |
dreschpe | 2:0cc880f230ad | 137 | * @param r radius |
dreschpe | 2:0cc880f230ad | 138 | * @param color 16 bit color * |
dreschpe | 2:0cc880f230ad | 139 | * |
dreschpe | 2:0cc880f230ad | 140 | */ |
dreschpe | 2:0cc880f230ad | 141 | void circle(int x, int y, int r, int colour); |
dreschpe | 4:e1e45f8a7664 | 142 | |
dreschpe | 4:e1e45f8a7664 | 143 | /** draw a filled circle |
dreschpe | 4:e1e45f8a7664 | 144 | * |
dreschpe | 4:e1e45f8a7664 | 145 | * @param x0,y0 center |
dreschpe | 4:e1e45f8a7664 | 146 | * @param r radius |
dreschpe | 4:e1e45f8a7664 | 147 | * @param color 16 bit color * |
dreschpe | 4:e1e45f8a7664 | 148 | * |
dreschpe | 4:e1e45f8a7664 | 149 | * use circle with different radius, |
dreschpe | 4:e1e45f8a7664 | 150 | * can miss some pixel |
dreschpe | 4:e1e45f8a7664 | 151 | */ |
dreschpe | 4:e1e45f8a7664 | 152 | void fillcircle(int x, int y, int r, int colour); |
dreschpe | 4:e1e45f8a7664 | 153 | |
dreschpe | 4:e1e45f8a7664 | 154 | |
dreschpe | 1:aa3356b16080 | 155 | |
dreschpe | 2:0cc880f230ad | 156 | /** draw a 1 pixel line |
dreschpe | 2:0cc880f230ad | 157 | * |
dreschpe | 2:0cc880f230ad | 158 | * @param x0,y0 start point |
dreschpe | 2:0cc880f230ad | 159 | * @param x1,y1 stop point |
dreschpe | 2:0cc880f230ad | 160 | * @param color 16 bit color |
dreschpe | 2:0cc880f230ad | 161 | * |
dreschpe | 2:0cc880f230ad | 162 | */ |
dreschpe | 2:0cc880f230ad | 163 | void line(int x0, int y0, int x1, int y1, int colour); |
dreschpe | 1:aa3356b16080 | 164 | |
dreschpe | 2:0cc880f230ad | 165 | /** draw a rect |
dreschpe | 2:0cc880f230ad | 166 | * |
dreschpe | 2:0cc880f230ad | 167 | * @param x0,y0 top left corner |
dreschpe | 2:0cc880f230ad | 168 | * @param x1,y1 down right corner |
dreschpe | 2:0cc880f230ad | 169 | * @param color 16 bit color |
dreschpe | 2:0cc880f230ad | 170 | * * |
dreschpe | 2:0cc880f230ad | 171 | */ |
dreschpe | 2:0cc880f230ad | 172 | void rect(int x0, int y0, int x1, int y1, int colour); |
dreschpe | 1:aa3356b16080 | 173 | |
dreschpe | 2:0cc880f230ad | 174 | /** draw a filled rect |
dreschpe | 2:0cc880f230ad | 175 | * |
dreschpe | 2:0cc880f230ad | 176 | * @param x0,y0 top left corner |
dreschpe | 2:0cc880f230ad | 177 | * @param x1,y1 down right corner |
dreschpe | 2:0cc880f230ad | 178 | * @param color 16 bit color |
dreschpe | 2:0cc880f230ad | 179 | * |
dreschpe | 2:0cc880f230ad | 180 | */ |
dreschpe | 2:0cc880f230ad | 181 | void fillrect(int x0, int y0, int x1, int y1, int colour); |
dreschpe | 1:aa3356b16080 | 182 | |
dreschpe | 2:0cc880f230ad | 183 | /** setup cursor position |
dreschpe | 2:0cc880f230ad | 184 | * |
dreschpe | 6:fc33e4a5713e | 185 | * @param x x-position (top left) |
dreschpe | 6:fc33e4a5713e | 186 | * @param y y-position |
dreschpe | 2:0cc880f230ad | 187 | */ |
dreschpe | 6:fc33e4a5713e | 188 | void locate(int x, int y); |
dreschpe | 1:aa3356b16080 | 189 | |
dreschpe | 2:0cc880f230ad | 190 | /** Fill the screen with _backgroun color |
dreschpe | 2:0cc880f230ad | 191 | * |
dreschpe | 2:0cc880f230ad | 192 | */ |
dreschpe | 2:0cc880f230ad | 193 | virtual void cls (void); |
dreschpe | 1:aa3356b16080 | 194 | |
dreschpe | 2:0cc880f230ad | 195 | /** calculate the max number of char in a line |
dreschpe | 2:0cc880f230ad | 196 | * |
dreschpe | 2:0cc880f230ad | 197 | * @returns max columns |
dreschpe | 2:0cc880f230ad | 198 | * depends on actual font size |
dreschpe | 2:0cc880f230ad | 199 | * |
dreschpe | 2:0cc880f230ad | 200 | */ |
dreschpe | 2:0cc880f230ad | 201 | int columns(void); |
dreschpe | 1:aa3356b16080 | 202 | |
dreschpe | 2:0cc880f230ad | 203 | /** calculate the max number of columns |
dreschpe | 2:0cc880f230ad | 204 | * |
dreschpe | 2:0cc880f230ad | 205 | * @returns max column |
dreschpe | 2:0cc880f230ad | 206 | * depends on actual font size |
dreschpe | 2:0cc880f230ad | 207 | * |
dreschpe | 2:0cc880f230ad | 208 | */ |
dreschpe | 2:0cc880f230ad | 209 | int rows(void); |
dreschpe | 1:aa3356b16080 | 210 | |
dreschpe | 2:0cc880f230ad | 211 | /** put a char on the screen |
dreschpe | 2:0cc880f230ad | 212 | * |
dreschpe | 2:0cc880f230ad | 213 | * @param value char to print |
dreschpe | 2:0cc880f230ad | 214 | * @returns printed char |
dreschpe | 2:0cc880f230ad | 215 | * |
dreschpe | 2:0cc880f230ad | 216 | */ |
dreschpe | 2:0cc880f230ad | 217 | int _putc(int value); |
dreschpe | 1:aa3356b16080 | 218 | |
dreschpe | 2:0cc880f230ad | 219 | /** draw a character on given position out of the active font to the TFT |
dreschpe | 2:0cc880f230ad | 220 | * |
dreschpe | 6:fc33e4a5713e | 221 | * @param x x-position of char (top left) |
dreschpe | 6:fc33e4a5713e | 222 | * @param y y-position |
dreschpe | 2:0cc880f230ad | 223 | * @param c char to print |
dreschpe | 2:0cc880f230ad | 224 | * |
dreschpe | 2:0cc880f230ad | 225 | */ |
dreschpe | 6:fc33e4a5713e | 226 | virtual void character(int x, int y, int c); |
dreschpe | 1:aa3356b16080 | 227 | |
dreschpe | 2:0cc880f230ad | 228 | /** paint a bitmap on the TFT |
dreschpe | 2:0cc880f230ad | 229 | * |
dreschpe | 2:0cc880f230ad | 230 | * @param x,y : upper left corner |
dreschpe | 2:0cc880f230ad | 231 | * @param w width of bitmap |
dreschpe | 2:0cc880f230ad | 232 | * @param h high of bitmap |
dreschpe | 2:0cc880f230ad | 233 | * @param *bitmap pointer to the bitmap data |
dreschpe | 2:0cc880f230ad | 234 | * |
dreschpe | 2:0cc880f230ad | 235 | * bitmap format: 16 bit R5 G6 B5 |
dreschpe | 2:0cc880f230ad | 236 | * |
dreschpe | 2:0cc880f230ad | 237 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
dreschpe | 2:0cc880f230ad | 238 | * use winhex to load this file and mark data stating at offset 0x46 to end |
dreschpe | 2:0cc880f230ad | 239 | * use edit -> copy block -> C Source to export C array |
dreschpe | 2:0cc880f230ad | 240 | * paste this array into your program |
dreschpe | 2:0cc880f230ad | 241 | * |
dreschpe | 6:fc33e4a5713e | 242 | * define the array as static const unsigned char to put it into flash memory |
dreschpe | 6:fc33e4a5713e | 243 | * cast the pointer to (unsigned char *) : |
dreschpe | 6:fc33e4a5713e | 244 | * tft.Bitmap(10,40,309,50,(unsigned char *)scala); |
dreschpe | 2:0cc880f230ad | 245 | */ |
dreschpe | 2:0cc880f230ad | 246 | void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap); |
dreschpe | 1:aa3356b16080 | 247 | |
dreschpe | 5:2db1b8070d94 | 248 | |
dreschpe | 5:2db1b8070d94 | 249 | /** paint a 16 bit BMP from local filesytem on the TFT (slow) |
dreschpe | 5:2db1b8070d94 | 250 | * |
dreschpe | 5:2db1b8070d94 | 251 | * @param x,y : upper left corner |
dreschpe | 5:2db1b8070d94 | 252 | * @param *Name_BMP name of the BMP file |
dreschpe | 5:2db1b8070d94 | 253 | * @returns 1 if bmp file was found and painted |
dreschpe | 5:2db1b8070d94 | 254 | * @returns -1 if bmp file was found not found |
dreschpe | 5:2db1b8070d94 | 255 | * @returns -2 if bmp file is not 16bit |
dreschpe | 5:2db1b8070d94 | 256 | * @returns -3 if bmp file is to big for screen |
dreschpe | 5:2db1b8070d94 | 257 | * @returns -4 if buffer malloc go wrong |
dreschpe | 5:2db1b8070d94 | 258 | * |
dreschpe | 5:2db1b8070d94 | 259 | * bitmap format: 16 bit R5 G6 B5 |
dreschpe | 5:2db1b8070d94 | 260 | * |
dreschpe | 5:2db1b8070d94 | 261 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
dreschpe | 5:2db1b8070d94 | 262 | * copy to internal file system |
dreschpe | 5:2db1b8070d94 | 263 | * |
dreschpe | 5:2db1b8070d94 | 264 | */ |
dreschpe | 5:2db1b8070d94 | 265 | |
dreschpe | 5:2db1b8070d94 | 266 | int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP); |
dreschpe | 5:2db1b8070d94 | 267 | |
dreschpe | 5:2db1b8070d94 | 268 | |
dreschpe | 5:2db1b8070d94 | 269 | |
dreschpe | 2:0cc880f230ad | 270 | /** select the font to use |
dreschpe | 2:0cc880f230ad | 271 | * |
dreschpe | 2:0cc880f230ad | 272 | * @param f pointer to font array |
dreschpe | 2:0cc880f230ad | 273 | * |
dreschpe | 2:0cc880f230ad | 274 | * font array can created with GLCD Font Creator from http://www.mikroe.com |
dreschpe | 2:0cc880f230ad | 275 | * you have to add 4 parameter at the beginning of the font array to use: |
dreschpe | 2:0cc880f230ad | 276 | * - the number of byte / char |
dreschpe | 2:0cc880f230ad | 277 | * - the vertial size in pixel |
dreschpe | 2:0cc880f230ad | 278 | * - the horizontal size in pixel |
dreschpe | 2:0cc880f230ad | 279 | * - the number of byte per vertical line |
dreschpe | 2:0cc880f230ad | 280 | * you also have to change the array to char[] |
dreschpe | 2:0cc880f230ad | 281 | * |
dreschpe | 5:2db1b8070d94 | 282 | */ |
dreschpe | 2:0cc880f230ad | 283 | void set_font(unsigned char* f); |
dreschpe | 1:aa3356b16080 | 284 | |
dreschpe | 2:0cc880f230ad | 285 | /** Set the orientation of the screen |
dreschpe | 2:0cc880f230ad | 286 | * x,y: 0,0 is always top left |
dreschpe | 2:0cc880f230ad | 287 | * |
dreschpe | 4:e1e45f8a7664 | 288 | * @param o direction to use the screen (0-3) 90� Steps |
dreschpe | 2:0cc880f230ad | 289 | * |
dreschpe | 2:0cc880f230ad | 290 | */ |
dreschpe | 2:0cc880f230ad | 291 | void set_orientation(unsigned int o); |
dreschpe | 0:cccc5726bdf3 | 292 | |
dreschpe | 2:0cc880f230ad | 293 | SPI _spi; |
dreschpe | 12:b2dd49f04d5d | 294 | // DigitalOut _cs; we use SSEL0/1 |
dreschpe | 2:0cc880f230ad | 295 | DigitalOut _reset; |
dreschpe | 2:0cc880f230ad | 296 | unsigned char* font; |
dreschpe | 8:e1f5232d93a0 | 297 | |
dreschpe | 8:e1f5232d93a0 | 298 | |
dreschpe | 8:e1f5232d93a0 | 299 | |
dreschpe | 2:0cc880f230ad | 300 | |
dreschpe | 0:cccc5726bdf3 | 301 | protected: |
dreschpe | 1:aa3356b16080 | 302 | |
dreschpe | 8:e1f5232d93a0 | 303 | /** Set draw window region to whole screen |
dreschpe | 8:e1f5232d93a0 | 304 | * |
dreschpe | 8:e1f5232d93a0 | 305 | */ |
dreschpe | 8:e1f5232d93a0 | 306 | void WindowMax (void); |
dreschpe | 8:e1f5232d93a0 | 307 | |
dreschpe | 8:e1f5232d93a0 | 308 | |
dreschpe | 2:0cc880f230ad | 309 | /** draw a horizontal line |
dreschpe | 2:0cc880f230ad | 310 | * |
dreschpe | 2:0cc880f230ad | 311 | * @param x0 horizontal start |
dreschpe | 2:0cc880f230ad | 312 | * @param x1 horizontal stop |
dreschpe | 2:0cc880f230ad | 313 | * @param y vertical position |
dreschpe | 2:0cc880f230ad | 314 | * @param color 16 bit color |
dreschpe | 2:0cc880f230ad | 315 | * |
dreschpe | 2:0cc880f230ad | 316 | */ |
dreschpe | 2:0cc880f230ad | 317 | void hline(int x0, int x1, int y, int colour); |
dreschpe | 1:aa3356b16080 | 318 | |
dreschpe | 2:0cc880f230ad | 319 | /** draw a vertical line |
dreschpe | 2:0cc880f230ad | 320 | * |
dreschpe | 2:0cc880f230ad | 321 | * @param x horizontal position |
dreschpe | 2:0cc880f230ad | 322 | * @param y0 vertical start |
dreschpe | 2:0cc880f230ad | 323 | * @param y1 vertical stop |
dreschpe | 2:0cc880f230ad | 324 | * @param color 16 bit color |
dreschpe | 2:0cc880f230ad | 325 | */ |
dreschpe | 2:0cc880f230ad | 326 | void vline(int y0, int y1, int x, int colour); |
dreschpe | 1:aa3356b16080 | 327 | |
dreschpe | 2:0cc880f230ad | 328 | /** Set draw window region |
dreschpe | 2:0cc880f230ad | 329 | * |
dreschpe | 2:0cc880f230ad | 330 | * @param x horizontal position |
dreschpe | 2:0cc880f230ad | 331 | * @param y vertical position |
dreschpe | 2:0cc880f230ad | 332 | * @param w window width in pixel |
dreschpe | 2:0cc880f230ad | 333 | * @param h window height in pixels |
dreschpe | 2:0cc880f230ad | 334 | */ |
dreschpe | 2:0cc880f230ad | 335 | void window (unsigned int x, unsigned int y, unsigned int w, unsigned int h); |
dreschpe | 1:aa3356b16080 | 336 | |
dreschpe | 8:e1f5232d93a0 | 337 | |
dreschpe | 1:aa3356b16080 | 338 | |
dreschpe | 2:0cc880f230ad | 339 | /** Init the HX8347D controller |
dreschpe | 2:0cc880f230ad | 340 | * |
dreschpe | 2:0cc880f230ad | 341 | */ |
dreschpe | 2:0cc880f230ad | 342 | void tft_reset(); |
dreschpe | 1:aa3356b16080 | 343 | |
dreschpe | 2:0cc880f230ad | 344 | /** Write data to the LCD controller |
dreschpe | 2:0cc880f230ad | 345 | * |
dreschpe | 2:0cc880f230ad | 346 | * @param dat data written to LCD controller |
dreschpe | 2:0cc880f230ad | 347 | * |
dreschpe | 2:0cc880f230ad | 348 | */ |
dreschpe | 12:b2dd49f04d5d | 349 | //void wr_dat(unsigned int value); |
dreschpe | 12:b2dd49f04d5d | 350 | void wr_dat(unsigned char value); |
dreschpe | 1:aa3356b16080 | 351 | |
dreschpe | 2:0cc880f230ad | 352 | /** Write a command the LCD controller |
dreschpe | 2:0cc880f230ad | 353 | * |
dreschpe | 2:0cc880f230ad | 354 | * @param cmd: command to be written |
dreschpe | 2:0cc880f230ad | 355 | * |
dreschpe | 2:0cc880f230ad | 356 | */ |
dreschpe | 12:b2dd49f04d5d | 357 | void wr_cmd(unsigned char value); |
dreschpe | 1:aa3356b16080 | 358 | |
dreschpe | 2:0cc880f230ad | 359 | /** Start data sequence to the LCD controller |
dreschpe | 2:0cc880f230ad | 360 | * |
dreschpe | 2:0cc880f230ad | 361 | */ |
dreschpe | 12:b2dd49f04d5d | 362 | //void wr_dat_start(); |
dreschpe | 1:aa3356b16080 | 363 | |
dreschpe | 2:0cc880f230ad | 364 | /** Stop of data writing to the LCD controller |
dreschpe | 2:0cc880f230ad | 365 | * |
dreschpe | 2:0cc880f230ad | 366 | */ |
dreschpe | 12:b2dd49f04d5d | 367 | //void wr_dat_stop(); |
dreschpe | 1:aa3356b16080 | 368 | |
dreschpe | 2:0cc880f230ad | 369 | /** write data to the LCD controller |
dreschpe | 2:0cc880f230ad | 370 | * |
dreschpe | 2:0cc880f230ad | 371 | * @param data to be written |
dreschpe | 2:0cc880f230ad | 372 | * * |
dreschpe | 2:0cc880f230ad | 373 | */ |
dreschpe | 2:0cc880f230ad | 374 | void wr_dat_only(unsigned short dat); |
dreschpe | 1:aa3356b16080 | 375 | |
dreschpe | 2:0cc880f230ad | 376 | /** Read data from the LCD controller |
dreschpe | 2:0cc880f230ad | 377 | * |
dreschpe | 2:0cc880f230ad | 378 | * @returns data from LCD controller |
dreschpe | 2:0cc880f230ad | 379 | * |
dreschpe | 2:0cc880f230ad | 380 | */ |
dreschpe | 2:0cc880f230ad | 381 | unsigned short rd_dat(void); |
dreschpe | 1:aa3356b16080 | 382 | |
dreschpe | 2:0cc880f230ad | 383 | /** Write a value to the to a LCD register |
dreschpe | 2:0cc880f230ad | 384 | * |
dreschpe | 2:0cc880f230ad | 385 | * @param reg register to be written |
dreschpe | 2:0cc880f230ad | 386 | * @param val data to be written |
dreschpe | 2:0cc880f230ad | 387 | */ |
dreschpe | 12:b2dd49f04d5d | 388 | void wr_reg (unsigned char reg, unsigned char val); |
dreschpe | 1:aa3356b16080 | 389 | |
dreschpe | 2:0cc880f230ad | 390 | /** Read a LCD register |
dreschpe | 2:0cc880f230ad | 391 | * |
dreschpe | 2:0cc880f230ad | 392 | * @param reg register to be read |
dreschpe | 2:0cc880f230ad | 393 | * @returns value of the register |
dreschpe | 2:0cc880f230ad | 394 | */ |
dreschpe | 2:0cc880f230ad | 395 | unsigned short rd_reg (unsigned char reg); |
dreschpe | 0:cccc5726bdf3 | 396 | |
dreschpe | 12:b2dd49f04d5d | 397 | unsigned char spi_port; |
dreschpe | 2:0cc880f230ad | 398 | unsigned int orientation; |
dreschpe | 2:0cc880f230ad | 399 | unsigned int char_x; |
dreschpe | 6:fc33e4a5713e | 400 | unsigned int char_y; |
dreschpe | 5:2db1b8070d94 | 401 | |
dreschpe | 0:cccc5726bdf3 | 402 | |
dreschpe | 0:cccc5726bdf3 | 403 | }; |
dreschpe | 0:cccc5726bdf3 | 404 | |
dreschpe | 0:cccc5726bdf3 | 405 | #endif |