diff options
| author | Ryan Caltabiano <rcalt2vt@gmail.com> | 2019-04-15 22:32:57 -0500 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-04-20 08:05:10 -0700 |
| commit | 0a645225b9c863a106921185a6c2e0c340f10694 (patch) | |
| tree | 2bf8c295650e54fb4548a7ac4d348ccfc8caa307 /drivers/oled/oled_driver.h | |
| parent | b5cb5ec6ddb15cfe336b835055f546f72d440a66 (diff) | |
| download | qmk_firmware-0a645225b9c863a106921185a6c2e0c340f10694.tar.gz qmk_firmware-0a645225b9c863a106921185a6c2e0c340f10694.zip | |
OLED Driver Feature
Diffstat (limited to 'drivers/oled/oled_driver.h')
| -rw-r--r-- | drivers/oled/oled_driver.h | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h new file mode 100644 index 000000000..1ca31df11 --- /dev/null +++ b/drivers/oled/oled_driver.h | |||
| @@ -0,0 +1,183 @@ | |||
| 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 | |||
| 23 | #if defined(OLED_DISPLAY_CUSTOM) | ||
| 24 | // Expected user to implement the necessary defines | ||
| 25 | #elif defined(OLED_DISPLAY_128X64) | ||
| 26 | // Double height 128x64 | ||
| 27 | #define OLED_DISPLAY_WIDTH 128 | ||
| 28 | #define OLED_DISPLAY_HEIGHT 64 | ||
| 29 | #define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 1024 (compile time mathed) | ||
| 30 | #define OLED_BLOCK_TYPE uint16_t | ||
| 31 | #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 16 (compile time mathed) | ||
| 32 | #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 64 (compile time mathed) | ||
| 33 | |||
| 34 | // For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays | ||
| 35 | // The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode | ||
| 36 | #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 } | ||
| 37 | #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 } | ||
| 38 | // If OLED_BLOCK_TYPE is uint8_t, these tables would look like: | ||
| 39 | // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 } | ||
| 40 | // #define OLED_TARGET_MAP { 56, 120, 48, 112, 40, 104, 32, 96, 24, 88, 16, 80, 8, 72, 0, 64 } | ||
| 41 | #else // defined(OLED_DISPLAY_128X64) | ||
| 42 | // Default 128x32 | ||
| 43 | #define OLED_DISPLAY_WIDTH 128 | ||
| 44 | #define OLED_DISPLAY_HEIGHT 32 | ||
| 45 | #define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 512 (compile time mathed) | ||
| 46 | #define OLED_BLOCK_TYPE uint8_t // Type to use for segmenting the oled display for smart rendering, use unsigned types only | ||
| 47 | #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 8 (compile time mathed) | ||
| 48 | #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 128 (compile time mathed) | ||
| 49 | |||
| 50 | // For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays | ||
| 51 | // The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode | ||
| 52 | #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 } | ||
| 53 | #define OLED_TARGET_MAP { 48, 32, 16, 0, 56, 40, 24, 8 } | ||
| 54 | #endif // defined(OLED_DISPLAY_CUSTOM) | ||
| 55 | |||
| 56 | // Address to use for tthe i2d oled communication | ||
| 57 | #if !defined(OLED_DISPLAY_ADDRESS) | ||
| 58 | #define OLED_DISPLAY_ADDRESS 0x3C | ||
| 59 | #endif | ||
| 60 | |||
| 61 | // Custom font file to use | ||
| 62 | #if !defined(OLED_FONT_H) | ||
| 63 | #define OLED_FONT_H "glcdfont.c" | ||
| 64 | #endif | ||
| 65 | // unsigned char value of the first character in the font file | ||
| 66 | #if !defined(OLED_FONT_START) | ||
| 67 | #define OLED_FONT_START 0 | ||
| 68 | #endif | ||
| 69 | // unsigned char value of the last character in the font file | ||
| 70 | #if !defined(OLED_FONT_END) | ||
| 71 | #define OLED_FONT_END 224 | ||
| 72 | #endif | ||
| 73 | // Font render width | ||
| 74 | #if !defined(OLED_FONT_WIDTH) | ||
| 75 | #define OLED_FONT_WIDTH 6 | ||
| 76 | #endif | ||
| 77 | // Font render height | ||
| 78 | #if !defined(OLED_FONT_HEIGHT) | ||
| 79 | #define OLED_FONT_HEIGHT 8 | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #define OLED_ROTATION_0 0x00 | ||
| 83 | #define OLED_ROTATION_90 0x01 | ||
| 84 | #define OLED_ROTATION_180 0x02 | ||
| 85 | #define OLED_ROTATION_270 0x03 | ||
| 86 | |||
| 87 | // Initialize the oled display, rotating the rendered output based on the define passed in. | ||
| 88 | // Returns true if the OLED was initialized successfully | ||
| 89 | bool oled_init(uint8_t rotation); | ||
| 90 | |||
| 91 | // Called at the start of oled_init, weak function overridable by the user | ||
| 92 | // rotation - the value passed into oled_init | ||
| 93 | // Return new uint8_t if you want to override default rotation | ||
| 94 | uint8_t oled_init_user(uint8_t rotation); | ||
| 95 | |||
| 96 | // Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering | ||
| 97 | void oled_clear(void); | ||
| 98 | |||
| 99 | // Renders the dirty chunks of the buffer to oled display | ||
| 100 | void oled_render(void); | ||
| 101 | |||
| 102 | // Moves cursor to character position indicated by column and line, wraps if out of bounds | ||
| 103 | // Max column denoted by 'oled_max_chars()' and max lines by 'oled_max_lines()' functions | ||
| 104 | void oled_set_cursor(uint8_t col, uint8_t line); | ||
| 105 | |||
| 106 | // Advances the cursor to the next page, writing ' ' if true | ||
| 107 | // Wraps to the begining when out of bounds | ||
| 108 | void oled_advance_page(bool clearPageRemainder); | ||
| 109 | |||
| 110 | // Moves the cursor forward 1 character length | ||
| 111 | // Advance page if there is not enough room for the next character | ||
| 112 | // Wraps to the begining when out of bounds | ||
| 113 | void oled_advance_char(void); | ||
| 114 | |||
| 115 | // Writes a single character to the buffer at current cursor position | ||
| 116 | // Advances the cursor while writing, inverts the pixels if true | ||
| 117 | // Main handler that writes character data to the display buffer | ||
| 118 | void oled_write_char(const char data, bool invert); | ||
| 119 | |||
| 120 | // Writes a string to the buffer at current cursor position | ||
| 121 | // Advances the cursor while writing, inverts the pixels if true | ||
| 122 | void oled_write(const char *data, bool invert); | ||
| 123 | |||
| 124 | // Writes a string to the buffer at current cursor position | ||
| 125 | // Advances the cursor while writing, inverts the pixels if true | ||
| 126 | // Advances the cursor to the next page, wiring ' ' to the remainder of the current page | ||
| 127 | void oled_write_ln(const char *data, bool invert); | ||
| 128 | |||
| 129 | #if defined(__AVR__) | ||
| 130 | // Writes a PROGMEM string to the buffer at current cursor position | ||
| 131 | // Advances the cursor while writing, inverts the pixels if true | ||
| 132 | // Remapped to call 'void oled_write(const char *data, bool invert);' on ARM | ||
| 133 | void oled_write_P(const char *data, bool invert); | ||
| 134 | |||
| 135 | // Writes a PROGMEM string to the buffer at current cursor position | ||
| 136 | // Advances the cursor while writing, inverts the pixels if true | ||
| 137 | // Advances the cursor to the next page, wiring ' ' to the remainder of the current page | ||
| 138 | // Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM | ||
| 139 | void oled_write_ln_P(const char *data, bool invert); | ||
| 140 | #else | ||
| 141 | // Writes a string to the buffer at current cursor position | ||
| 142 | // Advances the cursor while writing, inverts the pixels if true | ||
| 143 | #define oled_write_P(data, invert) oled_write(data, invert) | ||
| 144 | |||
| 145 | // Writes a string to the buffer at current cursor position | ||
| 146 | // Advances the cursor while writing, inverts the pixels if true | ||
| 147 | // Advances the cursor to the next page, wiring ' ' to the remainder of the current page | ||
| 148 | #define oled_write_ln_P(data, invert) oled_write(data, invert) | ||
| 149 | #endif // defined(__AVR__) | ||
| 150 | |||
| 151 | // Can be used to manually turn on the screen if it is off | ||
| 152 | // Returns true if the screen was on or turns on | ||
| 153 | bool oled_on(void); | ||
| 154 | |||
| 155 | // Can be used to manually turn off the screen if it is on | ||
| 156 | // Returns true if the screen was off or turns off | ||
| 157 | bool oled_off(void); | ||
| 158 | |||
| 159 | // Basically it's oled_render, but with timeout management and oled_task_user calling! | ||
| 160 | void oled_task(void); | ||
| 161 | |||
| 162 | // Called at the start of oled_task, weak function overridable by the user | ||
| 163 | void oled_task_user(void); | ||
| 164 | |||
| 165 | // Scrolls the entire display right | ||
| 166 | // Returns true if the screen was scrolling or starts scrolling | ||
| 167 | // NOTE: display contents cannot be changed while scrolling | ||
| 168 | bool oled_scroll_right(void); | ||
| 169 | |||
| 170 | // Scrolls the entire display left | ||
| 171 | // Returns true if the screen was scrolling or starts scrolling | ||
| 172 | // NOTE: display contents cannot be changed while scrolling | ||
| 173 | bool oled_scroll_left(void); | ||
| 174 | |||
| 175 | // Turns off display scrolling | ||
| 176 | // Returns true if the screen was not scrolling or stops scrolling | ||
| 177 | bool oled_scroll_off(void); | ||
| 178 | |||
| 179 | // Returns the maximum number of characters that will fit on a line | ||
| 180 | uint8_t oled_max_chars(void); | ||
| 181 | |||
| 182 | // Returns the maximum number of lines that will fit on the oled | ||
| 183 | uint8_t oled_max_lines(void); | ||
