A class for managing SSD1306 controlled LCD´s (cheap 128x64 models, 0.96'') with more scroll features

Dependents:   2PA2S 2PA2S_v2

Revision:
0:3d84b3bfb794
Child:
1:c5cf4ca5939f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ssd1306.h	Wed Oct 25 16:28:07 2017 +0200
@@ -0,0 +1,122 @@
+/*
+* ssd1306.cpp
+*
+*  Created on: 20 oct. 2017
+*      Author: rodriguj
+*/
+#ifndef MBED_SSD1306_LIBRARY
+#define MBED_SSD1306_LIBRARY
+
+#include "mbed.h"
+
+#define IS_COMMAND         0x00
+#define IS_DATA            0x40
+#define IS_NOT_LAST        0x80
+#define IS_LAST            0x00
+
+#define SSD1306_SETCONTRAST 0x81
+#define SSD1306_DISPLAYALLON_RESUME 0xA4
+#define SSD1306_DISPLAYALLON 0xA5
+#define SSD1306_NORMALDISPLAY 0xA6
+#define SSD1306_INVERTDISPLAY 0xA7
+#define SSD1306_DISPLAYOFF 0xAE
+#define SSD1306_DISPLAYON 0xAF
+
+#define SSD1306_SETDISPLAYOFFSET 0xD3
+#define SSD1306_SETCOMPINS 0xDA
+
+#define SSD1306_SETVCOMDETECT 0xDB
+
+#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
+#define SSD1306_SETPRECHARGE 0xD9
+
+#define SSD1306_SETMULTIPLEX 0xA8
+
+#define SSD1306_SETLOWCOLUMN 0x00
+#define SSD1306_SETHIGHCOLUMN 0x10
+
+#define SSD1306_SETSTARTLINE 0x40
+
+#define SSD1306_MEMORYMODE 0x20
+
+#define SSD1306_COMSCANINC 0xC0
+#define SSD1306_COMSCANDEC 0xC8
+
+#define SSD1306_SEGREMAP 0xA0
+
+#define SSD1306_CHARGEPUMP 0x8D
+
+#define SSD1306_EXTERNALVCC 0x1
+#define SSD1306_SWITCHCAPVCC 0x2
+
+// Scrolling #defines
+#define SSD1306_ACTIVATE_SCROLL 0x2F
+#define SSD1306_DEACTIVATE_SCROLL 0x2E
+#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
+#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
+#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
+#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
+#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
+
+class SSD1306 : private NonCopyable<SSD1306> {
+    
+public:
+    enum PlotStyle
+    {
+        Normal,
+        Inverse,
+        Xor
+    };
+    
+    enum I2CSpeed
+    {
+        Low,
+        Medium,
+        Fast
+    };
+    
+    /** Crea una interfaz al display OLED usando el bus I2C
+    *
+    *  @param sda I2C data line pin
+    *  @param scl I2C clock line pin
+    */
+    SSD1306 (PinName sda, PinName scl);
+    
+    /** Set the frequency of the I2C interface
+    *
+    *  @param hz The bus frequency in hertz
+    */
+    void speed (I2CSpeed spd);
+    
+    int init (void);
+    
+    void scroll (void);
+    
+    void putchar (char c);
+    
+    void display (void);
+    
+    void set_contrast (char v);
+    
+    void cls (void);
+    
+    void plot (char x, char y, PlotStyle modo);
+    
+    virtual ~SSD1306 () {
+        delete bus;
+        delete fb;
+    }
+    
+protected:
+    I2C *bus;
+    char ssd1306_i2c_addr;
+    char *fb;
+    int idxfb;
+    int command (char c);
+    int data (char d);
+    int command_data (char c, char c_or_d, char lastitem);
+    char scan ();
+    
+};
+
+#endif