Updated

Dependents:   Assignment_5

Committer:
DrCoyle
Date:
Tue Aug 26 13:19:39 2014 +0000
Revision:
4:f79c4a74f266
Parent:
0:c3dcd4c4983a
Child:
5:c3e0f8165538
Slight modification to original library to allow highlighting of text

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 below 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 #include "mbed.h"
nkhorman 0:c3dcd4c4983a 24 #include "Adafruit_SSD1306.h"
nkhorman 0:c3dcd4c4983a 25
nkhorman 0:c3dcd4c4983a 26 uint8_t splashScreen[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = {
nkhorman 0:c3dcd4c4983a 27 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 28 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 31 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 35 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0x98, 0x70, 0xE6, 0x9C, 0x78, 0xE7, 0x8E, 0x38, 0xF0, 0xC0,
DrCoyle 4:f79c4a74f266 36 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 37 0x00, 0x00, 0x00, 0x80, 0xC0, 0x20, 0xC0, 0x60, 0xB0, 0xD8, 0x68, 0x34, 0xB0, 0xC8, 0x64, 0xB2,
DrCoyle 4:f79c4a74f266 38 0xD8, 0x68, 0x24, 0x14, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 42 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 43 0x00, 0x00, 0x00, 0x12, 0x24, 0x4C, 0x9B, 0xB6, 0x6C, 0x5B, 0xB2, 0xAC, 0x59, 0xD3, 0xA4, 0x49,
DrCoyle 4:f79c4a74f266 44 0xD3, 0xA6, 0x6C, 0x58, 0xB0, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x10,
DrCoyle 4:f79c4a74f266 45 0xE0, 0x38, 0xC6, 0x39, 0xCE, 0x7B, 0x1C, 0x46, 0x63, 0x39, 0x0E, 0x17, 0x0B, 0x06, 0x03, 0x01,
DrCoyle 4:f79c4a74f266 46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0x10, 0x10, 0x18, 0x10,
DrCoyle 4:f79c4a74f266 47 0x10, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x40, 0xC0, 0x00,
DrCoyle 4:f79c4a74f266 48 0x00, 0x00, 0xC0, 0x40, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x80, 0x80,
DrCoyle 4:f79c4a74f266 49 0x00, 0x00, 0x00, 0xF8, 0xF8, 0x98, 0x98, 0x98, 0xF0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80,
DrCoyle 4:f79c4a74f266 50 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 51 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x04, 0x05, 0x0B, 0xAA, 0x36, 0x57, 0x46, 0x4F, 0xCD,
DrCoyle 4:f79c4a74f266 52 0x2A, 0x1A, 0x55, 0xD5, 0xCA, 0xAA, 0xA1, 0x8C, 0xB0, 0xC0, 0x80, 0xF8, 0x00, 0xFF, 0xF0, 0xFE,
DrCoyle 4:f79c4a74f266 53 0x81, 0x0E, 0xF3, 0xCC, 0x32, 0x04, 0x58, 0x22, 0x18, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x08, 0x08, 0x18, 0x08,
DrCoyle 4:f79c4a74f266 55 0x0C, 0x04, 0x00, 0x00, 0x02, 0x0F, 0x08, 0x18, 0x08, 0x0F, 0x07, 0x00, 0x00, 0x40, 0xC3, 0x4E,
DrCoyle 4:f79c4a74f266 56 0x78, 0x0E, 0x03, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x07, 0x0A, 0x1A, 0x1A, 0x0A, 0x0B,
DrCoyle 4:f79c4a74f266 57 0x02, 0x00, 0x00, 0x1F, 0x1F, 0x19, 0x19, 0x19, 0x09, 0x0F, 0x06, 0x00, 0x00, 0x07, 0x0F, 0x08,
DrCoyle 4:f79c4a74f266 58 0x18, 0x08, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x07, 0x03, 0x0A,
DrCoyle 4:f79c4a74f266 60 0x2A, 0x2A, 0x2A, 0xE1, 0xE0, 0x4A, 0x4A, 0x2B, 0x29, 0x68, 0x69, 0x6A, 0xD4, 0x8B, 0x93, 0x27,
DrCoyle 4:f79c4a74f266 61 0xFF, 0xE0, 0xEB, 0xF5, 0xF2, 0xF1, 0xF0, 0xF8, 0xFC, 0xFC, 0xFC, 0x78, 0x7E, 0x2E, 0x28, 0x18,
DrCoyle 4:f79c4a74f266 62 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 64 0x00, 0xC0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 65 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x60, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 67 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0,
DrCoyle 4:f79c4a74f266 68 0xE0, 0xE1, 0xF1, 0xF1, 0xF5, 0xFD, 0xFB, 0xFA, 0xFA, 0x7C, 0xFC, 0xF8, 0xFA, 0xFD, 0xFD, 0xFE,
DrCoyle 4:f79c4a74f266 69 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xE3, 0xC1, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 70 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1F, 0x70, 0x70,
DrCoyle 4:f79c4a74f266 72 0x3E, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70,
DrCoyle 4:f79c4a74f266 73 0x00, 0x00, 0x00, 0x1F, 0x30, 0x60, 0x60, 0x20, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 74 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 75 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0B, 0x0B, 0x0F, 0x17,
DrCoyle 4:f79c4a74f266 76 0x1F, 0x0F, 0x1F, 0x1F, 0x0F, 0x1F, 0x1F, 0x07, 0x0F, 0x08, 0x00, 0x00, 0x03, 0x07, 0x07, 0x0F,
DrCoyle 4:f79c4a74f266 77 0x0F, 0x0F, 0x0E, 0x7D, 0xAB, 0x8D, 0x1D, 0x15, 0x01, 0x03, 0x03, 0x03, 0x0F, 0x48, 0x3C, 0x8C,
DrCoyle 4:f79c4a74f266 78 0x0C, 0x1C, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
DrCoyle 4:f79c4a74f266 82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
nkhorman 0:c3dcd4c4983a 90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
nkhorman 0:c3dcd4c4983a 91 };
nkhorman 0:c3dcd4c4983a 92
nkhorman 0:c3dcd4c4983a 93 Adafruit_SSD1306::Adafruit_SSD1306(SPI &spi, PinName DC, PinName RST, PinName CS)
nkhorman 0:c3dcd4c4983a 94 : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT)
nkhorman 0:c3dcd4c4983a 95 , rst(RST,false), cs(CS,true), dc(DC,false), mspi(spi)
nkhorman 0:c3dcd4c4983a 96 {
nkhorman 0:c3dcd4c4983a 97 memcpy(buffer,splashScreen,sizeof(buffer));
nkhorman 0:c3dcd4c4983a 98 begin();
nkhorman 0:c3dcd4c4983a 99 display();
nkhorman 0:c3dcd4c4983a 100 };
nkhorman 0:c3dcd4c4983a 101
nkhorman 0:c3dcd4c4983a 102 void Adafruit_SSD1306::begin(uint8_t vccstate)
nkhorman 0:c3dcd4c4983a 103 {
nkhorman 0:c3dcd4c4983a 104 rst = 1;
nkhorman 0:c3dcd4c4983a 105 // VDD (3.3V) goes high at start, lets just chill for a ms
nkhorman 0:c3dcd4c4983a 106 wait_ms(1);
nkhorman 0:c3dcd4c4983a 107 // bring reset low
nkhorman 0:c3dcd4c4983a 108 rst = 0;
nkhorman 0:c3dcd4c4983a 109 // wait 10ms
nkhorman 0:c3dcd4c4983a 110 wait_ms(10);
nkhorman 0:c3dcd4c4983a 111 // bring out of reset
nkhorman 0:c3dcd4c4983a 112 rst = 1;
nkhorman 0:c3dcd4c4983a 113 // turn on VCC (9V?)
nkhorman 0:c3dcd4c4983a 114
DrCoyle 4:f79c4a74f266 115 /*#if defined SSD1306_128_32
nkhorman 0:c3dcd4c4983a 116 // Init sequence for 128x32 OLED module
nkhorman 0:c3dcd4c4983a 117 ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE
nkhorman 0:c3dcd4c4983a 118 ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
nkhorman 0:c3dcd4c4983a 119 ssd1306_command(0x80); // the suggested ratio 0x80
nkhorman 0:c3dcd4c4983a 120 ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8
nkhorman 0:c3dcd4c4983a 121 ssd1306_command(0x1F);
nkhorman 0:c3dcd4c4983a 122 ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3
nkhorman 0:c3dcd4c4983a 123 ssd1306_command(0x0); // no offset
nkhorman 0:c3dcd4c4983a 124 ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0
nkhorman 0:c3dcd4c4983a 125 ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D
nkhorman 0:c3dcd4c4983a 126 if (vccstate == SSD1306_EXTERNALVCC)
nkhorman 0:c3dcd4c4983a 127 { ssd1306_command(0x10); }
nkhorman 0:c3dcd4c4983a 128 else
nkhorman 0:c3dcd4c4983a 129 { ssd1306_command(0x14); }
nkhorman 0:c3dcd4c4983a 130 ssd1306_command(SSD1306_MEMORYMODE); // 0x20
nkhorman 0:c3dcd4c4983a 131 ssd1306_command(0x00); // 0x0 act like ks0108
nkhorman 0:c3dcd4c4983a 132 ssd1306_command(SSD1306_SEGREMAP | 0x1);
nkhorman 0:c3dcd4c4983a 133 ssd1306_command(SSD1306_COMSCANDEC);
nkhorman 0:c3dcd4c4983a 134 ssd1306_command(SSD1306_SETCOMPINS); // 0xDA
nkhorman 0:c3dcd4c4983a 135 ssd1306_command(0x02);
nkhorman 0:c3dcd4c4983a 136 ssd1306_command(SSD1306_SETCONTRAST); // 0x81
nkhorman 0:c3dcd4c4983a 137 ssd1306_command(0x8F);
nkhorman 0:c3dcd4c4983a 138 ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9
nkhorman 0:c3dcd4c4983a 139 if (vccstate == SSD1306_EXTERNALVCC)
nkhorman 0:c3dcd4c4983a 140 { ssd1306_command(0x22); }
nkhorman 0:c3dcd4c4983a 141 else
nkhorman 0:c3dcd4c4983a 142 { ssd1306_command(0xF1); }
nkhorman 0:c3dcd4c4983a 143 ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB
nkhorman 0:c3dcd4c4983a 144 ssd1306_command(0x40);
nkhorman 0:c3dcd4c4983a 145 ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
nkhorman 0:c3dcd4c4983a 146 ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6
DrCoyle 4:f79c4a74f266 147 #endif*/
nkhorman 0:c3dcd4c4983a 148
nkhorman 0:c3dcd4c4983a 149 #if defined SSD1306_128_64
nkhorman 0:c3dcd4c4983a 150 // Init sequence for 128x64 OLED module
nkhorman 0:c3dcd4c4983a 151 ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE
nkhorman 0:c3dcd4c4983a 152 ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
nkhorman 0:c3dcd4c4983a 153 ssd1306_command(0x80); // the suggested ratio 0x80
nkhorman 0:c3dcd4c4983a 154 ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8
nkhorman 0:c3dcd4c4983a 155 ssd1306_command(0x3F);
nkhorman 0:c3dcd4c4983a 156 ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3
nkhorman 0:c3dcd4c4983a 157 ssd1306_command(0x0); // no offset
nkhorman 0:c3dcd4c4983a 158 ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0
nkhorman 0:c3dcd4c4983a 159 ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D
nkhorman 0:c3dcd4c4983a 160 if (vccstate == SSD1306_EXTERNALVCC)
nkhorman 0:c3dcd4c4983a 161 { ssd1306_command(0x10); }
nkhorman 0:c3dcd4c4983a 162 else
nkhorman 0:c3dcd4c4983a 163 { ssd1306_command(0x14); }
nkhorman 0:c3dcd4c4983a 164 ssd1306_command(SSD1306_MEMORYMODE); // 0x20
nkhorman 0:c3dcd4c4983a 165 ssd1306_command(0x00); // 0x0 act like ks0108
nkhorman 0:c3dcd4c4983a 166 ssd1306_command(SSD1306_SEGREMAP | 0x1);
nkhorman 0:c3dcd4c4983a 167 ssd1306_command(SSD1306_COMSCANDEC);
nkhorman 0:c3dcd4c4983a 168 ssd1306_command(SSD1306_SETCOMPINS); // 0xDA
nkhorman 0:c3dcd4c4983a 169 ssd1306_command(0x12);
nkhorman 0:c3dcd4c4983a 170 ssd1306_command(SSD1306_SETCONTRAST); // 0x81
nkhorman 0:c3dcd4c4983a 171 if (vccstate == SSD1306_EXTERNALVCC)
nkhorman 0:c3dcd4c4983a 172 { ssd1306_command(0x9F); }
nkhorman 0:c3dcd4c4983a 173 else
nkhorman 0:c3dcd4c4983a 174 { ssd1306_command(0xCF); }
nkhorman 0:c3dcd4c4983a 175 ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9
nkhorman 0:c3dcd4c4983a 176 if (vccstate == SSD1306_EXTERNALVCC)
nkhorman 0:c3dcd4c4983a 177 { ssd1306_command(0x22); }
nkhorman 0:c3dcd4c4983a 178 else
nkhorman 0:c3dcd4c4983a 179 { ssd1306_command(0xF1); }
nkhorman 0:c3dcd4c4983a 180 ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB
nkhorman 0:c3dcd4c4983a 181 ssd1306_command(0x40);
nkhorman 0:c3dcd4c4983a 182 ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
nkhorman 0:c3dcd4c4983a 183 ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6
nkhorman 0:c3dcd4c4983a 184 #endif
nkhorman 0:c3dcd4c4983a 185
nkhorman 0:c3dcd4c4983a 186 ssd1306_command(SSD1306_DISPLAYON);//--turn on oled panel
nkhorman 0:c3dcd4c4983a 187 }
nkhorman 0:c3dcd4c4983a 188
nkhorman 0:c3dcd4c4983a 189 // the most basic function, set a single pixel
nkhorman 0:c3dcd4c4983a 190 void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color)
nkhorman 0:c3dcd4c4983a 191 {
nkhorman 0:c3dcd4c4983a 192 if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
nkhorman 0:c3dcd4c4983a 193 return;
nkhorman 0:c3dcd4c4983a 194
nkhorman 0:c3dcd4c4983a 195 // check rotation, move pixel around if necessary
nkhorman 0:c3dcd4c4983a 196 switch (getRotation())
nkhorman 0:c3dcd4c4983a 197 {
nkhorman 0:c3dcd4c4983a 198 case 1:
nkhorman 0:c3dcd4c4983a 199 swap(x, y);
nkhorman 0:c3dcd4c4983a 200 x = _rawWidth - x - 1;
nkhorman 0:c3dcd4c4983a 201 break;
nkhorman 0:c3dcd4c4983a 202 case 2:
nkhorman 0:c3dcd4c4983a 203 x = _rawWidth - x - 1;
nkhorman 0:c3dcd4c4983a 204 y = _rawHeight - y - 1;
nkhorman 0:c3dcd4c4983a 205 break;
nkhorman 0:c3dcd4c4983a 206 case 3:
nkhorman 0:c3dcd4c4983a 207 swap(x, y);
nkhorman 0:c3dcd4c4983a 208 y = _rawHeight - y - 1;
nkhorman 0:c3dcd4c4983a 209 break;
nkhorman 0:c3dcd4c4983a 210 }
nkhorman 0:c3dcd4c4983a 211
nkhorman 0:c3dcd4c4983a 212 // x is which column
nkhorman 0:c3dcd4c4983a 213 if (color == WHITE)
nkhorman 0:c3dcd4c4983a 214 buffer[x+ (y/8)*SSD1306_LCDWIDTH] |= _BV((y%8));
nkhorman 0:c3dcd4c4983a 215 else
nkhorman 0:c3dcd4c4983a 216 buffer[x+ (y/8)*SSD1306_LCDWIDTH] &= ~_BV((y%8));
nkhorman 0:c3dcd4c4983a 217 }
nkhorman 0:c3dcd4c4983a 218
nkhorman 0:c3dcd4c4983a 219 void Adafruit_SSD1306::invertDisplay(bool i)
nkhorman 0:c3dcd4c4983a 220 {
nkhorman 0:c3dcd4c4983a 221 if (i)
nkhorman 0:c3dcd4c4983a 222 ssd1306_command(SSD1306_INVERTDISPLAY);
nkhorman 0:c3dcd4c4983a 223 else
nkhorman 0:c3dcd4c4983a 224 ssd1306_command(SSD1306_NORMALDISPLAY);
nkhorman 0:c3dcd4c4983a 225 }
nkhorman 0:c3dcd4c4983a 226
DrCoyle 4:f79c4a74f266 227 //function inverts display of num characters starting at row x, column y
DrCoyle 4:f79c4a74f266 228 void Adafruit_SSD1306::invertSection(int16_t x, int16_t y, int16_t num)
DrCoyle 4:f79c4a74f266 229 {
DrCoyle 4:f79c4a74f266 230 if (x+num > 21 || y>8)
DrCoyle 4:f79c4a74f266 231 return;
DrCoyle 4:f79c4a74f266 232 else {
DrCoyle 4:f79c4a74f266 233 int k;
DrCoyle 4:f79c4a74f266 234 for (k=0;k<(num*6);k++)
DrCoyle 4:f79c4a74f266 235 buffer[x*6+y*SSD1306_LCDWIDTH+k]=~buffer[x*6+y*SSD1306_LCDWIDTH+k];
DrCoyle 4:f79c4a74f266 236 }
DrCoyle 4:f79c4a74f266 237 }
DrCoyle 4:f79c4a74f266 238
nkhorman 0:c3dcd4c4983a 239 void Adafruit_SSD1306::ssd1306_command(uint8_t c)
nkhorman 0:c3dcd4c4983a 240 {
nkhorman 0:c3dcd4c4983a 241 cs = 1;
nkhorman 0:c3dcd4c4983a 242 dc = 0;
nkhorman 0:c3dcd4c4983a 243 cs = 0;
nkhorman 0:c3dcd4c4983a 244 mspi.write(c);
nkhorman 0:c3dcd4c4983a 245 cs = 1;
nkhorman 0:c3dcd4c4983a 246 }
nkhorman 0:c3dcd4c4983a 247
nkhorman 0:c3dcd4c4983a 248 void Adafruit_SSD1306::ssd1306_data(uint8_t c)
nkhorman 0:c3dcd4c4983a 249 {
nkhorman 0:c3dcd4c4983a 250 cs = 1;
nkhorman 0:c3dcd4c4983a 251 dc = 1;
nkhorman 0:c3dcd4c4983a 252 cs = 0;
nkhorman 0:c3dcd4c4983a 253 mspi.write(c);
nkhorman 0:c3dcd4c4983a 254 cs = 1;
nkhorman 0:c3dcd4c4983a 255 }
nkhorman 0:c3dcd4c4983a 256
nkhorman 0:c3dcd4c4983a 257 void Adafruit_SSD1306::display(void)
nkhorman 0:c3dcd4c4983a 258 {
nkhorman 0:c3dcd4c4983a 259 ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0
nkhorman 0:c3dcd4c4983a 260 ssd1306_command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0
nkhorman 0:c3dcd4c4983a 261 ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0
nkhorman 0:c3dcd4c4983a 262
nkhorman 0:c3dcd4c4983a 263 cs = 1;
nkhorman 0:c3dcd4c4983a 264 dc = 1;
nkhorman 0:c3dcd4c4983a 265 cs = 0;
nkhorman 0:c3dcd4c4983a 266
nkhorman 0:c3dcd4c4983a 267 for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++)
nkhorman 0:c3dcd4c4983a 268 mspi.write(buffer[i]);
nkhorman 0:c3dcd4c4983a 269
nkhorman 0:c3dcd4c4983a 270 // i wonder why we have to do this (check datasheet)
nkhorman 0:c3dcd4c4983a 271 if (SSD1306_LCDHEIGHT == 32)
nkhorman 0:c3dcd4c4983a 272 {
nkhorman 0:c3dcd4c4983a 273 for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++)
nkhorman 0:c3dcd4c4983a 274 mspi.write(0);
nkhorman 0:c3dcd4c4983a 275 }
nkhorman 0:c3dcd4c4983a 276
nkhorman 0:c3dcd4c4983a 277 cs = 1;
nkhorman 0:c3dcd4c4983a 278 }
nkhorman 0:c3dcd4c4983a 279
nkhorman 0:c3dcd4c4983a 280 // clear everything
nkhorman 0:c3dcd4c4983a 281 void Adafruit_SSD1306::clearDisplay(void)
nkhorman 0:c3dcd4c4983a 282 {
nkhorman 0:c3dcd4c4983a 283 memset(buffer,0,sizeof(buffer));
nkhorman 0:c3dcd4c4983a 284 }