TR-mbed 1.0
Loading...
Searching...
No Matches
SSD1308.h
Go to the documentation of this file.
1#include <stdint.h>
2#include <I2C.h>
3#include "platform/Stream.h"
9// The original code by Andrew Schamp is using (and has been submitted as a part of) Jeff Rowberg's I2Cdevlib library,
10// which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
11// Some parts also mashed up from Graphic Library for driving monochrome displays based on the PCD8544,
12// Copyright (c) 2011, Wim De Roeve, who in turn did partial port of code found on
13// http://serdisplib.sourceforge.net/ser/pcd8544.html#links and by Petras Saduikis <petras@petras.co.uk>
14//
15// Changelog:
16// 2011-08-25 - Initial release by Andrew Schamp <schamp@gmail.com>
17// 2012-06-19 - Ported to mbed and optimised (WH)
18// 2013-07-12 - Minor comment fix and placeholder for SSD1306 (WH)
19// 2015-01-01 - Switch for optimised I2C calls to test on F401 (WH)
20// 2017-12-18 - Fixed non-copyable issue (Thx kenjiArai)
21//
22/*
23================================================================================
24I2Cdev device library code is placed under the MIT license
25Copyright (c) 2011 Andrew Schamp
26Copyright (c) 2012,2013,2017 WH (mbed port)
27
28Permission is hereby granted, free of charge, to any person obtaining a copy
29of this software and associated documentation files (the "Software"), to deal
30in the Software without restriction, including without limitation the rights
31to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32copies of the Software, and to permit persons to whom the Software is
33furnished to do so, subject to the following conditions:
34
35The above copyright notice and this permission notice shall be included in
36all copies or substantial portions of the Software.
37
38THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
44THE SOFTWARE.
45================================================================================
46*/
47
48#ifndef SSD1308_H
49#define SSD1308_H
50
51// This is the I2C address (8 bit)
52// There are two possible addresses: with D/C# (pin 13) grounded, the address is 0x78,
53// with D/C# tied high it is 0x7A. Assume grounded by default.
54#define SSD1308_SA0 0x78
55#define SSD1308_SA1 0x7A
56#define SSD1308_DEF_SA SSD1308_SA0
57
58// Display dimensions
59#define ROWS 64
60#define COLUMNS 128
61#define PAGES (ROWS / 8)
62#define MAX_PAGE (PAGES - 1)
63#define MAX_ROW (ROWS - 1)
64#define MAX_COL (COLUMNS - 1)
65
66// Character dimensions 8x8 font
67#define CHARS (COLUMNS / FONT8x8_WIDTH)
68
69// Command and Datamode
70#define COMMAND_MODE 0x80 // continuation bit is set!
71#define DATA_MODE 0x40
72
73// Commands and Parameter defines
74#define SET_LOWER_COLUMN 0x00 // | with lower nibble (Page mode only)
75#define SET_HIGHER_COLUMN 0x10 // | with higher nibble (Page mode only)
76
77#define HORIZONTAL_ADDRESSING_MODE 0x00
78#define VERTICAL_ADDRESSING_MODE 0x01
79#define PAGE_ADDRESSING_MODE 0x02
80#define SET_MEMORY_ADDRESSING_MODE 0x20 // takes one byte as given above
81
82#define SET_COLUMN_ADDRESS 0x21 // takes two bytes, start address and end address of display data RAM
83#define SET_PAGE_ADDRESS 0x22 // takes two bytes, start address and end address of display data RAM
84
85// Command maybe unsupported by SSD1308
86#define FADE_INTERVAL_8_FRAMES 0x00
87#define FADE_INTERVAL_16_FRAMES 0x01
88#define FADE_INTERVAL_24_FRAMES 0x02
89#define FADE_INTERVAL_32_FRAMES 0x03
90#define FADE_INTERVAL_64_FRAMES 0x07
91#define FADE_INTERVAL_128_FRAMES 0x0F
92#define FADE_BLINK_DISABLE 0x00
93#define FADE_OUT_ENABLE 0x20
94#define BLINK_ENABLE 0x30
95#define SET_FADE_BLINK 0x23 // takes one byte
96 // bit5-4 = 0, fade/blink mode
97 // bit3-0 = Time interval in frames
98
99#define SET_DISPLAY_START_LINE 0x40 // | with a row number 0-63 to set start row. (Reset = 0)
100
101#define SET_CONTRAST 0x81 // takes one byte, 0x00 - 0xFF
102
103#define SET_SEGMENT_REMAP_0 0xA0 // column address 0 is mapped to SEG0 (Reset)
104#define SET_SEGMENT_REMAP_127 0xA1 // column address 127 is mapped to SEG0
105
106#define SET_DISPLAY_GDDRAM 0xA4 // restores display to contents of RAM
107#define SET_ENTIRE_DISPLAY_ON 0xA5 // turns all pixels on, does not affect RAM
108
109#define SET_NORMAL_DISPLAY 0xA6 // a databit of 1 indicates pixel 'ON'
110#define SET_INVERSE_DISPLAY 0xA7 // a databit of 1 indicates pixel 'OFF'
111
112#define SET_MULTIPLEX_RATIO 0xA8 // takes one byte, from 16xMUX to 64xMUX (MUX Ratio = byte+1; Default 64)
113
114#define EXTERNAL_IREF 0x10
115#define INTERNAL_IREF 0x00
116#define SET_IREF_SELECTION 0xAD // sets internal or external Iref
117
118#define SET_DISPLAY_POWER_OFF 0xAE
119#define SET_DISPLAY_POWER_ON 0xAF
120
121#define PAGE0 0x00
122#define PAGE1 0x01
123#define PAGE2 0x02
124#define PAGE3 0x03
125#define PAGE4 0x04
126#define PAGE5 0x05
127#define PAGE6 0x06
128#define PAGE7 0x07
129#define SET_PAGE_START_ADDRESS 0xB0 // | with a page number to get start address (Page mode only)
130
131#define SET_COMMON_REMAP_0 0xC0 // row address 0 is mapped to COM0 (Reset)
132#define SET_COMMON_REMAP_63 0xC8 // row address 63 is mapped to COM0
133
134#define SET_DISPLAY_OFFSET 0xD3 // takes one byte from 0-63 for vertical shift, Reset = 0
135
136#define SET_DISPLAY_CLOCK 0xD5 // takes one byte
137 // bit7-4 = Osc Freq DCLK (Reset = 1000b)
138 // bit3-0 = Divide ration (Reset = oooob, Ratio = 1)
139
140#define SET_PRECHARGE_TIME 0xD9 // takes one byte
141 // bit7-4 = Phase2, upto 15 DCLKs (Reset = 0010b)
142 // bit3-0 = Phase1, upto 15 DCLKs (Reset = 0010b)
143
144
145#define COMMON_BASE 0x02 //
146#define COMMON_SEQUENTIAL 0x00 // Sequential common pins config
147#define COMMON_ALTERNATIVE 0x10 // Odd/Even common pins config (Reset)
148#define COMMON_LEFTRIGHT_NORMAL 0x00 // LeftRight Normal (Reset)
149#define COMMON_LEFTRIGHT_FLIP 0x20 // LeftRight Flip
150#define SET_COMMON_CONF 0xDA // takes one byte as given above
151
152
153#define VCOMH_DESELECT_0_65_CODE 0x00
154#define VCOMH_DESELECT_0_77_CODE 0x20
155#define VCOMH_DESELECT_0_83_CODE 0x30
156#define SET_VCOMH_DESELECT_LEVEL 0xDB // takes one byte as given above
157
158#define NOP 0xE3
159
160#define SCROLL_INTERVAL_5_FRAMES 0x00
161#define SCROLL_INTERVAL_64_FRAMES 0x01
162#define SCROLL_INTERVAL_128_FRAMES 0x02
163#define SCROLL_INTERVAL_256_FRAMES 0x03
164#define SCROLL_INTERVAL_3_FRAMES 0x04
165#define SCROLL_INTERVAL_4_FRAMES 0x05
166#define SCROLL_INTERVAL_25_FRAMES 0x06
167#define SCROLL_INTERVAL_2_FRAMES 0x07
168
169#define SET_RIGHT_HOR_SCROLL 0x26 // takes 6 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, 0x00, 0xFF
170#define SET_LEFT_HOR_SCROLL 0x27 // takes 6 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, 0x00, 0xFF
171
172#define SET_VERT_RIGHT_HOR_SCROLL 0x29 // takes 5 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, VertOffset
173#define SET_VERT_LEFT_HOR_SCROLL 0x2A // takes 5 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, VertOffset
174
175#define SET_DEACTIVATE_SCROLL 0x2E
176#define SET_ACTIVATE_SCROLL 0x2F
177
178#define SET_VERTICAL_SCROLL_AREA 0xA3 // takes 2 bytes: Rows in Top Area (Reset=0), Rows in Scroll Area (Reset=64)
179
180
181
223class SSD1308 : public mbed::Stream {
224 public:
225
231 SSD1308(mbed::I2C *i2c, uint8_t address = SSD1308_DEF_SA);
232
233// High Level methods
234
237 void initialize();
238
241 void clearDisplay();
242
243
251 void fillDisplay(uint8_t pattern = 0x00,
252 uint8_t start_page=0, uint8_t end_page=MAX_PAGE,
253 uint8_t start_col=0, uint8_t end_col=MAX_COL);
254
255
263 void writeBitmap(uint8_t* data,
264 uint8_t start_page=0, uint8_t end_page=MAX_PAGE,
265 uint8_t start_col=0, uint8_t end_col=MAX_COL);
266
272 void writeProgressBar(uint8_t page, uint8_t col, int percentage);
273
274
280 void writeLevelBar(uint8_t page, uint8_t col, int percentage);
281
282 //void setXY(uint8_t, uint8_t y);
283
284 // Select inverted or normal text
285 void setInverted(bool inverted) { _inverted = inverted; };
286
291 int writeChar(char chr);
292
298 void writeBigChar(uint8_t row, uint8_t col, char chr);
299
306 void writeString(uint8_t row, uint8_t col, const char* txt);
307
308 // Stream implementation - provides printf() interface
309 // You would otherwise be forced to use writeChar() or writeString()
310 virtual int _putc(int value) { writeChar(value); return 1; };
311 virtual int _getc() { return -1; };
312
313// Future extension with graphics features
314 // this must be defined by the subclass
315// virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
316
317// Medium Level methods
318
323
328
333
337 void setMemoryAddressingMode(uint8_t mode);
338
339
344 void setColumnStartForPageAddressingMode(uint8_t column);
345
350 void setPageStartForPageAddressingMode(uint8_t page);
351
352
353
357 void setColumnAddress(uint8_t start, uint8_t end);
358
362 void setPageAddress(uint8_t start, uint8_t end);
363
364
369 void setDisplayStartLine(uint8_t line);
370
374 void setContrastControl(uint8_t contrast);
375
376
379 void setEntireDisplayOn();
380
383 void setEntireDisplayRAM();
384
388 void setEntireDisplay(bool on);
389
390
391 // @brief Set Display line MPX Ratio, takes one byte, 0x00-0x3F
392 // @param uint8_t lines (valid range 0..MAX_ROWS)
394
395
398 void setInternalIref();
399
402 void setExternalIref();
403
404
407 void setDisplayOn();
408
411 void setDisplayOff();
412
416 void setDisplayPower(bool on);
417
420 void setDisplayNormal();
421
424 void setDisplayInverse();
425
429 void setDisplayBlink(bool on);
430
434 void setDisplayFade(bool on);
435
440 void setDisplayFlip(bool left, bool down);
441
442 // Set vertical shift by COM from 0 - 63 (0x00 - 0x3F) (Reset = 0x00)
444
445 // Oscillator freq 0x00-0x0F (reset 0x08)
446 // Divide ratio 0x00-0x0F, value +1 (reset 0x00)
447 void setDisplayClock(uint8_t divideRatio, uint8_t oscFreq);
448
449 // Phase1 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid)
450 // Phase2 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid)
451 void setPrechargePeriod(uint8_t phase1, uint8_t phase2);
452
453 // See defines above for levels
455
456
457 // Command for no-operation
458 void nop();
459
460
467 void setContinuousHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page, uint8_t interval);
468
469
477 void setContinuousVerticalAndHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page,
478 uint8_t offset, uint8_t interval);
479
484 void setDisplayScroll(bool on);
485
486
491 void setVerticalScrollArea(uint8_t topRowsFixed, uint8_t scrollRows);
492
493 private:
494
495// Low Level methods
496
499 void _sendCommand(uint8_t command);
500
503 void _sendCommand(uint8_t command, uint8_t param1);
504
507 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2);
508// void sendCommands(uint8_t len, uint8_t* buf);
509
512 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2,
513 uint8_t param3, uint8_t param4,
514 uint8_t param5);
515
518 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2,
519 uint8_t param3, uint8_t param4,
520 uint8_t param5, uint8_t param6);
521
526 bool _sendData(uint8_t data);
527
533 void _sendData(uint8_t len, uint8_t* data);
534
538 void _init();
539
540 mbed::I2C *_i2c; // I2C bus reference
541 uint8_t _readOpcode; // contains the I2C address of the device
542 uint8_t _writeOpcode; // contains the I2C address of the device
543
544 bool _inverted; // inverted or normal text
545};
546
547#endif
int data[]
Definition Map_placement_new.cpp:1
m col(1)
m row(1)
#define SSD1308_DEF_SA
Definition SSD1308.h:56
#define MAX_PAGE
Definition SSD1308.h:62
#define MAX_COL
Definition SSD1308.h:64
Definition SSD1308.h:223
void setDisplayOn()
Enable Display.
Definition SSD1308.cpp:838
void setDisplayNormal()
Show White pixels on Black background.
Definition SSD1308.cpp:861
void setDisplayOff()
Disable Display.
Definition SSD1308.cpp:844
void writeProgressBar(uint8_t page, uint8_t col, int percentage)
write a level meter to the display, Width is (PRG_MAX_SCALE + 2) pixels
Definition SSD1308.cpp:256
virtual int _putc(int value)
Definition SSD1308.h:310
void setEntireDisplay(bool on)
Shows Pixels On or as RAM content.
Definition SSD1308.cpp:954
void setDisplayClock(uint8_t divideRatio, uint8_t oscFreq)
void setMultiplexRatio(uint8_t lines)
void setDisplayScroll(bool on)
Activate or Deactivate Horizontal and Vertical scroll.
Definition SSD1308.cpp:1016
void setDisplayBlink(bool on)
Blink display by fading in and out over a set number of frames.
Definition SSD1308.cpp:874
void setDisplayInverse()
Show Black pixels on White background.
Definition SSD1308.cpp:867
void initialize()
High level Init, most settings remain at Power-On reset value.
Definition SSD1308.cpp:76
virtual int _getc()
Definition SSD1308.h:311
void fillDisplay(uint8_t pattern=0x00, uint8_t start_page=0, uint8_t end_page=MAX_PAGE, uint8_t start_col=0, uint8_t end_col=MAX_COL)
fill the display
Definition SSD1308.cpp:140
void setHorizontalAddressingMode()
Set Horizontal Addressing Mode (cursor incr left-to-right, top-to-bottom)
Definition SSD1308.cpp:746
void setDisplayFade(bool on)
Fade out display in set number of frames.
Definition SSD1308.cpp:887
void setPrechargePeriod(uint8_t phase1, uint8_t phase2)
void setVcomhDeselectLevel(uint8_t level)
void nop()
void writeLevelBar(uint8_t page, uint8_t col, int percentage)
write a level meter to the display, Width is (PRG_MAX_SCALE + 2) pixels
Definition SSD1308.cpp:340
void setContrastControl(uint8_t contrast)
Set Contrast.
Definition SSD1308.cpp:831
void writeString(uint8_t row, uint8_t col, const char *txt)
Write a string to the display using the 8x8 font.
Definition SSD1308.cpp:446
void writeBitmap(uint8_t *data, uint8_t start_page=0, uint8_t end_page=MAX_PAGE, uint8_t start_col=0, uint8_t end_col=MAX_COL)
write a bitmap to the display
Definition SSD1308.cpp:196
void setPageAddressingMode()
Set Page Addressing Mode (cursor incr left-to-right)
Definition SSD1308.cpp:760
void setEntireDisplayOn()
Shows All Pixels On.
Definition SSD1308.cpp:941
void setEntireDisplayRAM()
Shows Pixels as RAM content.
Definition SSD1308.cpp:947
void setInverted(bool inverted)
Definition SSD1308.h:285
void writeBigChar(uint8_t row, uint8_t col, char chr)
Write large character (16x24 font)
Definition SSD1308.cpp:486
void setInternalIref()
Sets Internal Iref.
Definition SSD1308.cpp:923
void setContinuousVerticalAndHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page, uint8_t offset, uint8_t interval)
Horizontal and Vertical scroll by one column per interval.
Definition SSD1308.cpp:988
void setColumnStartForPageAddressingMode(uint8_t column)
Set Column Start (for Page Addressing Mode only)
Definition SSD1308.cpp:806
void setExternalIref()
Sets External Iref (default)
Definition SSD1308.cpp:932
void setPageAddress(uint8_t start, uint8_t end)
Definition SSD1308.cpp:776
void setPageStartForPageAddressingMode(uint8_t page)
Set Page Start (for Page Addressing Mode only)
Definition SSD1308.cpp:819
void setVerticalScrollArea(uint8_t topRowsFixed, uint8_t scrollRows)
Set Vertical scroll area.
Definition SSD1308.cpp:1003
void clearDisplay()
clear the display
Definition SSD1308.cpp:91
void setVerticalAddressingMode()
Set Vertical Addressing Mode (cursor incr top-to-bottom, left-to-right)
Definition SSD1308.cpp:753
void setDisplayPower(bool on)
Enable or Disable Display.
Definition SSD1308.cpp:851
void setMemoryAddressingMode(uint8_t mode)
Set Addressing Mode.
Definition SSD1308.cpp:767
void setContinuousHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page, uint8_t interval)
Horizontal scroll by one column per interval.
Definition SSD1308.cpp:970
int writeChar(char chr)
Write single character to the display using the 8x8 fontable.
Definition SSD1308.cpp:421
void setColumnAddress(uint8_t start, uint8_t end)
Definition SSD1308.cpp:785
void setDisplayStartLine(uint8_t line)
Set Display StartLine, takes one byte, 0x00-0x3F.
Definition SSD1308.cpp:794
void setDisplayOffset(uint8_t offset)
void setDisplayFlip(bool left, bool down)
Display Flip (Left/Right, Up/Down)
Definition SSD1308.cpp:900
void lines()
Definition geo_hyperplane.cpp:88
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate offset
Definition gnuplot_common_settings.hh:64
I2C i2c(PB_9, PB_8)
uint8_t level
Definition ref_serial.h:254