Feature esp32s2 adccal
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request. To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
- [ ] I have updated existing examples or added new ones (if applicable).
- [ ] I have used
cargo xtask fmt-packagescommand to ensure that all changed code is formatted correctly. - [ ] My changes were added to the
CHANGELOG.mdin the proper section. - [ ] I have added necessary changes to user code to the Migration Guide.
- [x] My changes are in accordance to the esp-rs developer guidelines
Extra:
- [x] I have read the CONTRIBUTING.md guide and followed its instructions.
Pull Request Details 📖
I'm working on implementing ADC calibration for the ESP32-S2. I've made some progress, specifically reading calibration values from eFuse. I followed the code path in IDF’s examples/peripherals/adc/oneshot_read/main/oneshot_read_main.c as a guide.
Still running into a few issues:
-
init_code: The V1 eFuse lacks an init_code, so manual calibration is required, but I haven’t gotten it to work yet.
-
set_init_code didn’t do anything until @JurajSadel’s recent regi2c commits for the S2.
-
Right now, the manual calibration logic lives in
AdcConfig::enable_pin_with_cal(). But this runs before the ADC peripheral is initialized. This means it will hang onwhile !ADCI::is_done() {}and just not work properly in general. Probably better to add acalibrate()method to AdcCalSource and call it fromAdc::new()in a loop over the pins. -
Manual calibration always reads 0 for me, even though post-calibration reads do register a signal. I tested this by copy-pasting the
Adc::newinit code into adc_calibrate to get past the init ordering issue. The idf's self-calibration init code is around 0x680.
-
-
scheme_line_fitting from IDF: This calculates slope and y-intercept from eFuse or a self-cal step. The y-intercept is often positive, which makes it unusable with AdcCalBasic, since that applies correction before the scaling in AdcCalLine. Also, the example seems to use both init_code AND a full affine correction
-
Cleanup
Description
Implement adc calibration for the esp32s2.
#1203 #326
Testing
Some manual testing, not yet finished. I get the same efuse line calibration values as idf.