Confused by a line of code in GxEPD2 library

@ZinggJM

This likely needs to be answered by someone familiar with the GxEPD2 ePaper Library since I can only attach a fraction of the library.

I'm new ePaper, the GxEPD2 library is working great for me :slight_smile: But I have much to learn.

I have been looking at the different procedures to help me understand how to best use them and have found some code that confuses me. I'm fair and c programming but not so much with c++ to the answer may be in how I'm interpreting the code.

My confusion is with the _rst variable on an "if" test.

The constructor assigns the EPD panel Reset to (_rst) pin. Which is connected to GPIO2 of the ESP8266.

This being the case, I don't understand what the test (below) of if (_rst >= 0) means. I would think it would always be >= 0 being a GPIO input.

Am I missing something?

from GxEPD2 by Jean-Marc Zingg
both the below snippets from file: GxEPD2_270.cpp

// constructor
GxEPD2_EPD::GxEPD2_EPD(int8_t cs, int8_t dc, int8_t rst, int8_t busy, int8_t busy_level, uint32_t busy_timeout,
                       uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu) :
  WIDTH(w), HEIGHT(h), panel(p), hasColor(c), hasPartialUpdate(pu), hasFastPartialUpdate(fpu),
  _cs(cs), _dc(dc), _rst(rst), _busy(busy), _busy_level(busy_level), _busy_timeout(busy_timeout), 
  _diag_enabled(false),
  _spi_settings(4000000, MSBFIRST, SPI_MODE0)


// _reset (also same for hibernate)
void GxEPD2_EPD::_reset()
{
  if (_rst >= 0)
  {
    if (_pulldown_rst_mode)
    {
      digitalWrite(_rst, LOW);
      pinMode(_rst, OUTPUT);
      delay(_reset_duration);
      pinMode(_rst, INPUT_PULLUP);
      delay(200);
    }
    else
    {
      digitalWrite(_rst, HIGH);
      pinMode(_rst, OUTPUT);
      delay(20);
      digitalWrite(_rst, LOW);
      delay(_reset_duration);
      digitalWrite(_rst, HIGH);
      delay(200);
    }
    _hibernating = false;
  }
}

There used to be some e-paper boards that hat no connection for RST. Use -1 in this case.

I suggest you use one topic for your e-paper questions, and maybe one for your success stories. Please avoid to clutter the Displays section with separate topics. It will also help you for reference.

1 Like