2 Copyright 2019 Ryan Caltabiano <https://github.com/XScorpion2>
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.
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.
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/>.
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 #ifndef OLED_DISPLAY_WIDTH
28 #define OLED_DISPLAY_WIDTH 128
30 #ifndef OLED_DISPLAY_HEIGHT
31 #define OLED_DISPLAY_HEIGHT 64
33 #ifndef OLED_MATRIX_SIZE
34 #define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 1024 (compile time mathed)
36 #ifndef OLED_BLOCK_TYPE
37 #define OLED_BLOCK_TYPE uint16_t
39 #ifndef OLED_BLOCK_COUNT
40 #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 32 (compile time mathed)
42 #ifndef OLED_BLOCK_SIZE
43 #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed)
46 #define OLED_COM_PINS COM_PINS_ALT
49 // For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays
50 // The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode
51 #ifndef OLED_SOURCE_MAP
52 #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
54 #ifndef OLED_TARGET_MAP
55 #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 }
57 // If OLED_BLOCK_TYPE is uint32_t, these tables would look like:
58 // #define OLED_SOURCE_MAP { 32, 40, 48, 56 }
59 // #define OLED_TARGET_MAP { 24, 16, 8, 0 }
60 // If OLED_BLOCK_TYPE is uint16_t, these tables would look like:
61 // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
62 // #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 }
63 // If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
64 // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 }
65 // #define OLED_TARGET_MAP { 56, 120, 48, 112, 40, 104, 32, 96, 24, 88, 16, 80, 8, 72, 0, 64 }
66 #else // defined(OLED_DISPLAY_128X64)
68 #ifndef OLED_DISPLAY_WIDTH
69 #define OLED_DISPLAY_WIDTH 128
71 #ifndef OLED_DISPLAY_HEIGHT
72 #define OLED_DISPLAY_HEIGHT 32
74 #ifndef OLED_MATRIX_SIZE
75 #define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 512 (compile time mathed)
77 #ifndef OLED_BLOCK_TYPE
78 #define OLED_BLOCK_TYPE uint16_t // Type to use for segmenting the oled display for smart rendering, use unsigned types only
80 #ifndef OLED_BLOCK_COUNT
81 #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 16 (compile time mathed)
83 #ifndef OLED_BLOCK_SIZE
84 #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed)
87 #define OLED_COM_PINS COM_PINS_SEQ
90 // For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays
91 // The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode
92 #ifndef OLED_SOURCE_MAP
93 #define OLED_SOURCE_MAP { 0, 8, 16, 24 }
95 #ifndef OLED_TARGET_MAP
96 #define OLED_TARGET_MAP { 24, 16, 8, 0 }
98 // If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
99 // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
100 // #define OLED_TARGET_MAP { 48, 32, 16, 0, 56, 40, 24, 8 }
101 #endif // defined(OLED_DISPLAY_CUSTOM)
103 // Address to use for tthe i2d oled communication
104 #if !defined(OLED_DISPLAY_ADDRESS)
105 #define OLED_DISPLAY_ADDRESS 0x3C
108 // Custom font file to use
109 #if !defined(OLED_FONT_H)
110 #define OLED_FONT_H "glcdfont.c"
112 // unsigned char value of the first character in the font file
113 #if !defined(OLED_FONT_START)
114 #define OLED_FONT_START 0
116 // unsigned char value of the last character in the font file
117 #if !defined(OLED_FONT_END)
118 #define OLED_FONT_END 224
121 #if !defined(OLED_FONT_WIDTH)
122 #define OLED_FONT_WIDTH 6
124 // Font render height
125 #if !defined(OLED_FONT_HEIGHT)
126 #define OLED_FONT_HEIGHT 8
129 // OLED Rotation enum values are flags
132 OLED_ROTATION_90 = 1,
133 OLED_ROTATION_180 = 2,
134 OLED_ROTATION_270 = 3, // OLED_ROTATION_90 | OLED_ROTATION_180
137 // Initialize the oled display, rotating the rendered output based on the define passed in.
138 // Returns true if the OLED was initialized successfully
139 bool oled_init(oled_rotation_t rotation);
141 // Called at the start of oled_init, weak function overridable by the user
142 // rotation - the value passed into oled_init
143 // Return new oled_rotation_t if you want to override default rotation
144 oled_rotation_t oled_init_user(oled_rotation_t rotation);
146 // Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering
147 void oled_clear(void);
149 // Renders the dirty chunks of the buffer to oled display
150 void oled_render(void);
152 // Moves cursor to character position indicated by column and line, wraps if out of bounds
153 // Max column denoted by 'oled_max_chars()' and max lines by 'oled_max_lines()' functions
154 void oled_set_cursor(uint8_t col, uint8_t line);
156 // Advances the cursor to the next page, writing ' ' if true
157 // Wraps to the begining when out of bounds
158 void oled_advance_page(bool clearPageRemainder);
160 // Moves the cursor forward 1 character length
161 // Advance page if there is not enough room for the next character
162 // Wraps to the begining when out of bounds
163 void oled_advance_char(void);
165 // Writes a single character to the buffer at current cursor position
166 // Advances the cursor while writing, inverts the pixels if true
167 // Main handler that writes character data to the display buffer
168 void oled_write_char(const char data, bool invert);
170 // Writes a string to the buffer at current cursor position
171 // Advances the cursor while writing, inverts the pixels if true
172 void oled_write(const char *data, bool invert);
174 // Writes a string to the buffer at current cursor position
175 // Advances the cursor while writing, inverts the pixels if true
176 // Advances the cursor to the next page, wiring ' ' to the remainder of the current page
177 void oled_write_ln(const char *data, bool invert);
180 // Writes a PROGMEM string to the buffer at current cursor position
181 // Advances the cursor while writing, inverts the pixels if true
182 // Remapped to call 'void oled_write(const char *data, bool invert);' on ARM
183 void oled_write_P(const char *data, bool invert);
185 // Writes a PROGMEM string to the buffer at current cursor position
186 // Advances the cursor while writing, inverts the pixels if true
187 // Advances the cursor to the next page, wiring ' ' to the remainder of the current page
188 // Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM
189 void oled_write_ln_P(const char *data, bool invert);
191 // Writes a string to the buffer at current cursor position
192 // Advances the cursor while writing, inverts the pixels if true
193 #define oled_write_P(data, invert) oled_write(data, invert)
195 // Writes a string to the buffer at current cursor position
196 // Advances the cursor while writing, inverts the pixels if true
197 // Advances the cursor to the next page, wiring ' ' to the remainder of the current page
198 #define oled_write_ln_P(data, invert) oled_write(data, invert)
199 #endif // defined(__AVR__)
201 // Can be used to manually turn on the screen if it is off
202 // Returns true if the screen was on or turns on
205 // Can be used to manually turn off the screen if it is on
206 // Returns true if the screen was off or turns off
209 // Basically it's oled_render, but with timeout management and oled_task_user calling!
210 void oled_task(void);
212 // Called at the start of oled_task, weak function overridable by the user
213 void oled_task_user(void);
215 // Scrolls the entire display right
216 // Returns true if the screen was scrolling or starts scrolling
217 // NOTE: display contents cannot be changed while scrolling
218 bool oled_scroll_right(void);
220 // Scrolls the entire display left
221 // Returns true if the screen was scrolling or starts scrolling
222 // NOTE: display contents cannot be changed while scrolling
223 bool oled_scroll_left(void);
225 // Turns off display scrolling
226 // Returns true if the screen was not scrolling or stops scrolling
227 bool oled_scroll_off(void);
229 // Returns the maximum number of characters that will fit on a line
230 uint8_t oled_max_chars(void);
232 // Returns the maximum number of lines that will fit on the oled
233 uint8_t oled_max_lines(void);