Cannot call member function 'void TAMC_GT911::read()' without object

Hi,

This library is basically came with commented interrupt functions, so I uncommented the lines because I want to use it with my EA7013 ESP32 TFT display model.

So I got this error, but I don't know how to solve it.

  1. Header code:
class TAMC_GT911 {
  public:
    TAMC_GT911(uint8_t _sda, uint8_t _scl, uint8_t _int, uint8_t _rst, uint16_t _width, uint16_t _height);
    void begin(uint8_t _addr = GT911_ADDR1);
    void reset();
    void setResolution(uint16_t _width, uint16_t _height);
    // void setOnRead(void (*isr)());
    void read(void);

  private:
    static void IRAM_ATTR onInterrupt();
    TP_Point readPoint(uint8_t *data);
    void (*onRead)();
    void setOnRead(void (*isr)());
...
};
  1. Source code:
void TAMC_GT911::reset() {
  pinMode(pinInt, OUTPUT);
  pinMode(pinRst, OUTPUT);
  digitalWrite(pinInt, 0);
  digitalWrite(pinRst, 0);
  delay(10);
  digitalWrite(pinInt, addr==GT911_ADDR2);
  delay(1);
  digitalWrite(pinRst, 1);
  delay(5);
  digitalWrite(pinInt, 0);
  delay(50);
  pinMode(pinInt, INPUT);
  attachInterrupt(pinInt, onInterrupt, RISING);
  delay(50);
  readBlockData(configBuf, GT911_CONFIG_START, GT911_CONFIG_SIZE);
  setResolution(width, height);
}


void IRAM_ATTR TAMC_GT911::onInterrupt() {
  read();
  //TAMC_GT911::onRead();
}

void TAMC_GT911::setOnRead(void (*isr)()) {
  onRead = isr;
}
void TAMC_GT911::read(void) {
  uint8_t data[7];
  uint8_t id;
  uint16_t x, y, size;

  uint8_t pointInfo = readByteData(GT911_POINT_INFO);
  uint8_t bufferStatus = pointInfo >> 7 & 1;
  uint8_t proximityValid = pointInfo >> 5 & 1;
  uint8_t haveKey = pointInfo >> 4 & 1;
  isLargeDetect = pointInfo >> 6 & 1;
  touches = pointInfo & 0xF;
  isTouched = touches > 0;
  if (bufferStatus == 1 && isTouched) {
    for (uint8_t i=0; i<touches; i++) {
      readBlockData(data, GT911_POINT_1 + i * 8, 7);
      points[i] = readPoint(data);
    }
  }
  writeByteData(GT911_POINT_INFO, 0);
}

Also, IRAM_ATTR was ARDUINO_ISR_ATTR, but it caused an error so I changed it to IRAM_ATTR.

When I compile the code I get this error:

Arduino: 1.8.19 (Windows 10), Board: "ESP32S3 Dev Module, Disabled, OPI PSRAM, QIO 80MHz, 4MB (32Mb), Core 1, Core 1, Hardware CDC and JTAG, Disabled, Disabled, Disabled, UART0 / Hardware CDC, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi), 921600, None, Enabled"

E:\Programs_Files\Arduino\libraries\gt911-arduino-main\TAMC_GT911.cpp: In static member function 'static void TAMC_GT911::onInterrupt()':

E:\Programs_Files\Arduino\libraries\gt911-arduino-main\TAMC_GT911.cpp:68:8: error: cannot call member function 'void TAMC_GT911::read()' without object

   read();

        ^

exit status 1

Error compiling for board ESP32S3 Dev Module.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

This is after looking at the code for all of 30 seconds, so, grain of salt, etc., etc., but you're trying to call a member function (something that needs a pointer to an instance of a TAMC_GT911 object in front of it) from a static function and w/o a TAMC_GT911 pointer. That's not going to work.

The commented out line //TAMC_GT911::onRead(); looks like it was intended to call another static function, which makes more sense at first glance. But it's after midnight here so the finer points may be escaping me.

That's all I've got right now; sleep is calling and will not be denied.

1 Like

Yep, I think they've put it here because of the tft models that is using the interrupt pin. Which is what I've having with the display model I have which is this one:

This is the schematic of the pins connected to the capacitive touch driver:

When I run the example code, of the TAMC_GT911 library, it doesn't work. That's why I think it's conncted with the interrupt pin.

I have another ESP32 display using the same touch driver but not using the interrupt pin, so the display works fine.

So I thought I must enable the interrupt function of the library. So as you guessed, you're right, I uncommented and found this problem.

I want the interrupt to call read(), to read the touch coordinates.

Yep, it won't work at all.

And if I removed the static, I will get this error:

E:\Programs_Files\Arduino\libraries\gt911-arduino-main\TAMC_GT911.cpp:30:46: error: invalid use of non-static member function 'void TAMC_GT911::onInterrupt()'
   attachInterrupt(pinInt, onInterrupt, RISING);

[quote]The commented out line //TAMC_GT911::onRead(); looks like it was intended to call another static function, which makes more sense at first glance. But it's after midnight here so the finer points may be escaping me.
[/quote]

It's to call read(); that's the main goal, the GT911 capacitive touch driver has this pin to call this function, of course it could be assigned to anything else but it's defined in the original library copy as this, they are all commneted out:

// void ARDUINO_ISR_ATTR TAMC_GT911::onInterrupt() {
//   read();
//   TAMC_GT911::onRead();
// }

// void TAMC_GT911::setOnRead(void (*isr)()) {
//   onRead = isr;
// }

No way sir, a call for a good sleep to wake up and solve new issues :slight_smile:

Looking at what I assume is the original library, I see that all the interrupt stuff is commented out. It would appear that the original author had plans of supporting interrupt operations, but discovered that classes and interrupts and calling member functions from static functions is harder in practice than it at first appears. Long story short: it can be done but it's a can of worms usually best left unopened.

1 Like

Well, the first problem is that the pinInt was left pulled to HIGH all the time. That's why the display was in interrupt mode all the time.

I pulled it LOW, and commented:

attachInterrupt(pinInt, onInterrupt, RISING);

And it's working. It would be nice if I can figure out re-enabling the interrupt functionality in the future, but now I'm quite happy I got it to work.

One issue I found, is that putting pinInt in input mode, locks the display in constant interrupt mode, even if I'm not enabling attachInterrupt function.

void TAMC_GT911::reset() {
  pinMode(pinInt, OUTPUT);
  pinMode(pinRst, OUTPUT);
  digitalWrite(pinInt, 0);
  digitalWrite(pinRst, 0);
  delay(10);
  digitalWrite(pinInt, 0);//addr==GT911_ADDR2
  delay(1);
  digitalWrite(pinRst, 1);
  delay(5);
  digitalWrite(pinInt, 0);
  delay(50);
  pinMode(pinInt, INPUT);
  //attachInterrupt(pinInt, onInterrupt, RISING);
  delay(50);
  readBlockData(configBuf, GT911_CONFIG_START, GT911_CONFIG_SIZE);
  setResolution(width, height);
}

So, commenting pinMode(pinInt, INPUT); leave the pinInt pulled down and problem solved.

I have another question, since configuring this pin to be input will cause the ESP32 to be locked and can't process any code, I thought of pulling this pin to LOW with a resistor. Like this:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.