ThingPulse / esp8266-oled-ssd1306

Driver for the SSD1306 and SH1106 based 128x64, 128x32, 64x48 pixel OLED display running on ESP8266/ESP32
https://thingpulse.com
Other
2k stars 638 forks source link

CS pin declaration in SH1106 OLED on SPI mode not present in header file #223

Closed fa1ke5 closed 4 years ago

fa1ke5 commented 5 years ago

in file SH1106Spi CS pin for display is not programmed and multi SPI devices is not work with display correctly `class SH1106Spi : public OLEDDisplay { private: uint8_t _rst; uint8_t _dc;

public: SH1106Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { setGeometry(g);

  this->_rst = _rst;
  this->_dc  = _dc;
}`

you can see only RST and DC and CS declaration not present :( I find this bug only then i take oscilloscope. i'm add some code in SH1106Spi.h and now it work great `

ifndef SH1106Spi_h

define SH1106Spi_h

include "OLEDDisplay.h"

include

class SH1106Spi : public OLEDDisplay { private: uint8_t _rst; uint8_t _dc; uint8_t _cs;

public: SH1106Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { setGeometry(g);

  this->_rst = _rst;
  this->_dc  = _dc;
  this->_cs  = _cs;
}

bool connect(){
  pinMode(_dc, OUTPUT);
  pinMode(_rst, OUTPUT);
  pinMode(_cs, OUTPUT);

  SPI.begin ();
  SPI.setClockDivider (SPI_CLOCK_DIV2);

  // Pulse Reset low for 10ms
  digitalWrite(_rst, HIGH);
  delay(1);
  digitalWrite(_rst, LOW);
  delay(10);
  digitalWrite(_rst, HIGH);
  return true;
}

void display(void) {
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
   uint8_t minBoundY = UINT8_MAX;
   uint8_t maxBoundY = 0;

   uint8_t minBoundX = UINT8_MAX;
   uint8_t maxBoundX = 0;

   uint8_t x, y;

   // Calculate the Y bounding box of changes
   // and copy buffer[pos] to buffer_back[pos];
   for (y = 0; y < (displayHeight / 8); y++) {
     for (x = 0; x < displayWidth; x++) {
      uint16_t pos = x + y * displayWidth;
      if (buffer[pos] != buffer_back[pos]) {
        minBoundY = _min(minBoundY, y);
        maxBoundY = _max(maxBoundY, y);
        minBoundX = _min(minBoundX, x);
        maxBoundX = _max(maxBoundX, x);
      }
      buffer_back[pos] = buffer[pos];
    }
    yield();
   }

   // If the minBoundY wasn't updated
   // we can savely assume that buffer_back[pos] == buffer[pos]
   // holdes true for all values of pos
   if (minBoundY == UINT8_MAX) return;

   // Calculate the colum offset
   uint8_t minBoundXp2H = (minBoundX + 2) & 0x0F;
   uint8_t minBoundXp2L = 0x10 | ((minBoundX + 2) >> 4 );

   for (y = minBoundY; y <= maxBoundY; y++) {
     sendCommand(0xB0 + y);
     sendCommand(minBoundXp2H);
     sendCommand(minBoundXp2L);
   digitalWrite(_cs, HIGH);
   digitalWrite(_dc, HIGH);   // data mode
   digitalWrite(_cs, LOW);
     for (x = minBoundX; x <= maxBoundX; x++) {
       SPI.transfer(buffer[x + y * displayWidth]);
     }
     yield();
   }
 digitalWrite(_cs, HIGH);
 #else
  for (uint8_t y=0; y<displayHeight/8; y++) {
    sendCommand(0xB0 + y);
    sendCommand(0x02);
    sendCommand(0x10);
   digitalWrite(_cs, HIGH);
   digitalWrite(_dc, HIGH);   // data mode
   digitalWrite(_cs, LOW);
    for( uint8_t x=0; x < displayWidth; x++) {
      SPI.transfer(buffer[x + y * displayWidth]);
    }
    yield();
  }
digitalWrite(_cs, HIGH);
 #endif
}

private: inline void sendCommand(uint8_t com) attribute((always_inline)){ digitalWrite(_cs, HIGH); digitalWrite(_dc, LOW); digitalWrite(_cs, LOW); SPI.transfer(com); digitalWrite(_cs, HIGH); } };

endif

`

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.