Skip to content

Commit be6562a

Browse files
Thomas Baartdrashna
Thomas Baart
authored andcommitted
Adds raw write functions to the OLED driver (#7237)
* Added oled_write_raw and oled_write_raw_P functions to the OLED driver * Added oled_write_raw method calls to feature_oled_driver.md
1 parent 732d1dd commit be6562a

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

docs/feature_oled_driver.md

+6
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ void oled_write_P(const char *data, bool invert);
229229
// Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM
230230
void oled_write_ln_P(const char *data, bool invert);
231231

232+
// Writes a string to the buffer at current cursor position
233+
void oled_write_raw(const char *data, uint16_t size);
234+
235+
// Writes a PROGMEM string to the buffer at current cursor position
236+
void oled_write_raw_P(const char *data, uint16_t size);
237+
232238
// Can be used to manually turn on the screen if it is off
233239
// Returns true if the screen was on or turns on
234240
bool oled_on(void);

drivers/oled/oled_driver.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,15 @@ void oled_write_ln(const char *data, bool invert) {
431431
oled_advance_page(true);
432432
}
433433

434+
void oled_write_raw(const char *data, uint16_t size) {
435+
if (size > OLED_MATRIX_SIZE) size = OLED_MATRIX_SIZE;
436+
for (uint16_t i = 0; i < size; i++) {
437+
if (oled_buffer[i] == data[i]) continue;
438+
oled_buffer[i] = data[i];
439+
oled_dirty |= (1 << (i / OLED_BLOCK_SIZE));
440+
}
441+
}
442+
434443
#if defined(__AVR__)
435444
void oled_write_P(const char *data, bool invert) {
436445
uint8_t c = pgm_read_byte(data);
@@ -444,6 +453,16 @@ void oled_write_ln_P(const char *data, bool invert) {
444453
oled_write_P(data, invert);
445454
oled_advance_page(true);
446455
}
456+
457+
void oled_write_raw_P(const char *data, uint16_t size) {
458+
if (size > OLED_MATRIX_SIZE) size = OLED_MATRIX_SIZE;
459+
for (uint16_t i = 0; i < size; i++) {
460+
uint8_t c = pgm_read_byte(++data);
461+
if (oled_buffer[i] == c) continue;
462+
oled_buffer[i] = c;
463+
oled_dirty |= (1 << (i / OLED_BLOCK_SIZE));
464+
}
465+
}
447466
#endif // defined(__AVR__)
448467

449468
bool oled_on(void) {
@@ -566,4 +585,4 @@ void oled_task(void) {
566585
#endif
567586
}
568587

569-
__attribute__((weak)) void oled_task_user(void) {}
588+
__attribute__((weak)) void oled_task_user(void) {}

drivers/oled/oled_driver.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ void oled_write(const char *data, bool invert);
200200
// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
201201
void oled_write_ln(const char *data, bool invert);
202202

203+
void oled_write_raw(const char *data, uint16_t size);
204+
203205
#if defined(__AVR__)
204206
// Writes a PROGMEM string to the buffer at current cursor position
205207
// Advances the cursor while writing, inverts the pixels if true
@@ -211,6 +213,8 @@ void oled_write_P(const char *data, bool invert);
211213
// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
212214
// Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM
213215
void oled_write_ln_P(const char *data, bool invert);
216+
217+
void oled_write_raw_P(const char *data, uint16_t size);
214218
#else
215219
// Writes a string to the buffer at current cursor position
216220
// Advances the cursor while writing, inverts the pixels if true
@@ -254,4 +258,4 @@ bool oled_scroll_off(void);
254258
uint8_t oled_max_chars(void);
255259

256260
// Returns the maximum number of lines that will fit on the oled
257-
uint8_t oled_max_lines(void);
261+
uint8_t oled_max_lines(void);

0 commit comments

Comments
 (0)