我定义这个宏:多方论证宏定义错误
#define DEF_CONCAT(a, b) a ## b
#define _internal_RCC(gpio, io) DEF_CONCAT(RCC_GPIO, gpio)
#define _internal_IO(gpio, io) DEF_CONCAT(GPIO, io)
#define IO_CFG_OUTPUT(gpio) {rcc_periph_clock_enable(_internal_RCC(gpio));gpio_set_mode(gpio, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, _internal_IO(gpio));}
而且我想调用这个:
IO_CFG_OUTPUT(LED_STATE);
LED_STATE
被定义为:#define LED_STATE C,12
但是,当我运行我的程序,编译器告诉我:
In file included from inc/Robot.hpp:6:0,
from src/Robot.cpp:1:
src/Robot.cpp: In member function 'void Robot::setup()':
inc/IODefines.hpp:13:19: error: 'C' was not declared in this scope
#define LED_STATE C,12
^
我做错了什么?来源
'#define LED_STATE C,12'这似乎是错误的,你打算做什么? –
是的,但是为什么?它应该使用C作为字母在IO_CFG_OUTPUT中通过DEF_CONCAT将它结合到RCC_GPIOC中。怎么样? –
你也可以在'gpio_set_mode(gpio,..)'中使用它,'C'是否存在? gpio_set_mode是一个宏吗? – Jarod42