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 #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 uint32_t
31 #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 32 (compile time mathed)
32 #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed)
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 { 32, 40, 48, 56 }
37 #define OLED_TARGET_MAP { 24, 16, 8, 0 }
38 // If OLED_BLOCK_TYPE is uint16_t, these tables would look like:
39 // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
40 // #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 }
41 // If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
42 // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 }
43 // #define OLED_TARGET_MAP { 56, 120, 48, 112, 40, 104, 32, 96, 24, 88, 16, 80, 8, 72, 0, 64 }
44 #else // defined(OLED_DISPLAY_128X64)
46 #define OLED_DISPLAY_WIDTH 128
47 #define OLED_DISPLAY_HEIGHT 32
48 #define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 512 (compile time mathed)
49 #define OLED_BLOCK_TYPE uint16_t // Type to use for segmenting the oled display for smart rendering, use unsigned types only
50 #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 16 (compile time mathed)
51 #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed)
53 // For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays
54 // The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode
55 #define OLED_SOURCE_MAP { 0, 8, 16, 24 }
56 #define OLED_TARGET_MAP { 24, 16, 8, 0 }
57 // If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
58 // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
59 // #define OLED_TARGET_MAP { 48, 32, 16, 0, 56, 40, 24, 8 }
60 #endif // defined(OLED_DISPLAY_CUSTOM)
62 // Address to use for tthe i2d oled communication
63 #if !defined(OLED_DISPLAY_ADDRESS)
64 #define OLED_DISPLAY_ADDRESS 0x3C
67 // Custom font file to use
68 #if !defined(OLED_FONT_H)
69 #define OLED_FONT_H "glcdfont.c"
71 // unsigned char value of the first character in the font file
72 #if !defined(OLED_FONT_START)
73 #define OLED_FONT_START 0
75 // unsigned char value of the last character in the font file
76 #if !defined(OLED_FONT_END)
77 #define OLED_FONT_END 224
80 #if !defined(OLED_FONT_WIDTH)
81 #define OLED_FONT_WIDTH 6
84 #if !defined(OLED_FONT_HEIGHT)
85 #define OLED_FONT_HEIGHT 8
88 // OLED Rotation enum values are flags
92 OLED_ROTATION_180 = 2,
93 OLED_ROTATION_270 = 3, // OLED_ROTATION_90 | OLED_ROTATION_180
96 // Initialize the oled display, rotating the rendered output based on the define passed in.
97 // Returns true if the OLED was initialized successfully
98 bool oled_init(oled_rotation_t rotation);
100 // Called at the start of oled_init, weak function overridable by the user
101 // rotation - the value passed into oled_init
102 // Return new oled_rotation_t if you want to override default rotation
103 oled_rotation_t oled_init_user(oled_rotation_t rotation);
105 // Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering
106 void oled_clear(void);
108 // Renders the dirty chunks of the buffer to oled display
109 void oled_render(void);
111 // Moves cursor to character position indicated by column and line, wraps if out of bounds
112 // Max column denoted by 'oled_max_chars()' and max lines by 'oled_max_lines()' functions
113 void oled_set_cursor(uint8_t col, uint8_t line);
115 // Advances the cursor to the next page, writing ' ' if true
116 // Wraps to the begining when out of bounds
117 void oled_advance_page(bool clearPageRemainder);
119 // Moves the cursor forward 1 character length
120 // Advance page if there is not enough room for the next character
121 // Wraps to the begining when out of bounds
122 void oled_advance_char(void);
124 // Writes a single character to the buffer at current cursor position
125 // Advances the cursor while writing, inverts the pixels if true
126 // Main handler that writes character data to the display buffer
127 void oled_write_char(const char data, bool invert);
129 // Writes a string to the buffer at current cursor position
130 // Advances the cursor while writing, inverts the pixels if true
131 void oled_write(const char *data, bool invert);
133 // Writes a string to the buffer at current cursor position
134 // Advances the cursor while writing, inverts the pixels if true
135 // Advances the cursor to the next page, wiring ' ' to the remainder of the current page
136 void oled_write_ln(const char *data, bool invert);
139 // Writes a PROGMEM string to the buffer at current cursor position
140 // Advances the cursor while writing, inverts the pixels if true
141 // Remapped to call 'void oled_write(const char *data, bool invert);' on ARM
142 void oled_write_P(const char *data, bool invert);
144 // Writes a PROGMEM string to the buffer at current cursor position
145 // Advances the cursor while writing, inverts the pixels if true
146 // Advances the cursor to the next page, wiring ' ' to the remainder of the current page
147 // Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM
148 void oled_write_ln_P(const char *data, bool invert);
150 // Writes a string to the buffer at current cursor position
151 // Advances the cursor while writing, inverts the pixels if true
152 #define oled_write_P(data, invert) oled_write(data, invert)
154 // Writes a string to the buffer at current cursor position
155 // Advances the cursor while writing, inverts the pixels if true
156 // Advances the cursor to the next page, wiring ' ' to the remainder of the current page
157 #define oled_write_ln_P(data, invert) oled_write(data, invert)
158 #endif // defined(__AVR__)
160 // Can be used to manually turn on the screen if it is off
161 // Returns true if the screen was on or turns on
164 // Can be used to manually turn off the screen if it is on
165 // Returns true if the screen was off or turns off
168 // Basically it's oled_render, but with timeout management and oled_task_user calling!
169 void oled_task(void);
171 // Called at the start of oled_task, weak function overridable by the user
172 void oled_task_user(void);
174 // Scrolls the entire display right
175 // Returns true if the screen was scrolling or starts scrolling
176 // NOTE: display contents cannot be changed while scrolling
177 bool oled_scroll_right(void);
179 // Scrolls the entire display left
180 // Returns true if the screen was scrolling or starts scrolling
181 // NOTE: display contents cannot be changed while scrolling
182 bool oled_scroll_left(void);
184 // Turns off display scrolling
185 // Returns true if the screen was not scrolling or stops scrolling
186 bool oled_scroll_off(void);
188 // Returns the maximum number of characters that will fit on a line
189 uint8_t oled_max_chars(void);
191 // Returns the maximum number of lines that will fit on the oled
192 uint8_t oled_max_lines(void);