@@ -454,7 +454,7 @@ void Adafruit_SSD1306::ssd1306_command(uint8_t c) {
454
454
boolean Adafruit_SSD1306::begin (uint8_t vcs, uint8_t addr, boolean reset,
455
455
boolean periphBegin) {
456
456
457
- if ((!buffer) && !(buffer = (uint8_t *)malloc (WIDTH * ((HEIGHT + 7 ) / 8 ))))
457
+ if ((!buffer) && !(buffer = (uint8_t *)malloc (SSD1306_SEGMENTS * ((HEIGHT + 7 ) / 8 ))))
458
458
return false ;
459
459
460
460
clearDisplay ();
@@ -628,10 +628,11 @@ void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
628
628
y = HEIGHT - y - 1 ;
629
629
break ;
630
630
}
631
+ if ((WIDTH == 64 ) && (HEIGHT == 48 )) x += 32 ;
631
632
switch (color) {
632
- case SSD1306_WHITE: buffer[x + (y/8 )*WIDTH ] |= (1 << (y&7 )); break ;
633
- case SSD1306_BLACK: buffer[x + (y/8 )*WIDTH ] &= ~(1 << (y&7 )); break ;
634
- case SSD1306_INVERSE: buffer[x + (y/8 )*WIDTH ] ^= (1 << (y&7 )); break ;
633
+ case SSD1306_WHITE: buffer[x + (y/8 )* SSD1306_SEGMENTS ] |= (1 << (y&7 )); break ;
634
+ case SSD1306_BLACK: buffer[x + (y/8 )* SSD1306_SEGMENTS ] &= ~(1 << (y&7 )); break ;
635
+ case SSD1306_INVERSE: buffer[x + (y/8 )* SSD1306_SEGMENTS ] ^= (1 << (y&7 )); break ;
635
636
}
636
637
}
637
638
}
@@ -644,7 +645,7 @@ void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
644
645
commands as needed by one's own application.
645
646
*/
646
647
void Adafruit_SSD1306::clearDisplay (void ) {
647
- memset (buffer, 0 , WIDTH * ((HEIGHT + 7 ) / 8 ));
648
+ memset (buffer, 0 , SSD1306_SEGMENTS * ((HEIGHT + 7 ) / 8 ));
648
649
}
649
650
650
651
/* !
@@ -705,8 +706,9 @@ void Adafruit_SSD1306::drawFastHLineInternal(
705
706
w = (WIDTH - x);
706
707
}
707
708
if (w > 0 ) { // Proceed only if width is positive
708
- uint8_t *pBuf = &buffer[(y / 8 ) * WIDTH + x],
709
- mask = 1 << (y & 7 );
709
+ if ((WIDTH == 64 ) && (HEIGHT == 48 )) x += 32 ;
710
+ uint8_t * pBuf = &buffer[x + (y / 8 ) * SSD1306_SEGMENTS];
711
+ uint8_t mask = 1 << (y & 7 );
710
712
switch (color) {
711
713
case SSD1306_WHITE: while (w--) { *pBuf++ |= mask; }; break ;
712
714
case SSD1306_BLACK: mask = ~mask; while (w--) { *pBuf++ &= mask; }; break ;
@@ -777,7 +779,8 @@ void Adafruit_SSD1306::drawFastVLineInternal(
777
779
// this display doesn't need ints for coordinates,
778
780
// use local byte registers for faster juggling
779
781
uint8_t y = __y, h = __h;
780
- uint8_t *pBuf = &buffer[(y / 8 ) * WIDTH + x];
782
+ if ((WIDTH == 64 ) && (HEIGHT == 48 )) x += 32 ;
783
+ uint8_t *pBuf = &buffer[x + (y / 8 ) * SSD1306_SEGMENTS];
781
784
782
785
// do the first partial byte, if necessary - this requires some masking
783
786
uint8_t mod = (y & 7 );
@@ -798,7 +801,7 @@ void Adafruit_SSD1306::drawFastVLineInternal(
798
801
case SSD1306_BLACK: *pBuf &= ~mask; break ;
799
802
case SSD1306_INVERSE: *pBuf ^= mask; break ;
800
803
}
801
- pBuf += WIDTH ;
804
+ pBuf += SSD1306_SEGMENTS ;
802
805
}
803
806
804
807
if (h >= mod) { // More to go?
@@ -810,15 +813,15 @@ void Adafruit_SSD1306::drawFastVLineInternal(
810
813
// black/white write version with an extra comparison per loop
811
814
do {
812
815
*pBuf ^= 0xFF ; // Invert byte
813
- pBuf += WIDTH ; // Advance pointer 8 rows
816
+ pBuf += SSD1306_SEGMENTS ; // Advance pointer 8 rows
814
817
h -= 8 ; // Subtract 8 rows from height
815
818
} while (h >= 8 );
816
819
} else {
817
820
// store a local value to work with
818
821
uint8_t val = (color != SSD1306_BLACK) ? 255 : 0 ;
819
822
do {
820
823
*pBuf = val; // Set byte
821
- pBuf += WIDTH ; // Advance pointer 8 rows
824
+ pBuf += SSD1306_SEGMENTS ; // Advance pointer 8 rows
822
825
h -= 8 ; // Subtract 8 rows from height
823
826
} while (h >= 8 );
824
827
}
@@ -873,7 +876,8 @@ boolean Adafruit_SSD1306::getPixel(int16_t x, int16_t y) {
873
876
y = HEIGHT - y - 1 ;
874
877
break ;
875
878
}
876
- return (buffer[x + (y / 8 ) * WIDTH] & (1 << (y & 7 )));
879
+ if ((WIDTH == 64 ) && (HEIGHT == 48 )) x += 32 ;
880
+ return (buffer[x + (y / 8 ) * SSD1306_SEGMENTS] & (1 << (y & 7 )));
877
881
}
878
882
return false ; // Pixel out of bounds
879
883
}
@@ -898,27 +902,16 @@ uint8_t *Adafruit_SSD1306::getBuffer(void) {
898
902
*/
899
903
void Adafruit_SSD1306::display (void ) {
900
904
TRANSACTION_START
901
- if ((WIDTH != 64 ) || (HEIGHT != 48 )) {
902
- static const uint8_t PROGMEM dlist1a[] = {
903
- SSD1306_PAGEADDR,
904
- 0 , // Page start address
905
- 0xFF , // Page end (not really, but works here)
906
- SSD1306_COLUMNADDR,
907
- 0 }; // Column start address
908
- ssd1306_commandList (dlist1a, sizeof (dlist1a));
909
- ssd1306_command1 (WIDTH - 1 ); // Column end address
910
- } else {
911
- static const uint8_t PROGMEM dlist1b[] = {
912
- SSD1306_PAGEADDR,
913
- 0 }; // Page start address
914
- ssd1306_commandList (dlist1b, sizeof (dlist1b));
915
- ssd1306_command1 ((HEIGHT / 8 ) - 1 ); // Page end address
916
- static const uint8_t PROGMEM dlist2b[] = {
917
- SSD1306_COLUMNADDR,
918
- 32 }; // Column start address
919
- ssd1306_commandList (dlist2b, sizeof (dlist2b));
920
- ssd1306_command1 (32 + WIDTH - 1 ); // Column end address
921
- }
905
+ static const uint8_t PROGMEM dlist1[] = {
906
+ SSD1306_PAGEADDR,
907
+ 0 }; // Page start address
908
+ ssd1306_commandList (dlist1, sizeof (dlist1));
909
+ ssd1306_command1 ((HEIGHT + 7 ) / 8 - 1 ); // Page end address
910
+ static const uint8_t PROGMEM dlist2[] = {
911
+ SSD1306_COLUMNADDR,
912
+ 0 }; // Column start address
913
+ ssd1306_commandList (dlist2, sizeof (dlist2));
914
+ ssd1306_command1 (SSD1306_SEGMENTS - 1 ); // Column end address
922
915
923
916
#if defined(ESP8266)
924
917
// ESP8266 needs a periodic yield() call to avoid watchdog reset.
@@ -929,7 +922,7 @@ void Adafruit_SSD1306::display(void) {
929
922
// 32-byte transfer condition below.
930
923
yield ();
931
924
#endif
932
- uint16_t count = WIDTH * ((HEIGHT + 7 ) / 8 );
925
+ uint16_t count = SSD1306_SEGMENTS * ((HEIGHT + 7 ) / 8 );
933
926
uint8_t *ptr = buffer;
934
927
if (wire) { // I2C
935
928
wire->beginTransmission (i2caddr);
0 commit comments