A buffered display driver for the SSD1306 OLED controller. Please note that this is a work-in-progress; only very rudimentary drawing support is provided.

Dependents:   Projetv0 greenhouse_proj ProjetLong_Serre_V3 ProjetLong_Serre_V3_1 ... more

Example of use:

#include "mbed.h"

#include "ssd1306.h"
#include "standard_font.h"
#include "bold_font.h"

SSD1306 oled(p8 /* cs */, p9 /* reset */, p14 /* dc */,
             p13 /* clock */, p11 /* data */);

int main()
{
    oled.initialise();
    oled.clear();
    oled.set_contrast(255); // max contrast

    oled.set_font(bold_font, 8);
    oled.printf("Heading\r\n");

    oled.set_font(standard_font, 6);
    oled.printf("Hello World!\r\n");
    oled.printf("Some more text here...");

    oled.update();

    while (1)
    {
        wait(2);
        oled.scroll_up();
        oled.update();
    }
}
Revision:
1:1d58d378221c
Parent:
0:21cb91208386
Child:
2:e479b0296757
--- a/ssd1306.h	Tue Feb 05 09:46:58 2013 +0000
+++ b/ssd1306.h	Tue Feb 05 17:18:23 2013 +0000
@@ -6,9 +6,20 @@
 #define FONT_DATA_OFFSET    2    /* Data starts at this position */
 #define FONT_START          ' '  /* First character value in the font table */
 
+/** SSD1306 Controller Driver
+ *
+ * Information taken from the datasheet at: 
+ *   http://www.adafruit.com/datasheets/SSD1306.pdf
+ */
 class SSD1306
 {
 public:
+    /** Construct a new SSD1306 object.
+     *  @param cs The connected C/S pin.
+     *  @param rs The connected RS pin.
+     *  @param dc The connected DC pin.
+     *  @param clk The connected CLK pin.
+     *  @param data The connected Data pin.
     SSD1306(PinName cs, PinName rs, PinName dc, PinName clk, PinName data);
 
     void initialise();
@@ -17,13 +28,15 @@
     void off();
     void on();
     
-    void invert(int i);
-
+    // Sends the display to sleep, but leaves RAM intact
+    void sleep();
+    
+    // 
+    void wake();
+   
     void set_low_column(int value);
     void set_high_column(int value);
-    void set_start_line(int value);
-
-    void set_display_offset(int value);
+    void set_start_line(int value);    
 
     void clear();
     void set_pixel(int x, int y);
@@ -32,6 +45,15 @@
     
     void draw_string(char *font, int x, int y, const char *string);
     void draw_char(char *font, int x, int y, char c);
+    
+    void set_contrast(unsigned char value); // 1-256
+    void set_inverse(unsigned char value); // 0 or 1
+    void set_display_start_line(unsigned char value); // 0-63
+    void set_horizontal_flip(unsigned char value); // 0 or 1
+    void set_display_offset(unsigned char value); // 0-63
+    void set_multiplex_ratio(unsigned char value); // 15-63 (value+1 mux)
+    void set_com_output_scan_direction(unsigned char value); // 0 or 1
+    void set_com_pins_hardware_configuration(unsigned char sequential, unsigned char lr_remap); // 0 or 1 for both parametrs
 
 private:
     SPI _spi;
@@ -40,8 +62,8 @@
 
     int _cursor_x, _cursor_y;
 
-    void _send_command(int code);
-    void _send_data(int value);
+    void _send_command(unsigned char code);
+    void _send_data(unsigned char value);
 };
 
 #define SSD1306_LCDWIDTH 128