compilation errors with static and member elements

33 Views Asked by At

I'm trying to make this program work in the Arduino IDE. I get messages: "error: invalid use of member xxx in static member function" It uses 2 interrupt service routines defined in a class. They must be defined as static, and that works. However, it causes problems to access non-static members in the same class.

I would need the magic combination of 'static', 'volatile', etc. that would make this work, thanks!

interface_8255.ino

#include "intf_8255.h"

class intf_8255 my_intf;

void setup() {
  my_intf.init();
}

void loop() {
}

intf_8255.cpp

#include "intf_8255.h"

intf_8255::intf_8255() {}

//8255 to Redboard
void intf_8255::OBF_Isr(void) {
byte value;

  //PC6  /ACK   input from PC5
  //read data
  digitalWrite(ACK_out, LOW);
  
  // Setup bus as input
  DDRD = DDRD & 0x0F;   // clear bits 7-4
  DDRC = DDRD & 0xF0;   // clear bits 3-0

  value = (PINC & 0x0F) | (PIND & 0xF0);
  
  digitalWrite(ACK_out, HIGH);

  //put in circular buffer  
  if (Rx_8255.isFull()) {
    // volatile RxState = full
  }
  else
  {
    Rx_8255.push(value);
  }
}

//Redboard to 8255
void intf_8255::IBF_Isr(void) {
byte value;

  //get from circular buffer
  if (Tx_8255.isEmpty())
  {
    Wrote1stByte = false;
    return;
  }

  //write data (if not empty)
  value = Tx_8255.pop();
  
//  WriteData(value);  
}

void intf_8255::init() {  
  /* skip some code */
  attachInterrupt(digitalPinToInterrupt(OBF_int), OBF_Isr, FALLING);
  attachInterrupt(digitalPinToInterrupt(IBF_int), IBF_Isr, FALLING);

  Wrote1stByte = false;
}

void intf_8255::WriteData(byte value)
{
  // Setup bus as output
  DDRD = DDRD | 0xF0;   // set bits 7-4
  DDRC = DDRC | 0x0F;   // set bits 3-0

  PORTC = (PORTC & 0x30) | (value & 0x0F);
  PORTD = (PORTD & 0xF2) | (value & 0xF0);
  
  //PC4  /STB   input from PC4
  digitalWrite(STB_out, LOW);
  digitalWrite(STB_out, HIGH);

  // Setup bus as input
  DDRD = DDRD & 0x0F;   // clear bits 7-4
  DDRC = DDRD & 0xF0;   // clear bits 3-0
}

// blocking read
byte intf_8255::ReadFrom8255()
{
  while (Rx_8255.isEmpty()) /* wait */;

  return Rx_8255.pop();
}

void intf_8255::WriteTo8255(byte value)
{
  while (Tx_8255.isFull()) /* wait */;

  /* if empty send 1st byte*/
  if (Wrote1stByte)
  {
    Tx_8255.push(value);
  }
  else
  {
    WriteData(value);
    Wrote1stByte = true;
  }
}

intf_8255.h

#pragma once

#include <Arduino.h>
#include <CircularBuffer.h>

#define CIRCULAR_BUFFER_INT_SAFE

const byte OBF_int = 2;
const byte IBF_int = 3;
const byte ACK_out = A5;   //PC5 A5/D19
const byte STB_out = A4;   //PC4 A4/D18

class intf_8255
{
  private:
    CircularBuffer<byte, 256> Tx_8255;  
    CircularBuffer<byte, 256> Rx_8255;  

    volatile bool Wrote1stByte;
    
    static void OBF_Isr(void);
    static void IBF_Isr(void);

    void WriteData(byte value);
    
  public:
    intf_8255();
    
    void init();
    byte ReadFrom8255();
    void WriteTo8255(byte value);
};
0

There are 0 best solutions below