Skip to content

Commit 92d0a71

Browse files
OLED driver function to set pixels (qmk#9713)
* Add a function to set individual pixels * Add documentation for oled_write_pixel * use smaller data type for oled_write_pixel * Fix boundary check edge case * Update oled_write_pixel doc Co-authored-by: Ryan <fauxpark@gmail.com> Co-authored-by: Ryan <fauxpark@gmail.com>
1 parent 08b405e commit 92d0a71

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

docs/feature_oled_driver.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ void oled_write_raw_byte(const char data, uint16_t index);
247247
// Writes a PROGMEM string to the buffer at current cursor position
248248
void oled_write_raw_P(const char *data, uint16_t size);
249249

250+
// Sets a specific pixel on or off
251+
// Coordinates start at top-left and go right and down for positive x and y
252+
void oled_write_pixel(uint8_t x, uint8_t y, bool on);
253+
250254
// Can be used to manually turn on the screen if it is off
251255
// Returns true if the screen was on or turns on
252256
bool oled_on(void);

drivers/oled/oled_driver.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,19 @@ void oled_write_raw(const char *data, uint16_t size) {
462462
}
463463
}
464464

465+
void oled_write_pixel(uint8_t x, uint8_t y, bool on) {
466+
if (x >= OLED_DISPLAY_WIDTH || y >= OLED_DISPLAY_HEIGHT) {
467+
return;
468+
}
469+
uint16_t index = x + (y / 8) * OLED_DISPLAY_WIDTH;
470+
if (on) {
471+
oled_buffer[index] |= (1 << (y % 8));
472+
} else {
473+
oled_buffer[index] &= ~(1 << (y % 8));
474+
}
475+
oled_dirty |= (1 << (index / OLED_BLOCK_SIZE));
476+
}
477+
465478
#if defined(__AVR__)
466479
void oled_write_P(const char *data, bool invert) {
467480
uint8_t c = pgm_read_byte(data);

drivers/oled/oled_driver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ void oled_pan(bool left);
206206
void oled_write_raw(const char *data, uint16_t size);
207207
void oled_write_raw_byte(const char data, uint16_t index);
208208

209+
// Sets a specific pixel on or off
210+
// Coordinates start at top-left and go right and down for positive x and y
211+
void oled_write_pixel(uint8_t x, uint8_t y, bool on);
212+
209213
#if defined(__AVR__)
210214
// Writes a PROGMEM string to the buffer at current cursor position
211215
// Advances the cursor while writing, inverts the pixels if true

0 commit comments

Comments
 (0)