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.
Fork of SFE_MicroOLED by
SFE_MicroOLED.h
00001 /****************************************************************************** 00002 SFE_MicroOLED.h 00003 Header file for the MicroOLED mbed Library 00004 Jim Lindblom @ SparkFun Electronics 00005 October 26, 2014 00006 https://github.com/sparkfun/Micro_OLED_Breakout/tree/master/Firmware/Arduino/libraries/SFE_MicroOLED 00007 Adapted for mbed by Nenad Milosevic 00008 March, 2015 00009 This file defines the hardware SPI interface for the Micro OLED Breakout. 00010 Development environment specifics: 00011 Various suitable mbed platforms 00012 Micro OLED Breakout v1.0 00013 This code was heavily based around the MicroView library, written by GeekAmmo 00014 (https://github.com/geekammo/MicroView-Arduino-Library), and released under 00015 the terms of the GNU General Public License as published by the Free Software 00016 Foundation, either version 3 of the License, or (at your option) any later 00017 version. 00018 This program is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 You should have received a copy of the GNU General Public License 00023 along with this program. If not, see <http://www.gnu.org/licenses/>. 00024 ******************************************************************************/ 00025 00026 #ifndef SFE_MICROOLED_H 00027 #define SFE_MICROOLED_H 00028 00029 static inline void swap(uint8_t &a, uint8_t &b) 00030 { 00031 00032 } 00033 00034 #ifndef _BV 00035 #define _BV(bit) (1<<(bit)) 00036 #endif 00037 00038 #define BLACK 0 00039 #define WHITE 1 00040 00041 #define LCDWIDTH 64 00042 #define LCDHEIGHT 32 00043 #define LCDCOLUMNOFFSET 0 // Visible start column within SSD1306 controller memory 00044 #define FONTHEADERSIZE 6 00045 00046 #define LCDTOTALWIDTH 128 // Full width of SSD1306 controller memory 00047 #define LCDTOTALHEIGHT 64 // Full height of SSD1306 controller memory 00048 00049 #define LCDTOTALPAGES (LCDTOTALHEIGHT / 8) 00050 #define LCDPAGES (LCDHEIGHT / 8) 00051 00052 #define NORM 0 00053 #define XOR 1 00054 00055 #define PAGE 0 00056 #define ALL 1 00057 00058 #define SETCONTRAST 0x81 00059 #define DISPLAYALLONRESUME 0xA4 00060 #define DISPLAYALLON 0xA5 00061 #define NORMALDISPLAY 0xA6 00062 #define INVERTDISPLAY 0xA7 00063 #define DISPLAYOFF 0xAE 00064 #define DISPLAYON 0xAF 00065 #define SETDISPLAYOFFSET 0xD3 00066 #define SETCOMPINS 0xDA 00067 #define SETVCOMDESELECT 0xDB 00068 #define SETDISPLAYCLOCKDIV 0xD5 00069 #define SETPRECHARGE 0xD9 00070 #define SETMULTIPLEX 0xA8 00071 #define SETLOWCOLUMN 0x00 00072 #define SETHIGHCOLUMN 0x12 00073 #define SETSTARTLINE 0x00 00074 #define MEMORYMODE 0x20 00075 #define SETCOLUMNBOUNDS 0x21 00076 #define SETPAGEBOUNDS 0x22 00077 #define SETPAGE 0xB0 00078 #define COMSCANINC 0xC0 00079 #define COMSCANDEC 0xC8 00080 #define SEGREMAP 0xA1 00081 #define CHARGEPUMP 0x8D 00082 #define EXTERNALVCC 0x01 00083 #define SWITCHCAPVCC 0x02 00084 00085 // Scroll 00086 #define ACTIVATESCROLL 0x2F 00087 #define DEACTIVATESCROLL 0x2E 00088 #define SETVERTICALSCROLLAREA 0xA3 00089 #define RIGHTHORIZONTALSCROLL 0x26 00090 #define LEFTHORIZONTALSCROLL 0x27 00091 #define VERTICALRIGHTHORIZONTALSCROLL 0x29 00092 #define VERTICALLEFTHORIZONTALSCROLL 0x2A 00093 00094 typedef uint8_t boolean; 00095 00096 class MicroOLED { 00097 public: 00098 // Constructor 00099 MicroOLED(SPI &spi, PinName rst, PinName dc, PinName cs) : miol_spi(spi), rstPin(rst), dcPin(dc), csPin(cs) 00100 { 00101 // Set default states for the DigitalOut pins. 00102 rstPin = 1; 00103 dcPin = 0; 00104 csPin = 1; 00105 }; 00106 00107 // Initialize SPI mode and frequency and SSD1306 for particular display 00108 void init(int spi_mode, int spi_freq); 00109 00110 // Standard text output functions 00111 void putc(char c); 00112 void puts(const char *cstring); 00113 void printf(const char *format, ...); 00114 00115 // RAW LCD functions 00116 void command(uint8_t c); 00117 void command(uint8_t c1, uint8_t c2); 00118 void command(uint8_t c1, uint8_t c2, uint8_t c3); 00119 void command(uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5, uint8_t c6, uint8_t c7, uint8_t c8); 00120 void command(uint8_t cmds[],int length); 00121 void setColumnAddress(uint8_t add); 00122 void setPageAddress(uint8_t add); 00123 00124 // LCD Draw functions 00125 void clear(uint8_t mode); 00126 void clear(uint8_t mode, uint8_t c); 00127 void invert(boolean inv); 00128 void contrast(uint8_t contrast); 00129 void display(void); 00130 void setCursor(uint8_t x, uint8_t y); 00131 void pixel(uint8_t x, uint8_t y); 00132 void pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode); 00133 void line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1); 00134 void line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode); 00135 void lineH(uint8_t x, uint8_t y, uint8_t width); 00136 void lineH(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode); 00137 void lineV(uint8_t x, uint8_t y, uint8_t height); 00138 void lineV(uint8_t x, uint8_t y, uint8_t height, uint8_t color, uint8_t mode); 00139 void rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height); 00140 void rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode); 00141 void rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height); 00142 void rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode); 00143 void circle(uint8_t x, uint8_t y, uint8_t radius); 00144 void circle(uint8_t x, uint8_t y, uint8_t radius, uint8_t color, uint8_t mode); 00145 void circleFill(uint8_t x0, uint8_t y0, uint8_t radius); 00146 void circleFill(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t mode); 00147 void drawChar(uint8_t x, uint8_t y, uint8_t c); 00148 void drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode); 00149 void drawBitmap(const uint8_t * bitArray); 00150 uint8_t getLCDWidth(void); 00151 uint8_t getLCDHeight(void); 00152 void setColor(uint8_t color); 00153 void setDrawMode(uint8_t mode); 00154 uint8_t *getScreenBuffer(void); 00155 00156 // Font functions 00157 uint8_t getFontWidth(void); 00158 uint8_t getFontHeight(void); 00159 uint8_t getTotalFonts(void); 00160 uint8_t getFontType(void); 00161 uint8_t setFontType(uint8_t type); 00162 uint8_t getFontStartChar(void); 00163 uint8_t getFontTotalChar(void); 00164 00165 // LCD Rotate Scroll functions 00166 void scrollRight(uint8_t start, uint8_t stop); 00167 void scrollLeft(uint8_t start, uint8_t stop); 00168 void scrollStop(void); 00169 void flipVertical(boolean flip); 00170 void flipHorizontal(boolean flip); 00171 00172 private: 00173 SPI &miol_spi; 00174 DigitalOut rstPin, dcPin, csPin; 00175 uint8_t foreColor, drawMode, fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY; 00176 uint16_t fontMapWidth; 00177 static const unsigned char *fontsPointer[]; 00178 }; 00179 #endif
Generated on Sun Jul 17 2022 15:06:09 by
1.7.2
