#DEFINE placement
Posted: Mon Apr 08, 2024 9:15 pm
Thought I'd put in here as it's not so much an ESP IDF question as a general C question. For the sake of making my code logical/easy to read I'd like to put some #DEFINE statements in with the gpio_config statements I have in a void pin_setup() function. Is it legitimate to have a #DEFINE at this level or must it be outside of any functions to avoid future issues?
Thanks in advance.
Thanks in advance.
Code: Select all
void pin_setup()
{
/////////////////////////////////////////////////////////////////////
//Pin definition on ESP DOIT Devkit V1 and pin config
//D1 - Red lane Dog 1 Fault light
gpio_config_t io_conf1;
io_conf1.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf1.mode = GPIO_MODE_OUTPUT;//set as output mode
io_conf1.pin_bit_mask = (1ULL<<1);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf1.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf1.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error=gpio_config(&io_conf1);//configure GPIO with the given settings
if(error!=ESP_OK){
printf("error configuring GPIO1 \n");
}
gpio_set_direction(GPIO_NUM_1, GPIO_MODE_OUTPUT);
#define RED_FAULT_1 GPIO_NUM_1
//more code beyond this but cut it for simplicity of post
}