Skip to content

Commit 09c5946

Browse files
committed
Support for user access to SSD1306 commands longer than one byte
1 parent 590f512 commit 09c5946

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
@@ -497,13 +497,58 @@ void Adafruit_SSD1306::Transaction::data(uint8_t byte) { send(false, byte); }
497497
/*!
498498
@brief Issue a single low-level command directly to the SSD1306
499499
display, bypassing the library.
500-
@param c
500+
@param cmd
501+
Command to issue (0x00 to 0xFF, see datasheet).
502+
@return None (void).
503+
*/
504+
void Adafruit_SSD1306::ssd1306_command(uint8_t cmd) {
505+
Transaction trans(*this);
506+
trans.command(cmd);
507+
}
508+
509+
/*!
510+
@brief Issue a two byte low-level command directly to the SSD1306
511+
display, bypassing the library.
512+
@param cmd
513+
Command to issue (0x00 to 0xFF, see datasheet).
514+
@param a
515+
The second byte of the command.
516+
@return None (void).
517+
*/
518+
void Adafruit_SSD1306::ssd1306_command(uint8_t cmd, uint8_t a) {
519+
Transaction trans(*this);
520+
trans.command(cmd, a);
521+
}
522+
523+
/*!
524+
@brief Issue a three byte low-level command directly to the SSD1306
525+
display, bypassing the library.
526+
@param cmd
501527
Command to issue (0x00 to 0xFF, see datasheet).
528+
@param a
529+
The second byte of the command.
530+
@param b
531+
The third byte of the command.
532+
@return None (void).
533+
*/
534+
void Adafruit_SSD1306::ssd1306_command(uint8_t cmd, uint8_t a, uint8_t b) {
535+
Transaction trans(*this);
536+
trans.command(cmd, a, b);
537+
}
538+
539+
/*!
540+
@brief Issue a multi byte low-level command directly to the SSD1306
541+
display, bypassing the library.
542+
@param cmd
543+
Pointer to command bytes to issue.
544+
@param n
545+
Number of bytes in the command.
502546
@return None (void).
503547
*/
504-
void Adafruit_SSD1306::ssd1306_command(uint8_t c) {
548+
void Adafruit_SSD1306::ssd1306_command(const uint8_t *cmd, uint8_t n) {
505549
Transaction trans(*this);
506-
trans.command(c);
550+
while (n--)
551+
trans.command(pgm_read_byte(cmd++));
507552
}
508553

509554
// 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)