invalid conversion from 'int' to 'adc_bits_width_t' [-fpermissive]

mmmunir966
Posts: 12
Joined: Tue Feb 08, 2022 2:02 pm

invalid conversion from 'int' to 'adc_bits_width_t' [-fpermissive]

Postby mmmunir966 » Fri Sep 02, 2022 7:36 am

Hi,
I am getting the error

Code: Select all

invalid conversion from 'int' to 'adc_bits_width_t' [-fpermissive] [98,47]
on line 98 in adc.h in code line

Code: Select all

#define ADC_WIDTH_BIT_DEFAULT   (ADC_WIDTH_MAX-1)
I am using esp-idf version 4.4 in VS code.

Please guide me how to fix this?

noweare
Posts: 79
Joined: Tue Jul 02, 2019 11:35 am

Re: invalid conversion from 'int' to 'adc_bits_width_t' [-fpermissive]

Postby noweare » Fri Sep 02, 2022 1:58 pm

How are you setting the width ?
There are enumerated values of that type you can use.

enum adc_bitwidth_t
Values:

enumerator ADC_BITWIDTH_DEFAULT
Default ADC output bits, max supported width will be selected.

enumerator ADC_BITWIDTH_9
ADC output width is 9Bit.

enumerator ADC_BITWIDTH_10
ADC output width is 10Bit.

enumerator ADC_BITWIDTH_11
ADC output width is 11Bit.

enumerator ADC_BITWIDTH_12
ADC output width is 12Bit.

enumerator ADC_BITWIDTH_13
ADC output width is 13Bit.

rboeije
Posts: 1
Joined: Mon Jul 17, 2023 2:27 pm

Re: invalid conversion from 'int' to 'adc_bits_width_t' [-fpermissive]

Postby rboeije » Mon Jul 17, 2023 3:02 pm

While it looks like an old post, there is no solution listed. That is, the proposed solution is the source of the problem.
I got the error after the Arduino 2.2.2 updated the libraries to 2.0.10. Maybe it was resolved in the old version, but that is deleted as part of the upgrade.
As the original poster states, in adc.h (C:\Users\XXX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.10\tools\sdk\esp32\include\driver\include\driver)
line 98, the line

#define ADC_WIDTH_BIT_DEFAULT (ADC_WIDTH_MAX -1)

causes a compiler error fpermissive on subtracting 1 from a enum type:

C:\Users\XXX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.10/tools/sdk/esp32/include/driver/include/driver/adc.h:98:47: error: invalid conversion from 'int' to 'adc_bits_width_t' [-fpermissive]
#define ADC_WIDTH_BIT_DEFAULT (ADC_WIDTH_MAX -1)
~~~~~~~~~~~~~~~^~~
C:\Users\XXX\OneDrive\Documenten\Arduino\YYYYY_ESP32\YYYYY_ESP32.ino:1204:55: note: in expansion of macro 'ADC_WIDTH_BIT_DEFAULT'
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_DEFAULT, 0, &adc1_chars);
^~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\XXX\OneDrive\Documenten\Arduino\YYYYY_ESP32\YYYYY_ESP32.ino:62:
C:\Users\XXX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.10/tools/sdk/esp32/include/esp_adc_cal/include/esp_adc_cal.h:90:63: note: initializing argument 3 of 'esp_adc_cal_value_t esp_adc_cal_characterize(adc_unit_t, adc_atten_t, adc_bits_width_t, uint32_t, esp_adc_cal_characteristics_t*)'
adc_bits_width_t bit_width,
~~~~~~~~~~~~~~~~~^~~~~~~~~

Who is online

Users browsing this forum: No registered users and 142 guests