esp-idf-hal icon indicating copy to clipboard operation
esp-idf-hal copied to clipboard

Bugfix: drop calibration handle on driver drop; more control on the r…

Open ivmarkov opened this issue 1 year ago • 1 comments
trafficstars

  • 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 avatar Aug 07 '24 10:08 ivmarkov

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

ivmarkov avatar Aug 10 '24 17:08 ivmarkov