Hexiwear specific mods for SSD1351
Fork of Adafruit_GFX_1351 by
Adafruit_SSD1351.h@19:ca4a631bfbd8, 2016-08-19 (annotated)
- Committer:
- whatnick
- Date:
- Fri Aug 19 02:22:03 2016 +0000
- Revision:
- 19:ca4a631bfbd8
- Parent:
- 17:0a4bb1070fd5
Better offsets for Hexi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lionello | 17:0a4bb1070fd5 | 1 | /*************************************************** |
lionello | 17:0a4bb1070fd5 | 2 | This is a library for the 1.5" & 1.27" 16-bit Color OLEDs |
lionello | 17:0a4bb1070fd5 | 3 | with SSD1331 driver chip |
lionello | 17:0a4bb1070fd5 | 4 | |
lionello | 17:0a4bb1070fd5 | 5 | Pick one up today in the adafruit shop! |
lionello | 17:0a4bb1070fd5 | 6 | ------> http://www.adafruit.com/products/1431 |
lionello | 17:0a4bb1070fd5 | 7 | ------> http://www.adafruit.com/products/1673 |
lionello | 17:0a4bb1070fd5 | 8 | |
lionello | 17:0a4bb1070fd5 | 9 | These displays use SPI to communicate, 4 or 5 pins are required to |
lionello | 17:0a4bb1070fd5 | 10 | interface |
lionello | 17:0a4bb1070fd5 | 11 | Adafruit invests time and resources providing this open source code, |
lionello | 17:0a4bb1070fd5 | 12 | please support Adafruit and open-source hardware by purchasing |
lionello | 17:0a4bb1070fd5 | 13 | products from Adafruit! |
lionello | 17:0a4bb1070fd5 | 14 | |
lionello | 17:0a4bb1070fd5 | 15 | Written by Limor Fried/Ladyada for Adafruit Industries. |
lionello | 17:0a4bb1070fd5 | 16 | BSD license, all text above must be included in any redistribution |
lionello | 17:0a4bb1070fd5 | 17 | ****************************************************/ |
lionello | 17:0a4bb1070fd5 | 18 | #pragma once |
lionello | 17:0a4bb1070fd5 | 19 | |
lionello | 17:0a4bb1070fd5 | 20 | #include <mbed.h> |
lionello | 17:0a4bb1070fd5 | 21 | |
lionello | 17:0a4bb1070fd5 | 22 | #include "Adafruit_GFX.h" |
lionello | 17:0a4bb1070fd5 | 23 | |
lionello | 17:0a4bb1070fd5 | 24 | #define swap(a, b) { uint16_t t = a; a = b; b = t; } |
lionello | 17:0a4bb1070fd5 | 25 | |
lionello | 17:0a4bb1070fd5 | 26 | #define SSD1351WIDTH 128 |
lionello | 17:0a4bb1070fd5 | 27 | #define SSD1351HEIGHT 128 // SET THIS TO 96 FOR 1.27"! |
lionello | 17:0a4bb1070fd5 | 28 | |
lionello | 17:0a4bb1070fd5 | 29 | // Select one of these defines to set the pixel color order |
lionello | 17:0a4bb1070fd5 | 30 | #define SSD1351_COLORORDER_RGB |
lionello | 17:0a4bb1070fd5 | 31 | // #define SSD1351_COLORORDER_BGR |
lionello | 17:0a4bb1070fd5 | 32 | |
lionello | 17:0a4bb1070fd5 | 33 | #if defined SSD1351_COLORORDER_RGB && defined SSD1351_COLORORDER_BGR |
lionello | 17:0a4bb1070fd5 | 34 | #error "RGB and BGR can not both be defined for SSD1351_COLORODER." |
lionello | 17:0a4bb1070fd5 | 35 | #endif |
lionello | 17:0a4bb1070fd5 | 36 | |
lionello | 17:0a4bb1070fd5 | 37 | // Timing Delays |
lionello | 17:0a4bb1070fd5 | 38 | #define SSD1351_DELAYS_HWFILL (3) |
lionello | 17:0a4bb1070fd5 | 39 | #define SSD1351_DELAYS_HWLINE (1) |
lionello | 17:0a4bb1070fd5 | 40 | |
lionello | 17:0a4bb1070fd5 | 41 | // SSD1351 Commands |
lionello | 17:0a4bb1070fd5 | 42 | #define SSD1351_CMD_SETCOLUMN 0x15 |
lionello | 17:0a4bb1070fd5 | 43 | #define SSD1351_CMD_SETROW 0x75 |
lionello | 17:0a4bb1070fd5 | 44 | #define SSD1351_CMD_WRITERAM 0x5C |
lionello | 17:0a4bb1070fd5 | 45 | #define SSD1351_CMD_READRAM 0x5D |
lionello | 17:0a4bb1070fd5 | 46 | #define SSD1351_CMD_SETREMAP 0xA0 |
lionello | 17:0a4bb1070fd5 | 47 | #define SSD1351_CMD_STARTLINE 0xA1 |
lionello | 17:0a4bb1070fd5 | 48 | #define SSD1351_CMD_DISPLAYOFFSET 0xA2 |
lionello | 17:0a4bb1070fd5 | 49 | #define SSD1351_CMD_DISPLAYALLOFF 0xA4 |
lionello | 17:0a4bb1070fd5 | 50 | #define SSD1351_CMD_DISPLAYALLON 0xA5 |
lionello | 17:0a4bb1070fd5 | 51 | #define SSD1351_CMD_NORMALDISPLAY 0xA6 |
lionello | 17:0a4bb1070fd5 | 52 | #define SSD1351_CMD_INVERTDISPLAY 0xA7 |
lionello | 17:0a4bb1070fd5 | 53 | #define SSD1351_CMD_FUNCTIONSELECT 0xAB |
lionello | 17:0a4bb1070fd5 | 54 | #define SSD1351_CMD_DISPLAYOFF 0xAE |
lionello | 17:0a4bb1070fd5 | 55 | #define SSD1351_CMD_DISPLAYON 0xAF |
lionello | 17:0a4bb1070fd5 | 56 | #define SSD1351_CMD_PRECHARGE 0xB1 |
lionello | 17:0a4bb1070fd5 | 57 | #define SSD1351_CMD_DISPLAYENHANCE 0xB2 |
lionello | 17:0a4bb1070fd5 | 58 | #define SSD1351_CMD_CLOCKDIV 0xB3 |
lionello | 17:0a4bb1070fd5 | 59 | #define SSD1351_CMD_SETVSL 0xB4 |
lionello | 17:0a4bb1070fd5 | 60 | #define SSD1351_CMD_SETGPIO 0xB5 |
lionello | 17:0a4bb1070fd5 | 61 | #define SSD1351_CMD_PRECHARGE2 0xB6 |
lionello | 17:0a4bb1070fd5 | 62 | #define SSD1351_CMD_SETGRAY 0xB8 |
lionello | 17:0a4bb1070fd5 | 63 | #define SSD1351_CMD_USELUT 0xB9 |
lionello | 17:0a4bb1070fd5 | 64 | #define SSD1351_CMD_PRECHARGELEVEL 0xBB |
lionello | 17:0a4bb1070fd5 | 65 | #define SSD1351_CMD_VCOMH 0xBE |
lionello | 17:0a4bb1070fd5 | 66 | #define SSD1351_CMD_CONTRASTABC 0xC1 |
lionello | 17:0a4bb1070fd5 | 67 | #define SSD1351_CMD_CONTRASTMASTER 0xC7 |
lionello | 17:0a4bb1070fd5 | 68 | #define SSD1351_CMD_MUXRATIO 0xCA |
lionello | 17:0a4bb1070fd5 | 69 | #define SSD1351_CMD_COMMANDLOCK 0xFD |
lionello | 17:0a4bb1070fd5 | 70 | #define SSD1351_CMD_HORIZSCROLL 0x96 |
lionello | 17:0a4bb1070fd5 | 71 | #define SSD1351_CMD_STOPSCROLL 0x9E |
lionello | 17:0a4bb1070fd5 | 72 | #define SSD1351_CMD_STARTSCROLL 0x9F |
lionello | 17:0a4bb1070fd5 | 73 | |
lionello | 17:0a4bb1070fd5 | 74 | |
lionello | 17:0a4bb1070fd5 | 75 | class Adafruit_SSD1351 : public virtual Adafruit_GFX |
lionello | 17:0a4bb1070fd5 | 76 | { |
lionello | 17:0a4bb1070fd5 | 77 | public: |
lionello | 17:0a4bb1070fd5 | 78 | Adafruit_SSD1351(PinName cs, PinName rs, PinName dc, PinName clk, PinName data); |
lionello | 17:0a4bb1070fd5 | 79 | |
lionello | 17:0a4bb1070fd5 | 80 | void on(); |
lionello | 17:0a4bb1070fd5 | 81 | void off(); |
lionello | 17:0a4bb1070fd5 | 82 | |
lionello | 17:0a4bb1070fd5 | 83 | uint16_t Color565(uint8_t r, uint8_t g, uint8_t b); |
lionello | 17:0a4bb1070fd5 | 84 | |
lionello | 17:0a4bb1070fd5 | 85 | // drawing primitives! |
lionello | 17:0a4bb1070fd5 | 86 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color); |
lionello | 17:0a4bb1070fd5 | 87 | void fillRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color); |
lionello | 17:0a4bb1070fd5 | 88 | void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); |
lionello | 17:0a4bb1070fd5 | 89 | void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); |
lionello | 17:0a4bb1070fd5 | 90 | void fillScreen(uint16_t fillcolor); |
lionello | 17:0a4bb1070fd5 | 91 | |
lionello | 17:0a4bb1070fd5 | 92 | void invert(bool); |
lionello | 17:0a4bb1070fd5 | 93 | // commands |
lionello | 17:0a4bb1070fd5 | 94 | void begin(void); |
lionello | 17:0a4bb1070fd5 | 95 | void goTo(int x, int y); |
lionello | 17:0a4bb1070fd5 | 96 | |
lionello | 17:0a4bb1070fd5 | 97 | void reset(void); |
lionello | 17:0a4bb1070fd5 | 98 | |
lionello | 17:0a4bb1070fd5 | 99 | /* low level */ |
lionello | 17:0a4bb1070fd5 | 100 | |
lionello | 17:0a4bb1070fd5 | 101 | void writeData(uint8_t d); |
lionello | 17:0a4bb1070fd5 | 102 | void writeCommand(uint8_t c); |
lionello | 17:0a4bb1070fd5 | 103 | |
lionello | 17:0a4bb1070fd5 | 104 | |
lionello | 17:0a4bb1070fd5 | 105 | void writeData_unsafe(uint16_t d); |
lionello | 17:0a4bb1070fd5 | 106 | |
lionello | 17:0a4bb1070fd5 | 107 | void setWriteDir(void); |
lionello | 17:0a4bb1070fd5 | 108 | void write8(uint8_t d); |
lionello | 17:0a4bb1070fd5 | 109 | |
lionello | 17:0a4bb1070fd5 | 110 | private: |
lionello | 17:0a4bb1070fd5 | 111 | SPI _spi; |
lionello | 17:0a4bb1070fd5 | 112 | DigitalOut _cs, _dc, _reset; |
lionello | 17:0a4bb1070fd5 | 113 | |
lionello | 17:0a4bb1070fd5 | 114 | void rawFillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor); |
lionello | 17:0a4bb1070fd5 | 115 | void rawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); |
lionello | 17:0a4bb1070fd5 | 116 | void rawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); |
lionello | 17:0a4bb1070fd5 | 117 | }; |