Fork of SSD1306 by
ssd1306.h@1:1d58d378221c, 2013-02-05 (annotated)
- Committer:
- Byrn
- Date:
- Tue Feb 05 17:18:23 2013 +0000
- Revision:
- 1:1d58d378221c
- Parent:
- 0:21cb91208386
- Child:
- 2:e479b0296757
intiial commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Byrn | 0:21cb91208386 | 1 | #ifndef __SSD1306_H__ |
Byrn | 0:21cb91208386 | 2 | #define __SSD1306_H__ |
Byrn | 0:21cb91208386 | 3 | |
Byrn | 0:21cb91208386 | 4 | #define FONT_HEIGHT_OFFSET 0 /* Character pixel height (in multiples of 8) at this position */ |
Byrn | 0:21cb91208386 | 5 | #define FONT_SIZE_OFFSET 1 /* Character data size (in bytes) at this position */ |
Byrn | 0:21cb91208386 | 6 | #define FONT_DATA_OFFSET 2 /* Data starts at this position */ |
Byrn | 0:21cb91208386 | 7 | #define FONT_START ' ' /* First character value in the font table */ |
Byrn | 0:21cb91208386 | 8 | |
Byrn | 1:1d58d378221c | 9 | /** SSD1306 Controller Driver |
Byrn | 1:1d58d378221c | 10 | * |
Byrn | 1:1d58d378221c | 11 | * Information taken from the datasheet at: |
Byrn | 1:1d58d378221c | 12 | * http://www.adafruit.com/datasheets/SSD1306.pdf |
Byrn | 1:1d58d378221c | 13 | */ |
Byrn | 0:21cb91208386 | 14 | class SSD1306 |
Byrn | 0:21cb91208386 | 15 | { |
Byrn | 0:21cb91208386 | 16 | public: |
Byrn | 1:1d58d378221c | 17 | /** Construct a new SSD1306 object. |
Byrn | 1:1d58d378221c | 18 | * @param cs The connected C/S pin. |
Byrn | 1:1d58d378221c | 19 | * @param rs The connected RS pin. |
Byrn | 1:1d58d378221c | 20 | * @param dc The connected DC pin. |
Byrn | 1:1d58d378221c | 21 | * @param clk The connected CLK pin. |
Byrn | 1:1d58d378221c | 22 | * @param data The connected Data pin. |
Byrn | 0:21cb91208386 | 23 | SSD1306(PinName cs, PinName rs, PinName dc, PinName clk, PinName data); |
Byrn | 0:21cb91208386 | 24 | |
Byrn | 0:21cb91208386 | 25 | void initialise(); |
Byrn | 0:21cb91208386 | 26 | void update(); |
Byrn | 0:21cb91208386 | 27 | |
Byrn | 0:21cb91208386 | 28 | void off(); |
Byrn | 0:21cb91208386 | 29 | void on(); |
Byrn | 0:21cb91208386 | 30 | |
Byrn | 1:1d58d378221c | 31 | // Sends the display to sleep, but leaves RAM intact |
Byrn | 1:1d58d378221c | 32 | void sleep(); |
Byrn | 1:1d58d378221c | 33 | |
Byrn | 1:1d58d378221c | 34 | // |
Byrn | 1:1d58d378221c | 35 | void wake(); |
Byrn | 1:1d58d378221c | 36 | |
Byrn | 0:21cb91208386 | 37 | void set_low_column(int value); |
Byrn | 0:21cb91208386 | 38 | void set_high_column(int value); |
Byrn | 1:1d58d378221c | 39 | void set_start_line(int value); |
Byrn | 0:21cb91208386 | 40 | |
Byrn | 0:21cb91208386 | 41 | void clear(); |
Byrn | 0:21cb91208386 | 42 | void set_pixel(int x, int y); |
Byrn | 0:21cb91208386 | 43 | void clear_pixel(int x, int y); |
Byrn | 0:21cb91208386 | 44 | void line(int x0, int y0, int x1, int y1); |
Byrn | 0:21cb91208386 | 45 | |
Byrn | 0:21cb91208386 | 46 | void draw_string(char *font, int x, int y, const char *string); |
Byrn | 0:21cb91208386 | 47 | void draw_char(char *font, int x, int y, char c); |
Byrn | 1:1d58d378221c | 48 | |
Byrn | 1:1d58d378221c | 49 | void set_contrast(unsigned char value); // 1-256 |
Byrn | 1:1d58d378221c | 50 | void set_inverse(unsigned char value); // 0 or 1 |
Byrn | 1:1d58d378221c | 51 | void set_display_start_line(unsigned char value); // 0-63 |
Byrn | 1:1d58d378221c | 52 | void set_horizontal_flip(unsigned char value); // 0 or 1 |
Byrn | 1:1d58d378221c | 53 | void set_display_offset(unsigned char value); // 0-63 |
Byrn | 1:1d58d378221c | 54 | void set_multiplex_ratio(unsigned char value); // 15-63 (value+1 mux) |
Byrn | 1:1d58d378221c | 55 | void set_com_output_scan_direction(unsigned char value); // 0 or 1 |
Byrn | 1:1d58d378221c | 56 | void set_com_pins_hardware_configuration(unsigned char sequential, unsigned char lr_remap); // 0 or 1 for both parametrs |
Byrn | 0:21cb91208386 | 57 | |
Byrn | 0:21cb91208386 | 58 | private: |
Byrn | 0:21cb91208386 | 59 | SPI _spi; |
Byrn | 0:21cb91208386 | 60 | DigitalOut _cs, _reset, _dc; |
Byrn | 0:21cb91208386 | 61 | char _screen[1024]; |
Byrn | 0:21cb91208386 | 62 | |
Byrn | 0:21cb91208386 | 63 | int _cursor_x, _cursor_y; |
Byrn | 0:21cb91208386 | 64 | |
Byrn | 1:1d58d378221c | 65 | void _send_command(unsigned char code); |
Byrn | 1:1d58d378221c | 66 | void _send_data(unsigned char value); |
Byrn | 0:21cb91208386 | 67 | }; |
Byrn | 0:21cb91208386 | 68 | |
Byrn | 0:21cb91208386 | 69 | #define SSD1306_LCDWIDTH 128 |
Byrn | 0:21cb91208386 | 70 | #define SSD1306_LCDHEIGHT 64 |
Byrn | 0:21cb91208386 | 71 | |
Byrn | 0:21cb91208386 | 72 | #define SSD1306_SETCONTRAST 0x81 |
Byrn | 0:21cb91208386 | 73 | #define SSD1306_DISPLAYALLON_RESUME 0xA4 |
Byrn | 0:21cb91208386 | 74 | #define SSD1306_DISPLAYALLON 0xA5 |
Byrn | 0:21cb91208386 | 75 | #define SSD1306_NORMALDISPLAY 0xA6 |
Byrn | 0:21cb91208386 | 76 | #define SSD1306_INVERTDISPLAY 0xA7 |
Byrn | 0:21cb91208386 | 77 | #define SSD1306_DISPLAYOFF 0xAE |
Byrn | 0:21cb91208386 | 78 | #define SSD1306_DISPLAYON 0xAF |
Byrn | 0:21cb91208386 | 79 | |
Byrn | 0:21cb91208386 | 80 | #define SSD1306_SETDISPLAYOFFSET 0xD3 |
Byrn | 0:21cb91208386 | 81 | #define SSD1306_SETCOMPINS 0xDA |
Byrn | 0:21cb91208386 | 82 | |
Byrn | 0:21cb91208386 | 83 | #define SSD1306_SETVCOMDETECT 0xDB |
Byrn | 0:21cb91208386 | 84 | |
Byrn | 0:21cb91208386 | 85 | #define SSD1306_SETDISPLAYCLOCKDIV 0xD5 |
Byrn | 0:21cb91208386 | 86 | #define SSD1306_SETPRECHARGE 0xD9 |
Byrn | 0:21cb91208386 | 87 | |
Byrn | 0:21cb91208386 | 88 | #define SSD1306_SETMULTIPLEX 0xA8 |
Byrn | 0:21cb91208386 | 89 | |
Byrn | 0:21cb91208386 | 90 | #define SSD1306_SETLOWCOLUMN 0x00 |
Byrn | 0:21cb91208386 | 91 | #define SSD1306_SETHIGHCOLUMN 0x10 |
Byrn | 0:21cb91208386 | 92 | |
Byrn | 0:21cb91208386 | 93 | #define SSD1306_SETSTARTLINE 0x40 |
Byrn | 0:21cb91208386 | 94 | |
Byrn | 0:21cb91208386 | 95 | #define SSD1306_MEMORYMODE 0x20 |
Byrn | 0:21cb91208386 | 96 | |
Byrn | 0:21cb91208386 | 97 | #define SSD1306_COMSCANINC 0xC0 |
Byrn | 0:21cb91208386 | 98 | #define SSD1306_COMSCANDEC 0xC8 |
Byrn | 0:21cb91208386 | 99 | |
Byrn | 0:21cb91208386 | 100 | #define SSD1306_SEGREMAP 0xA0 |
Byrn | 0:21cb91208386 | 101 | |
Byrn | 0:21cb91208386 | 102 | #define SSD1306_CHARGEPUMP 0x8D |
Byrn | 0:21cb91208386 | 103 | |
Byrn | 0:21cb91208386 | 104 | #define SSD1306_EXTERNALVCC 0x1 |
Byrn | 0:21cb91208386 | 105 | #define SSD1306_SWITCHCAPVCC 0x2 |
Byrn | 0:21cb91208386 | 106 | |
Byrn | 0:21cb91208386 | 107 | #endif |