]> git.donarmstrong.com Git - qmk_firmware.git/blob - drivers/oled/oled_driver.h
[Keyboard] fixed pins for numpad_5x4 layout (#6311)
[qmk_firmware.git] / drivers / oled / oled_driver.h
1 /*
2 Copyright 2019 Ryan Caltabiano <https://github.com/XScorpion2>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 #pragma once
18
19 #include <stdint.h>
20 #include <stdbool.h>
21
22 // an enumeration of the chips this driver supports
23 #define OLED_IC_SSD1306 0
24 #define OLED_IC_SH1106  1
25
26 #if defined(OLED_DISPLAY_CUSTOM)
27   // Expected user to implement the necessary defines
28 #elif defined(OLED_DISPLAY_128X64)
29   // Double height 128x64
30 #ifndef OLED_DISPLAY_WIDTH
31   #define OLED_DISPLAY_WIDTH 128
32 #endif
33 #ifndef OLED_DISPLAY_HEIGHT
34   #define OLED_DISPLAY_HEIGHT 64
35 #endif
36 #ifndef OLED_MATRIX_SIZE
37   #define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 1024 (compile time mathed)
38 #endif
39 #ifndef OLED_BLOCK_TYPE
40   #define OLED_BLOCK_TYPE uint16_t
41 #endif
42 #ifndef OLED_BLOCK_COUNT
43   #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 32 (compile time mathed)
44 #endif
45 #ifndef OLED_BLOCK_SIZE
46   #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed)
47 #endif
48 #ifndef OLED_COM_PINS
49   #define OLED_COM_PINS COM_PINS_ALT
50 #endif
51
52   // For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays
53   // The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode
54 #ifndef OLED_SOURCE_MAP
55   #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
56 #endif
57 #ifndef OLED_TARGET_MAP
58   #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 }
59 #endif
60   // If OLED_BLOCK_TYPE is uint32_t, these tables would look like:
61   // #define OLED_SOURCE_MAP { 32, 40, 48, 56 }
62   // #define OLED_TARGET_MAP { 24, 16, 8, 0 }
63   // If OLED_BLOCK_TYPE is uint16_t, these tables would look like:
64   // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
65   // #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 }
66   // If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
67   // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 }
68   // #define OLED_TARGET_MAP { 56, 120, 48, 112, 40, 104, 32, 96, 24, 88, 16, 80, 8, 72, 0, 64 }
69 #else // defined(OLED_DISPLAY_128X64)
70   // Default 128x32
71 #ifndef OLED_DISPLAY_WIDTH
72   #define OLED_DISPLAY_WIDTH 128
73 #endif
74 #ifndef OLED_DISPLAY_HEIGHT
75   #define OLED_DISPLAY_HEIGHT 32
76 #endif
77 #ifndef OLED_MATRIX_SIZE
78   #define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 512 (compile time mathed)
79 #endif
80 #ifndef OLED_BLOCK_TYPE
81   #define OLED_BLOCK_TYPE uint16_t // Type to use for segmenting the oled display for smart rendering, use unsigned types only
82 #endif
83 #ifndef OLED_BLOCK_COUNT
84   #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 16 (compile time mathed)
85 #endif
86 #ifndef OLED_BLOCK_SIZE
87   #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed)
88 #endif
89 #ifndef OLED_COM_PINS
90   #define OLED_COM_PINS COM_PINS_SEQ
91 #endif
92
93   // For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays
94   // The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode
95 #ifndef OLED_SOURCE_MAP
96   #define OLED_SOURCE_MAP { 0, 8, 16, 24 }
97 #endif
98 #ifndef OLED_TARGET_MAP
99   #define OLED_TARGET_MAP { 24, 16, 8, 0 }
100 #endif
101   // If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
102   // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
103   // #define OLED_TARGET_MAP { 48, 32, 16, 0, 56, 40, 24, 8 }
104 #endif // defined(OLED_DISPLAY_CUSTOM)
105
106 #if !defined(OLED_IC)
107   #define OLED_IC OLED_IC_SSD1306
108 #endif
109
110 // the column address corresponding to the first column in the display hardware
111 #if !defined(OLED_COLUMN_OFFSET)
112   #define OLED_COLUMN_OFFSET 0
113 #endif
114
115 // Address to use for the i2c oled communication
116 #if !defined(OLED_DISPLAY_ADDRESS)
117   #define OLED_DISPLAY_ADDRESS 0x3C
118 #endif
119
120 // Custom font file to use
121 #if !defined(OLED_FONT_H)
122   #define OLED_FONT_H "glcdfont.c"
123 #endif
124 // unsigned char value of the first character in the font file
125 #if !defined(OLED_FONT_START)
126   #define OLED_FONT_START 0
127 #endif
128 // unsigned char value of the last character in the font file
129 #if !defined(OLED_FONT_END)
130   #define OLED_FONT_END 224
131 #endif
132 // Font render width
133 #if !defined(OLED_FONT_WIDTH)
134   #define OLED_FONT_WIDTH 6
135 #endif
136 // Font render height
137 #if !defined(OLED_FONT_HEIGHT)
138   #define OLED_FONT_HEIGHT 8
139 #endif
140
141 // OLED Rotation enum values are flags
142 typedef enum {
143     OLED_ROTATION_0   = 0,
144     OLED_ROTATION_90  = 1,
145     OLED_ROTATION_180 = 2,
146     OLED_ROTATION_270 = 3, // OLED_ROTATION_90 | OLED_ROTATION_180
147 } oled_rotation_t;
148
149 // Initialize the oled display, rotating the rendered output based on the define passed in.
150 // Returns true if the OLED was initialized successfully
151 bool oled_init(oled_rotation_t rotation);
152
153 // Called at the start of oled_init, weak function overridable by the user
154 // rotation - the value passed into oled_init
155 // Return new oled_rotation_t if you want to override default rotation
156 oled_rotation_t oled_init_user(oled_rotation_t rotation);
157
158 // Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering
159 void oled_clear(void);
160
161 // Renders the dirty chunks of the buffer to oled display
162 void oled_render(void);
163
164 // Moves cursor to character position indicated by column and line, wraps if out of bounds
165 // Max column denoted by 'oled_max_chars()' and max lines by 'oled_max_lines()' functions
166 void oled_set_cursor(uint8_t col, uint8_t line);
167
168 // Advances the cursor to the next page, writing ' ' if true
169 // Wraps to the begining when out of bounds
170 void oled_advance_page(bool clearPageRemainder);
171
172 // Moves the cursor forward 1 character length
173 // Advance page if there is not enough room for the next character
174 // Wraps to the begining when out of bounds
175 void oled_advance_char(void);
176
177 // Writes a single character to the buffer at current cursor position
178 // Advances the cursor while writing, inverts the pixels if true
179 // Main handler that writes character data to the display buffer
180 void oled_write_char(const char data, bool invert);
181
182 // Writes a string to the buffer at current cursor position
183 // Advances the cursor while writing, inverts the pixels if true
184 void oled_write(const char *data, bool invert);
185
186 // Writes a string to the buffer at current cursor position
187 // Advances the cursor while writing, inverts the pixels if true
188 // Advances the cursor to the next page, wiring ' ' to the remainder of the current page
189 void oled_write_ln(const char *data, bool invert);
190
191 #if defined(__AVR__)
192 // Writes a PROGMEM string to the buffer at current cursor position
193 // Advances the cursor while writing, inverts the pixels if true
194 // Remapped to call 'void oled_write(const char *data, bool invert);' on ARM
195 void oled_write_P(const char *data, bool invert);
196
197 // Writes a PROGMEM string to the buffer at current cursor position
198 // Advances the cursor while writing, inverts the pixels if true
199 // Advances the cursor to the next page, wiring ' ' to the remainder of the current page
200 // Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM
201 void oled_write_ln_P(const char *data, bool invert);
202 #else
203   // Writes a string to the buffer at current cursor position
204   // Advances the cursor while writing, inverts the pixels if true
205   #define oled_write_P(data, invert) oled_write(data, invert)
206
207   // Writes a string to the buffer at current cursor position
208   // Advances the cursor while writing, inverts the pixels if true
209   // Advances the cursor to the next page, wiring ' ' to the remainder of the current page
210   #define oled_write_ln_P(data, invert) oled_write(data, invert)
211 #endif // defined(__AVR__)
212
213 // Can be used to manually turn on the screen if it is off
214 // Returns true if the screen was on or turns on
215 bool oled_on(void);
216
217 // Can be used to manually turn off the screen if it is on
218 // Returns true if the screen was off or turns off
219 bool oled_off(void);
220
221 // Basically it's oled_render, but with timeout management and oled_task_user calling!
222 void oled_task(void);
223
224 // Called at the start of oled_task, weak function overridable by the user
225 void oled_task_user(void);
226
227 // Scrolls the entire display right
228 // Returns true if the screen was scrolling or starts scrolling
229 // NOTE: display contents cannot be changed while scrolling
230 bool oled_scroll_right(void);
231
232 // Scrolls the entire display left
233 // Returns true if the screen was scrolling or starts scrolling
234 // NOTE: display contents cannot be changed while scrolling
235 bool oled_scroll_left(void);
236
237 // Turns off display scrolling
238 // Returns true if the screen was not scrolling or stops scrolling
239 bool oled_scroll_off(void);
240
241 // Returns the maximum number of characters that will fit on a line
242 uint8_t oled_max_chars(void);
243
244 // Returns the maximum number of lines that will fit on the oled
245 uint8_t oled_max_lines(void);