aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRyan Caltabiano <rcalt2vt@gmail.com>2019-04-15 22:32:57 -0500
committerskullydazed <skullydazed@users.noreply.github.com>2019-04-20 08:05:10 -0700
commit0a645225b9c863a106921185a6c2e0c340f10694 (patch)
tree2bf8c295650e54fb4548a7ac4d348ccfc8caa307 /docs
parentb5cb5ec6ddb15cfe336b835055f546f72d440a66 (diff)
downloadqmk_firmware-0a645225b9c863a106921185a6c2e0c340f10694.tar.gz
qmk_firmware-0a645225b9c863a106921185a6c2e0c340f10694.zip
OLED Driver Feature
Diffstat (limited to 'docs')
-rw-r--r--docs/feature_oled_driver.md246
-rw-r--r--docs/hardware_drivers.md6
2 files changed, 249 insertions, 3 deletions
diff --git a/docs/feature_oled_driver.md b/docs/feature_oled_driver.md
new file mode 100644
index 000000000..f261bbef1
--- /dev/null
+++ b/docs/feature_oled_driver.md
@@ -0,0 +1,246 @@
1# OLED Driver
2
3## OLED Supported Hardware
4
5128x32 OLED modules using SSD1306 driver IC over I2C. Supported on AVR based keyboards. Possible but untested hardware includes ARM based keyboards and other sized OLED modules using SSD1306 over I2C, such as 128x64.
6
7!> Warning: This OLED Driver currently uses the new i2c_master driver from split common code. If your split keyboard uses i2c to communication between sides this driver could cause an address conflict (serial is fine). Please contact your keyboard vendor and ask them to migrate to the latest split common code to fix this.
8
9## Usage
10
11To enable the OLED feature, there are three steps. First, when compiling your keyboard, you'll need to set `OLED_DRIVER_ENABLE=yes` in `rules.mk`, e.g.:
12
13```
14BOOTMAGIC_ENABLE = no
15MOUSEKEY_ENABLE = no
16STENO_ENABLE = no
17EXTRAKEY_ENABLE = yes
18OLED_DRIVER_ENABLE = yes
19```
20
21This enables the feature and the `OLED_DRIVER_ENABLE` define. Then in your `keymap.c` file, you will need to implement the user task call, e.g:
22
23```C++
24#ifdef OLED_DRIVER_ENABLE
25void oled_task_user(void) {
26 // Host Keyboard Layer Status
27 oled_write_P(PSTR("Layer: "), false);
28 switch (biton32(layer_state)) {
29 case _QWERTY:
30 oled_write_P(PSTR("Default\n"), false);
31 break;
32 case _FN:
33 oled_write_P(PSTR("FN\n"), false);
34 break;
35 case _ADJ:
36 oled_write_P(PSTR("ADJ\n"), false);
37 break;
38 default:
39 // Or use the write_ln shortcut
40 oled_write_P(PSTR("Undefined\n"), false);
41 }
42
43 // Host Keyboard LED Status
44 uint8_t led_usb_state = host_keyboard_leds();
45 oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("NUMLCK ") : PSTR(" "), false);
46 oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR("CAPLCK ") : PSTR(" "), false);
47 oled_write_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("SCRLCK ") : PSTR(" "), false);
48}
49#endif
50```
51
52
53## Other Examples
54
55In split keyboards, it is very common to have two OLED displays that each render different content and oriented flipped differently. You can do this by switching which content to render by using the return from `is_keyboard_master()` or `is_keyboard_left()` found in `split_util.h`, e.g:
56
57```C++
58#ifdef OLED_DRIVER_ENABLE
59uint8_t oled_init_user(uint8_t rotation) {
60 if (!is_keyboard_master())
61 return OLED_ROTATION_180; // flips the display 180 degrees if offhand
62 return rotation;
63}
64
65void oled_task_user(void) {
66 if (is_keyboard_master()) {
67 render_status(); // Renders the current keyboard state (layer, lock, caps, scroll, etc)
68 } else {
69 render_logo(); // Renders a statuc logo
70 oled_scroll_left(); // Turns on scrolling
71 }
72}
73#endif
74```
75
76
77 ## Basic Configuration
78
79|Define |Default |Description |
80|-----------------------|---------------|------------------------------------------------|
81|`OLED_DISPLAY_ADDRESS` |`0x3C` |The i2c address of the OLED Display |
82|`OLED_FONT_H` |`"glcdfont.c"` |The font code file to use for custom fonts |
83|`OLED_FONT_START` |`0` |The starting characer index for custom fonts |
84|`OLED_FONT_END` |`224` |The ending characer index for custom fonts |
85|`OLED_FONT_WIDTH` |`6` |The font width |
86|`OLED_FONT_HEIGHT` |`8` |The font height (untested) |
87|`OLED_DISABLE_TIMEOUT` |*Not defined* |Disables the built in OLED timeout feature. Useful when implementing custom timeout rules.|
88
89
90
91 ## 128x64 & Custom sized OLED Displays
92
93 The default display size for this feature is 128x32 and all necessary defines are precalculated with that in mind. We have added a define, `OLED_DISPLAY_128X64`, to switch all the values to be used in a 128x64 display, as well as added a custom define, `OLED_DISPLAY_CUSTOM`, that allows you to provide the necessary values to the driver.
94
95|Define |Default |Description |
96|-----------------------|---------------|-----------------------------------------------------------------|
97|`OLED_DISPLAY_128X64` |*Not defined* |Changes the display defines for use with 128x64 displays. |
98|`OLED_DISPLAY_CUSTOM` |*Not defined* |Changes the display defines for use with custom displays.<br />Requires user to implement the below defines. |
99|`OLED_DISPLAY_WIDTH` |`128` |The width of the OLED display. |
100|`OLED_DISPLAY_HEIGHT` |`32` |The height of the OLED display. |
101|`OLED_MATRIX_SIZE` |`512` |The local buffer size to allocate.<br />`(OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH)`|
102|`OLED_BLOCK_TYPE` |`uint8_t` |The unsigned integer type to use for dirty rendering.|
103|`OLED_BLOCK_COUNT` |`8` |The number of blocks the display is divided into for dirty rendering.<br />`(sizeof(OLED_BLOCK_TYPE) * 8)`|
104|`OLED_BLOCK_SIZE` |`64` |The size of each block for dirty rendering<br />`(OLED_MATRIX_SIZE / OLED_BLOCK_COUNT)`|
105|`OLED_SOURCE_MAP` |`{ 0, ... N }` |Precalculated source array to use for mapping source buffer to target OLED memory in 90 degree rendering. |
106|`OLED_TARGET_MAP` |`{ 48, ... N }`|Precalculated target array to use for mapping source buffer to target OLED memory in 90 degree rendering. |
107
108
109### 90 Degree Rotation - Technical Mumbo Jumbo
110
111 OLED displays driven by SSD1306 drivers only natively support in hard ware 0 degree and 180 degree rendering. This feature is done in software and not free. Using this feature will increase the time to calculate what data to send over i2c to the OLED. If you are strapped for cycles, this can cause keycodes to not register. In testing however, the rendering time on an `atmega32u4` board only went from 2ms to 5ms and keycodes not registering was only noticed once we hit 15ms.
112
113 90 Degree Rotated Rendering is achieved by using bitwise operations to rotate each 8 block of memory and uses two precalculated arrays to remap buffer memory to OLED memory. The memory map defines are precalculated for remap performance and are calculated based on the OLED Height, Width, and Block Size. For example, in the default 128x32 implementation we have a 64 byte block size. This gives us eight 8 byte blocks that need to be rotated and rendered. The OLED renders horizontally two 8 byte blocks before moving down a page, e.g:
114
115| | | | | | |
116|---|---|---|---|---|---|
117| 0 | 1 | | | | |
118| 2 | 3 | | | | |
119| 4 | 5 | | | | |
120| 6 | 7 | | | | |
121
122However the local buffer is stored as if it was Height x Width display instead of Width x Height, e.g:
123
124| | | | | | |
125|---|---|---|---|---|---|
126| 3 | 7 | | | | |
127| 2 | 6 | | | | |
128| 1 | 5 | | | | |
129| 0 | 4 | | | | |
130
131So those precalculated arrays just index the memory offsets in the order in which each one iterates its data.
132
133## OLED API
134
135```C++
136// Initialize the OLED display, rotating the rendered output 180 degrees if true.
137// Returns true if the OLED was initialized successfully
138bool oled_init(bool flip180);
139
140// Called at the start of oled_init, weak function overridable by the user
141// flip180 - the value passed into oled_init
142// Return true if you want the oled to be flip180
143bool oled_init_user(bool flip180);
144
145// Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering
146void oled_clear(void);
147
148// Renders the dirty chunks of the buffer to OLED display
149void oled_render(void);
150
151// Moves cursor to character position indicated by column and line, wraps if out of bounds
152// Max column denoted by 'oled_max_chars()' and max lines by 'oled_max_lines()' functions
153void oled_set_cursor(uint8_t col, uint8_t line);
154
155// Advances the cursor to the next page, writing ' ' if true
156// Wraps to the begining when out of bounds
157void oled_advance_page(bool clearPageRemainder);
158
159// Moves the cursor forward 1 character length
160// Advance page if there is not enough room for the next character
161// Wraps to the begining when out of bounds
162void oled_advance_char(void);
163
164// Writes a single character to the buffer at current cursor position
165// Advances the cursor while writing, inverts the pixels if true
166// Main handler that writes character data to the display buffer
167void oled_write_char(const char data, bool invert);
168
169// Writes a string to the buffer at current cursor position
170// Advances the cursor while writing, inverts the pixels if true
171void oled_write(const char *data, bool invert);
172
173// Writes a string to the buffer at current cursor position
174// Advances the cursor while writing, inverts the pixels if true
175// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
176void oled_write_ln(const char *data, bool invert);
177
178// Writes a PROGMEM string to the buffer at current cursor position
179// Advances the cursor while writing, inverts the pixels if true
180// Remapped to call 'void oled_write(const char *data, bool invert);' on ARM
181void oled_write_P(const char *data, bool invert);
182
183// Writes a PROGMEM string to the buffer at current cursor position
184// Advances the cursor while writing, inverts the pixels if true
185// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
186// Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM
187void oled_write_ln_P(const char *data, bool invert);
188
189// Can be used to manually turn on the screen if it is off
190// Returns true if the screen was on or turns on
191bool oled_on(void);
192
193// Can be used to manually turn off the screen if it is on
194// Returns true if the screen was off or turns off
195bool oled_off(void);
196
197// Basically it's oled_render, but with timeout management and oled_task_user calling!
198void oled_task(void);
199
200// Called at the start of oled_task, weak function overridable by the user
201void oled_task_user(void);
202
203// Scrolls the entire display right
204// Returns true if the screen was scrolling or starts scrolling
205// NOTE: display contents cannot be changed while scrolling
206bool oled_scroll_right(void);
207
208// Scrolls the entire display left
209// Returns true if the screen was scrolling or starts scrolling
210// NOTE: display contents cannot be changed while scrolling
211bool oled_scroll_left(void);
212
213// Turns off display scrolling
214// Returns true if the screen was not scrolling or stops scrolling
215bool oled_scroll_off(void);
216
217// Returns the maximum number of characters that will fit on a line
218uint8_t oled_max_chars(void);
219
220// Returns the maximum number of lines that will fit on the oled
221uint8_t oled_max_lines(void);
222```
223
224## SSD1306.h driver conversion guide
225
226|Old API |Recommended New API |
227|---------------------------|-----------------------------------|
228|`struct CharacterMatrix` |*removed - delete all references* |
229|`iota_gfx_init` |`oled_init` |
230|`iota_gfx_on` |`oled_on` |
231|`iota_gfx_off` |`oled_off` |
232|`iota_gfx_flush` |`oled_render` |
233|`iota_gfx_write_char` |`oled_write_char` |
234|`iota_gfx_write` |`oled_write` |
235|`iota_gfx_write_P` |`oled_write_P` |
236|`iota_gfx_clear_screen` |`oled_clear` |
237|`matrix_clear` |*removed - delete all references* |
238|`matrix_write_char_inner` |`oled_write_char` |
239|`matrix_write_char` |`oled_write_char` |
240|`matrix_write` |`oled_write` |
241|`matrix_write_ln` |`oled_write_ln` |
242|`matrix_write_P` |`oled_write_P` |
243|`matrix_write_ln_P` |`oled_write_ln_P` |
244|`matrix_render` |`oled_render` |
245|`iota_gfx_task` |`oled_task` |
246|`iota_gfx_task_user` |`oled_task_user` |
diff --git a/docs/hardware_drivers.md b/docs/hardware_drivers.md
index 4c1266f22..023e92982 100644
--- a/docs/hardware_drivers.md
+++ b/docs/hardware_drivers.md
@@ -14,9 +14,9 @@ QMK is used on a lot of different hardware. While support for the most common MC
14 14
15Support for addressing pins on the ProMicro by their Arduino name rather than their AVR name. This needs to be better documented, if you are trying to do this and reading the code doesn't help please [open an issue](https://github.com/qmk/qmk_firmware/issues/new) and we can help you through the process. 15Support for addressing pins on the ProMicro by their Arduino name rather than their AVR name. This needs to be better documented, if you are trying to do this and reading the code doesn't help please [open an issue](https://github.com/qmk/qmk_firmware/issues/new) and we can help you through the process.
16 16
17## SSD1306 (AVR Only) 17## SSD1306 OLED Driver
18 18
19Support for SSD1306 based OLED displays. This needs to be better documented, if you are trying to do this and reading the code doesn't help please [open an issue](https://github.com/qmk/qmk_firmware/issues/new) and we can help you through the process. 19Support for SSD1306 based OLED displays. For more information see the [OLED Driver Feature](feature_oled_driver.md) page.
20 20
21## uGFX 21## uGFX
22 22
@@ -32,4 +32,4 @@ Support for up to 2 drivers. Each driver impliments 2 charlieplex matrices to in
32 32
33## IS31FL3733 33## IS31FL3733
34 34
35Support for up to a single driver with room for expansion. Each driver can control 192 individual LEDs or 64 RGB LEDs. For more information on how to setup the driver see the [RGB Matrix](feature_rgb_matrix.md) page. \ No newline at end of file 35Support for up to a single driver with room for expansion. Each driver can control 192 individual LEDs or 64 RGB LEDs. For more information on how to setup the driver see the [RGB Matrix](feature_rgb_matrix.md) page.