在宏扩展中未在此范围内声明c ++变量

时间:2018-09-17 15:41:54

标签: c++ declaration adafruit

尊敬的Stackoverflowers

我正在尝试从Adafruit(link)的HX8357D 3.5英寸TFT显示器中增加对esp32的支持。我从Adafruit(link)的库中派生了一个库,用于处理8-位并行接口并添加了esp32分支。我找出了所需的大多数组件,但我无法编译代码。有人可以帮助我使其正常工作吗?

我用必须在库中实现的代码制作了Arduino草图:

//Not used in this sketch, but these are the 5 control pins for the TFT display
#define LCD_CS 27
#define LCD_CD 26
#define LCD_WR 25
#define LCD_RD 14
#define LCD_RESET 13

//8 data pins (random, but made sure they are all ardressable with one register)
#define DATA_PIN0 3
#define DATA_PIN1 18
#define DATA_PIN2 5
#define DATA_PIN3 17
#define DATA_PIN4 16
#define DATA_PIN5 4
#define DATA_PIN6 2
#define DATA_PIN7 15

#define DELAY     200

gpio_config_t io_conf;

//Some random data to write to the gpio pins, creates a pattern to the LED's that I connected
uint32_t data[] {
  0b00000000000000001000000000001000,
  0b00000000000001000000000000000100,
  0b00000000000000000000000000110000,
  0b00000000000000110000000000000000,
  0b00000000000000000000000000000000,
  0b00000000000000110000000000000000,
  0b00000000000000000000000000110000,
  0b00000000000001000000000000000100,
  0b00000000000000001000000000001000
};

void setup() {
  Serial.begin(115200);
  setReadDir();
  print32Bits(GPIO.in);
  setWriteDir();
}

void loop() {
  for (int i = 0; i < 9; i++) {
    GPIO.out_w1tc = 0xFFFFFFFF;
    GPIO.out_w1ts = data[i];
    delay(DELAY);
  }
}

//Set 8 data pins to OUTPUT
void setWriteDir() {
  io_conf.intr_type = GPIO_INTR_DISABLE;
  io_conf.mode = GPIO_MODE_OUTPUT;
  io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
  io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
  io_conf.pin_bit_mask =  ((1ULL << DATA_PIN0 ) | (1ULL << DATA_PIN1) | (1ULL << DATA_PIN2) | (1ULL << DATA_PIN3) | (1ULL << DATA_PIN4) | (1ULL << DATA_PIN5) | (1ULL << DATA_PIN6) | (1ULL << DATA_PIN7)); // of course, do like this all the pins
  gpio_config(&io_conf);
}

//Set 8 data pins to INPUT
void setReadDir() {
  io_conf.intr_type = GPIO_INTR_DISABLE;
  io_conf.mode = GPIO_MODE_INPUT;
  io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
  io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
  io_conf.pin_bit_mask =  ((1ULL << LCD_CS ) | (1ULL << LCD_CD) | (1ULL << LCD_WR) | (1ULL << LCD_RD) | (1ULL << LCD_RESET)); // of course, do like this all the pins
  gpio_config(&io_conf);
}

//Function to print 32 bit interger to Serial, just for convenience
void print32Bits(uint32_t myByte) {
  for (uint32_t mask = 0x80000000; mask; mask >>= 1) {
    if (mask  & myByte) {
      Serial.print('1');
    } else {
      Serial.print('0');
    }
  }
  Serial.println();
}

我将必要的代码添加到了ADAFRUIT_TFTLCD.hADAFRUIT_TFTLCD.cpppin_magic.h

pin_magic.hwrite8inlinread8inlin)中的功能尚未完全完成。我试图编译代码以测试到目前为止所做的工作是否可以正确编译,但是我遇到了许多....was not declared in this scope错误。

pin_magic.h中,我有:

#define RD_ACTIVE  GPIO.out_w1tc |=  rdPinset
#define RD_IDLE    GPIO.out_w1ts |=  rdPinSet
#define WR_ACTIVE  GPIO.out_w1tc |=  wrPinset
#define WR_IDLE    GPIO.out_w1ts |=  wrPinSet
#define CD_COMMAND GPIO.out_w1tc |=  cdPinset
#define CD_DATA    GPIO.out_w1ts |=  cdPinSet
#define CS_ACTIVE  GPIO.out_w1tc |=  csPinset
#define CS_IDLE    GPIO.out_w1ts |=  csPinSet

我得到的错误的第一部分:

D:\ProgramData\Arduino\libraries\TFTLCD-Library\pin_magic.h:389:42: error: 'csPinset' was not declared in this scope

     #define CS_ACTIVE  GPIO.out_w1tc |=  csPinset

                                          ^

D:\ProgramData\Arduino\libraries\TFTLCD-Library\Adafruit_TFTLCD.cpp:268:5: note: in expansion of macro 'CS_ACTIVE'

     CS_ACTIVE;

     ^

如果有更多C / C ++经验的人可以看看它,我将非常感激。

1 个答案:

答案 0 :(得分:1)

我查看了您的代码,您是否在PC中进行编译?看起来由于#ifdef块,编译器正在忽略csPinset等的声明-

我不熟悉AVR环境,但是我建议在预期的环境中使用正确的编译器(例如,符合AVR的标准)来编译代码。另外,您还可以在编译时使用-D选项定义__ AVR __:

g ++ -D__AVR __

编辑

要确保在所有环境中都声明了所需的变量,可以将头文件更改为以下内容-

#ifndef USE_ADAFRUIT_SHIELD_PINOUT

    #ifdef AVR
        // "Variable declaration for AVR goes here"

    #elif defined SAM
       //"Variable declaration for SAM goes here"

    /*else block, in case ESP32 is not the correct macro name*/
    #else
      //"General Variables for everything else other than SAM or AVR."
    #endif

//in case the ADA SHIELD PINOUT is defined
#else
//"General Variables for when USE_ADAFRUIT_SHIELD_PINOUT is defined."

#endif

这应该解决“未声明变量”错误。您可以在https://arduino.stackexchange.com中探索或询问为ESP32 env定制此标头的正确方法。