提问人: 提问时间:3/23/2023 更新时间:3/23/2023 访问量:30
静态元素和成员元素的编译错误
compilation errors with static and member elements
问:
我正在尝试使该程序在Arduino IDE中工作。 我收到消息: “错误:在静态成员函数中无效使用成员 XXX” 它使用一个类中定义的 2 个中断服务例程。它们必须被定义为静态的,这是有效的。但是,它会导致访问同一类中的非静态成员时出现问题。
我需要“静态”、“易失性”等的神奇组合才能使这项工作,谢谢!
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);
};
答: 暂无答案
评论
class intf_8255 my_intf;
class
intf_8255 my_intf;
static
#define CIRCULAR_BUFFER_INT_SAFE
必须先去才能使其中断安全。#include <CircularBuffer.h>