Skip to content

Commit 9f1330c

Browse files
authored
esp32s2 temp sensor (espressif#5044)
1 parent ec7aeb4 commit 9f1330c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cores/esp32/esp32-hal-misc.c

+15
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
#include "esp32/rom/rtc.h"
4141
#elif CONFIG_IDF_TARGET_ESP32S2
4242
#include "esp32s2/rom/rtc.h"
43+
#include "driver/temp_sensor.h"
4344
#elif CONFIG_IDF_TARGET_ESP32C3
4445
#include "esp32c3/rom/rtc.h"
46+
#include "driver/temp_sensor.h"
4547
#else
4648
#error Target CONFIG_IDF_TARGET is not supported
4749
#endif
@@ -51,12 +53,25 @@
5153

5254
//Undocumented!!! Get chip temperature in Farenheit
5355
//Source: https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_int_temp_sensor/ESP32_int_temp_sensor.ino
56+
#ifdef CONFIG_IDF_TARGET_ESP32
5457
uint8_t temprature_sens_read();
5558

5659
float temperatureRead()
5760
{
5861
return (temprature_sens_read() - 32) / 1.8;
5962
}
63+
#else
64+
float temperatureRead()
65+
{
66+
float result = NAN;
67+
temp_sensor_config_t tsens = TSENS_CONFIG_DEFAULT();
68+
temp_sensor_set_config(tsens);
69+
temp_sensor_start();
70+
temp_sensor_read_celsius(&result);
71+
temp_sensor_stop();
72+
return result;
73+
}
74+
#endif
6075

6176
void __yield()
6277
{

0 commit comments

Comments
 (0)