Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SSD1306_mini.cpp
00001 /********************************************************************* 00002 This is a library for our Monochrome OLEDs based on SSD1306 drivers 00003 00004 Pick one up today in the adafruit shop! 00005 ------> http://www.adafruit.com/category/63_98 00006 00007 These displays use SPI to communicate, 4 or 5 pins are required to 00008 interface 00009 00010 Adafruit invests time and resources providing this open source code, 00011 please support Adafruit and open-source hardware by purchasing 00012 products from Adafruit! 00013 00014 Written by Limor Fried/Ladyada for Adafruit Industries. 00015 BSD license, check license.txt for more information 00016 All text above, and the splash screen below must be included in any redistribution 00017 *********************************************************************/ 00018 00019 /* 00020 * Modified by Neal Horman 7/14/2012 for use in mbed 00021 * Modified by Jiri Stepanovsky 6/4/2018 for LPE compatibility 00022 */ 00023 00024 #include "mbed.h" 00025 #include "SSD1306_mini.h" 00026 00027 #define SSD1306_SETCONTRAST 0x81 00028 #define SSD1306_DISPLAYALLON_RESUME 0xA4 00029 #define SSD1306_DISPLAYALLON 0xA5 00030 #define SSD1306_NORMALDISPLAY 0xA6 00031 #define SSD1306_INVERTDISPLAY 0xA7 00032 #define SSD1306_DISPLAYOFF 0xAE 00033 #define SSD1306_DISPLAYON 0xAF 00034 #define SSD1306_SETDISPLAYOFFSET 0xD3 00035 #define SSD1306_SETCOMPINS 0xDA 00036 #define SSD1306_SETVCOMDETECT 0xDB 00037 #define SSD1306_SETDISPLAYCLOCKDIV 0xD5 00038 #define SSD1306_SETPRECHARGE 0xD9 00039 #define SSD1306_SETMULTIPLEX 0xA8 00040 #define SSD1306_SETLOWCOLUMN 0x00 00041 #define SSD1306_SETHIGHCOLUMN 0x10 00042 #define SSD1306_SETSTARTLINE 0x40 00043 #define SSD1306_MEMORYMODE 0x20 00044 #define SSD1306_COMSCANINC 0xC0 00045 #define SSD1306_COMSCANDEC 0xC8 00046 #define SSD1306_SEGREMAP 0xA0 00047 #define SSD1306_CHARGEPUMP 0x8D 00048 00049 void SSD1306_mini::begin(uint8_t vccstate) 00050 { 00051 rst = 1; 00052 // VDD (3.3V) goes high at start, lets just chill for a ms 00053 wait_ms(1); 00054 // bring reset low 00055 rst = 0; 00056 // wait 10ms 00057 wait_ms(10); 00058 // bring out of reset 00059 rst = 1; 00060 // turn on VCC (9V?) 00061 00062 command(SSD1306_DISPLAYOFF); 00063 command(SSD1306_SETDISPLAYCLOCKDIV); 00064 command(0x80); // the suggested ratio 0x80 00065 00066 command(SSD1306_SETMULTIPLEX); 00067 command(OLED_HEIGHT-1); 00068 00069 command(SSD1306_SETDISPLAYOFFSET); 00070 command(0x0); // no offset 00071 00072 command(SSD1306_SETSTARTLINE | 0x0); // line #0 00073 00074 command(SSD1306_CHARGEPUMP); 00075 command((vccstate == SSD1306_EXTERNALVCC) ? 0x10 : 0x14); 00076 00077 command(SSD1306_MEMORYMODE); 00078 command(0x00); // 0x0 act like ks0108 00079 00080 command(SSD1306_SEGREMAP | 0x1); 00081 00082 command(SSD1306_COMSCANDEC); 00083 00084 command(SSD1306_SETCOMPINS); 00085 command(OLED_HEIGHT == 32 ? 0x02 : 0x12); // TODO - calculate based on _rawHieght ? 00086 00087 command(SSD1306_SETCONTRAST); 00088 command(OLED_HEIGHT == 32 ? 0x8F : ((vccstate == SSD1306_EXTERNALVCC) ? 0x9F : 0xCF) ); 00089 00090 command(SSD1306_SETPRECHARGE); 00091 command((vccstate == SSD1306_EXTERNALVCC) ? 0x22 : 0xF1); 00092 00093 command(SSD1306_SETVCOMDETECT); 00094 command(0x40); 00095 00096 command(SSD1306_DISPLAYALLON_RESUME); 00097 00098 command(SSD1306_NORMALDISPLAY); 00099 00100 command(SSD1306_DISPLAYON); 00101 } 00102 00103 // Set a single pixel 00104 void SSD1306_mini::drawPixel(int16_t x, int16_t y, uint16_t color) 00105 { 00106 if ((x < 0) || (x >= OLED_WIDTH) || (y < 0) || (y >= OLED_HEIGHT)) 00107 return; 00108 // x is which column 00109 if (color == WHITE) 00110 buffer[x+ (y/8)*OLED_WIDTH] |= 1<<(y%8); 00111 else // else black 00112 buffer[x+ (y/8)*OLED_WIDTH] &= ~(1<<(y%8)); 00113 } 00114 00115 void SSD1306_mini::invertDisplay(bool i) 00116 { 00117 command(i ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY); 00118 } 00119 00120 // Send the display buffer out to the display 00121 void SSD1306_mini::display(void) 00122 { 00123 command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 00124 command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0 00125 command(SSD1306_SETSTARTLINE | 0x0); // line #0 00126 sendDisplayBuffer(); 00127 } 00128 00129 // Clear the display buffer. Requires a display() call at some point afterwards 00130 void SSD1306_mini::clearDisplay(void) 00131 { 00132 for(uint16_t i=0, q=OLED_BUFFER_SIZE; i<q; i++) 00133 buffer[i] = 0; 00134 }
Generated on Thu Apr 20 2023 23:15:53 by
1.7.2