PlatformIO Community

#define results as incompatible type

I think this is a general C++ programming thing that I’ve forgotten…or maybe I don’t get how the definitions are being made. :thinking:

But, I have the following code:

  #define GPIO_SYNC0_IN   4
...
...
  mcpwm_pin_config_t pin_config {};
  pin_config.mcpwm_sync0_in_num  = GPIO_SYNC0_IN;
...
  gpio_pulldown_en(GPIO_SYNC0_IN);
...
...

On the line gpio_pulldown_en(GPIO_SYNC0_IN); I get the following error:

argument of type “int” is incompatible with parameter of type “gpio_num_t”

If I cas itt, as below, to gpio_num_t it seems to build ok, is that going to be gotcha somewhere else?
``
gpio_pulldown_en((gpio_num_t) GPIO_SYNC0_IN);

Well it’s defined as

and further

So in your cae the value 4 is also the value of the enum GPIO_NUM_4 (which is probably what you want to use), so you’re good in this case. In C++ however this enum and ints are distinctive types and a cast must be made.

Either use a C-style cast

  gpio_pulldown_en((gpio_num_t) GPIO_SYNC0_IN);

or C++ style static_cast

  gpio_pulldown_en(static_cast<gpio_num_t>(GPIO_SYNC0_IN));

Or redefine:
#define GPIO_SYNC0_IN GPIO_NUM_4