Skip to content

Commit

Permalink
OLED driver function to set pixels (qmk#9713)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: Ryan <[email protected]>
  • Loading branch information
GauthamYerroju and fauxpark authored Jul 16, 2020
1 parent 54e7756 commit a47233d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/feature_oled_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ void oled_write_raw_byte(const char data, uint16_t index);
// Writes a PROGMEM string to the buffer at current cursor position
void oled_write_raw_P(const char *data, uint16_t size);

// Sets a specific pixel on or off
// Coordinates start at top-left and go right and down for positive x and y
void oled_write_pixel(uint8_t x, uint8_t y, bool on);

// Can be used to manually turn on the screen if it is off
// Returns true if the screen was on or turns on
bool oled_on(void);
Expand Down
13 changes: 13 additions & 0 deletions drivers/oled/oled_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,19 @@ void oled_write_raw(const char *data, uint16_t size) {
}
}

void oled_write_pixel(uint8_t x, uint8_t y, bool on) {
if (x >= OLED_DISPLAY_WIDTH || y >= OLED_DISPLAY_HEIGHT) {
return;
}
uint16_t index = x + (y / 8) * OLED_DISPLAY_WIDTH;
if (on) {
oled_buffer[index] |= (1 << (y % 8));
} else {
oled_buffer[index] &= ~(1 << (y % 8));
}
oled_dirty |= (1 << (index / OLED_BLOCK_SIZE));
}

#if defined(__AVR__)
void oled_write_P(const char *data, bool invert) {
uint8_t c = pgm_read_byte(data);
Expand Down
4 changes: 4 additions & 0 deletions drivers/oled/oled_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ void oled_pan(bool left);
void oled_write_raw(const char *data, uint16_t size);
void oled_write_raw_byte(const char data, uint16_t index);

// Sets a specific pixel on or off
// Coordinates start at top-left and go right and down for positive x and y
void oled_write_pixel(uint8_t x, uint8_t y, bool on);

#if defined(__AVR__)
// Writes a PROGMEM string to the buffer at current cursor position
// Advances the cursor while writing, inverts the pixels if true
Expand Down

0 comments on commit a47233d

Please sign in to comment.