1 | /*********************************************************************
|
---|
2 | This is a library for our Monochrome OLEDs based on SSD1306 drivers
|
---|
3 |
|
---|
4 | Pick one up today in the adafruit shop!
|
---|
5 | ------> http://www.adafruit.com/category/63_98
|
---|
6 |
|
---|
7 | These displays use SPI to communicate, 4 or 5 pins are required to
|
---|
8 | interface
|
---|
9 |
|
---|
10 | Adafruit invests time and resources providing this open source code,
|
---|
11 | please support Adafruit and open-source hardware by purchasing
|
---|
12 | products from Adafruit!
|
---|
13 |
|
---|
14 | Written by Limor Fried/Ladyada for Adafruit Industries.
|
---|
15 | BSD license, check license.txt for more information
|
---|
16 | All text above, and the splash screen must be included in any redistribution
|
---|
17 | *********************************************************************/
|
---|
18 | #ifndef _Adafruit_SSD1306_H_
|
---|
19 | #define _Adafruit_SSD1306_H_
|
---|
20 |
|
---|
21 | #include <stdint.h>
|
---|
22 | #include <stdbool.h>
|
---|
23 | #include <time.h>
|
---|
24 | #include "gpio_api.h"
|
---|
25 | #include "spi_api.h"
|
---|
26 | #include "i2c_api.h"
|
---|
27 | #include "gfxfont.h"
|
---|
28 |
|
---|
29 | #define BLACK 0
|
---|
30 | #define WHITE 1
|
---|
31 | #define INVERSE 2
|
---|
32 |
|
---|
33 | #define SSD1306_I2C_ADDRESS 0x78 // 011110+SA0+RW - 0x78 or 0x7A
|
---|
34 | // Address for 128x32 is 0x3C
|
---|
35 | // Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded)
|
---|
36 |
|
---|
37 | /*=========================================================================
|
---|
38 | SSD1306 Displays
|
---|
39 | -----------------------------------------------------------------------
|
---|
40 | The driver is used in multiple displays (128x64, 128x32, etc.).
|
---|
41 | Select the appropriate display below to create an appropriately
|
---|
42 | sized framebuffer, etc.
|
---|
43 |
|
---|
44 | SSD1306_128_64 128x64 pixel display
|
---|
45 |
|
---|
46 | SSD1306_128_32 128x32 pixel display
|
---|
47 |
|
---|
48 | SSD1306_96_16
|
---|
49 |
|
---|
50 | -----------------------------------------------------------------------*/
|
---|
51 | #define SSD1306_128_64
|
---|
52 | //#define SSD1306_128_32
|
---|
53 | // #define SSD1306_96_16
|
---|
54 | /*=========================================================================*/
|
---|
55 |
|
---|
56 | #if defined SSD1306_128_64 && defined SSD1306_128_32
|
---|
57 | #error "Only one SSD1306 display can be specified at once in SSD1306.h"
|
---|
58 | #endif
|
---|
59 | #if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16
|
---|
60 | #error "At least one SSD1306 display must be specified in SSD1306.h"
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | #if defined SSD1306_128_64
|
---|
64 | #define SSD1306_LCDWIDTH 128
|
---|
65 | #define SSD1306_LCDHEIGHT 64
|
---|
66 | #endif
|
---|
67 | #if defined SSD1306_128_32
|
---|
68 | #define SSD1306_LCDWIDTH 128
|
---|
69 | #define SSD1306_LCDHEIGHT 32
|
---|
70 | #endif
|
---|
71 | #if defined SSD1306_96_16
|
---|
72 | #define SSD1306_LCDWIDTH 96
|
---|
73 | #define SSD1306_LCDHEIGHT 16
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | #define SSD1306_SETCONTRAST 0x81
|
---|
77 | #define SSD1306_DISPLAYALLON_RESUME 0xA4
|
---|
78 | #define SSD1306_DISPLAYALLON 0xA5
|
---|
79 | #define SSD1306_NORMALDISPLAY 0xA6
|
---|
80 | #define SSD1306_INVERTDISPLAY 0xA7
|
---|
81 | #define SSD1306_DISPLAYOFF 0xAE
|
---|
82 | #define SSD1306_DISPLAYON 0xAF
|
---|
83 |
|
---|
84 | #define SSD1306_SETDISPLAYOFFSET 0xD3
|
---|
85 | #define SSD1306_SETCOMPINS 0xDA
|
---|
86 |
|
---|
87 | #define SSD1306_SETVCOMDETECT 0xDB
|
---|
88 |
|
---|
89 | #define SSD1306_SETDISPLAYCLOCKDIV 0xD5
|
---|
90 | #define SSD1306_SETPRECHARGE 0xD9
|
---|
91 |
|
---|
92 | #define SSD1306_SETMULTIPLEX 0xA8
|
---|
93 |
|
---|
94 | #define SSD1306_SETLOWCOLUMN 0x00
|
---|
95 | #define SSD1306_SETHIGHCOLUMN 0x10
|
---|
96 |
|
---|
97 | #define SSD1306_SETSTARTLINE 0x40
|
---|
98 |
|
---|
99 | #define SSD1306_MEMORYMODE 0x20
|
---|
100 | #define SSD1306_COLUMNADDR 0x21
|
---|
101 | #define SSD1306_PAGEADDR 0x22
|
---|
102 |
|
---|
103 | #define SSD1306_COMSCANINC 0xC0
|
---|
104 | #define SSD1306_COMSCANDEC 0xC8
|
---|
105 |
|
---|
106 | #define SSD1306_SEGREMAP 0xA0
|
---|
107 |
|
---|
108 | #define SSD1306_CHARGEPUMP 0x8D
|
---|
109 |
|
---|
110 | #define SSD1306_EXTERNALVCC 0x1
|
---|
111 | #define SSD1306_SWITCHCAPVCC 0x2
|
---|
112 |
|
---|
113 | // Scrolling #defines
|
---|
114 | #define SSD1306_ACTIVATE_SCROLL 0x2F
|
---|
115 | #define SSD1306_DEACTIVATE_SCROLL 0x2E
|
---|
116 | #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
|
---|
117 | #define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
|
---|
118 | #define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
|
---|
119 | #define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
|
---|
120 | #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
|
---|
121 |
|
---|
122 | typedef struct
|
---|
123 | {
|
---|
124 | uint16_t _width; /* 幅ピクセル数 */
|
---|
125 | uint16_t _height; /* 高さピクセル数 */
|
---|
126 | int16_t cursor_x, cursor_y;
|
---|
127 | uint16_t textcolor, textbgcolor;
|
---|
128 | uint8_t textsize, rotation;
|
---|
129 | bool wrap;
|
---|
130 | GFXfont *gfxFont;
|
---|
131 | int8_t _i2caddr, _vccstate;
|
---|
132 | gpio_t sid, sclk, dc, rst, cs;
|
---|
133 | bool hwSPI;
|
---|
134 | i2c_t i2c;
|
---|
135 | spi_t spi;
|
---|
136 | } LCD_Handler_t;
|
---|
137 |
|
---|
138 | void lcd_init1(LCD_Handler_t *lcd, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS);
|
---|
139 | void lcd_init2(LCD_Handler_t *lcd, int8_t DC, int8_t RST, int8_t CS);
|
---|
140 | //void lcd_init3(LCD_Handler_t *lcd, int8_t RST = -1);
|
---|
141 | void lcd_init3(LCD_Handler_t *lcd, int8_t RST);
|
---|
142 |
|
---|
143 | //void lcd_begin(LCD_Handler_t *lcd, uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = SSD1306_I2C_ADDRESS, bool reset = true);
|
---|
144 | void lcd_begin(LCD_Handler_t *lcd, uint8_t switchvcc, uint8_t i2caddr, bool reset);
|
---|
145 | void lcd_command(LCD_Handler_t *lcd, uint8_t c);
|
---|
146 |
|
---|
147 | void lcd_clearDisplay(LCD_Handler_t *lcd);
|
---|
148 | void lcd_invertDisplay(LCD_Handler_t *lcd, uint8_t i);
|
---|
149 | void lcd_display(LCD_Handler_t *lcd);
|
---|
150 |
|
---|
151 | void lcd_startscrollright(LCD_Handler_t *lcd, uint8_t start, uint8_t stop);
|
---|
152 | void lcd_startscrollleft(LCD_Handler_t *lcd, uint8_t start, uint8_t stop);
|
---|
153 |
|
---|
154 | void lcd_startscrolldiagright(LCD_Handler_t *lcd, uint8_t start, uint8_t stop);
|
---|
155 | void lcd_startscrolldiagleft(LCD_Handler_t *lcd, uint8_t start, uint8_t stop);
|
---|
156 | void lcd_stopscroll(LCD_Handler_t *lcd);
|
---|
157 |
|
---|
158 | void lcd_dim(LCD_Handler_t *lcd, bool dim);
|
---|
159 |
|
---|
160 | void lcd_drawPixel(LCD_Handler_t *lcd, int16_t x, int16_t y, uint16_t color);
|
---|
161 |
|
---|
162 | void lcd_drawFastVLine(LCD_Handler_t *lcd, int16_t x, int16_t y, int16_t h, uint16_t color);
|
---|
163 | void lcd_drawFastHLine(LCD_Handler_t *lcd, int16_t x, int16_t y, int16_t w, uint16_t color);
|
---|
164 |
|
---|
165 | void lcd_drawFastVLineInternal(LCD_Handler_t *lcd, int16_t x, int16_t y, int16_t h, uint16_t color);
|
---|
166 | void lcd_drawFastHLineInternal(LCD_Handler_t *lcd, int16_t x, int16_t y, int16_t w, uint16_t color);
|
---|
167 |
|
---|
168 | #endif /* _Adafruit_SSD1306_H_ */
|
---|