derived from Aidafruit SSD1306 library

Dependents:   Test_SSD1306 L152RE_OLED_SSD1306 EcranZumo

Fork of SSD1306 by Jonathan Gaul

ssd1306.h

Committer:
Byrn
Date:
2013-02-05
Revision:
1:1d58d378221c
Parent:
0:21cb91208386
Child:
2:e479b0296757

File content as of revision 1:1d58d378221c:

#ifndef __SSD1306_H__
#define __SSD1306_H__

#define FONT_HEIGHT_OFFSET  0    /* Character pixel height (in multiples of 8) at this position */
#define FONT_SIZE_OFFSET    1    /* Character data size (in bytes) at this position */
#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();
    void update();

    void off();
    void on();
    
    // 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 clear();
    void set_pixel(int x, int y);
    void clear_pixel(int x, int y);
    void line(int x0, int y0, int x1, int y1);
    
    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;
    DigitalOut _cs, _reset, _dc;
    char _screen[1024];

    int _cursor_x, _cursor_y;

    void _send_command(unsigned char code);
    void _send_data(unsigned char value);
};

#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 64

#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

#endif