Sérgio Natan
/
luva_tatil_repo
teste
ST7735_TFT.h@0:cf17b1f16335, 2017-10-24 (annotated)
- Committer:
- sergionatan
- Date:
- Tue Oct 24 20:12:54 2017 +0000
- Revision:
- 0:cf17b1f16335
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sergionatan | 0:cf17b1f16335 | 1 | // ST7735 8 Bit SPI Library |
sergionatan | 0:cf17b1f16335 | 2 | |
sergionatan | 0:cf17b1f16335 | 3 | #ifndef MBED_ST7735_TFT_H |
sergionatan | 0:cf17b1f16335 | 4 | #define MBED_ST7735_TFT_H |
sergionatan | 0:cf17b1f16335 | 5 | |
sergionatan | 0:cf17b1f16335 | 6 | #include "mbed.h" |
sergionatan | 0:cf17b1f16335 | 7 | #include "GraphicsDisplay.h" |
sergionatan | 0:cf17b1f16335 | 8 | #include "BurstSPI.h" |
sergionatan | 0:cf17b1f16335 | 9 | |
sergionatan | 0:cf17b1f16335 | 10 | #define RGB(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue |
sergionatan | 0:cf17b1f16335 | 11 | |
sergionatan | 0:cf17b1f16335 | 12 | /*define ST7735 Commands */ |
sergionatan | 0:cf17b1f16335 | 13 | |
sergionatan | 0:cf17b1f16335 | 14 | #define ST7735_NOP 0x0 |
sergionatan | 0:cf17b1f16335 | 15 | #define ST7735_SWRESET 0x01 |
sergionatan | 0:cf17b1f16335 | 16 | #define ST7735_RDDID 0x04 |
sergionatan | 0:cf17b1f16335 | 17 | #define ST7735_RDDST 0x09 |
sergionatan | 0:cf17b1f16335 | 18 | |
sergionatan | 0:cf17b1f16335 | 19 | #define ST7735_SLPIN 0x10 |
sergionatan | 0:cf17b1f16335 | 20 | #define ST7735_SLPOUT 0x11 |
sergionatan | 0:cf17b1f16335 | 21 | #define ST7735_PTLON 0x12 |
sergionatan | 0:cf17b1f16335 | 22 | #define ST7735_NORON 0x13 |
sergionatan | 0:cf17b1f16335 | 23 | |
sergionatan | 0:cf17b1f16335 | 24 | #define ST7735_INVOFF 0x20 |
sergionatan | 0:cf17b1f16335 | 25 | #define ST7735_INVON 0x21 |
sergionatan | 0:cf17b1f16335 | 26 | #define ST7735_DISPOFF 0x28 |
sergionatan | 0:cf17b1f16335 | 27 | #define ST7735_DISPON 0x29 |
sergionatan | 0:cf17b1f16335 | 28 | #define ST7735_CASET 0x2A |
sergionatan | 0:cf17b1f16335 | 29 | #define ST7735_RASET 0x2B |
sergionatan | 0:cf17b1f16335 | 30 | #define ST7735_RAMWR 0x2C |
sergionatan | 0:cf17b1f16335 | 31 | #define ST7735_RAMRD 0x2E |
sergionatan | 0:cf17b1f16335 | 32 | |
sergionatan | 0:cf17b1f16335 | 33 | #define ST7735_COLMOD 0x3A |
sergionatan | 0:cf17b1f16335 | 34 | #define ST7735_MADCTL 0x36 |
sergionatan | 0:cf17b1f16335 | 35 | |
sergionatan | 0:cf17b1f16335 | 36 | |
sergionatan | 0:cf17b1f16335 | 37 | #define ST7735_FRMCTR1 0xB1 |
sergionatan | 0:cf17b1f16335 | 38 | #define ST7735_FRMCTR2 0xB2 |
sergionatan | 0:cf17b1f16335 | 39 | #define ST7735_FRMCTR3 0xB3 |
sergionatan | 0:cf17b1f16335 | 40 | #define ST7735_INVCTR 0xB4 |
sergionatan | 0:cf17b1f16335 | 41 | #define ST7735_DISSET5 0xB6 |
sergionatan | 0:cf17b1f16335 | 42 | |
sergionatan | 0:cf17b1f16335 | 43 | #define ST7735_PWCTR1 0xC0 |
sergionatan | 0:cf17b1f16335 | 44 | #define ST7735_PWCTR2 0xC1 |
sergionatan | 0:cf17b1f16335 | 45 | #define ST7735_PWCTR3 0xC2 |
sergionatan | 0:cf17b1f16335 | 46 | #define ST7735_PWCTR4 0xC3 |
sergionatan | 0:cf17b1f16335 | 47 | #define ST7735_PWCTR5 0xC4 |
sergionatan | 0:cf17b1f16335 | 48 | #define ST7735_VMCTR1 0xC5 |
sergionatan | 0:cf17b1f16335 | 49 | |
sergionatan | 0:cf17b1f16335 | 50 | #define ST7735_RDID1 0xDA |
sergionatan | 0:cf17b1f16335 | 51 | #define ST7735_RDID2 0xDB |
sergionatan | 0:cf17b1f16335 | 52 | #define ST7735_RDID3 0xDC |
sergionatan | 0:cf17b1f16335 | 53 | #define ST7735_RDID4 0xDD |
sergionatan | 0:cf17b1f16335 | 54 | |
sergionatan | 0:cf17b1f16335 | 55 | #define ST7735_PWCTR6 0xFC |
sergionatan | 0:cf17b1f16335 | 56 | |
sergionatan | 0:cf17b1f16335 | 57 | #define ST7735_GMCTRP1 0xE0 |
sergionatan | 0:cf17b1f16335 | 58 | #define ST7735_GMCTRN1 0xE1 |
sergionatan | 0:cf17b1f16335 | 59 | |
sergionatan | 0:cf17b1f16335 | 60 | // some RGB color definitions RED GREEN BLUE |
sergionatan | 0:cf17b1f16335 | 61 | |
sergionatan | 0:cf17b1f16335 | 62 | #define Black 0x0000 // 0, 0, 0 |
sergionatan | 0:cf17b1f16335 | 63 | #define Navy 0x8000 // 0, 0, 128 |
sergionatan | 0:cf17b1f16335 | 64 | #define DarkGreen 0x0400 // 0, 128, 0 |
sergionatan | 0:cf17b1f16335 | 65 | #define DarkCyan 0x8400 // 0, 128, 128 |
sergionatan | 0:cf17b1f16335 | 66 | #define Maroon 0x0010 // 128, 0, 0 |
sergionatan | 0:cf17b1f16335 | 67 | #define Purple 0x8010 // 128, 0, 128 |
sergionatan | 0:cf17b1f16335 | 68 | #define Olive 0x0410 // 128, 128, 0 |
sergionatan | 0:cf17b1f16335 | 69 | #define LightGrey 0xC618 // 192, 192, 192 |
sergionatan | 0:cf17b1f16335 | 70 | #define DarkGrey 0x7BEF // 128, 128, 128 |
sergionatan | 0:cf17b1f16335 | 71 | #define Red 0x001F // 255, 0, 0 |
sergionatan | 0:cf17b1f16335 | 72 | #define Green 0x07E0 // 0, 255, 0 |
sergionatan | 0:cf17b1f16335 | 73 | #define Yellow 0x07FF // 255, 255, 0 |
sergionatan | 0:cf17b1f16335 | 74 | #define Blue 0xF800 // 0, 0, 255 |
sergionatan | 0:cf17b1f16335 | 75 | #define Magenta 0xF81F // 255, 0, 255 |
sergionatan | 0:cf17b1f16335 | 76 | #define Cyan 0xFFE0 // 0, 255, 255 |
sergionatan | 0:cf17b1f16335 | 77 | #define White 0xFFFF // 255, 255, 255 |
sergionatan | 0:cf17b1f16335 | 78 | #define Orange 0x053F // 255, 165, 0 |
sergionatan | 0:cf17b1f16335 | 79 | #define GreenYellow 0x2FF5 // 173, 255, 47 |
sergionatan | 0:cf17b1f16335 | 80 | |
sergionatan | 0:cf17b1f16335 | 81 | /* Use this to Calculate and define any colour |
sergionatan | 0:cf17b1f16335 | 82 | |
sergionatan | 0:cf17b1f16335 | 83 | #define RGB565CONVERT(red, green, blue) (uint16_t)( (( blue >> 3 ) << 11 ) | (( green >> 2 ) << 5 ) | ( red >> 3 )) |
sergionatan | 0:cf17b1f16335 | 84 | lcd.printf("%4X ",RGB565CONVERT(red value 0-255,green value 0-255,blue value 0-255)); |
sergionatan | 0:cf17b1f16335 | 85 | */ |
sergionatan | 0:cf17b1f16335 | 86 | |
sergionatan | 0:cf17b1f16335 | 87 | class ST7735_TFT : public GraphicsDisplay { |
sergionatan | 0:cf17b1f16335 | 88 | public: |
sergionatan | 0:cf17b1f16335 | 89 | |
sergionatan | 0:cf17b1f16335 | 90 | /** Create a ST7735_TFT object connected to SPI and three pins. ST7735 requires rs pin to toggle between data/command |
sergionatan | 0:cf17b1f16335 | 91 | * |
sergionatan | 0:cf17b1f16335 | 92 | * @param mosi(SDA),miso(NC),sclk(SCK) SPI |
sergionatan | 0:cf17b1f16335 | 93 | * @param cs pin connected to CS of display (called SS for 'Slave Select' in ST7735 datasheet) |
sergionatan | 0:cf17b1f16335 | 94 | * @param rs pin connected to RS (A0)of display (called D/CX in ST7735 datasheet) |
sergionatan | 0:cf17b1f16335 | 95 | * @param reset pin connected to RESET of display |
sergionatan | 0:cf17b1f16335 | 96 | * |
sergionatan | 0:cf17b1f16335 | 97 | */ |
sergionatan | 0:cf17b1f16335 | 98 | ST7735_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName rs, PinName reset,const char* name ="TFT"); |
sergionatan | 0:cf17b1f16335 | 99 | |
sergionatan | 0:cf17b1f16335 | 100 | /** Get the width of the screen in pixel |
sergionatan | 0:cf17b1f16335 | 101 | * |
sergionatan | 0:cf17b1f16335 | 102 | * @param |
sergionatan | 0:cf17b1f16335 | 103 | * @returns width of screen in pixel |
sergionatan | 0:cf17b1f16335 | 104 | * |
sergionatan | 0:cf17b1f16335 | 105 | */ |
sergionatan | 0:cf17b1f16335 | 106 | virtual int width(); |
sergionatan | 0:cf17b1f16335 | 107 | |
sergionatan | 0:cf17b1f16335 | 108 | /** Get the height of the screen in pixel |
sergionatan | 0:cf17b1f16335 | 109 | * |
sergionatan | 0:cf17b1f16335 | 110 | * @returns height of screen in pixel |
sergionatan | 0:cf17b1f16335 | 111 | * |
sergionatan | 0:cf17b1f16335 | 112 | */ |
sergionatan | 0:cf17b1f16335 | 113 | virtual int height(); |
sergionatan | 0:cf17b1f16335 | 114 | |
sergionatan | 0:cf17b1f16335 | 115 | /** Draw a pixel at x,y with color |
sergionatan | 0:cf17b1f16335 | 116 | * |
sergionatan | 0:cf17b1f16335 | 117 | * @param x horizontal position |
sergionatan | 0:cf17b1f16335 | 118 | * @param y vertical position |
sergionatan | 0:cf17b1f16335 | 119 | * @param color 16 bit pixel color |
sergionatan | 0:cf17b1f16335 | 120 | */ |
sergionatan | 0:cf17b1f16335 | 121 | virtual void pixel(int x, int y, int colour); |
sergionatan | 0:cf17b1f16335 | 122 | |
sergionatan | 0:cf17b1f16335 | 123 | /** Get colour of pixel at x,y |
sergionatan | 0:cf17b1f16335 | 124 | * |
sergionatan | 0:cf17b1f16335 | 125 | * @param x horizontal position |
sergionatan | 0:cf17b1f16335 | 126 | * @param y vertical position |
sergionatan | 0:cf17b1f16335 | 127 | */ |
sergionatan | 0:cf17b1f16335 | 128 | |
sergionatan | 0:cf17b1f16335 | 129 | int getpixel(unsigned int x, unsigned int y); |
sergionatan | 0:cf17b1f16335 | 130 | |
sergionatan | 0:cf17b1f16335 | 131 | /** draw a circle |
sergionatan | 0:cf17b1f16335 | 132 | * |
sergionatan | 0:cf17b1f16335 | 133 | * @param x0,y0 center |
sergionatan | 0:cf17b1f16335 | 134 | * @param r radius |
sergionatan | 0:cf17b1f16335 | 135 | * @param color 16 bit color * |
sergionatan | 0:cf17b1f16335 | 136 | * |
sergionatan | 0:cf17b1f16335 | 137 | */ |
sergionatan | 0:cf17b1f16335 | 138 | |
sergionatan | 0:cf17b1f16335 | 139 | void circle(int x, int y, int r, int colour); |
sergionatan | 0:cf17b1f16335 | 140 | |
sergionatan | 0:cf17b1f16335 | 141 | /** draw a filled circle |
sergionatan | 0:cf17b1f16335 | 142 | * |
sergionatan | 0:cf17b1f16335 | 143 | * @param x0,y0 center |
sergionatan | 0:cf17b1f16335 | 144 | * @param r radius |
sergionatan | 0:cf17b1f16335 | 145 | * @param color 16 bit color * |
sergionatan | 0:cf17b1f16335 | 146 | * |
sergionatan | 0:cf17b1f16335 | 147 | * use circle with different radius, |
sergionatan | 0:cf17b1f16335 | 148 | * can miss some pixel |
sergionatan | 0:cf17b1f16335 | 149 | */ |
sergionatan | 0:cf17b1f16335 | 150 | void fillcircle(int x, int y, int r, int colour); |
sergionatan | 0:cf17b1f16335 | 151 | |
sergionatan | 0:cf17b1f16335 | 152 | /** draw a 1 pixel line |
sergionatan | 0:cf17b1f16335 | 153 | * |
sergionatan | 0:cf17b1f16335 | 154 | * @param x0,y0 start point |
sergionatan | 0:cf17b1f16335 | 155 | * @param x1,y1 stop point |
sergionatan | 0:cf17b1f16335 | 156 | * @param color 16 bit color |
sergionatan | 0:cf17b1f16335 | 157 | * |
sergionatan | 0:cf17b1f16335 | 158 | */ |
sergionatan | 0:cf17b1f16335 | 159 | void line(int x0, int y0, int x1, int y1, int colour); |
sergionatan | 0:cf17b1f16335 | 160 | |
sergionatan | 0:cf17b1f16335 | 161 | /** draw a rect |
sergionatan | 0:cf17b1f16335 | 162 | * |
sergionatan | 0:cf17b1f16335 | 163 | * @param x0,y0 top left corner |
sergionatan | 0:cf17b1f16335 | 164 | * @param x1,y1 down right corner |
sergionatan | 0:cf17b1f16335 | 165 | * @param color 16 bit color |
sergionatan | 0:cf17b1f16335 | 166 | * * |
sergionatan | 0:cf17b1f16335 | 167 | */ |
sergionatan | 0:cf17b1f16335 | 168 | void rect(int x0, int y0, int x1, int y1, int colour); |
sergionatan | 0:cf17b1f16335 | 169 | |
sergionatan | 0:cf17b1f16335 | 170 | /** draw a filled rect |
sergionatan | 0:cf17b1f16335 | 171 | * |
sergionatan | 0:cf17b1f16335 | 172 | * @param x0,y0 top left corner |
sergionatan | 0:cf17b1f16335 | 173 | * @param x1,y1 down right corner |
sergionatan | 0:cf17b1f16335 | 174 | * @param color 16 bit color |
sergionatan | 0:cf17b1f16335 | 175 | * |
sergionatan | 0:cf17b1f16335 | 176 | */ |
sergionatan | 0:cf17b1f16335 | 177 | void fillrect(int x0, int y0, int x1, int y1, int colour); |
sergionatan | 0:cf17b1f16335 | 178 | |
sergionatan | 0:cf17b1f16335 | 179 | /** setup cursor position |
sergionatan | 0:cf17b1f16335 | 180 | * |
sergionatan | 0:cf17b1f16335 | 181 | * @param x x-position (top left) |
sergionatan | 0:cf17b1f16335 | 182 | * @param y y-position |
sergionatan | 0:cf17b1f16335 | 183 | */ |
sergionatan | 0:cf17b1f16335 | 184 | virtual void locate(int x, int y); |
sergionatan | 0:cf17b1f16335 | 185 | |
sergionatan | 0:cf17b1f16335 | 186 | /** Fill the screen with _backgroun color |
sergionatan | 0:cf17b1f16335 | 187 | * |
sergionatan | 0:cf17b1f16335 | 188 | */ |
sergionatan | 0:cf17b1f16335 | 189 | virtual void cls (void); |
sergionatan | 0:cf17b1f16335 | 190 | |
sergionatan | 0:cf17b1f16335 | 191 | |
sergionatan | 0:cf17b1f16335 | 192 | /** calculate the max number of char in a line |
sergionatan | 0:cf17b1f16335 | 193 | * |
sergionatan | 0:cf17b1f16335 | 194 | * @returns max columns |
sergionatan | 0:cf17b1f16335 | 195 | * depends on actual font size |
sergionatan | 0:cf17b1f16335 | 196 | * |
sergionatan | 0:cf17b1f16335 | 197 | */ |
sergionatan | 0:cf17b1f16335 | 198 | virtual int columns(void); |
sergionatan | 0:cf17b1f16335 | 199 | |
sergionatan | 0:cf17b1f16335 | 200 | /** calculate the max number of columns |
sergionatan | 0:cf17b1f16335 | 201 | * |
sergionatan | 0:cf17b1f16335 | 202 | * @returns max column |
sergionatan | 0:cf17b1f16335 | 203 | * depends on actual font size |
sergionatan | 0:cf17b1f16335 | 204 | * |
sergionatan | 0:cf17b1f16335 | 205 | */ |
sergionatan | 0:cf17b1f16335 | 206 | virtual int rows(void); |
sergionatan | 0:cf17b1f16335 | 207 | |
sergionatan | 0:cf17b1f16335 | 208 | /** put a char on the screen |
sergionatan | 0:cf17b1f16335 | 209 | * |
sergionatan | 0:cf17b1f16335 | 210 | * @param value char to print |
sergionatan | 0:cf17b1f16335 | 211 | * @returns printed char |
sergionatan | 0:cf17b1f16335 | 212 | * |
sergionatan | 0:cf17b1f16335 | 213 | */ |
sergionatan | 0:cf17b1f16335 | 214 | virtual int _putc(int value); |
sergionatan | 0:cf17b1f16335 | 215 | |
sergionatan | 0:cf17b1f16335 | 216 | /** draw a character on given position out of the active font to the TFT |
sergionatan | 0:cf17b1f16335 | 217 | * |
sergionatan | 0:cf17b1f16335 | 218 | * @param x x-position of char (top left) |
sergionatan | 0:cf17b1f16335 | 219 | * @param y y-position |
sergionatan | 0:cf17b1f16335 | 220 | * @param c char to print |
sergionatan | 0:cf17b1f16335 | 221 | * |
sergionatan | 0:cf17b1f16335 | 222 | */ |
sergionatan | 0:cf17b1f16335 | 223 | virtual void character(int x, int y, int c); |
sergionatan | 0:cf17b1f16335 | 224 | |
sergionatan | 0:cf17b1f16335 | 225 | /** paint a bitmap on the TFT |
sergionatan | 0:cf17b1f16335 | 226 | * |
sergionatan | 0:cf17b1f16335 | 227 | * @param x,y : upper left corner |
sergionatan | 0:cf17b1f16335 | 228 | * @param w width of bitmap |
sergionatan | 0:cf17b1f16335 | 229 | * @param h high of bitmap |
sergionatan | 0:cf17b1f16335 | 230 | * @param *bitmap pointer to the bitmap data |
sergionatan | 0:cf17b1f16335 | 231 | * |
sergionatan | 0:cf17b1f16335 | 232 | * bitmap format: 16 bit R5 G6 B5 |
sergionatan | 0:cf17b1f16335 | 233 | * |
sergionatan | 0:cf17b1f16335 | 234 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
sergionatan | 0:cf17b1f16335 | 235 | * use winhex to load this file and mark data stating at offset 0x46 to end |
sergionatan | 0:cf17b1f16335 | 236 | * use edit -> copy block -> C Source to export C array |
sergionatan | 0:cf17b1f16335 | 237 | * paste this array into your program |
sergionatan | 0:cf17b1f16335 | 238 | * |
sergionatan | 0:cf17b1f16335 | 239 | * define the array as static const unsigned char to put it into flash memory |
sergionatan | 0:cf17b1f16335 | 240 | * cast the pointer to (unsigned char *) : |
sergionatan | 0:cf17b1f16335 | 241 | * tft.Bitmap(10,40,309,50,(unsigned char *)scala); |
sergionatan | 0:cf17b1f16335 | 242 | */ |
sergionatan | 0:cf17b1f16335 | 243 | void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap); |
sergionatan | 0:cf17b1f16335 | 244 | |
sergionatan | 0:cf17b1f16335 | 245 | |
sergionatan | 0:cf17b1f16335 | 246 | /** paint a 16 bit BMP from local filesytem on the TFT (slow) |
sergionatan | 0:cf17b1f16335 | 247 | * |
sergionatan | 0:cf17b1f16335 | 248 | * @param x,y : upper left corner |
sergionatan | 0:cf17b1f16335 | 249 | * @param *Name_BMP name of the BMP file |
sergionatan | 0:cf17b1f16335 | 250 | * @returns 1 if bmp file was found and painted |
sergionatan | 0:cf17b1f16335 | 251 | * @returns -1 if bmp file was found not found |
sergionatan | 0:cf17b1f16335 | 252 | * @returns -2 if bmp file is not 16bit |
sergionatan | 0:cf17b1f16335 | 253 | * @returns -3 if bmp file is to big for screen |
sergionatan | 0:cf17b1f16335 | 254 | * @returns -4 if buffer malloc go wrong |
sergionatan | 0:cf17b1f16335 | 255 | * |
sergionatan | 0:cf17b1f16335 | 256 | * bitmap format: 16 bit R5 G6 B5 |
sergionatan | 0:cf17b1f16335 | 257 | * |
sergionatan | 0:cf17b1f16335 | 258 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
sergionatan | 0:cf17b1f16335 | 259 | * copy to internal file system |
sergionatan | 0:cf17b1f16335 | 260 | * |
sergionatan | 0:cf17b1f16335 | 261 | */ |
sergionatan | 0:cf17b1f16335 | 262 | |
sergionatan | 0:cf17b1f16335 | 263 | int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP); |
sergionatan | 0:cf17b1f16335 | 264 | |
sergionatan | 0:cf17b1f16335 | 265 | /** Read an area from the LCD RAM to MCU RAM |
sergionatan | 0:cf17b1f16335 | 266 | * |
sergionatan | 0:cf17b1f16335 | 267 | * @param x,y : upper left corner |
sergionatan | 0:cf17b1f16335 | 268 | * @param w width of bitmap |
sergionatan | 0:cf17b1f16335 | 269 | * @param h high of bitmap |
sergionatan | 0:cf17b1f16335 | 270 | * @param *buffer pointer to the buffer |
sergionatan | 0:cf17b1f16335 | 271 | */ |
sergionatan | 0:cf17b1f16335 | 272 | |
sergionatan | 0:cf17b1f16335 | 273 | void read_area(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *buffer); |
sergionatan | 0:cf17b1f16335 | 274 | |
sergionatan | 0:cf17b1f16335 | 275 | /** select the font to use |
sergionatan | 0:cf17b1f16335 | 276 | * |
sergionatan | 0:cf17b1f16335 | 277 | * @param f pointer to font array |
sergionatan | 0:cf17b1f16335 | 278 | * |
sergionatan | 0:cf17b1f16335 | 279 | * font array can created with GLCD Font Creator from http://www.mikroe.com |
sergionatan | 0:cf17b1f16335 | 280 | * you have to add 4 parameter at the beginning of the font array to use: |
sergionatan | 0:cf17b1f16335 | 281 | * - the number of byte / char |
sergionatan | 0:cf17b1f16335 | 282 | * - the vertial size in pixel |
sergionatan | 0:cf17b1f16335 | 283 | * - the horizontal size in pixel |
sergionatan | 0:cf17b1f16335 | 284 | * - the number of byte per vertical line |
sergionatan | 0:cf17b1f16335 | 285 | * you also have to change the array to char[] |
sergionatan | 0:cf17b1f16335 | 286 | * |
sergionatan | 0:cf17b1f16335 | 287 | */ |
sergionatan | 0:cf17b1f16335 | 288 | void set_font(unsigned char* f); |
sergionatan | 0:cf17b1f16335 | 289 | |
sergionatan | 0:cf17b1f16335 | 290 | /** Set the orientation of the screen |
sergionatan | 0:cf17b1f16335 | 291 | * x,y: 0,0 is always top left |
sergionatan | 0:cf17b1f16335 | 292 | * |
sergionatan | 0:cf17b1f16335 | 293 | * @param o direction to use the screen (0-3) 90� Steps |
sergionatan | 0:cf17b1f16335 | 294 | * |
sergionatan | 0:cf17b1f16335 | 295 | */ |
sergionatan | 0:cf17b1f16335 | 296 | void set_orientation(unsigned int o); |
sergionatan | 0:cf17b1f16335 | 297 | |
sergionatan | 0:cf17b1f16335 | 298 | //SPI _spi; |
sergionatan | 0:cf17b1f16335 | 299 | BurstSPI _spi; |
sergionatan | 0:cf17b1f16335 | 300 | DigitalOut _cs; |
sergionatan | 0:cf17b1f16335 | 301 | DigitalOut _rs; |
sergionatan | 0:cf17b1f16335 | 302 | DigitalOut _reset; |
sergionatan | 0:cf17b1f16335 | 303 | unsigned char* font; |
sergionatan | 0:cf17b1f16335 | 304 | |
sergionatan | 0:cf17b1f16335 | 305 | //protected: |
sergionatan | 0:cf17b1f16335 | 306 | |
sergionatan | 0:cf17b1f16335 | 307 | /** draw a horizontal line |
sergionatan | 0:cf17b1f16335 | 308 | * |
sergionatan | 0:cf17b1f16335 | 309 | * @param x0 horizontal start |
sergionatan | 0:cf17b1f16335 | 310 | * @param x1 horizontal stop |
sergionatan | 0:cf17b1f16335 | 311 | * @param y vertical position |
sergionatan | 0:cf17b1f16335 | 312 | * @param color 16 bit color |
sergionatan | 0:cf17b1f16335 | 313 | * |
sergionatan | 0:cf17b1f16335 | 314 | */ |
sergionatan | 0:cf17b1f16335 | 315 | void hline(int x0, int x1, int y, int colour); |
sergionatan | 0:cf17b1f16335 | 316 | |
sergionatan | 0:cf17b1f16335 | 317 | /** draw a vertical line |
sergionatan | 0:cf17b1f16335 | 318 | * |
sergionatan | 0:cf17b1f16335 | 319 | * @param x horizontal position |
sergionatan | 0:cf17b1f16335 | 320 | * @param y0 vertical start |
sergionatan | 0:cf17b1f16335 | 321 | * @param y1 vertical stop |
sergionatan | 0:cf17b1f16335 | 322 | * @param color 16 bit color |
sergionatan | 0:cf17b1f16335 | 323 | */ |
sergionatan | 0:cf17b1f16335 | 324 | void vline(int y0, int y1, int x, int colour); |
sergionatan | 0:cf17b1f16335 | 325 | |
sergionatan | 0:cf17b1f16335 | 326 | /** Set draw window region |
sergionatan | 0:cf17b1f16335 | 327 | * |
sergionatan | 0:cf17b1f16335 | 328 | * @param x horizontal position |
sergionatan | 0:cf17b1f16335 | 329 | * @param y vertical position |
sergionatan | 0:cf17b1f16335 | 330 | * @param w window width in pixel |
sergionatan | 0:cf17b1f16335 | 331 | * @param h window height in pixels |
sergionatan | 0:cf17b1f16335 | 332 | */ |
sergionatan | 0:cf17b1f16335 | 333 | protected: |
sergionatan | 0:cf17b1f16335 | 334 | void window (unsigned int x, unsigned int y, unsigned int w, unsigned int h); |
sergionatan | 0:cf17b1f16335 | 335 | |
sergionatan | 0:cf17b1f16335 | 336 | /** Set draw window region to whole screen |
sergionatan | 0:cf17b1f16335 | 337 | * |
sergionatan | 0:cf17b1f16335 | 338 | */ |
sergionatan | 0:cf17b1f16335 | 339 | void WindowMax (void); |
sergionatan | 0:cf17b1f16335 | 340 | |
sergionatan | 0:cf17b1f16335 | 341 | /** Init the ST7735 controller |
sergionatan | 0:cf17b1f16335 | 342 | * |
sergionatan | 0:cf17b1f16335 | 343 | */ |
sergionatan | 0:cf17b1f16335 | 344 | |
sergionatan | 0:cf17b1f16335 | 345 | void tft_reset(); |
sergionatan | 0:cf17b1f16335 | 346 | |
sergionatan | 0:cf17b1f16335 | 347 | /** Write data to the LCD controller |
sergionatan | 0:cf17b1f16335 | 348 | * |
sergionatan | 0:cf17b1f16335 | 349 | * @param dat data written to LCD controller |
sergionatan | 0:cf17b1f16335 | 350 | * |
sergionatan | 0:cf17b1f16335 | 351 | */ |
sergionatan | 0:cf17b1f16335 | 352 | void wr_dat(int value); |
sergionatan | 0:cf17b1f16335 | 353 | |
sergionatan | 0:cf17b1f16335 | 354 | /** Write a command the LCD controller |
sergionatan | 0:cf17b1f16335 | 355 | * |
sergionatan | 0:cf17b1f16335 | 356 | * @param cmd: command to be written |
sergionatan | 0:cf17b1f16335 | 357 | * |
sergionatan | 0:cf17b1f16335 | 358 | */ |
sergionatan | 0:cf17b1f16335 | 359 | void wr_cmd(int value); |
sergionatan | 0:cf17b1f16335 | 360 | |
sergionatan | 0:cf17b1f16335 | 361 | /** Start data sequence to the LCD controller |
sergionatan | 0:cf17b1f16335 | 362 | * |
sergionatan | 0:cf17b1f16335 | 363 | */ |
sergionatan | 0:cf17b1f16335 | 364 | void wr_dat_start(); |
sergionatan | 0:cf17b1f16335 | 365 | |
sergionatan | 0:cf17b1f16335 | 366 | /** Stop of data writing to the LCD controller |
sergionatan | 0:cf17b1f16335 | 367 | * |
sergionatan | 0:cf17b1f16335 | 368 | */ |
sergionatan | 0:cf17b1f16335 | 369 | void wr_dat_stop(); |
sergionatan | 0:cf17b1f16335 | 370 | |
sergionatan | 0:cf17b1f16335 | 371 | /** write data to the LCD controller |
sergionatan | 0:cf17b1f16335 | 372 | * |
sergionatan | 0:cf17b1f16335 | 373 | * @param data to be written |
sergionatan | 0:cf17b1f16335 | 374 | * * |
sergionatan | 0:cf17b1f16335 | 375 | */ |
sergionatan | 0:cf17b1f16335 | 376 | void wr_dat_only(unsigned short dat); |
sergionatan | 0:cf17b1f16335 | 377 | |
sergionatan | 0:cf17b1f16335 | 378 | /** Read data from the LCD controller |
sergionatan | 0:cf17b1f16335 | 379 | * |
sergionatan | 0:cf17b1f16335 | 380 | * @returns data from LCD controller |
sergionatan | 0:cf17b1f16335 | 381 | * |
sergionatan | 0:cf17b1f16335 | 382 | */ |
sergionatan | 0:cf17b1f16335 | 383 | unsigned short rd_dat(void); |
sergionatan | 0:cf17b1f16335 | 384 | |
sergionatan | 0:cf17b1f16335 | 385 | /** Write a value to the to a LCD register |
sergionatan | 0:cf17b1f16335 | 386 | * |
sergionatan | 0:cf17b1f16335 | 387 | * @param reg register to be written |
sergionatan | 0:cf17b1f16335 | 388 | * @param val data to be written |
sergionatan | 0:cf17b1f16335 | 389 | */ |
sergionatan | 0:cf17b1f16335 | 390 | void wr_reg (unsigned char reg, unsigned short val); |
sergionatan | 0:cf17b1f16335 | 391 | |
sergionatan | 0:cf17b1f16335 | 392 | /** Read a LCD register |
sergionatan | 0:cf17b1f16335 | 393 | * |
sergionatan | 0:cf17b1f16335 | 394 | * @param reg register to be read |
sergionatan | 0:cf17b1f16335 | 395 | * @returns value of the register |
sergionatan | 0:cf17b1f16335 | 396 | */ |
sergionatan | 0:cf17b1f16335 | 397 | unsigned short rd_reg (unsigned char reg); |
sergionatan | 0:cf17b1f16335 | 398 | |
sergionatan | 0:cf17b1f16335 | 399 | unsigned int orientation; |
sergionatan | 0:cf17b1f16335 | 400 | unsigned int char_x; |
sergionatan | 0:cf17b1f16335 | 401 | unsigned int char_y; |
sergionatan | 0:cf17b1f16335 | 402 | }; |
sergionatan | 0:cf17b1f16335 | 403 | #endif |