Skip to content

Commit 8b13a9a

Browse files
committed
Support for user access to SSD1306 commands longer than one byte
1 parent 347c5fc commit 8b13a9a

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

Adafruit_SSD1306.cpp

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,58 @@ void Adafruit_SSD1306::Transaction::data(uint8_t byte) { send(false, byte); }
493493
/*!
494494
@brief Issue a single low-level command directly to the SSD1306
495495
display, bypassing the library.
496-
@param c
496+
@param cmd
497+
Command to issue (0x00 to 0xFF, see datasheet).
498+
@return None (void).
499+
*/
500+
void Adafruit_SSD1306::ssd1306_command(uint8_t cmd) {
501+
Transaction trans(*this);
502+
trans.command(cmd);
503+
}
504+
505+
/*!
506+
@brief Issue a two byte low-level command directly to the SSD1306
507+
display, bypassing the library.
508+
@param cmd
509+
Command to issue (0x00 to 0xFF, see datasheet).
510+
@param a
511+
The second byte of the command.
512+
@return None (void).
513+
*/
514+
void Adafruit_SSD1306::ssd1306_command(uint8_t cmd, uint8_t a) {
515+
Transaction trans(*this);
516+
trans.command(cmd, a);
517+
}
518+
519+
/*!
520+
@brief Issue a three byte low-level command directly to the SSD1306
521+
display, bypassing the library.
522+
@param cmd
497523
Command to issue (0x00 to 0xFF, see datasheet).
524+
@param a
525+
The second byte of the command.
526+
@param b
527+
The third byte of the command.
528+
@return None (void).
529+
*/
530+
void Adafruit_SSD1306::ssd1306_command(uint8_t cmd, uint8_t a, uint8_t b) {
531+
Transaction trans(*this);
532+
trans.command(cmd, a, b);
533+
}
534+
535+
/*!
536+
@brief Issue a multi byte low-level command directly to the SSD1306
537+
display, bypassing the library.
538+
@param cmd
539+
Pointer to command bytes to issue.
540+
@param n
541+
Number of bytes in the command.
498542
@return None (void).
499543
*/
500-
void Adafruit_SSD1306::ssd1306_command(uint8_t c) {
544+
void Adafruit_SSD1306::ssd1306_command(const uint8_t *cmd, uint8_t n) {
501545
Transaction trans(*this);
502-
trans.command(c);
546+
while (n--)
547+
trans.command(pgm_read_byte(cmd++));
503548
}
504549

505550
// ALLOCATE & INIT DISPLAY -------------------------------------------------

Adafruit_SSD1306.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,15 @@ class Adafruit_SSD1306 : public Adafruit_GFX {
156156
void startscrolldiagright(uint8_t start, uint8_t stop);
157157
void startscrolldiagleft(uint8_t start, uint8_t stop);
158158
void stopscroll(void);
159-
void ssd1306_command(uint8_t c);
160159
bool getPixel(int16_t x, int16_t y);
161160
uint8_t *getBuffer(void);
162161

162+
// low level access to SSD1306 commands
163+
void ssd1306_command(uint8_t cmd);
164+
void ssd1306_command(uint8_t cmd, uint8_t a);
165+
void ssd1306_command(uint8_t cmd, uint8_t a, uint8_t b);
166+
void ssd1306_command(const uint8_t *cmd, uint8_t n);
167+
163168
private:
164169
inline void SPIwrite(uint8_t d) __attribute__((always_inline));
165170
void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color);

0 commit comments

Comments
 (0)