![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test st7735 on lpc1768 with mbed v5. bug with spi frequency...
ST7735/ST7735.h@2:2946f9eefcae, 2020-04-08 (annotated)
- Committer:
- skydarc
- Date:
- Wed Apr 08 15:00:13 2020 +0000
- Revision:
- 2:2946f9eefcae
v2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
skydarc | 2:2946f9eefcae | 1 | /*************************************************** |
skydarc | 2:2946f9eefcae | 2 | This is a library for the Adafruit 1.8" SPI display. |
skydarc | 2:2946f9eefcae | 3 | This library works with the Adafruit 1.8" TFT Breakout w/SD card |
skydarc | 2:2946f9eefcae | 4 | ----> http://www.adafruit.com/products/358 |
skydarc | 2:2946f9eefcae | 5 | as well as Adafruit raw 1.8" TFT display |
skydarc | 2:2946f9eefcae | 6 | ----> http://www.adafruit.com/products/618 |
skydarc | 2:2946f9eefcae | 7 | |
skydarc | 2:2946f9eefcae | 8 | Check out the links above for our tutorials and wiring diagrams |
skydarc | 2:2946f9eefcae | 9 | These displays use SPI to communicate, 4 or 5 pins are required to |
skydarc | 2:2946f9eefcae | 10 | interface (RST is optional) |
skydarc | 2:2946f9eefcae | 11 | Adafruit invests time and resources providing this open source code, |
skydarc | 2:2946f9eefcae | 12 | please support Adafruit and open-source hardware by purchasing |
skydarc | 2:2946f9eefcae | 13 | products from Adafruit! |
skydarc | 2:2946f9eefcae | 14 | |
skydarc | 2:2946f9eefcae | 15 | Written by Limor Fried/Ladyada for Adafruit Industries. |
skydarc | 2:2946f9eefcae | 16 | MIT license, all text above must be included in any redistribution |
skydarc | 2:2946f9eefcae | 17 | ****************************************************/ |
skydarc | 2:2946f9eefcae | 18 | |
skydarc | 2:2946f9eefcae | 19 | #ifndef _ADAFRUIT_ST7735H_ |
skydarc | 2:2946f9eefcae | 20 | #define _ADAFRUIT_ST7735H_ |
skydarc | 2:2946f9eefcae | 21 | |
skydarc | 2:2946f9eefcae | 22 | #include "mbed.h" |
skydarc | 2:2946f9eefcae | 23 | #include "GFX.h" |
skydarc | 2:2946f9eefcae | 24 | |
skydarc | 2:2946f9eefcae | 25 | #define boolean bool |
skydarc | 2:2946f9eefcae | 26 | |
skydarc | 2:2946f9eefcae | 27 | // some flags for initR() :( |
skydarc | 2:2946f9eefcae | 28 | // some flags for initR() :( |
skydarc | 2:2946f9eefcae | 29 | #define INITR_GREENTAB 0x0 |
skydarc | 2:2946f9eefcae | 30 | #define INITR_REDTAB 0x1 |
skydarc | 2:2946f9eefcae | 31 | #define INITR_BLACKTAB 0x2 |
skydarc | 2:2946f9eefcae | 32 | |
skydarc | 2:2946f9eefcae | 33 | #define INITR_18GREENTAB INITR_GREENTAB |
skydarc | 2:2946f9eefcae | 34 | #define INITR_18REDTAB INITR_REDTAB |
skydarc | 2:2946f9eefcae | 35 | #define INITR_18BLACKTAB INITR_BLACKTAB |
skydarc | 2:2946f9eefcae | 36 | #define INITR_144GREENTAB 0x1 |
skydarc | 2:2946f9eefcae | 37 | #define INITR_MINI160x80 0x4 |
skydarc | 2:2946f9eefcae | 38 | #define INITR_MINI160x80_RS 0x5 |
skydarc | 2:2946f9eefcae | 39 | // for 1.44 and mini |
skydarc | 2:2946f9eefcae | 40 | #define ST7735_TFTWIDTH_128 128 |
skydarc | 2:2946f9eefcae | 41 | // for mini |
skydarc | 2:2946f9eefcae | 42 | #define ST7735_TFTWIDTH_80 80 |
skydarc | 2:2946f9eefcae | 43 | // for 1.44" display |
skydarc | 2:2946f9eefcae | 44 | #define ST7735_TFTHEIGHT_128 128 |
skydarc | 2:2946f9eefcae | 45 | // for 1.8" and mini display |
skydarc | 2:2946f9eefcae | 46 | #define ST7735_TFTHEIGHT_160 161 |
skydarc | 2:2946f9eefcae | 47 | |
skydarc | 2:2946f9eefcae | 48 | #define ST7735_NOP 0x00 |
skydarc | 2:2946f9eefcae | 49 | #define ST7735_SWRESET 0x01 |
skydarc | 2:2946f9eefcae | 50 | #define ST7735_RDDID 0x04 |
skydarc | 2:2946f9eefcae | 51 | #define ST7735_RDDST 0x09 |
skydarc | 2:2946f9eefcae | 52 | |
skydarc | 2:2946f9eefcae | 53 | #define ST7735_SLPIN 0x10 |
skydarc | 2:2946f9eefcae | 54 | #define ST7735_SLPOUT 0x11 |
skydarc | 2:2946f9eefcae | 55 | #define ST7735_PTLON 0x12 |
skydarc | 2:2946f9eefcae | 56 | #define ST7735_NORON 0x13 |
skydarc | 2:2946f9eefcae | 57 | |
skydarc | 2:2946f9eefcae | 58 | #define ST7735_INVOFF 0x20 |
skydarc | 2:2946f9eefcae | 59 | #define ST7735_INVON 0x21 |
skydarc | 2:2946f9eefcae | 60 | #define ST7735_DISPOFF 0x28 |
skydarc | 2:2946f9eefcae | 61 | #define ST7735_DISPON 0x29 |
skydarc | 2:2946f9eefcae | 62 | #define ST7735_CASET 0x2A |
skydarc | 2:2946f9eefcae | 63 | #define ST7735_RASET 0x2B |
skydarc | 2:2946f9eefcae | 64 | #define ST7735_RAMWR 0x2C |
skydarc | 2:2946f9eefcae | 65 | #define ST7735_RAMRD 0x2E |
skydarc | 2:2946f9eefcae | 66 | |
skydarc | 2:2946f9eefcae | 67 | #define ST7735_PTLAR 0x30 |
skydarc | 2:2946f9eefcae | 68 | #define ST7735_VSCRDEF 0x33 |
skydarc | 2:2946f9eefcae | 69 | #define ST7735_COLMOD 0x3A |
skydarc | 2:2946f9eefcae | 70 | #define ST7735_MADCTL 0x36 |
skydarc | 2:2946f9eefcae | 71 | #define ST7735_VSCRSADD 0x37 |
skydarc | 2:2946f9eefcae | 72 | #define ST7735_FRMCTR1 0xB1 |
skydarc | 2:2946f9eefcae | 73 | #define ST7735_FRMCTR2 0xB2 |
skydarc | 2:2946f9eefcae | 74 | #define ST7735_FRMCTR3 0xB3 |
skydarc | 2:2946f9eefcae | 75 | #define ST7735_INVCTR 0xB4 |
skydarc | 2:2946f9eefcae | 76 | #define ST7735_DISSET5 0xB6 |
skydarc | 2:2946f9eefcae | 77 | |
skydarc | 2:2946f9eefcae | 78 | #define ST7735_PWCTR1 0xC0 |
skydarc | 2:2946f9eefcae | 79 | #define ST7735_PWCTR2 0xC1 |
skydarc | 2:2946f9eefcae | 80 | #define ST7735_PWCTR3 0xC2 |
skydarc | 2:2946f9eefcae | 81 | #define ST7735_PWCTR4 0xC3 |
skydarc | 2:2946f9eefcae | 82 | #define ST7735_PWCTR5 0xC4 |
skydarc | 2:2946f9eefcae | 83 | #define ST7735_VMCTR1 0xC5 |
skydarc | 2:2946f9eefcae | 84 | |
skydarc | 2:2946f9eefcae | 85 | #define ST7735_RDID1 0xDA |
skydarc | 2:2946f9eefcae | 86 | #define ST7735_RDID2 0xDB |
skydarc | 2:2946f9eefcae | 87 | #define ST7735_RDID3 0xDC |
skydarc | 2:2946f9eefcae | 88 | #define ST7735_RDID4 0xDD |
skydarc | 2:2946f9eefcae | 89 | |
skydarc | 2:2946f9eefcae | 90 | #define ST7735_PWCTR6 0xFC |
skydarc | 2:2946f9eefcae | 91 | |
skydarc | 2:2946f9eefcae | 92 | #define ST7735_GMCTRP1 0xE0 |
skydarc | 2:2946f9eefcae | 93 | #define ST7735_GMCTRN1 0xE1 |
skydarc | 2:2946f9eefcae | 94 | |
skydarc | 2:2946f9eefcae | 95 | // Color definitions |
skydarc | 2:2946f9eefcae | 96 | #define ST7735_BLACK 0x0000 |
skydarc | 2:2946f9eefcae | 97 | #define ST7735_BLUE 0x001F |
skydarc | 2:2946f9eefcae | 98 | #define ST7735_RED 0xF800 |
skydarc | 2:2946f9eefcae | 99 | #define ST7735_GREEN 0x07E0 |
skydarc | 2:2946f9eefcae | 100 | #define ST7735_CYAN 0x07FF |
skydarc | 2:2946f9eefcae | 101 | #define ST7735_MAGENTA 0xF81F |
skydarc | 2:2946f9eefcae | 102 | #define ST7735_YELLOW 0xFFE0 |
skydarc | 2:2946f9eefcae | 103 | #define ST7735_WHITE 0xFFFF |
skydarc | 2:2946f9eefcae | 104 | |
skydarc | 2:2946f9eefcae | 105 | // scroll definition |
skydarc | 2:2946f9eefcae | 106 | #define BOTTOM_TO_TOP 0 |
skydarc | 2:2946f9eefcae | 107 | #define TOP_TO_BOTTOM 1 |
skydarc | 2:2946f9eefcae | 108 | |
skydarc | 2:2946f9eefcae | 109 | |
skydarc | 2:2946f9eefcae | 110 | |
skydarc | 2:2946f9eefcae | 111 | typedef struct |
skydarc | 2:2946f9eefcae | 112 | { |
skydarc | 2:2946f9eefcae | 113 | float xpos, ypos; |
skydarc | 2:2946f9eefcae | 114 | short zpos, speed; |
skydarc | 2:2946f9eefcae | 115 | unsigned int color; |
skydarc | 2:2946f9eefcae | 116 | } STAR; |
skydarc | 2:2946f9eefcae | 117 | |
skydarc | 2:2946f9eefcae | 118 | class ST7735 : public GFX { |
skydarc | 2:2946f9eefcae | 119 | |
skydarc | 2:2946f9eefcae | 120 | public: |
skydarc | 2:2946f9eefcae | 121 | |
skydarc | 2:2946f9eefcae | 122 | ST7735(PinName mosi, PinName miso, PinName sck, PinName CS, PinName RS, PinName RST); |
skydarc | 2:2946f9eefcae | 123 | |
skydarc | 2:2946f9eefcae | 124 | void initB(void); // for ST7735B displays |
skydarc | 2:2946f9eefcae | 125 | void initR(uint8_t options = INITR_GREENTAB); // for ST7735R |
skydarc | 2:2946f9eefcae | 126 | void setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1); |
skydarc | 2:2946f9eefcae | 127 | void pushColor(uint16_t color); |
skydarc | 2:2946f9eefcae | 128 | |
skydarc | 2:2946f9eefcae | 129 | void fillScreen(uint16_t color); |
skydarc | 2:2946f9eefcae | 130 | void drawPixel(int16_t x, int16_t y, uint16_t color); |
skydarc | 2:2946f9eefcae | 131 | void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); |
skydarc | 2:2946f9eefcae | 132 | void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); |
skydarc | 2:2946f9eefcae | 133 | void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
skydarc | 2:2946f9eefcae | 134 | void invertDisplay(boolean i); |
skydarc | 2:2946f9eefcae | 135 | void DrawBMP(int offsetx, int offsety, FILE *Image); |
skydarc | 2:2946f9eefcae | 136 | void DrawRam(unsigned int x, unsigned int y, unsigned int w, unsigned int h, int *Image); |
skydarc | 2:2946f9eefcae | 137 | void DrawGIF(int offsetx, int offsety, FILE *Image); |
skydarc | 2:2946f9eefcae | 138 | void DrawANI(int offsetx, int offsety, FILE *Image, int frame); |
skydarc | 2:2946f9eefcae | 139 | void DrawStarfield(int centerx, int centery, int acc, int color, int NbrsStars, int duration); |
skydarc | 2:2946f9eefcae | 140 | void setRotation(uint8_t r); |
skydarc | 2:2946f9eefcae | 141 | void setScrollDefinition(uint8_t top_fix_height, uint8_t bottom_fix_height, int _scroll_direction); |
skydarc | 2:2946f9eefcae | 142 | void VerticalScroll(uint8_t _vsp); |
skydarc | 2:2946f9eefcae | 143 | void scrollBmp(uint8_t top_fix_height, uint8_t bottom_fix_height, int _scroll_direction, int *bitmap); |
skydarc | 2:2946f9eefcae | 144 | |
skydarc | 2:2946f9eefcae | 145 | uint16_t Color565(uint8_t r, uint8_t g, uint8_t b); |
skydarc | 2:2946f9eefcae | 146 | char* Color565string(uint8_t r, uint8_t g, uint8_t b); |
skydarc | 2:2946f9eefcae | 147 | |
skydarc | 2:2946f9eefcae | 148 | void read_area(unsigned int x, unsigned int y, unsigned int w, unsigned int h); |
skydarc | 2:2946f9eefcae | 149 | void setAddrWindow2(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1); |
skydarc | 2:2946f9eefcae | 150 | |
skydarc | 2:2946f9eefcae | 151 | private: |
skydarc | 2:2946f9eefcae | 152 | uint8_t tabcolor; |
skydarc | 2:2946f9eefcae | 153 | void spiwrite(uint8_t), |
skydarc | 2:2946f9eefcae | 154 | writecommand(uint8_t c), |
skydarc | 2:2946f9eefcae | 155 | writedata(uint8_t d), |
skydarc | 2:2946f9eefcae | 156 | commandList(uint8_t *addr), |
skydarc | 2:2946f9eefcae | 157 | commonInit(uint8_t *cmdList); |
skydarc | 2:2946f9eefcae | 158 | |
skydarc | 2:2946f9eefcae | 159 | uint8_t colstart, rowstart, xstart, ystart, _tft_type, _orientation; // some displays need this changed |
skydarc | 2:2946f9eefcae | 160 | |
skydarc | 2:2946f9eefcae | 161 | SPI lcdPort; // does SPI MOSI, MISO and SCK |
skydarc | 2:2946f9eefcae | 162 | DigitalOut _cs; // does SPI CE |
skydarc | 2:2946f9eefcae | 163 | DigitalOut _rs; // register/date select |
skydarc | 2:2946f9eefcae | 164 | DigitalOut _rst; // does 3310 LCD_RST |
skydarc | 2:2946f9eefcae | 165 | |
skydarc | 2:2946f9eefcae | 166 | |
skydarc | 2:2946f9eefcae | 167 | |
skydarc | 2:2946f9eefcae | 168 | |
skydarc | 2:2946f9eefcae | 169 | void init_star(STAR* star, int i); |
skydarc | 2:2946f9eefcae | 170 | |
skydarc | 2:2946f9eefcae | 171 | int oct2dec(int n); |
skydarc | 2:2946f9eefcae | 172 | int bitExtracted(int number, int k, int p) ; |
skydarc | 2:2946f9eefcae | 173 | |
skydarc | 2:2946f9eefcae | 174 | void makeTable(void); |
skydarc | 2:2946f9eefcae | 175 | uint16_t readTable(unsigned int y, unsigned int x); |
skydarc | 2:2946f9eefcae | 176 | void addrowTable(uint16_t *row); |
skydarc | 2:2946f9eefcae | 177 | void supprTable(void); |
skydarc | 2:2946f9eefcae | 178 | |
skydarc | 2:2946f9eefcae | 179 | }; |
skydarc | 2:2946f9eefcae | 180 | |
skydarc | 2:2946f9eefcae | 181 | |
skydarc | 2:2946f9eefcae | 182 | #endif |