aboutsummaryrefslogtreecommitdiff
path: root/drivers/oled/oled_driver.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/oled/oled_driver.h')
-rw-r--r--drivers/oled/oled_driver.h206
1 files changed, 105 insertions, 101 deletions
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h
index 4f6254c98..ac8a1c765 100644
--- a/drivers/oled/oled_driver.h
+++ b/drivers/oled/oled_driver.h
@@ -21,129 +21,133 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21
22// an enumeration of the chips this driver supports 22// an enumeration of the chips this driver supports
23#define OLED_IC_SSD1306 0 23#define OLED_IC_SSD1306 0
24#define OLED_IC_SH1106 1 24#define OLED_IC_SH1106 1
25 25
26#if defined(OLED_DISPLAY_CUSTOM) 26#if defined(OLED_DISPLAY_CUSTOM)
27 // Expected user to implement the necessary defines 27// Expected user to implement the necessary defines
28#elif defined(OLED_DISPLAY_128X64) 28#elif defined(OLED_DISPLAY_128X64)
29 // Double height 128x64 29// Double height 128x64
30#ifndef OLED_DISPLAY_WIDTH 30# ifndef OLED_DISPLAY_WIDTH
31 #define OLED_DISPLAY_WIDTH 128 31# define OLED_DISPLAY_WIDTH 128
32#endif 32# endif
33#ifndef OLED_DISPLAY_HEIGHT 33# ifndef OLED_DISPLAY_HEIGHT
34 #define OLED_DISPLAY_HEIGHT 64 34# define OLED_DISPLAY_HEIGHT 64
35#endif 35# endif
36#ifndef OLED_MATRIX_SIZE 36# ifndef OLED_MATRIX_SIZE
37 #define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 1024 (compile time mathed) 37# define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 1024 (compile time mathed)
38#endif 38# endif
39#ifndef OLED_BLOCK_TYPE 39# ifndef OLED_BLOCK_TYPE
40 #define OLED_BLOCK_TYPE uint16_t 40# define OLED_BLOCK_TYPE uint16_t
41#endif 41# endif
42#ifndef OLED_BLOCK_COUNT 42# ifndef OLED_BLOCK_COUNT
43 #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 32 (compile time mathed) 43# define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 32 (compile time mathed)
44#endif 44# endif
45#ifndef OLED_BLOCK_SIZE 45# ifndef OLED_BLOCK_SIZE
46 #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed) 46# define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed)
47#endif 47# endif
48#ifndef OLED_COM_PINS 48# ifndef OLED_COM_PINS
49 #define OLED_COM_PINS COM_PINS_ALT 49# define OLED_COM_PINS COM_PINS_ALT
50#endif 50# endif
51 51
52 // For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays 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 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 54# ifndef OLED_SOURCE_MAP
55 #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 } 55# define OLED_SOURCE_MAP \
56#endif 56 { 0, 8, 16, 24, 32, 40, 48, 56 }
57#ifndef OLED_TARGET_MAP 57# endif
58 #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 } 58# ifndef OLED_TARGET_MAP
59#endif 59# define OLED_TARGET_MAP \
60 // If OLED_BLOCK_TYPE is uint32_t, these tables would look like: 60 { 56, 48, 40, 32, 24, 16, 8, 0 }
61 // #define OLED_SOURCE_MAP { 32, 40, 48, 56 } 61# endif
62 // #define OLED_TARGET_MAP { 24, 16, 8, 0 } 62// If OLED_BLOCK_TYPE is uint32_t, these tables would look like:
63 // If OLED_BLOCK_TYPE is uint16_t, these tables would look like: 63// #define OLED_SOURCE_MAP { 32, 40, 48, 56 }
64 // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 } 64// #define OLED_TARGET_MAP { 24, 16, 8, 0 }
65 // #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 } 65// If OLED_BLOCK_TYPE is uint16_t, these tables would look like:
66 // If OLED_BLOCK_TYPE is uint8_t, these tables would look like: 66// #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
67 // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 } 67// #define OLED_TARGET_MAP { 56, 48, 40, 32, 24, 16, 8, 0 }
68 // #define OLED_TARGET_MAP { 56, 120, 48, 112, 40, 104, 32, 96, 24, 88, 16, 80, 8, 72, 0, 64 } 68// If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
69#else // defined(OLED_DISPLAY_128X64) 69// #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 }
70 // Default 128x32 70// #define OLED_TARGET_MAP { 56, 120, 48, 112, 40, 104, 32, 96, 24, 88, 16, 80, 8, 72, 0, 64 }
71#ifndef OLED_DISPLAY_WIDTH 71#else // defined(OLED_DISPLAY_128X64)
72 #define OLED_DISPLAY_WIDTH 128 72// Default 128x32
73#endif 73# ifndef OLED_DISPLAY_WIDTH
74#ifndef OLED_DISPLAY_HEIGHT 74# define OLED_DISPLAY_WIDTH 128
75 #define OLED_DISPLAY_HEIGHT 32 75# endif
76#endif 76# ifndef OLED_DISPLAY_HEIGHT
77#ifndef OLED_MATRIX_SIZE 77# define OLED_DISPLAY_HEIGHT 32
78 #define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 512 (compile time mathed) 78# endif
79#endif 79# ifndef OLED_MATRIX_SIZE
80#ifndef OLED_BLOCK_TYPE 80# define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 512 (compile time mathed)
81 #define OLED_BLOCK_TYPE uint16_t // Type to use for segmenting the oled display for smart rendering, use unsigned types only 81# endif
82#endif 82# ifndef OLED_BLOCK_TYPE
83#ifndef OLED_BLOCK_COUNT 83# define OLED_BLOCK_TYPE uint16_t // Type to use for segmenting the oled display for smart rendering, use unsigned types only
84 #define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 16 (compile time mathed) 84# endif
85#endif 85# ifndef OLED_BLOCK_COUNT
86#ifndef OLED_BLOCK_SIZE 86# define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 16 (compile time mathed)
87 #define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed) 87# endif
88#endif 88# ifndef OLED_BLOCK_SIZE
89#ifndef OLED_COM_PINS 89# define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed)
90 #define OLED_COM_PINS COM_PINS_SEQ 90# endif
91#endif 91# ifndef OLED_COM_PINS
92 92# define OLED_COM_PINS COM_PINS_SEQ
93 // For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays 93# endif
94 // The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode 94
95#ifndef OLED_SOURCE_MAP 95// For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays
96 #define OLED_SOURCE_MAP { 0, 8, 16, 24 } 96// The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode
97#endif 97# ifndef OLED_SOURCE_MAP
98#ifndef OLED_TARGET_MAP 98# define OLED_SOURCE_MAP \
99 #define OLED_TARGET_MAP { 24, 16, 8, 0 } 99 { 0, 8, 16, 24 }
100#endif 100# endif
101 // If OLED_BLOCK_TYPE is uint8_t, these tables would look like: 101# ifndef OLED_TARGET_MAP
102 // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 } 102# define OLED_TARGET_MAP \
103 // #define OLED_TARGET_MAP { 48, 32, 16, 0, 56, 40, 24, 8 } 103 { 24, 16, 8, 0 }
104#endif // defined(OLED_DISPLAY_CUSTOM) 104# endif
105// If OLED_BLOCK_TYPE is uint8_t, these tables would look like:
106// #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 }
107// #define OLED_TARGET_MAP { 48, 32, 16, 0, 56, 40, 24, 8 }
108#endif // defined(OLED_DISPLAY_CUSTOM)
105 109
106#if !defined(OLED_IC) 110#if !defined(OLED_IC)
107 #define OLED_IC OLED_IC_SSD1306 111# define OLED_IC OLED_IC_SSD1306
108#endif 112#endif
109 113
110// the column address corresponding to the first column in the display hardware 114// the column address corresponding to the first column in the display hardware
111#if !defined(OLED_COLUMN_OFFSET) 115#if !defined(OLED_COLUMN_OFFSET)
112 #define OLED_COLUMN_OFFSET 0 116# define OLED_COLUMN_OFFSET 0
113#endif 117#endif
114 118
115// Address to use for the i2c oled communication 119// Address to use for the i2c oled communication
116#if !defined(OLED_DISPLAY_ADDRESS) 120#if !defined(OLED_DISPLAY_ADDRESS)
117 #define OLED_DISPLAY_ADDRESS 0x3C 121# define OLED_DISPLAY_ADDRESS 0x3C
118#endif 122#endif
119 123
120// Custom font file to use 124// Custom font file to use
121#if !defined(OLED_FONT_H) 125#if !defined(OLED_FONT_H)
122 #define OLED_FONT_H "glcdfont.c" 126# define OLED_FONT_H "glcdfont.c"
123#endif 127#endif
124// unsigned char value of the first character in the font file 128// unsigned char value of the first character in the font file
125#if !defined(OLED_FONT_START) 129#if !defined(OLED_FONT_START)
126 #define OLED_FONT_START 0 130# define OLED_FONT_START 0
127#endif 131#endif
128// unsigned char value of the last character in the font file 132// unsigned char value of the last character in the font file
129#if !defined(OLED_FONT_END) 133#if !defined(OLED_FONT_END)
130 #define OLED_FONT_END 224 134# define OLED_FONT_END 224
131#endif 135#endif
132// Font render width 136// Font render width
133#if !defined(OLED_FONT_WIDTH) 137#if !defined(OLED_FONT_WIDTH)
134 #define OLED_FONT_WIDTH 6 138# define OLED_FONT_WIDTH 6
135#endif 139#endif
136// Font render height 140// Font render height
137#if !defined(OLED_FONT_HEIGHT) 141#if !defined(OLED_FONT_HEIGHT)
138 #define OLED_FONT_HEIGHT 8 142# define OLED_FONT_HEIGHT 8
139#endif 143#endif
140 144
141#if !defined(OLED_TIMEOUT) 145#if !defined(OLED_TIMEOUT)
142 #if defined(OLED_DISABLE_TIMEOUT) 146# if defined(OLED_DISABLE_TIMEOUT)
143 #define OLED_TIMEOUT 0 147# define OLED_TIMEOUT 0
144 #else 148# else
145 #define OLED_TIMEOUT 60000 149# define OLED_TIMEOUT 60000
146 #endif 150# endif
147#endif 151#endif
148 152
149// OLED Rotation enum values are flags 153// OLED Rotation enum values are flags
@@ -151,7 +155,7 @@ typedef enum {
151 OLED_ROTATION_0 = 0, 155 OLED_ROTATION_0 = 0,
152 OLED_ROTATION_90 = 1, 156 OLED_ROTATION_90 = 1,
153 OLED_ROTATION_180 = 2, 157 OLED_ROTATION_180 = 2,
154 OLED_ROTATION_270 = 3, // OLED_ROTATION_90 | OLED_ROTATION_180 158 OLED_ROTATION_270 = 3, // OLED_ROTATION_90 | OLED_ROTATION_180
155} oled_rotation_t; 159} oled_rotation_t;
156 160
157// Initialize the oled display, rotating the rendered output based on the define passed in. 161// Initialize the oled display, rotating the rendered output based on the define passed in.
@@ -208,15 +212,15 @@ void oled_write_P(const char *data, bool invert);
208// Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM 212// Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM
209void oled_write_ln_P(const char *data, bool invert); 213void oled_write_ln_P(const char *data, bool invert);
210#else 214#else
211 // Writes a string to the buffer at current cursor position 215// Writes a string to the buffer at current cursor position
212 // Advances the cursor while writing, inverts the pixels if true 216// Advances the cursor while writing, inverts the pixels if true
213 #define oled_write_P(data, invert) oled_write(data, invert) 217# define oled_write_P(data, invert) oled_write(data, invert)
214 218
215 // Writes a string to the buffer at current cursor position 219// Writes a string to the buffer at current cursor position
216 // Advances the cursor while writing, inverts the pixels if true 220// Advances the cursor while writing, inverts the pixels if true
217 // Advances the cursor to the next page, wiring ' ' to the remainder of the current page 221// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
218 #define oled_write_ln_P(data, invert) oled_write(data, invert) 222# define oled_write_ln_P(data, invert) oled_write(data, invert)
219#endif // defined(__AVR__) 223#endif // defined(__AVR__)
220 224
221// Can be used to manually turn on the screen if it is off 225// Can be used to manually turn on the screen if it is off
222// Returns true if the screen was on or turns on 226// Returns true if the screen was on or turns on