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