@@ -463,7 +463,7 @@ void Adafruit_SSD1306::ssd1306_command(uint8_t c) {
463
463
bool Adafruit_SSD1306::begin (uint8_t vcs, uint8_t addr, bool reset,
464
464
bool periphBegin) {
465
465
466
- if ((!buffer) && !(buffer = (uint8_t *)malloc (WIDTH * ((HEIGHT + 7 ) / 8 ))))
466
+ if ((!buffer) && !(buffer = (uint8_t *)malloc (SSD1306_SEGMENTS * ((HEIGHT + 7 ) / 8 ))))
467
467
return false ;
468
468
469
469
clearDisplay ();
@@ -632,16 +632,17 @@ void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
632
632
y = HEIGHT - y - 1 ;
633
633
break ;
634
634
}
635
+ if ((WIDTH == 64 ) && (HEIGHT == 48 )) x += 32 ;
635
636
switch (color) {
636
- case SSD1306_WHITE:
637
- buffer[x + (y / 8 ) * WIDTH ] |= (1 << (y & 7 ));
638
- break ;
639
- case SSD1306_BLACK:
640
- buffer[x + (y / 8 ) * WIDTH ] &= ~(1 << (y & 7 ));
641
- break ;
642
- case SSD1306_INVERSE:
643
- buffer[x + (y / 8 ) * WIDTH ] ^= (1 << (y & 7 ));
644
- break ;
637
+ case SSD1306_WHITE:
638
+ buffer[x + (y / 8 ) * SSD1306_SEGMENTS ] |= (1 << (y & 7 ));
639
+ break ;
640
+ case SSD1306_BLACK:
641
+ buffer[x + (y / 8 ) * SSD1306_SEGMENTS ] &= ~(1 << (y & 7 ));
642
+ break ;
643
+ case SSD1306_INVERSE:
644
+ buffer[x + (y / 8 ) * SSD1306_SEGMENTS ] ^= (1 << (y & 7 ));
645
+ break ;
645
646
}
646
647
}
647
648
}
@@ -654,7 +655,7 @@ void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
654
655
commands as needed by one's own application.
655
656
*/
656
657
void Adafruit_SSD1306::clearDisplay (void ) {
657
- memset (buffer, 0 , WIDTH * ((HEIGHT + 7 ) / 8 ));
658
+ memset (buffer, 0 , SSD1306_SEGMENTS * ((HEIGHT + 7 ) / 8 ));
658
659
}
659
660
660
661
/* !
@@ -717,7 +718,9 @@ void Adafruit_SSD1306::drawFastHLineInternal(int16_t x, int16_t y, int16_t w,
717
718
w = (WIDTH - x);
718
719
}
719
720
if (w > 0 ) { // Proceed only if width is positive
720
- uint8_t *pBuf = &buffer[(y / 8 ) * WIDTH + x], mask = 1 << (y & 7 );
721
+ if ((WIDTH == 64 ) && (HEIGHT == 48 )) x += 32 ;
722
+ uint8_t * pBuf = &buffer[x + (y / 8 ) * SSD1306_SEGMENTS];
723
+ uint8_t mask = 1 << (y & 7 );
721
724
switch (color) {
722
725
case SSD1306_WHITE:
723
726
while (w--) {
@@ -803,7 +806,8 @@ void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y,
803
806
// this display doesn't need ints for coordinates,
804
807
// use local byte registers for faster juggling
805
808
uint8_t y = __y, h = __h;
806
- uint8_t *pBuf = &buffer[(y / 8 ) * WIDTH + x];
809
+ if ((WIDTH == 64 ) && (HEIGHT == 48 )) x += 32 ;
810
+ uint8_t *pBuf = &buffer[x + (y / 8 ) * SSD1306_SEGMENTS];
807
811
808
812
// do the first partial byte, if necessary - this requires some masking
809
813
uint8_t mod = (y & 7 );
@@ -831,7 +835,7 @@ void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y,
831
835
*pBuf ^= mask;
832
836
break ;
833
837
}
834
- pBuf += WIDTH ;
838
+ pBuf += SSD1306_SEGMENTS ;
835
839
}
836
840
837
841
if (h >= mod) { // More to go?
@@ -843,15 +847,15 @@ void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y,
843
847
// black/white write version with an extra comparison per loop
844
848
do {
845
849
*pBuf ^= 0xFF ; // Invert byte
846
- pBuf += WIDTH ; // Advance pointer 8 rows
850
+ pBuf += SSD1306_SEGMENTS ; // Advance pointer 8 rows
847
851
h -= 8 ; // Subtract 8 rows from height
848
852
} while (h >= 8 );
849
853
} else {
850
854
// store a local value to work with
851
855
uint8_t val = (color != SSD1306_BLACK) ? 255 : 0 ;
852
856
do {
853
857
*pBuf = val; // Set byte
854
- pBuf += WIDTH; // Advance pointer 8 rows
858
+ pBuf += SSD1306_SEGMENTS; // Advance pointer 8 rows
855
859
h -= 8 ; // Subtract 8 rows from height
856
860
} while (h >= 8 );
857
861
}
@@ -912,7 +916,8 @@ bool Adafruit_SSD1306::getPixel(int16_t x, int16_t y) {
912
916
y = HEIGHT - y - 1 ;
913
917
break ;
914
918
}
915
- return (buffer[x + (y / 8 ) * WIDTH] & (1 << (y & 7 )));
919
+ if ((WIDTH == 64 ) && (HEIGHT == 48 )) x += 32 ;
920
+ return (buffer[x + (y / 8 ) * SSD1306_SEGMENTS] & (1 << (y & 7 )));
916
921
}
917
922
return false ; // Pixel out of bounds
918
923
}
@@ -935,27 +940,16 @@ uint8_t *Adafruit_SSD1306::getBuffer(void) { return buffer; }
935
940
*/
936
941
void Adafruit_SSD1306::display (void ) {
937
942
TRANSACTION_START
938
- if ((WIDTH != 64 ) || (HEIGHT != 48 )) {
939
- static const uint8_t PROGMEM dlist1a[] = {
940
- SSD1306_PAGEADDR,
941
- 0 , // Page start address
942
- 0xFF , // Page end (not really, but works here)
943
- SSD1306_COLUMNADDR,
944
- 0 }; // Column start address
945
- ssd1306_commandList (dlist1a, sizeof (dlist1a));
946
- ssd1306_command1 (WIDTH - 1 ); // Column end address
947
- } else {
948
- static const uint8_t PROGMEM dlist1b[] = {
949
- SSD1306_PAGEADDR,
950
- 0 }; // Page start address
951
- ssd1306_commandList (dlist1b, sizeof (dlist1b));
952
- ssd1306_command1 ((HEIGHT / 8 ) - 1 ); // Page end address
953
- static const uint8_t PROGMEM dlist2b[] = {
954
- SSD1306_COLUMNADDR,
955
- 32 }; // Column start address
956
- ssd1306_commandList (dlist2b, sizeof (dlist2b));
957
- ssd1306_command1 (32 + WIDTH - 1 ); // Column end address
958
- }
943
+ static const uint8_t PROGMEM dlist1[] = {
944
+ SSD1306_PAGEADDR,
945
+ 0 }; // Page start address
946
+ ssd1306_commandList (dlist1, sizeof (dlist1));
947
+ ssd1306_command1 ((HEIGHT + 7 ) / 8 - 1 ); // Page end address
948
+ static const uint8_t PROGMEM dlist2[] = {
949
+ SSD1306_COLUMNADDR,
950
+ 0 }; // Column start address
951
+ ssd1306_commandList (dlist2, sizeof (dlist2));
952
+ ssd1306_command1 (SSD1306_SEGMENTS - 1 ); // Column end address
959
953
960
954
#if defined(ESP8266)
961
955
// ESP8266 needs a periodic yield() call to avoid watchdog reset.
@@ -966,7 +960,7 @@ void Adafruit_SSD1306::display(void) {
966
960
// 32-byte transfer condition below.
967
961
yield ();
968
962
#endif
969
- uint16_t count = WIDTH * ((HEIGHT + 7 ) / 8 );
963
+ uint16_t count = SSD1306_SEGMENTS * ((HEIGHT + 7 ) / 8 );
970
964
uint8_t *ptr = buffer;
971
965
if (wire) { // I2C
972
966
wire->beginTransmission (i2caddr);
0 commit comments