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 "gpio_api.h"
|
---|
22 | #include "spi_api.h"
|
---|
23 | #include "i2c_api.h"
|
---|
24 |
|
---|
25 | #define BLACK 0
|
---|
26 | #define WHITE 1
|
---|
27 | #define INVERSE 2
|
---|
28 |
|
---|
29 | #define SSD1306_I2C_ADDRESS 0x78 // 011110+SA0+RW - 0x78 or 0x7A
|
---|
30 | // Address for 128x32 is 0x3C
|
---|
31 | // Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded)
|
---|
32 |
|
---|
33 | /*=========================================================================
|
---|
34 | SSD1306 Displays
|
---|
35 | -----------------------------------------------------------------------
|
---|
36 | The driver is used in multiple displays (128x64, 128x32, etc.).
|
---|
37 | Select the appropriate display below to create an appropriately
|
---|
38 | sized framebuffer, etc.
|
---|
39 |
|
---|
40 | SSD1306_128_64 128x64 pixel display
|
---|
41 |
|
---|
42 | SSD1306_128_32 128x32 pixel display
|
---|
43 |
|
---|
44 | SSD1306_96_16
|
---|
45 |
|
---|
46 | -----------------------------------------------------------------------*/
|
---|
47 | #define SSD1306_128_64
|
---|
48 | //#define SSD1306_128_32
|
---|
49 | // #define SSD1306_96_16
|
---|
50 | /*=========================================================================*/
|
---|
51 |
|
---|
52 | #if defined SSD1306_128_64 && defined SSD1306_128_32
|
---|
53 | #error "Only one SSD1306 display can be specified at once in SSD1306.h"
|
---|
54 | #endif
|
---|
55 | #if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16
|
---|
56 | #error "At least one SSD1306 display must be specified in SSD1306.h"
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | #if defined SSD1306_128_64
|
---|
60 | #define SSD1306_LCDWIDTH 128
|
---|
61 | #define SSD1306_LCDHEIGHT 64
|
---|
62 | #endif
|
---|
63 | #if defined SSD1306_128_32
|
---|
64 | #define SSD1306_LCDWIDTH 128
|
---|
65 | #define SSD1306_LCDHEIGHT 32
|
---|
66 | #endif
|
---|
67 | #if defined SSD1306_96_16
|
---|
68 | #define SSD1306_LCDWIDTH 96
|
---|
69 | #define SSD1306_LCDHEIGHT 16
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | #define SSD1306_SETCONTRAST 0x81
|
---|
73 | #define SSD1306_DISPLAYALLON_RESUME 0xA4
|
---|
74 | #define SSD1306_DISPLAYALLON 0xA5
|
---|
75 | #define SSD1306_NORMALDISPLAY 0xA6
|
---|
76 | #define SSD1306_INVERTDISPLAY 0xA7
|
---|
77 | #define SSD1306_DISPLAYOFF 0xAE
|
---|
78 | #define SSD1306_DISPLAYON 0xAF
|
---|
79 |
|
---|
80 | #define SSD1306_SETDISPLAYOFFSET 0xD3
|
---|
81 | #define SSD1306_SETCOMPINS 0xDA
|
---|
82 |
|
---|
83 | #define SSD1306_SETVCOMDETECT 0xDB
|
---|
84 |
|
---|
85 | #define SSD1306_SETDISPLAYCLOCKDIV 0xD5
|
---|
86 | #define SSD1306_SETPRECHARGE 0xD9
|
---|
87 |
|
---|
88 | #define SSD1306_SETMULTIPLEX 0xA8
|
---|
89 |
|
---|
90 | #define SSD1306_SETLOWCOLUMN 0x00
|
---|
91 | #define SSD1306_SETHIGHCOLUMN 0x10
|
---|
92 |
|
---|
93 | #define SSD1306_SETSTARTLINE 0x40
|
---|
94 |
|
---|
95 | #define SSD1306_MEMORYMODE 0x20
|
---|
96 | #define SSD1306_COLUMNADDR 0x21
|
---|
97 | #define SSD1306_PAGEADDR 0x22
|
---|
98 |
|
---|
99 | #define SSD1306_COMSCANINC 0xC0
|
---|
100 | #define SSD1306_COMSCANDEC 0xC8
|
---|
101 |
|
---|
102 | #define SSD1306_SEGREMAP 0xA0
|
---|
103 |
|
---|
104 | #define SSD1306_CHARGEPUMP 0x8D
|
---|
105 |
|
---|
106 | #define SSD1306_EXTERNALVCC 0x1
|
---|
107 | #define SSD1306_SWITCHCAPVCC 0x2
|
---|
108 |
|
---|
109 | // Scrolling #defines
|
---|
110 | #define SSD1306_ACTIVATE_SCROLL 0x2F
|
---|
111 | #define SSD1306_DEACTIVATE_SCROLL 0x2E
|
---|
112 | #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
|
---|
113 | #define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
|
---|
114 | #define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
|
---|
115 | #define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
|
---|
116 | #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
|
---|
117 |
|
---|
118 | typedef struct
|
---|
119 | {
|
---|
120 | uint16_t _width; /* 幅ピクセル数 */
|
---|
121 | uint16_t _height; /* 高さピクセル数 */
|
---|
122 | int rotation;
|
---|
123 | int8_t _i2caddr, _vccstate;
|
---|
124 | gpio_t sid, sclk, dc, rst, cs;
|
---|
125 | bool_t hwSPI;
|
---|
126 | i2c_t i2c;
|
---|
127 | spi_t spi;
|
---|
128 | } LCD_Handler_t;
|
---|
129 |
|
---|
130 | void lcd_init1(LCD_Handler_t *lcd, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS);
|
---|
131 | void lcd_init2(LCD_Handler_t *lcd, int8_t DC, int8_t RST, int8_t CS);
|
---|
132 | //void lcd_init3(LCD_Handler_t *lcd, int8_t RST = -1);
|
---|
133 | void lcd_init3(LCD_Handler_t *lcd, int8_t RST);
|
---|
134 |
|
---|
135 | //void lcd_begin(LCD_Handler_t *lcd, uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = SSD1306_I2C_ADDRESS, bool_t reset = true);
|
---|
136 | void lcd_begin(LCD_Handler_t *lcd, uint8_t switchvcc, uint8_t i2caddr, bool_t reset);
|
---|
137 | void lcd_command(LCD_Handler_t *lcd, uint8_t c);
|
---|
138 |
|
---|
139 | void lcd_clearDisplay(LCD_Handler_t *lcd);
|
---|
140 | void lcd_invertDisplay(LCD_Handler_t *lcd, uint8_t i);
|
---|
141 | void lcd_display(LCD_Handler_t *lcd);
|
---|
142 |
|
---|
143 | void lcd_startscrollright(LCD_Handler_t *lcd, uint8_t start, uint8_t stop);
|
---|
144 | void lcd_startscrollleft(LCD_Handler_t *lcd, uint8_t start, uint8_t stop);
|
---|
145 |
|
---|
146 | void lcd_startscrolldiagright(LCD_Handler_t *lcd, uint8_t start, uint8_t stop);
|
---|
147 | void lcd_startscrolldiagleft(LCD_Handler_t *lcd, uint8_t start, uint8_t stop);
|
---|
148 | void lcd_stopscroll(LCD_Handler_t *lcd);
|
---|
149 |
|
---|
150 | void lcd_dim(LCD_Handler_t *lcd, bool_t dim);
|
---|
151 |
|
---|
152 | void lcd_drawPixel(LCD_Handler_t *lcd, int16_t x, int16_t y, uint16_t color);
|
---|
153 |
|
---|
154 | void lcd_drawFastVLine(LCD_Handler_t *lcd, int16_t x, int16_t y, int16_t h, uint16_t color);
|
---|
155 | void lcd_drawFastHLine(LCD_Handler_t *lcd, int16_t x, int16_t y, int16_t w, uint16_t color);
|
---|
156 |
|
---|
157 | void lcd_drawFastVLineInternal(LCD_Handler_t *lcd, int16_t x, int16_t y, int16_t h, uint16_t color);
|
---|
158 | void lcd_drawFastHLineInternal(LCD_Handler_t *lcd, int16_t x, int16_t y, int16_t w, uint16_t color);
|
---|
159 |
|
---|
160 | #endif /* _Adafruit_SSD1306_H_ */
|
---|