-
Notifications
You must be signed in to change notification settings - Fork 171
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
Bugfix: drop calibration handle on driver drop; more control on the r… #470
base: master
Are you sure you want to change the base?
Conversation
…aw-to-mv conversion
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.
Overall looks good though we have to dig into the 11db problem a bit
let attenuation = self.0; | ||
|
||
#[cfg(esp32)] | ||
let mv = match attenuation { |
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.
it turns out that ESP-IDF f'ed up itself. The ADC_ATTEN_DB_11 is a lie. In truths its more a ADC_ATTEN_DB12 :D
They removed it from the just released ESP-IDF v5.3. For more info you can look at this PR
So we also need to make this work for v5.3
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.
They did not remove it, they renamed it. I think we need to address this separately, in a "5.3" compatibility PR or something. But I don't think that's a big deal. Seems very doable to me.
#[cfg(any(esp32c3, esp32s2, esp32c2, esp32h2, esp32c5, esp32c6, esp32p4))] | ||
let mv = match attenuation { | ||
adc_atten_t_ADC_ATTEN_DB_0 => 750, | ||
adc_atten_t_ADC_ATTEN_DB_2_5 => 1050, |
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.
esp32c2 can only use 0 or 11 aka 12 bit
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.
Besides the small c2 thing, i am a bit skeptical about the correctness of the magic numbers we set on the attenuation matcher. E.g the return values we define as get_max_mv.
But since that is not something you touched i am fine with the PR.
The magic numbers are taken from the 4.4.X oneshot driver documentation here. Weird, but while the new oneshot driver does explicitly list the same raw-level-to-mV conversion formula, it does not list reference min and max mV for each attenuation. Maybe just an omission in the documentation? Also the listed reference numbers are for esp32 and esp32s2, and no info for new MCUs, but this is the best we have. But regardless - my point is - if you find "less magical" reference numbers for doing raw-to-mV conversion without calibration (and yes, I still think it is worth it to support this use case given that its conversion formula is explicitly documented in ESP IDF - both in legacy and new oneshot driver) - please paste the link here and I would gladly use your reference numbers instead! :D |
adc_cali_handle
on drop.calibration
bool from theConfig
does not have any effect. The driver always uses calibration, even ifcalibration
is set tofalse
(which it is by default).The fix also introduces a breaking change, in that the user is now capable of selecting the calibration scheme when configuring the driver (or no calibration), with:
Calibration::None
Calibration::CurveFitting
Calibration::LineFitting