A derived version of the BSD licensed Adafrut GFX library for the SSD1306 controller for an OLED 128x32 or 128x64 display using SPI or I2C.

Dependents:   mbed-TFT-example-NCS36510

Fork of Adafruit_GFX by Neal Horman

Committer:
nkhorman
Date:
Wed Jan 23 02:43:38 2013 +0000
Revision:
3:969ca9fe5e2b
Parent:
0:c3dcd4c4983a
Child:
6:1be3e3b46eb7
line endings ?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nkhorman 0:c3dcd4c4983a 1 /*********************************************************************
nkhorman 0:c3dcd4c4983a 2 This is a library for our Monochrome OLEDs based on SSD1306 drivers
nkhorman 0:c3dcd4c4983a 3
nkhorman 0:c3dcd4c4983a 4 Pick one up today in the adafruit shop!
nkhorman 0:c3dcd4c4983a 5 ------> http://www.adafruit.com/category/63_98
nkhorman 0:c3dcd4c4983a 6
nkhorman 0:c3dcd4c4983a 7 These displays use SPI to communicate, 4 or 5 pins are required to
nkhorman 0:c3dcd4c4983a 8 interface
nkhorman 0:c3dcd4c4983a 9
nkhorman 0:c3dcd4c4983a 10 Adafruit invests time and resources providing this open source code,
nkhorman 0:c3dcd4c4983a 11 please support Adafruit and open-source hardware by purchasing
nkhorman 0:c3dcd4c4983a 12 products from Adafruit!
nkhorman 0:c3dcd4c4983a 13
nkhorman 0:c3dcd4c4983a 14 Written by Limor Fried/Ladyada for Adafruit Industries.
nkhorman 0:c3dcd4c4983a 15 BSD license, check license.txt for more information
nkhorman 0:c3dcd4c4983a 16 All text above, and the splash screen must be included in any redistribution
nkhorman 0:c3dcd4c4983a 17 *********************************************************************/
nkhorman 0:c3dcd4c4983a 18
nkhorman 0:c3dcd4c4983a 19 /*
nkhorman 0:c3dcd4c4983a 20 * Modified by Neal Horman 7/14/2012 for use in LPC1768
nkhorman 0:c3dcd4c4983a 21 */
nkhorman 0:c3dcd4c4983a 22
nkhorman 0:c3dcd4c4983a 23 #ifndef _ADAFRUIT_SSD1306_H_
nkhorman 0:c3dcd4c4983a 24 #define _ADAFRUIT_SSD1306_H_
nkhorman 0:c3dcd4c4983a 25
nkhorman 0:c3dcd4c4983a 26 #include "mbed.h"
nkhorman 0:c3dcd4c4983a 27 #include "Adafruit_GFX.h"
nkhorman 0:c3dcd4c4983a 28
nkhorman 0:c3dcd4c4983a 29 /*=========================================================================
nkhorman 0:c3dcd4c4983a 30 SSD1306 Displays
nkhorman 0:c3dcd4c4983a 31 -----------------------------------------------------------------------
nkhorman 0:c3dcd4c4983a 32 The driver is used in multiple displays (128x64, 128x32, etc.).
nkhorman 0:c3dcd4c4983a 33 Select the appropriate display below to create an appropriately
nkhorman 0:c3dcd4c4983a 34 sized framebuffer, etc.
nkhorman 0:c3dcd4c4983a 35
nkhorman 0:c3dcd4c4983a 36 SSD1306_128_64 128x64 pixel display
nkhorman 0:c3dcd4c4983a 37
nkhorman 0:c3dcd4c4983a 38 SSD1306_128_32 128x32 pixel display
nkhorman 0:c3dcd4c4983a 39
nkhorman 0:c3dcd4c4983a 40 You also need to set the LCDWIDTH and LCDHEIGHT defines to an
nkhorman 0:c3dcd4c4983a 41 appropriate size
nkhorman 0:c3dcd4c4983a 42
nkhorman 0:c3dcd4c4983a 43 -----------------------------------------------------------------------*/
nkhorman 0:c3dcd4c4983a 44 //#define SSD1306_128_64
nkhorman 0:c3dcd4c4983a 45 #define SSD1306_128_32
nkhorman 0:c3dcd4c4983a 46 /*=========================================================================*/
nkhorman 0:c3dcd4c4983a 47
nkhorman 0:c3dcd4c4983a 48 #if defined SSD1306_128_64 && defined SSD1306_128_32
nkhorman 0:c3dcd4c4983a 49 #error "Only one SSD1306 display can be specified at once in SSD1306.h"
nkhorman 0:c3dcd4c4983a 50 #endif
nkhorman 0:c3dcd4c4983a 51 #if !defined SSD1306_128_64 && !defined SSD1306_128_32
nkhorman 0:c3dcd4c4983a 52 #error "At least one SSD1306 display must be specified in SSD1306.h"
nkhorman 0:c3dcd4c4983a 53 #endif
nkhorman 0:c3dcd4c4983a 54
nkhorman 0:c3dcd4c4983a 55 #if defined SSD1306_128_64
nkhorman 0:c3dcd4c4983a 56 #define SSD1306_LCDWIDTH 128
nkhorman 0:c3dcd4c4983a 57 #define SSD1306_LCDHEIGHT 64
nkhorman 0:c3dcd4c4983a 58 #endif
nkhorman 0:c3dcd4c4983a 59 #if defined SSD1306_128_32
nkhorman 0:c3dcd4c4983a 60 #define SSD1306_LCDWIDTH 128
nkhorman 0:c3dcd4c4983a 61 #define SSD1306_LCDHEIGHT 32
nkhorman 0:c3dcd4c4983a 62 #endif
nkhorman 0:c3dcd4c4983a 63
nkhorman 0:c3dcd4c4983a 64 #define SSD1306_SETCONTRAST 0x81
nkhorman 0:c3dcd4c4983a 65 #define SSD1306_DISPLAYALLON_RESUME 0xA4
nkhorman 0:c3dcd4c4983a 66 #define SSD1306_DISPLAYALLON 0xA5
nkhorman 0:c3dcd4c4983a 67 #define SSD1306_NORMALDISPLAY 0xA6
nkhorman 0:c3dcd4c4983a 68 #define SSD1306_INVERTDISPLAY 0xA7
nkhorman 0:c3dcd4c4983a 69 #define SSD1306_DISPLAYOFF 0xAE
nkhorman 0:c3dcd4c4983a 70 #define SSD1306_DISPLAYON 0xAF
nkhorman 0:c3dcd4c4983a 71 #define SSD1306_SETDISPLAYOFFSET 0xD3
nkhorman 0:c3dcd4c4983a 72 #define SSD1306_SETCOMPINS 0xDA
nkhorman 0:c3dcd4c4983a 73 #define SSD1306_SETVCOMDETECT 0xDB
nkhorman 0:c3dcd4c4983a 74 #define SSD1306_SETDISPLAYCLOCKDIV 0xD5
nkhorman 0:c3dcd4c4983a 75 #define SSD1306_SETPRECHARGE 0xD9
nkhorman 0:c3dcd4c4983a 76 #define SSD1306_SETMULTIPLEX 0xA8
nkhorman 0:c3dcd4c4983a 77 #define SSD1306_SETLOWCOLUMN 0x00
nkhorman 0:c3dcd4c4983a 78 #define SSD1306_SETHIGHCOLUMN 0x10
nkhorman 0:c3dcd4c4983a 79 #define SSD1306_SETSTARTLINE 0x40
nkhorman 0:c3dcd4c4983a 80 #define SSD1306_MEMORYMODE 0x20
nkhorman 0:c3dcd4c4983a 81 #define SSD1306_COMSCANINC 0xC0
nkhorman 0:c3dcd4c4983a 82 #define SSD1306_COMSCANDEC 0xC8
nkhorman 0:c3dcd4c4983a 83 #define SSD1306_SEGREMAP 0xA0
nkhorman 0:c3dcd4c4983a 84 #define SSD1306_CHARGEPUMP 0x8D
nkhorman 0:c3dcd4c4983a 85 #define SSD1306_EXTERNALVCC 0x1
nkhorman 0:c3dcd4c4983a 86 #define SSD1306_SWITCHCAPVCC 0x2
nkhorman 0:c3dcd4c4983a 87
nkhorman 0:c3dcd4c4983a 88 // an DigitalOut sub-class that provides a constructed default state
nkhorman 0:c3dcd4c4983a 89 class DigitalOut2 : public DigitalOut
nkhorman 0:c3dcd4c4983a 90 {
nkhorman 0:c3dcd4c4983a 91 public:
nkhorman 3:969ca9fe5e2b 92 DigitalOut2(PinName pin, bool active = false) : DigitalOut(pin) { write(active); };
nkhorman 0:c3dcd4c4983a 93 DigitalOut2& operator= (int value) { write(value); return *this; };
nkhorman 0:c3dcd4c4983a 94 DigitalOut2& operator= (DigitalOut2& rhs) { write(rhs.read()); return *this; };
nkhorman 0:c3dcd4c4983a 95 operator int() { return read(); };
nkhorman 0:c3dcd4c4983a 96 };
nkhorman 0:c3dcd4c4983a 97
nkhorman 0:c3dcd4c4983a 98 class Adafruit_SSD1306 : public Adafruit_GFX
nkhorman 0:c3dcd4c4983a 99 {
nkhorman 0:c3dcd4c4983a 100 public:
nkhorman 0:c3dcd4c4983a 101 Adafruit_SSD1306(SPI &spi, PinName DC, PinName RST, PinName CS);
nkhorman 0:c3dcd4c4983a 102 void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC);
nkhorman 0:c3dcd4c4983a 103 void ssd1306_command(uint8_t c);
nkhorman 0:c3dcd4c4983a 104 void ssd1306_data(uint8_t c);
nkhorman 0:c3dcd4c4983a 105
nkhorman 0:c3dcd4c4983a 106 void clearDisplay(void);
nkhorman 0:c3dcd4c4983a 107 virtual void invertDisplay(bool i);
nkhorman 0:c3dcd4c4983a 108 void display();
nkhorman 0:c3dcd4c4983a 109
nkhorman 0:c3dcd4c4983a 110 virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
nkhorman 0:c3dcd4c4983a 111
nkhorman 0:c3dcd4c4983a 112 private:
nkhorman 0:c3dcd4c4983a 113 DigitalOut2 rst,cs,dc;
nkhorman 0:c3dcd4c4983a 114 SPI &mspi;
nkhorman 0:c3dcd4c4983a 115 // the memory buffer for the LCD
nkhorman 0:c3dcd4c4983a 116 uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8];
nkhorman 0:c3dcd4c4983a 117 };
nkhorman 0:c3dcd4c4983a 118
nkhorman 0:c3dcd4c4983a 119 #endif