sandeep ponnuru / SFE_MicroOLED_debugPrint

Fork of SFE_MicroOLED by Nenad Milosevic

Committer:
synvox
Date:
Thu Mar 19 03:37:35 2015 +0000
Revision:
0:b7fc78d2b795
Child:
1:9c140b4e9453
Library for MicroOLED 0.66'' (64 x 48 pixel) display with SSD1306 controller

Who changed what in which revision?

UserRevisionLine numberNew contents of line
synvox 0:b7fc78d2b795 1 /******************************************************************************
synvox 0:b7fc78d2b795 2 SFE_MicroOLED.h
synvox 0:b7fc78d2b795 3 Header file for the MicroOLED mbed Library
synvox 0:b7fc78d2b795 4
synvox 0:b7fc78d2b795 5 Jim Lindblom @ SparkFun Electronics
synvox 0:b7fc78d2b795 6 October 26, 2014
synvox 0:b7fc78d2b795 7 https://github.com/sparkfun/Micro_OLED_Breakout/tree/master/Firmware/Arduino/libraries/SFE_MicroOLED
synvox 0:b7fc78d2b795 8
synvox 0:b7fc78d2b795 9 Adapted for mbed by Nenad Milosevic
synvox 0:b7fc78d2b795 10 March, 2015
synvox 0:b7fc78d2b795 11
synvox 0:b7fc78d2b795 12 This file defines the hardware SPI interface for the Micro OLED Breakout.
synvox 0:b7fc78d2b795 13
synvox 0:b7fc78d2b795 14 Development environment specifics:
synvox 0:b7fc78d2b795 15 Various suitable mbed platforms
synvox 0:b7fc78d2b795 16 Micro OLED Breakout v1.0
synvox 0:b7fc78d2b795 17
synvox 0:b7fc78d2b795 18 This code was heavily based around the MicroView library, written by GeekAmmo
synvox 0:b7fc78d2b795 19 (https://github.com/geekammo/MicroView-Arduino-Library), and released under
synvox 0:b7fc78d2b795 20 the terms of the GNU General Public License as published by the Free Software
synvox 0:b7fc78d2b795 21 Foundation, either version 3 of the License, or (at your option) any later
synvox 0:b7fc78d2b795 22 version.
synvox 0:b7fc78d2b795 23
synvox 0:b7fc78d2b795 24 This program is distributed in the hope that it will be useful,
synvox 0:b7fc78d2b795 25 but WITHOUT ANY WARRANTY; without even the implied warranty of
synvox 0:b7fc78d2b795 26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
synvox 0:b7fc78d2b795 27 GNU General Public License for more details.
synvox 0:b7fc78d2b795 28
synvox 0:b7fc78d2b795 29 You should have received a copy of the GNU General Public License
synvox 0:b7fc78d2b795 30 along with this program. If not, see <http://www.gnu.org/licenses/>.
synvox 0:b7fc78d2b795 31 ******************************************************************************/
synvox 0:b7fc78d2b795 32
synvox 0:b7fc78d2b795 33 #ifndef SFE_MICROOLED_H
synvox 0:b7fc78d2b795 34 #define SFE_MICROOLED_H
synvox 0:b7fc78d2b795 35
synvox 0:b7fc78d2b795 36 static inline void swap(uint8_t &a, uint8_t &b)
synvox 0:b7fc78d2b795 37 {
synvox 0:b7fc78d2b795 38 uint8_t t = a;
synvox 0:b7fc78d2b795 39
synvox 0:b7fc78d2b795 40 a = b;
synvox 0:b7fc78d2b795 41 b = t;
synvox 0:b7fc78d2b795 42 }
synvox 0:b7fc78d2b795 43
synvox 0:b7fc78d2b795 44 #ifndef _BV
synvox 0:b7fc78d2b795 45 #define _BV(bit) (1<<(bit))
synvox 0:b7fc78d2b795 46 #endif
synvox 0:b7fc78d2b795 47
synvox 0:b7fc78d2b795 48 #define BLACK 0
synvox 0:b7fc78d2b795 49 #define WHITE 1
synvox 0:b7fc78d2b795 50
synvox 0:b7fc78d2b795 51 #define LCDWIDTH 64
synvox 0:b7fc78d2b795 52 #define LCDHEIGHT 48
synvox 0:b7fc78d2b795 53 #define LCDCOLUMNOFFSET 32 // Visible start column within SSD1306 controller memory
synvox 0:b7fc78d2b795 54 #define FONTHEADERSIZE 6
synvox 0:b7fc78d2b795 55
synvox 0:b7fc78d2b795 56 #define LCDTOTALWIDTH 128 // Full width of SSD1306 controller memory
synvox 0:b7fc78d2b795 57 #define LCDTOTALHEIGHT 64 // Full height of SSD1306 controller memory
synvox 0:b7fc78d2b795 58
synvox 0:b7fc78d2b795 59 #define NORM 0
synvox 0:b7fc78d2b795 60 #define XOR 1
synvox 0:b7fc78d2b795 61
synvox 0:b7fc78d2b795 62 #define PAGE 0
synvox 0:b7fc78d2b795 63 #define ALL 1
synvox 0:b7fc78d2b795 64
synvox 0:b7fc78d2b795 65 #define SETCONTRAST 0x81
synvox 0:b7fc78d2b795 66 #define DISPLAYALLONRESUME 0xA4
synvox 0:b7fc78d2b795 67 #define DISPLAYALLON 0xA5
synvox 0:b7fc78d2b795 68 #define NORMALDISPLAY 0xA6
synvox 0:b7fc78d2b795 69 #define INVERTDISPLAY 0xA7
synvox 0:b7fc78d2b795 70 #define DISPLAYOFF 0xAE
synvox 0:b7fc78d2b795 71 #define DISPLAYON 0xAF
synvox 0:b7fc78d2b795 72 #define SETDISPLAYOFFSET 0xD3
synvox 0:b7fc78d2b795 73 #define SETCOMPINS 0xDA
synvox 0:b7fc78d2b795 74 #define SETVCOMDESELECT 0xDB
synvox 0:b7fc78d2b795 75 #define SETDISPLAYCLOCKDIV 0xD5
synvox 0:b7fc78d2b795 76 #define SETPRECHARGE 0xD9
synvox 0:b7fc78d2b795 77 #define SETMULTIPLEX 0xA8
synvox 0:b7fc78d2b795 78 #define SETLOWCOLUMN 0x00
synvox 0:b7fc78d2b795 79 #define SETHIGHCOLUMN 0x10
synvox 0:b7fc78d2b795 80 #define SETSTARTLINE 0x40
synvox 0:b7fc78d2b795 81 #define MEMORYMODE 0x20
synvox 0:b7fc78d2b795 82 #define SETCOLUMNBOUNDS 0x21
synvox 0:b7fc78d2b795 83 #define SETPAGEBOUNDS 0x22
synvox 0:b7fc78d2b795 84 #define COMSCANINC 0xC0
synvox 0:b7fc78d2b795 85 #define COMSCANDEC 0xC8
synvox 0:b7fc78d2b795 86 #define SEGREMAP 0xA0
synvox 0:b7fc78d2b795 87 #define CHARGEPUMP 0x8D
synvox 0:b7fc78d2b795 88 #define EXTERNALVCC 0x01
synvox 0:b7fc78d2b795 89 #define SWITCHCAPVCC 0x02
synvox 0:b7fc78d2b795 90
synvox 0:b7fc78d2b795 91 // Scroll
synvox 0:b7fc78d2b795 92 #define ACTIVATESCROLL 0x2F
synvox 0:b7fc78d2b795 93 #define DEACTIVATESCROLL 0x2E
synvox 0:b7fc78d2b795 94 #define SETVERTICALSCROLLAREA 0xA3
synvox 0:b7fc78d2b795 95 #define RIGHTHORIZONTALSCROLL 0x26
synvox 0:b7fc78d2b795 96 #define LEFTHORIZONTALSCROLL 0x27
synvox 0:b7fc78d2b795 97 #define VERTICALRIGHTHORIZONTALSCROLL 0x29
synvox 0:b7fc78d2b795 98 #define VERTICALLEFTHORIZONTALSCROLL 0x2A
synvox 0:b7fc78d2b795 99
synvox 0:b7fc78d2b795 100 typedef bool boolean;
synvox 0:b7fc78d2b795 101
synvox 0:b7fc78d2b795 102 class MicroOLED {
synvox 0:b7fc78d2b795 103 public:
synvox 0:b7fc78d2b795 104 // Constructor
synvox 0:b7fc78d2b795 105 MicroOLED(SPI &spi, PinName rst, PinName dc, PinName cs) : miol_spi(spi), rstPin(rst), dcPin(dc), csPin(cs)
synvox 0:b7fc78d2b795 106 {
synvox 0:b7fc78d2b795 107 // Set default states for the DigitalOut pins.
synvox 0:b7fc78d2b795 108 rstPin = 1;
synvox 0:b7fc78d2b795 109 dcPin = 0;
synvox 0:b7fc78d2b795 110 csPin = 1;
synvox 0:b7fc78d2b795 111 };
synvox 0:b7fc78d2b795 112
synvox 0:b7fc78d2b795 113 // Initialize SPI mode and frequency and SSD1306 for particular display
synvox 0:b7fc78d2b795 114 void init(int spi_mode, int spi_freq);
synvox 0:b7fc78d2b795 115
synvox 0:b7fc78d2b795 116 // Standard text output functions
synvox 0:b7fc78d2b795 117 void putc(char c);
synvox 0:b7fc78d2b795 118 void puts(const char *cstring);
synvox 0:b7fc78d2b795 119 void printf(const char *format, ...);
synvox 0:b7fc78d2b795 120
synvox 0:b7fc78d2b795 121 // RAW LCD functions
synvox 0:b7fc78d2b795 122 void command(uint8_t c);
synvox 0:b7fc78d2b795 123 void command(uint8_t c1, uint8_t c2);
synvox 0:b7fc78d2b795 124 void command(uint8_t c1, uint8_t c2, uint8_t c3);
synvox 0:b7fc78d2b795 125 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);
synvox 0:b7fc78d2b795 126
synvox 0:b7fc78d2b795 127 // LCD Draw functions
synvox 0:b7fc78d2b795 128 void clear(uint8_t mode);
synvox 0:b7fc78d2b795 129 void clear(uint8_t mode, uint8_t c);
synvox 0:b7fc78d2b795 130 void invert(boolean inv);
synvox 0:b7fc78d2b795 131 void contrast(uint8_t contrast);
synvox 0:b7fc78d2b795 132 void display(void);
synvox 0:b7fc78d2b795 133 void setCursor(uint8_t x, uint8_t y);
synvox 0:b7fc78d2b795 134 void pixel(uint8_t x, uint8_t y);
synvox 0:b7fc78d2b795 135 void pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode);
synvox 0:b7fc78d2b795 136 void line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
synvox 0:b7fc78d2b795 137 void line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode);
synvox 0:b7fc78d2b795 138 void lineH(uint8_t x, uint8_t y, uint8_t width);
synvox 0:b7fc78d2b795 139 void lineH(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode);
synvox 0:b7fc78d2b795 140 void lineV(uint8_t x, uint8_t y, uint8_t height);
synvox 0:b7fc78d2b795 141 void lineV(uint8_t x, uint8_t y, uint8_t height, uint8_t color, uint8_t mode);
synvox 0:b7fc78d2b795 142 void rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height);
synvox 0:b7fc78d2b795 143 void rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode);
synvox 0:b7fc78d2b795 144 void rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height);
synvox 0:b7fc78d2b795 145 void rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode);
synvox 0:b7fc78d2b795 146 void circle(uint8_t x, uint8_t y, uint8_t radius);
synvox 0:b7fc78d2b795 147 void circle(uint8_t x, uint8_t y, uint8_t radius, uint8_t color, uint8_t mode);
synvox 0:b7fc78d2b795 148 void circleFill(uint8_t x0, uint8_t y0, uint8_t radius);
synvox 0:b7fc78d2b795 149 void circleFill(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t mode);
synvox 0:b7fc78d2b795 150 void drawChar(uint8_t x, uint8_t y, uint8_t c);
synvox 0:b7fc78d2b795 151 void drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode);
synvox 0:b7fc78d2b795 152 void drawBitmap(const uint8_t * bitArray);
synvox 0:b7fc78d2b795 153 uint8_t getLCDWidth(void);
synvox 0:b7fc78d2b795 154 uint8_t getLCDHeight(void);
synvox 0:b7fc78d2b795 155 void setColor(uint8_t color);
synvox 0:b7fc78d2b795 156 void setDrawMode(uint8_t mode);
synvox 0:b7fc78d2b795 157 uint8_t *getScreenBuffer(void);
synvox 0:b7fc78d2b795 158
synvox 0:b7fc78d2b795 159 // Font functions
synvox 0:b7fc78d2b795 160 uint8_t getFontWidth(void);
synvox 0:b7fc78d2b795 161 uint8_t getFontHeight(void);
synvox 0:b7fc78d2b795 162 uint8_t getTotalFonts(void);
synvox 0:b7fc78d2b795 163 uint8_t getFontType(void);
synvox 0:b7fc78d2b795 164 uint8_t setFontType(uint8_t type);
synvox 0:b7fc78d2b795 165 uint8_t getFontStartChar(void);
synvox 0:b7fc78d2b795 166 uint8_t getFontTotalChar(void);
synvox 0:b7fc78d2b795 167
synvox 0:b7fc78d2b795 168 // LCD Rotate Scroll functions
synvox 0:b7fc78d2b795 169 void scrollRight(uint8_t start, uint8_t stop);
synvox 0:b7fc78d2b795 170 void scrollLeft(uint8_t start, uint8_t stop);
synvox 0:b7fc78d2b795 171 void scrollStop(void);
synvox 0:b7fc78d2b795 172 void flipVertical(boolean flip);
synvox 0:b7fc78d2b795 173 void flipHorizontal(boolean flip);
synvox 0:b7fc78d2b795 174
synvox 0:b7fc78d2b795 175 private:
synvox 0:b7fc78d2b795 176 SPI &miol_spi;
synvox 0:b7fc78d2b795 177 DigitalOut rstPin, dcPin, csPin;
synvox 0:b7fc78d2b795 178 uint8_t foreColor, drawMode, fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY;
synvox 0:b7fc78d2b795 179 uint16_t fontMapWidth;
synvox 0:b7fc78d2b795 180 static const unsigned char *fontsPointer[];
synvox 0:b7fc78d2b795 181 };
synvox 0:b7fc78d2b795 182 #endif