A derived version of the BSD licensed Adafrut GFX library for the SSD1351 controller for an OLED 128x 96or 128x128 display using SPI
Fork of Adafruit_GFX by
You can print russian. (font edited).
class SPIPreInit : public SPI { public: SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) { format(8,3); frequency(25000000); }; }; SPIPreInit gSpi(PB_15,NC,PB_13); PinName mosi(sda), PinName miso, PinName clk(scl) Adafruit_SSD1351_Spi oled(gSpi,PB_14,PB_1,PB_2); PinName DC, PinName RST, PinName CS
Revision 17:56015e4834e6, committed 2016-02-24
- Comitter:
- Dzhafarkhanov
- Date:
- Wed Feb 24 12:24:42 2016 +0000
- Parent:
- 16:7fb1d4d3525d
- Commit message:
- SSD1351;
Changed in this revision
diff -r 7fb1d4d3525d -r 56015e4834e6 Adafruit_GFX.cpp --- a/Adafruit_GFX.cpp Tue Nov 11 22:08:20 2014 +0000 +++ b/Adafruit_GFX.cpp Wed Feb 24 12:24:42 2016 +0000 @@ -266,88 +266,79 @@ // fill a triangle! void Adafruit_GFX::fillTriangle ( int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) { - int16_t a, b, y, last; - - // Sort coordinates by Y order (y2 >= y1 >= y0) - if (y0 > y1) - swap(y0, y1); swap(x0, x1); + int16_t a, b, y, last; - if (y1 > y2) - swap(y2, y1); swap(x2, x1); - - if (y0 > y1) - swap(y0, y1); swap(x0, x1); + // Sort coordinates by Y order (y2 >= y1 >= y0) + if (y0 > y1) { + swap(y0, y1); swap(x0, x1); + } + if (y1 > y2) { + swap(y2, y1); swap(x2, x1); + } + if (y0 > y1) { + swap(y0, y1); swap(x0, x1); + } - - if(y0 == y2) - { // Handle awkward all-on-same-line case as its own thing - a = b = x0; - if(x1 < a) - a = x1; - else if(x1 > b) - b = x1; - - if(x2 < a) - a = x2; - else if(x2 > b) b = x2; - drawFastHLine(a, y0, b-a+1, color); - return; - } + if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing + a = b = x0; + if(x1 < a) a = x1; + else if(x1 > b) b = x1; + if(x2 < a) a = x2; + else if(x2 > b) b = x2; + drawFastHLine(a, y0, b-a+1, color); + return; + } - int16_t - dx01 = x1 - x0, - dy01 = y1 - y0, - dx02 = x2 - x0, - dy02 = y2 - y0, - dx12 = x2 - x1, - dy12 = y2 - y1, - sa = 0, - sb = 0; + int16_t + dx01 = x1 - x0, + dy01 = y1 - y0, + dx02 = x2 - x0, + dy02 = y2 - y0, + dx12 = x2 - x1, + dy12 = y2 - y1; + int32_t + sa = 0, + sb = 0; - // For upper part of triangle, find scanline crossings for segments - // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1 - // is included here (and second loop will be skipped, avoiding a /0 - // error there), otherwise scanline y1 is skipped here and handled - // in the second loop...which also avoids a /0 error here if y0=y1 - // (flat-topped triangle). - if(y1 == y2) - last = y1; // Include y1 scanline - else - last = y1-1; // Skip it + // For upper part of triangle, find scanline crossings for segments + // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1 + // is included here (and second loop will be skipped, avoiding a /0 + // error there), otherwise scanline y1 is skipped here and handled + // in the second loop...which also avoids a /0 error here if y0=y1 + // (flat-topped triangle). + if(y1 == y2) last = y1; // Include y1 scanline + else last = y1-1; // Skip it - for(y=y0; y<=last; y++) - { - a = x0 + sa / dy01; - b = x0 + sb / dy02; - sa += dx01; - sb += dx02; - /* longhand: - a = x0 + (x1 - x0) * (y - y0) / (y1 - y0); - b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); - */ - if(a > b) - swap(a,b); - drawFastHLine(a, y, b-a+1, color); - } + for(y=y0; y<=last; y++) { + a = x0 + sa / dy01; + b = x0 + sb / dy02; + sa += dx01; + sb += dx02; + /* longhand: + a = x0 + (x1 - x0) * (y - y0) / (y1 - y0); + b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); + */ + if(a > b) swap(a,b); + drawFastHLine(a, y, b-a+1, color); + } - // For lower part of triangle, find scanline crossings for segments - // 0-2 and 1-2. This loop is skipped if y1=y2. - sa = dx12 * (y - y1); - sb = dx02 * (y - y0); - for(; y<=y2; y++) - { - a = x1 + sa / dy12; - b = x0 + sb / dy02; - sa += dx12; - sb += dx02; - /* longhand: - a = x1 + (x2 - x1) * (y - y1) / (y2 - y1); - b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); - */ - if(a > b) - swap(a,b); - drawFastHLine(a, y, b-a+1, color); - } + // For lower part of triangle, find scanline crossings for segments + // 0-2 and 1-2. This loop is skipped if y1=y2. + sa = dx12 * (y - y1); + sb = dx02 * (y - y0); + for(; y<=y2; y++) { + a = x1 + sa / dy12; + b = x0 + sb / dy02; + sa += dx12; + sb += dx02; + /* longhand: + a = x1 + (x2 - x1) * (y - y1) / (y2 - y1); + b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); + */ + if(a > b) swap(a,b); + drawFastHLine(a, y, b-a+1, color); + } + } void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) @@ -365,6 +356,8 @@ size_t Adafruit_GFX::writeChar(uint8_t c) { + if (( c == 0xD0 ) || ( c == 0xD1 )){ // Проверяем на соответствие utf8 и игнорируем если это начальный символ UTF8. + return;} if (c == '\n') { cursor_y += textsize*8; @@ -388,6 +381,8 @@ // draw a character void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size) { + if (( c == 0xD0 ) || ( c == 0xD1 )){ // Проверяем на соответствие utf8 и игнорируем если это начальный символ UTF8. + return;} if( (x >= _width) || // Clip right (y >= _height) || // Clip bottom
diff -r 7fb1d4d3525d -r 56015e4834e6 Adafruit_GFX.h --- a/Adafruit_GFX.h Tue Nov 11 22:08:20 2014 +0000 +++ b/Adafruit_GFX.h Wed Feb 24 12:24:42 2016 +0000 @@ -34,17 +34,11 @@ #define _BV(bit) (1<<(bit)) #endif -#define BLACK 0 -#define WHITE 1 - /** * This is a Text and Graphics element drawing class. * These functions draw to the display buffer. * - * Display drivers should be derived from here. - * The Display drivers push the display buffer to the - * hardware based on application control. - * + */ class Adafruit_GFX : public Stream { @@ -56,8 +50,8 @@ , _height(h) , cursor_x(0) , cursor_y(0) - , textcolor(WHITE) - , textbgcolor(BLACK) + , textcolor(0xFFFF) + , textbgcolor(0xFFFF) , textsize(1) , rotation(0) , wrap(true)
diff -r 7fb1d4d3525d -r 56015e4834e6 Adafruit_GFX_Config.h --- a/Adafruit_GFX_Config.h Tue Nov 11 22:08:20 2014 +0000 +++ b/Adafruit_GFX_Config.h Wed Feb 24 12:24:42 2016 +0000 @@ -1,11 +1,10 @@ #ifndef _ADAFRUIT_GFX_CONFIG_H_ #define _ADAFRUIT_GFX_CONFIG_H_ -// Uncomment this to turn off the builtin splash -//#define NO_SPLASH_ADAFRUIT + // Uncomment this to enable all functionality -//#define GFX_WANT_ABSTRACTS +#define GFX_WANT_ABSTRACTS // Uncomment this to enable only runtime font scaling, without all the rest of the Abstracts //#define GFX_SIZEABLE_TEXT
diff -r 7fb1d4d3525d -r 56015e4834e6 Adafruit_SSD1306.cpp --- a/Adafruit_SSD1306.cpp Tue Nov 11 22:08:20 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,230 +0,0 @@ -/********************************************************************* -This is a library for our Monochrome OLEDs based on SSD1306 drivers - - Pick one up today in the adafruit shop! - ------> http://www.adafruit.com/category/63_98 - -These displays use SPI to communicate, 4 or 5 pins are required to -interface - -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Written by Limor Fried/Ladyada for Adafruit Industries. -BSD license, check license.txt for more information -All text above, and the splash screen below must be included in any redistribution -*********************************************************************/ - -/* - * Modified by Neal Horman 7/14/2012 for use in mbed - */ - -#include "mbed.h" -#include "Adafruit_SSD1306.h" - -#define SSD1306_SETCONTRAST 0x81 -#define SSD1306_DISPLAYALLON_RESUME 0xA4 -#define SSD1306_DISPLAYALLON 0xA5 -#define SSD1306_NORMALDISPLAY 0xA6 -#define SSD1306_INVERTDISPLAY 0xA7 -#define SSD1306_DISPLAYOFF 0xAE -#define SSD1306_DISPLAYON 0xAF -#define SSD1306_SETDISPLAYOFFSET 0xD3 -#define SSD1306_SETCOMPINS 0xDA -#define SSD1306_SETVCOMDETECT 0xDB -#define SSD1306_SETDISPLAYCLOCKDIV 0xD5 -#define SSD1306_SETPRECHARGE 0xD9 -#define SSD1306_SETMULTIPLEX 0xA8 -#define SSD1306_SETLOWCOLUMN 0x00 -#define SSD1306_SETHIGHCOLUMN 0x10 -#define SSD1306_SETSTARTLINE 0x40 -#define SSD1306_MEMORYMODE 0x20 -#define SSD1306_COMSCANINC 0xC0 -#define SSD1306_COMSCANDEC 0xC8 -#define SSD1306_SEGREMAP 0xA0 -#define SSD1306_CHARGEPUMP 0x8D - -void Adafruit_SSD1306::begin(uint8_t vccstate) -{ - rst = 1; - // VDD (3.3V) goes high at start, lets just chill for a ms - wait_ms(1); - // bring reset low - rst = 0; - // wait 10ms - wait_ms(10); - // bring out of reset - rst = 1; - // turn on VCC (9V?) - - command(SSD1306_DISPLAYOFF); - command(SSD1306_SETDISPLAYCLOCKDIV); - command(0x80); // the suggested ratio 0x80 - - command(SSD1306_SETMULTIPLEX); - command(_rawHeight-1); - - command(SSD1306_SETDISPLAYOFFSET); - command(0x0); // no offset - - command(SSD1306_SETSTARTLINE | 0x0); // line #0 - - command(SSD1306_CHARGEPUMP); - command((vccstate == SSD1306_EXTERNALVCC) ? 0x10 : 0x14); - - command(SSD1306_MEMORYMODE); - command(0x00); // 0x0 act like ks0108 - - command(SSD1306_SEGREMAP | 0x1); - - command(SSD1306_COMSCANDEC); - - command(SSD1306_SETCOMPINS); - command(_rawHeight == 32 ? 0x02 : 0x12); // TODO - calculate based on _rawHieght ? - - command(SSD1306_SETCONTRAST); - command(_rawHeight == 32 ? 0x8F : ((vccstate == SSD1306_EXTERNALVCC) ? 0x9F : 0xCF) ); - - command(SSD1306_SETPRECHARGE); - command((vccstate == SSD1306_EXTERNALVCC) ? 0x22 : 0xF1); - - command(SSD1306_SETVCOMDETECT); - command(0x40); - - command(SSD1306_DISPLAYALLON_RESUME); - - command(SSD1306_NORMALDISPLAY); - - command(SSD1306_DISPLAYON); -} - -// Set a single pixel -void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) -{ - if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) - return; - - // check rotation, move pixel around if necessary - switch (getRotation()) - { - case 1: - swap(x, y); - x = _rawWidth - x - 1; - break; - case 2: - x = _rawWidth - x - 1; - y = _rawHeight - y - 1; - break; - case 3: - swap(x, y); - y = _rawHeight - y - 1; - break; - } - - // x is which column - if (color == WHITE) - buffer[x+ (y/8)*_rawWidth] |= _BV((y%8)); - else // else black - buffer[x+ (y/8)*_rawWidth] &= ~_BV((y%8)); -} - -void Adafruit_SSD1306::invertDisplay(bool i) -{ - command(i ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY); -} - -// Send the display buffer out to the display -void Adafruit_SSD1306::display(void) -{ - command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 - command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0 - command(SSD1306_SETSTARTLINE | 0x0); // line #0 - sendDisplayBuffer(); -} - -// Clear the display buffer. Requires a display() call at some point afterwards -void Adafruit_SSD1306::clearDisplay(void) -{ - std::fill(buffer.begin(),buffer.end(),0); -} - -void Adafruit_SSD1306::splash(void) -{ -#ifndef NO_SPLASH_ADAFRUIT - uint8_t adaFruitLogo[64 * 128 / 8] = - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, - 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF, - 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, - 0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8, - 0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, - 0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01, - 0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF, - 0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00, - 0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF, - 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF, - 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F, - 0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, - 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, - 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00, - 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03, - 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // 128x32^^^ 128x64vvv - 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F, - 0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F, - 0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, - 0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E, - 0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC, - 0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06, - 0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8, - 0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, - 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C, - 0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, - 0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, - 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07, - 0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - - std::copy( - &adaFruitLogo[0] - , &adaFruitLogo[0] + (_rawHeight == 32 ? sizeof(adaFruitLogo)/2 : sizeof(adaFruitLogo)) - , buffer.begin() - ); -#endif -}
diff -r 7fb1d4d3525d -r 56015e4834e6 Adafruit_SSD1306.h --- a/Adafruit_SSD1306.h Tue Nov 11 22:08:20 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,220 +0,0 @@ -/********************************************************************* -This is a library for our Monochrome OLEDs based on SSD1306 drivers - - Pick one up today in the adafruit shop! - ------> http://www.adafruit.com/category/63_98 - -These displays use SPI to communicate, 4 or 5 pins are required to -interface - -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Written by Limor Fried/Ladyada for Adafruit Industries. -BSD license, check license.txt for more information -All text above, and the splash screen must be included in any redistribution -*********************************************************************/ - -/* - * Modified by Neal Horman 7/14/2012 for use in mbed - */ - -#ifndef _ADAFRUIT_SSD1306_H_ -#define _ADAFRUIT_SSD1306_H_ - -#include "mbed.h" -#include "Adafruit_GFX.h" - -#include <vector> -#include <algorithm> - -// A DigitalOut sub-class that provides a constructed default state -class DigitalOut2 : public DigitalOut -{ -public: - DigitalOut2(PinName pin, bool active = false) : DigitalOut(pin) { write(active); }; - DigitalOut2& operator= (int value) { write(value); return *this; }; - DigitalOut2& operator= (DigitalOut2& rhs) { write(rhs.read()); return *this; }; - operator int() { return read(); }; -}; - -#define SSD1306_EXTERNALVCC 0x1 -#define SSD1306_SWITCHCAPVCC 0x2 - -/** The pure base class for the SSD1306 display driver. - * - * You should derive from this for a new transport interface type, - * such as the SPI and I2C drivers. - */ -class Adafruit_SSD1306 : public Adafruit_GFX -{ -public: - Adafruit_SSD1306(PinName RST, uint8_t rawHeight = 32, uint8_t rawWidth = 128) - : Adafruit_GFX(rawWidth,rawHeight) - , rst(RST,false) - { - buffer.resize(rawHeight * rawWidth / 8); - }; - - void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC); - - // These must be implemented in the derived transport driver - virtual void command(uint8_t c) = 0; - virtual void data(uint8_t c) = 0; - virtual void drawPixel(int16_t x, int16_t y, uint16_t color); - - /// Clear the display buffer - void clearDisplay(void); - virtual void invertDisplay(bool i); - - /// Cause the display to be updated with the buffer content. - void display(); - /// Fill the buffer with the AdaFruit splash screen. - virtual void splash(); - -protected: - virtual void sendDisplayBuffer() = 0; - DigitalOut2 rst; - - // the memory buffer for the LCD - std::vector<uint8_t> buffer; -}; - - -/** This is the SPI SSD1306 display driver transport class - * - */ -class Adafruit_SSD1306_Spi : public Adafruit_SSD1306 -{ -public: - /** Create a SSD1306 SPI transport display driver instance with the specified DC, RST, and CS pins, as well as the display dimentions - * - * Required parameters - * @param spi - a reference to an initialized SPI object - * @param DC (Data/Command) pin name - * @param RST (Reset) pin name - * @param CS (Chip Select) pin name - * - * Optional parameters - * @param rawHeight - the vertical number of pixels for the display, defaults to 32 - * @param rawWidth - the horizonal number of pixels for the display, defaults to 128 - */ - Adafruit_SSD1306_Spi(SPI &spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght = 32, uint8_t rawWidth = 128) - : Adafruit_SSD1306(RST, rawHieght, rawWidth) - , cs(CS,true) - , dc(DC,false) - , mspi(spi) - { - begin(); - splash(); - display(); - }; - - virtual void command(uint8_t c) - { - cs = 1; - dc = 0; - cs = 0; - mspi.write(c); - cs = 1; - }; - - virtual void data(uint8_t c) - { - cs = 1; - dc = 1; - cs = 0; - mspi.write(c); - cs = 1; - }; - -protected: - virtual void sendDisplayBuffer() - { - cs = 1; - dc = 1; - cs = 0; - - for(uint16_t i=0, q=buffer.size(); i<q; i++) - mspi.write(buffer[i]); - - if(height() == 32) - { - for(uint16_t i=0, q=buffer.size(); i<q; i++) - mspi.write(0); - } - - cs = 1; - }; - - DigitalOut2 cs, dc; - SPI &mspi; -}; - -/** This is the I2C SSD1306 display driver transport class - * - */ -class Adafruit_SSD1306_I2c : public Adafruit_SSD1306 -{ -public: - #define SSD_I2C_ADDRESS 0x78 - /** Create a SSD1306 I2C transport display driver instance with the specified RST pin name, the I2C address, as well as the display dimensions - * - * Required parameters - * @param i2c - A reference to an initialized I2C object - * @param RST - The Reset pin name - * - * Optional parameters - * @param i2cAddress - The i2c address of the display - * @param rawHeight - The vertical number of pixels for the display, defaults to 32 - * @param rawWidth - The horizonal number of pixels for the display, defaults to 128 - */ - Adafruit_SSD1306_I2c(I2C &i2c, PinName RST, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 32, uint8_t rawWidth = 128) - : Adafruit_SSD1306(RST, rawHeight, rawWidth) - , mi2c(i2c) - , mi2cAddress(i2cAddress) - { - begin(); - splash(); - display(); - }; - - virtual void command(uint8_t c) - { - char buff[2]; - buff[0] = 0; // Command Mode - buff[1] = c; - mi2c.write(mi2cAddress, buff, sizeof(buff)); - } - - virtual void data(uint8_t c) - { - char buff[2]; - buff[0] = 0x40; // Data Mode - buff[1] = c; - mi2c.write(mi2cAddress, buff, sizeof(buff)); - }; - -protected: - virtual void sendDisplayBuffer() - { - char buff[17]; - buff[0] = 0x40; // Data Mode - - // send display buffer in 16 byte chunks - for(uint16_t i=0, q=buffer.size(); i<q; i+=16 ) - { uint8_t x ; - - // TODO - this will segfault if buffer.size() % 16 != 0 - for(x=1; x<sizeof(buff); x++) - buff[x] = buffer[i+x-1]; - mi2c.write(mi2cAddress, buff, sizeof(buff)); - } - }; - - I2C &mi2c; - uint8_t mi2cAddress; -}; - -#endif \ No newline at end of file
diff -r 7fb1d4d3525d -r 56015e4834e6 Adafruit_SSD1351.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Adafruit_SSD1351.cpp Wed Feb 24 12:24:42 2016 +0000 @@ -0,0 +1,431 @@ +/********************************************************************* +This is a library for our Monochrome OLEDs based on SSD1351 drivers + + Pick one up today in the adafruit shop! + ------> http://www.adafruit.com/category/63_98 + +These displays use SPI to communicate, 4 or 5 pins are required to +interface + +Adafruit invests time and resources providing this open source code, +please support Adafruit and open-source hardware by purchasing +products from Adafruit! + +Written by Limor Fried/Ladyada for Adafruit Industries. +BSD license, check license.txt for more information +All text above, and the splash screen below must be included in any redistribution +*********************************************************************/ + +/* + * Modified by Neal Horman 7/14/2012 for use in mbed + */ + +#include "mbed.h" +#include "Adafruit_SSD1351.h" + +#ifndef _BV +#define _BV(bit) (1<<(bit)) +#endif + + +#define SSD1351_COLORORDER_BGR + + + + +// Timing Delays +#define SSD1351_DELAYS_HWFILL (3) +#define SSD1351_DELAYS_HWLINE (1) + +//old +#define SSD1351_SETHIGHCOLUMN 0x10 + +// SSD1351 Commands +#define SSD1351_CMD_SETCOLUMN 0x15 +#define SSD1351_CMD_SETROW 0x75 +#define SSD1351_CMD_WRITERAM 0x5C +#define SSD1351_CMD_READRAM 0x5D +#define SSD1351_CMD_SETREMAP 0xA0 +#define SSD1351_CMD_STARTLINE 0xA1 //Set display start line +#define SSD1351_CMD_DISPLAYOFFSET 0xA2 +#define SSD1351_CMD_DISPLAYALLOFF 0xA4 +#define SSD1351_CMD_DISPLAYALLON 0xA5 +#define SSD1351_CMD_NORMALDISPLAY 0xA6 +#define SSD1351_CMD_INVERTDISPLAY 0xA7 +#define SSD1351_CMD_FUNCTIONSELECT 0xAB +#define SSD1351_CMD_DISPLAYOFF 0xAE +#define SSD1351_CMD_DISPLAYON 0xAF +#define SSD1351_CMD_PRECHARGE 0xB1 +#define SSD1351_CMD_DISPLAYENHANCE 0xB2 +#define SSD1351_CMD_CLOCKDIV 0xB3 +#define SSD1351_CMD_SETVSL 0xB4 +#define SSD1351_CMD_SETGPIO 0xB5 +#define SSD1351_CMD_PRECHARGE2 0xB6 +#define SSD1351_CMD_SETGRAY 0xB8 +#define SSD1351_CMD_USELUT 0xB9 +#define SSD1351_CMD_PRECHARGELEVEL 0xBB +#define SSD1351_CMD_VCOMH 0xBE +#define SSD1351_CMD_CONTRASTABC 0xC1 +#define SSD1351_CMD_CONTRASTMASTER 0xC7 +#define SSD1351_CMD_MUXRATIO 0xCA +#define SSD1351_CMD_COMMANDLOCK 0xFD +#define SSD1351_CMD_HORIZSCROLL 0x96 +#define SSD1351_CMD_STOPSCROLL 0x9E +#define SSD1351_CMD_STARTSCROLL 0x9F + + + + +void Adafruit_SSD1351::begin(void)//oled init +{ + rst = 1; + // VDD (3.3V) goes high at start, lets just chill for a ms + wait_ms(10); + // bring reset low + rst = 0; + // wait 10ms + wait_ms(10); + // bring out of reset + rst = 1; + // turn on VCC (13V?) + wait_ms(10); + + + // Initialization Sequence + writeCommand(SSD1351_CMD_COMMANDLOCK); // set command lock + writeData(0x12); + writeCommand(SSD1351_CMD_COMMANDLOCK); // set command lock + writeData(0xB1); + + writeCommand(SSD1351_CMD_DISPLAYOFF); // 0xAE + + writeCommand(SSD1351_CMD_CLOCKDIV); // 0xB3 + writeCommand(0xF1); // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16) + + writeCommand(SSD1351_CMD_MUXRATIO); + writeData(127); + + writeCommand(SSD1351_CMD_SETREMAP); + writeData(0x74); + + writeCommand(SSD1351_CMD_SETCOLUMN); + writeData(0x00); + writeData(0x7F); + writeCommand(SSD1351_CMD_SETROW); + writeData(0x00); + writeData(0x7F); + + writeCommand(SSD1351_CMD_STARTLINE); // 0xA1 + + if (height() == 96) { + writeData(96); + } else { + writeData(0); + } + + writeCommand(SSD1351_CMD_DISPLAYOFFSET); // 0xA2 + writeData(0x00); + + writeCommand(SSD1351_CMD_SETGPIO); + writeData(0x00); + + writeCommand(SSD1351_CMD_FUNCTIONSELECT); + writeData(0x01); // internal (diode drop) + //writeData(0x01); // external bias + +// writeCommand(SSSD1351_CMD_SETPHASELENGTH); +// writeData(0x32); + + writeCommand(SSD1351_CMD_PRECHARGE); // 0xB1 + writeCommand(0x32); + + writeCommand(SSD1351_CMD_VCOMH); // 0xBE + writeCommand(0x05); + + writeCommand(SSD1351_CMD_NORMALDISPLAY); // 0xA6 + + writeCommand(SSD1351_CMD_CONTRASTABC); + writeData(0xC8); //0x8A //0xC8) + writeData(0x80);//0x51 //0x80 + writeData(0xC8);// 0x8A //0xC8 + + writeCommand(SSD1351_CMD_CONTRASTMASTER); + writeData(0x0F); + + writeCommand(SSD1351_CMD_SETVSL ); + writeData(0xA0); + writeData(0xB5); + writeData(0x55); + + writeCommand(SSD1351_CMD_PRECHARGE2); + writeData(0x01); + + writeCommand(SSD1351_CMD_DISPLAYON); //--turn on oled panel +} + +void Adafruit_SSD1351::invert(bool v) { + if (v) { + writeCommand(SSD1351_CMD_INVERTDISPLAY); + } else { + writeCommand(SSD1351_CMD_NORMALDISPLAY); + } + } + +void Adafruit_SSD1351::goTo(int x, int y) { + if ((x >= width()) || (y >= height())) return; + + // set x and y coordinate + writeCommand(SSD1351_CMD_SETCOLUMN); + writeData(x); + writeData(width()-1); + + writeCommand(SSD1351_CMD_SETROW); + writeData(y); + writeData(height()-1); + writeCommand(SSD1351_CMD_WRITERAM); +} + +uint16_t Adafruit_SSD1351::Color565(uint8_t r, uint8_t g, uint8_t b) { + uint16_t c; + c = r >> 3; + c <<= 6; + c |= g >> 2; + c <<= 5; + c |= b >> 3; + + return c; +} + +void Adafruit_SSD1351::fillScreen(uint16_t fillcolor) { + fillRect(0, 0, width(), height(), fillcolor); +} + +// Draw a filled rectangle with no rotation. +void Adafruit_SSD1351::rawFillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor) { + // Bounds check + if ((x >= width()) || (y >= height())) + return; + + // Y bounds check + if (y+h > height()) + { + h = height() - y - 1; + } + + // X bounds check + if (x+w > width()) + { + w = width() - x - 1; + } + + /* + Serial.print(x); Serial.print(", "); + Serial.print(y); Serial.print(", "); + Serial.print(w); Serial.print(", "); + Serial.print(h); Serial.println(", "); +*/ + + // set location + writeCommand(SSD1351_CMD_SETCOLUMN); + writeData(x); + writeData(x+w-1); + writeCommand(SSD1351_CMD_SETROW); + writeData(y); + writeData(y+h-1); + // fill! + writeCommand(SSD1351_CMD_WRITERAM); + + for (uint16_t i=0; i < w*h; i++) { + writeData(fillcolor >> 8); + writeData(fillcolor); + } +} + + +void Adafruit_SSD1351::fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor) { + // Transform x and y based on current rotation. + switch (getRotation()) { + case 0: // No rotation + rawFillRect(x, y, w, h, fillcolor); + break; + case 1: // Rotated 90 degrees clockwise. + swap(x, y); + x = _rawWidth - x - h; + rawFillRect(x, y, h, w, fillcolor); + break; + case 2: // Rotated 180 degrees clockwise. + x = _rawWidth - x - w; + y = _rawHeight - y - h; + rawFillRect(x, y, w, h, fillcolor); + break; + case 3: // Rotated 270 degrees clockwise. + swap(x, y); + y = _rawHeight - y - w; + rawFillRect(x, y, h, w, fillcolor); + break; + } +} + +// Draw a horizontal line ignoring any screen rotation. +void Adafruit_SSD1351::rawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { + // Bounds check + if ((x >= width()) || (y >= height())) + return; + + // X bounds check + if (x+w > width()) + { + w = width() - x - 1; + } + + if (w < 0) return; + + // set location + writeCommand(SSD1351_CMD_SETCOLUMN); + writeData(x); + writeData(x+w-1); + writeCommand(SSD1351_CMD_SETROW); + writeData(y); + writeData(y); + // fill! + writeCommand(SSD1351_CMD_WRITERAM); + + for (uint16_t i=0; i < w; i++) { + writeData(color >> 8); + writeData(color); + } +} + +// Draw a vertical line ignoring any screen rotation. +void Adafruit_SSD1351::rawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { + // Bounds check + if ((x >= width()) || (y >= height())) + return; + + // X bounds check + if (y+h > height()) + { + h = height() - y - 1; + } + + if (h < 0) return; + + // set location + writeCommand(SSD1351_CMD_SETCOLUMN); + writeData(x); + writeData(x); + writeCommand(SSD1351_CMD_SETROW); + writeData(y); + writeData(y+h-1); + // fill! + writeCommand(SSD1351_CMD_WRITERAM); + + for (uint16_t i=0; i < h; i++) { + writeData(color >> 8); + writeData(color); + } +} + +void Adafruit_SSD1351::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { + // Transform x and y based on current rotation. + switch (getRotation()) { + case 0: // No rotation + rawFastVLine(x, y, h, color); + break; + case 1: // Rotated 90 degrees clockwise. + swap(x, y); + x = _rawWidth - x - h; + rawFastHLine(x, y, h, color); + break; + case 2: // Rotated 180 degrees clockwise. + x = _rawWidth - x - 1; + y = _rawHeight - y - h; + rawFastVLine(x, y, h, color); + break; + case 3: // Rotated 270 degrees clockwise. + swap(x, y); + y = _rawHeight - y - 1; + rawFastHLine(x, y, h, color); + break; + } +} + +void Adafruit_SSD1351::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { + // Transform x and y based on current rotation. + switch (getRotation()) { + case 0: // No rotation. + rawFastHLine(x, y, w, color); + break; + case 1: // Rotated 90 degrees clockwise. + swap(x, y); + x = _rawWidth - x - 1; + rawFastVLine(x, y, w, color); + break; + case 2: // Rotated 180 degrees clockwise. + x = _rawWidth - x - w; + y = _rawHeight - y - 1; + rawFastHLine(x, y, w, color); + break; + case 3: // Rotated 270 degrees clockwise. + swap(x, y); + y = _rawHeight - y - w; + rawFastVLine(x, y, w, color); + break; + } +} + + +void Adafruit_SSD1351::setContrastControl(uint8_t contrast) { + + writeCommand(SSD1351_CMD_CONTRASTMASTER); + //writeData(0x0F); + writeData(contrast); + +} + + + + + + +// Set a single pixel +void Adafruit_SSD1351::drawPixel(int16_t x, int16_t y, uint16_t color) +{ + if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) // Bounds check. + return; + + // check rotation, move pixel around if necessary + switch (getRotation()) + { + case 1: // Rotated 90 degrees clockwise. + swap(x, y); + x = _rawWidth - x - 1; + break; + case 2: // Rotated 180 degrees clockwise. + x = _rawWidth - x - 1; + y = _rawHeight - y - 1; + break; + case 3: // Rotated 270 degrees clockwise. + swap(x, y); + y = _rawHeight - y - 1; + break; + } + +{ + + } + + goTo(x, y); + writeData(color >> 8) ; + writeData(color); + +} + + + + + + + + +
diff -r 7fb1d4d3525d -r 56015e4834e6 Adafruit_SSD1351.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Adafruit_SSD1351.h Wed Feb 24 12:24:42 2016 +0000 @@ -0,0 +1,174 @@ +/*************************************************** + This is a library for the 1.5" & 1.27" 16-bit Color OLEDs + with SSD1331 driver chip + + Pick one up today in the adafruit shop! + ------> http://www.adafruit.com/products/1431 + ------> http://www.adafruit.com/products/1673 + + These displays use SPI to communicate, 4 or 5 pins are required to + interface + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried/Ladyada for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ + + + +//#ifndef _ADAFRUIT_SSD1351_H_ +//#define _ADAFRUIT_SSD1351_H_ + +#include "mbed.h" +#include "Adafruit_GFX.h" + +#include <vector> +#include <algorithm> + + + + + + +/* some 16bit RGB color definitions */ +enum Color{ + Black = 0x0000, /* 0, 0, 0 */ + Navy = 0x000F, /* 0, 0, 128 */ + DarkGreen = 0x03E0, /* 0, 128, 0 */ + DarkCyan = 0x03EF, /* 0, 128, 128 */ + Maroon = 0x7800, /* 128, 0, 0 */ + Purple = 0x780F, /* 128, 0, 128 */ + Olive = 0x7BE0, /* 128, 128, 0 */ + LightGrey = 0xC618, /* 192, 192, 192 */ + DarkGrey = 0x7BEF, /* 128, 128, 128 */ + Blue = 0x001F, /* 0, 0, 255 */ + Green = 0x07E0, /* 0, 255, 0 */ + Cyan = 0x07FF, /* 0, 255, 255 */ + Red = 0xF800, /* 255, 0, 0 */ + Magenta = 0xF81F, /* 255, 0, 255 */ + Yellow = 0xFFE0, /* 255, 255, 0 */ + White = 0xFFFF, /* 255, 255, 255 */ + Orange = 0xFD20, /* 255, 165, 0 */ + GreenYellow = 0xAFE5, /* 173, 255, 47 */ + Pink = 0xF81F +}; + + +// A DigitalOut sub-class that provides a constructed default state +class DigitalOut2 : public DigitalOut +{ +public: + DigitalOut2(PinName pin, bool active = false) : DigitalOut(pin) { write(active); }; + DigitalOut2& operator= (int value) { write(value); return *this; }; + DigitalOut2& operator= (DigitalOut2& rhs) { write(rhs.read()); return *this; }; + operator int() { return read(); }; +}; + + + + +/** The pure base class for the SSD1351 display driver. + * + + */ +class Adafruit_SSD1351 : public Adafruit_GFX +{ +public: + Adafruit_SSD1351(PinName RST, uint8_t rawHeight = 96, uint8_t rawWidth = 128) + : Adafruit_GFX(rawWidth,rawHeight) + , rst(RST,false) + { + + + + }; + + void begin(); + void goTo(int x, int y); + uint16_t Color565(uint8_t r, uint8_t g, uint8_t b); + virtual void fillScreen(uint16_t fillcolor); + virtual void rawFillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor); + void fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor); + void rawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); + void rawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); + virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); + virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); + void setContrastControl(uint8_t contrast); + + + virtual void invert(bool v); + + + // These must be implemented in the derived transport driver + virtual void writeCommand(uint8_t c) = 0; + virtual void writeData(uint8_t c) = 0; + virtual void drawPixel(int16_t x, int16_t y, uint16_t color); + + +protected: + + DigitalOut2 rst; + + + +}; + + +/** This is the SPI SSD1351 display driver transport class + * + */ +class Adafruit_SSD1351_Spi : public Adafruit_SSD1351 +{ +public: + /** Create a SSD1351 SPI transport display driver instance with the specified DC, RST, and CS pins, as well as the display dimentions + * + * Required parameters + * @param spi - a reference to an initialized SPI object + * @param DC (Data/Command) pin name + * @param RST (Reset) pin name + * @param CS (Chip Select) pin name + * + * Optional parameters + * @param rawHeight - the vertical number of pixels for the display, defaults to 96 + * @param rawWidth - the horizonal number of pixels for the display, defaults to 128 + */ + Adafruit_SSD1351_Spi(SPI &spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght = 96, uint8_t rawWidth = 128) + : Adafruit_SSD1351(RST, rawHieght, rawWidth) + , cs(CS,true) + , dc(DC,false) + , mspi(spi) + { + begin(); + + + }; + + virtual void writeCommand(uint8_t c) + { + + dc = 0; + cs = 0; + mspi.write(c); + cs = 1; + }; + + virtual void writeData(uint8_t c) + { + + dc = 1; + cs = 0; + + mspi.write(c); + + cs = 1; + }; + + +protected: + + DigitalOut2 cs, dc; + SPI &mspi; +}; +
diff -r 7fb1d4d3525d -r 56015e4834e6 glcdfont.h --- a/glcdfont.h Tue Nov 11 22:08:20 2014 +0000 +++ b/glcdfont.h Wed Feb 24 12:24:42 2016 +0000 @@ -59,7 +59,7 @@ 0x30, 0x38, 0x3E, 0x38, 0x30, 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x5F, 0x00, 0x00, + 0x00, 0x00, 0x5F, 0x00, 0x00, // ! 0x21 0x00, 0x07, 0x00, 0x07, 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x24, 0x2A, 0x7F, 0x2A, 0x12, @@ -148,76 +148,76 @@ 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x44, 0x28, 0x10, 0x28, 0x44, 0x4C, 0x90, 0x90, 0x90, 0x7C, - 0x44, 0x64, 0x54, 0x4C, 0x44, - 0x00, 0x08, 0x36, 0x41, 0x00, - 0x00, 0x00, 0x77, 0x00, 0x00, - 0x00, 0x41, 0x36, 0x08, 0x00, + 0x44, 0x64, 0x54, 0x4C, 0x44, // z 0x7A + 0x00, 0x08, 0x36, 0x41, 0x00, // { 0x7B + 0x00, 0x00, 0x77, 0x00, 0x00, // | 0x7C + 0x00, 0x41, 0x36, 0x08, 0x00, // } 0x7D 0x02, 0x01, 0x02, 0x04, 0x02, 0x3C, 0x26, 0x23, 0x26, 0x3C, - 0x1E, 0xA1, 0xA1, 0x61, 0x12, - 0x3A, 0x40, 0x40, 0x20, 0x7A, - 0x38, 0x54, 0x54, 0x55, 0x59, - 0x21, 0x55, 0x55, 0x79, 0x41, - 0x21, 0x54, 0x54, 0x78, 0x41, - 0x21, 0x55, 0x54, 0x78, 0x40, - 0x20, 0x54, 0x55, 0x79, 0x40, - 0x0C, 0x1E, 0x52, 0x72, 0x12, - 0x39, 0x55, 0x55, 0x55, 0x59, - 0x39, 0x54, 0x54, 0x54, 0x59, - 0x39, 0x55, 0x54, 0x54, 0x58, - 0x00, 0x00, 0x45, 0x7C, 0x41, - 0x00, 0x02, 0x45, 0x7D, 0x42, - 0x00, 0x01, 0x45, 0x7C, 0x40, - 0xF0, 0x29, 0x24, 0x29, 0xF0, - 0xF0, 0x28, 0x25, 0x28, 0xF0, - 0x7C, 0x54, 0x55, 0x45, 0x00, - 0x20, 0x54, 0x54, 0x7C, 0x54, - 0x7C, 0x0A, 0x09, 0x7F, 0x49, - 0x32, 0x49, 0x49, 0x49, 0x32, - 0x32, 0x48, 0x48, 0x48, 0x32, - 0x32, 0x4A, 0x48, 0x48, 0x30, - 0x3A, 0x41, 0x41, 0x21, 0x7A, - 0x3A, 0x42, 0x40, 0x20, 0x78, - 0x00, 0x9D, 0xA0, 0xA0, 0x7D, - 0x39, 0x44, 0x44, 0x44, 0x39, - 0x3D, 0x40, 0x40, 0x40, 0x3D, - 0x3C, 0x24, 0xFF, 0x24, 0x24, - 0x48, 0x7E, 0x49, 0x43, 0x66, - 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, - 0xFF, 0x09, 0x29, 0xF6, 0x20, - 0xC0, 0x88, 0x7E, 0x09, 0x03, - 0x20, 0x54, 0x54, 0x79, 0x41, - 0x00, 0x00, 0x44, 0x7D, 0x41, - 0x30, 0x48, 0x48, 0x4A, 0x32, - 0x38, 0x40, 0x40, 0x22, 0x7A, - 0x00, 0x7A, 0x0A, 0x0A, 0x72, - 0x7D, 0x0D, 0x19, 0x31, 0x7D, - 0x26, 0x29, 0x29, 0x2F, 0x28, - 0x26, 0x29, 0x29, 0x29, 0x26, - 0x30, 0x48, 0x4D, 0x40, 0x20, - 0x38, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x38, - 0x2F, 0x10, 0xC8, 0xAC, 0xBA, - 0x2F, 0x10, 0x28, 0x34, 0xFA, - 0x00, 0x00, 0x7B, 0x00, 0x00, - 0x08, 0x14, 0x2A, 0x14, 0x22, - 0x22, 0x14, 0x2A, 0x14, 0x08, - 0xAA, 0x00, 0x55, 0x00, 0xAA, - 0xAA, 0x55, 0xAA, 0x55, 0xAA, - 0x00, 0x00, 0x00, 0xFF, 0x00, - 0x10, 0x10, 0x10, 0xFF, 0x00, - 0x14, 0x14, 0x14, 0xFF, 0x00, - 0x10, 0x10, 0xFF, 0x00, 0xFF, - 0x10, 0x10, 0xF0, 0x10, 0xF0, - 0x14, 0x14, 0x14, 0xFC, 0x00, - 0x14, 0x14, 0xF7, 0x00, 0xFF, - 0x00, 0x00, 0xFF, 0x00, 0xFF, - 0x14, 0x14, 0xF4, 0x04, 0xFC, - 0x14, 0x14, 0x17, 0x10, 0x1F, - 0x10, 0x10, 0x1F, 0x10, 0x1F, - 0x14, 0x14, 0x14, 0x1F, 0x00, - 0x10, 0x10, 0x10, 0xF0, 0x00, - 0x00, 0x00, 0x00, 0x1F, 0x10, + 0x7C, 0x14, 0x14, 0x14, 0x08,//p 0x80 + 0x38, 0x44, 0x44, 0x44, 0x20,//c 0x81 + 0x04, 0x04, 0x7c, 0x04, 0x04,//т 0x82 + 0x0C, 0x50, 0x50, 0x50, 0x3C,//у 0x83 + 0x30, 0x48, 0xfc, 0x48, 0x30,//ф 0x84 + 0x44, 0x28, 0x10, 0x28, 0x44,//x 0x85 + 0x7c, 0x40, 0x40, 0x40, 0xfc,//ц 0x86 + 0x0c, 0x10, 0x10, 0x10, 0x7c,//ч 0x87 + 0x7c, 0x40, 0x7c, 0x40, 0x7c,//ш 0x88 + 0x7c, 0x40, 0x7c, 0x40, 0xfc,//щ 0x89 + 0x04, 0x7c, 0x50, 0x50, 0x20,//ъ 0x8A + 0x7c, 0x50, 0x50, 0x20, 0x7c,//ы 0x8B + 0x7c, 0x50, 0x50, 0x20, 0x00,//ь 0x8C + 0x28, 0x44, 0x54, 0x54, 0x38,//э 0x8D + 0x7c, 0x10, 0x38, 0x44, 0x38,//ю 0x8E + 0x08, 0x54, 0x34, 0x14, 0x7c,//я 0x8F + 0x7e, 0x11, 0x11, 0x11, 0x7e,//A 0x90 + 0x7f, 0x49, 0x49, 0x49, 0x33,//Б 0x91 + 0x7f, 0x49, 0x49, 0x49, 0x36,//В 0x92 + 0x7f, 0x01, 0x01, 0x01, 0x03,//Г 0x93 + 0xe0, 0x51, 0x4f, 0x41, 0xff,//Д 0x94 + 0x7f, 0x49, 0x49, 0x49, 0x41,//E 0x95 + 0x77, 0x08, 0x7f, 0x08, 0x77,/*Ж 0x96*/ + 0x41, 0x49, 0x49, 0x49, 0x36,//З 0x97 + 0x7f, 0x10, 0x08, 0x04, 0x7f,//И 0x98 + 0x7c, 0x21, 0x12, 0x09, 0x7c,//Й 0x99 + 0x7f, 0x08, 0x14, 0x22, 0x41,//K 0x9A + 0x20, 0x41, 0x3f, 0x01, 0x7f,//Л 0x9B + 0x7f, 0x02, 0x0c, 0x02, 0x7f,//M 0x9C + 0x7f, 0x08, 0x08, 0x08, 0x7f,//H 0x9D + 0x3e, 0x41, 0x41, 0x41, 0x3e,//O 0x9E + 0x7f, 0x01, 0x01, 0x01, 0x7f,//П 0x9F + 0x7f, 0x09, 0x09, 0x09, 0x06,//P 0xA0 + 0x3e, 0x41, 0x41, 0x41, 0x22,//C 0xA1 + 0x01, 0x01, 0x7f, 0x01, 0x01,//T 0xA2 + 0x47, 0x28, 0x10, 0x08, 0x07,//У 0xA3 + 0x1c, 0x22, 0x7f, 0x22, 0x1c,//Ф 0xA4 + 0x63, 0x14, 0x08, 0x14, 0x63,//X 0xA5 + 0x7f, 0x40, 0x40, 0x40, 0xff,//Ц 0xA6 + 0x07, 0x08, 0x08, 0x08, 0x7f,//Ч 0xA7 + 0x7f, 0x40, 0x7f, 0x40, 0x7f,//Ш 0xA8 + 0x7f, 0x40, 0x7f, 0x40, 0xff,//Щ 0xA9 + 0x01, 0x7f, 0x48, 0x48, 0x30,//Ъ 0xAA + 0x7f, 0x48, 0x30, 0x00, 0x7f,//Ы 0xAB + 0x00, 0x7f, 0x48, 0x48, 0x30,//Э 0xAC + 0x22, 0x41, 0x49, 0x49, 0x3e,//Ь 0xAD + 0x7f, 0x08, 0x3e, 0x41, 0x3e,//Ю 0xAE + 0x46, 0x29, 0x19, 0x09, 0x7f,//Я 0xAF + 0x20, 0x54, 0x54, 0x54, 0x78,//a 0xB0 + 0x3c, 0x4a, 0x4a, 0x49, 0x31,//б 0xB1 + 0x7c, 0x54, 0x54, 0x28, 0x00,//в 0xB2 + 0x7c, 0x04, 0x04, 0x04, 0x0c,//г 0xB3 + 0xe0, 0x54, 0x4c, 0x44, 0xfc,//д 0xB4 + 0x38, 0x54, 0x54, 0x54, 0x18,//e 0xB5 + 0x6c, 0x10, 0x7c, 0x10, 0x6c,//ж 0xB6 + 0x44, 0x44, 0x54, 0x54, 0x28,//з 0xB7 + 0x7c, 0x20, 0x10, 0x08, 0x7c,//и 0xB8 + 0x7c, 0x41, 0x22, 0x11, 0x7c,//й 0xB9 + 0x7c, 0x10, 0x28, 0x44, 0x00,//к 0xBA + 0x20, 0x44, 0x3c, 0x04, 0x7c,//л 0xBB + 0x7c, 0x08, 0x10, 0x08, 0x7c,//м 0xBC + 0x7c, 0x10, 0x10, 0x10, 0x7c,//н 0xBD + 0x38, 0x44, 0x44, 0x44, 0x38,//o 0xBE + 0x7c, 0x04, 0x04, 0x04, 0x7c, //п 0xBF 0x10, 0x10, 0x10, 0x1F, 0x10, 0x10, 0x10, 0x10, 0xF0, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x10,