Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to read the OLED display buffer from user space #8777

Merged
merged 13 commits into from
Aug 24, 2020
4 changes: 4 additions & 0 deletions docs/feature_oled_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ void oled_write_P(const char *data, bool invert);
// Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM
void oled_write_ln_P(const char *data, bool invert);

// Returns a pointer to the requested start index in the buffer plus remaining
// buffer length as struct
oled_buffer_reader_t oled_read_raw(uint16_t start_index);

// Writes a string to the buffer at current cursor position
void oled_write_raw(const char *data, uint16_t size);

Expand Down
8 changes: 8 additions & 0 deletions drivers/oled/oled_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ void oled_pan(bool left) {
oled_dirty = ~((OLED_BLOCK_TYPE)0);
}

oled_buffer_reader_t oled_read_raw(uint16_t start_index) {
if (start_index > OLED_MATRIX_SIZE) start_index = OLED_MATRIX_SIZE;
oled_buffer_reader_t ret_reader;
ret_reader.current_element = &oled_buffer[start_index];
ret_reader.remaining_element_count = OLED_MATRIX_SIZE - start_index;
return ret_reader;
}

void oled_write_raw_byte(const char data, uint16_t index) {
if (index > OLED_MATRIX_SIZE) index = OLED_MATRIX_SIZE;
if (oled_buffer[index] == data) return;
Expand Down
11 changes: 11 additions & 0 deletions drivers/oled/oled_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# endif
#endif


typedef struct _oled_buffer_reader_t {
uint8_t *current_element;
uint16_t remaining_element_count;
brickbots marked this conversation as resolved.
Show resolved Hide resolved
} oled_buffer_reader_t;


// OLED Rotation enum values are flags
typedef enum {
OLED_ROTATION_0 = 0,
Expand Down Expand Up @@ -203,6 +210,10 @@ void oled_write_ln(const char *data, bool invert);
// Pans the buffer to the right (or left by passing true) by moving contents of the buffer
void oled_pan(bool left);

// Returns a pointer to the requested start index in the buffer plus remaining
// buffer length as struct
oled_buffer_reader_t oled_read_raw(uint16_t start_index);

void oled_write_raw(const char *data, uint16_t size);
void oled_write_raw_byte(const char data, uint16_t index);

Expand Down