-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
analogRead() return value according to value set in analogReadResolution() #5776
analogRead() return value according to value set in analogReadResolution() #5776
Conversation
cores/esp32/esp32-hal-adc.c
Outdated
@@ -48,12 +48,26 @@ static uint8_t __analogVRefPin = 0; | |||
static uint8_t __analogAttenuation = 3;//11db | |||
#if CONFIG_IDF_TARGET_ESP32S2 | |||
static uint8_t __analogWidth = 4; // 13 bits | |||
static uint8_t __analogReturnedWidth = 13; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we use some chip defines for those, instead of filtering by target?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is where you can get the value of __analogReturnedWidth
: https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/esp32s2/include/soc/esp32s2/include/soc/soc_caps.h#L75
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__analogWidth
can be made equal to ADC_WIDTH_MAX - 1
from here: https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/esp32s2/include/hal/include/hal/adc_types.h#L97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should be able to use SOC_ADC_MAX_BITWIDTH
for __analogReturnedWidth
for all platforms. It would need to be tested if ADC_WIDTH_MAX
value is consistent across supported platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the changes according your sugestions :) tested with esp32 and esp32s2
nice :) |
Summary
Function analogReadResolution set how many bits will analogRead return.
Find out that this functionality was added back 2017 by @me-no-dev in #161.
Related issues:
#5163
Impact
No impact