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

Is it possible to add the internal temperature sensor support?

Open lu-zero opened this issue 1 year ago • 3 comments

not esp32 has support for it https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/peripherals/temp_sensor.html

Twin issue for the esp-idf-hal crate https://github.com/esp-rs/esp-idf-hal/issues/333

lu-zero avatar Sep 08 '24 11:09 lu-zero

It's for sure possible, a PR would be most welcome :).

MabezDev avatar Sep 17 '24 12:09 MabezDev

I'd need lots of guidance first, I do not know enough of the esp-idf and esp-hal to commit to it yet ^^;

lu-zero avatar Sep 25 '24 07:09 lu-zero

Just some notes/thoughts. For anyone wanting to implement. Might make a good "beginner" task, since turning on is just a few bit flips, and you just read the lowest byte and follow a set algorithm.

  • T(°C) = 0.4386 ∗ VALUE–27.88 ∗ offset–20.52

Basic low-level bit-flipping and definitions for the TSENSor are here:

  • esp-pacs/esp32c3/src/apb_saradc/tsens_ctrl.rs
  • esp-pacs/esp32c3/src/apb_saradc/tsens_ctrl2.rs

Hardware ports/memory are already defined in:

  • esp-pacs/esp32c3/svd/esp32c3.base.svd

Would need to add the "tsens" peripheral here, I think

  • esp-hal/esp-hal/src/system.rs and possibly here? Not sure:
  • esp-hal/esp-hal/src/analog/adc/riscv.rs

Would it be better to add the higher level implementation here, since it's connected to the ADC peripheral? But then it might get "hidden" and hard to find.

  • esp-hal/esp-hal/src/analog/adc/esp32.rs

Or would it be better to implement this in

  • esp-hal/esp-hal/src/analog/tsens/esp32.rs

Hackswell avatar Oct 06 '24 00:10 Hackswell