Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ivmarkov
Copy link
Collaborator

@ivmarkov ivmarkov commented Aug 7, 2024

  • Turns out, the "new" oneshot ADC driver does not deallocate the adc_cali_handle on drop.
  • I also noticed that the calibration bool from the Config does not have any effect. The driver always uses calibration, even if calibration is set to false (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

@ivmarkov ivmarkov marked this pull request as ready for review August 9, 2024 09:33
Copy link
Collaborator

@Vollbrecht Vollbrecht left a 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 {
Copy link
Collaborator

@Vollbrecht Vollbrecht Aug 9, 2024

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

Copy link
Collaborator Author

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,
Copy link
Collaborator

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

Copy link
Collaborator

@Vollbrecht Vollbrecht left a 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.

@ivmarkov
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants