Skip to content

Commit

Permalink
esp32s2 temp sensor (#5044)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbernstone committed Apr 15, 2021
1 parent ec7aeb4 commit 9f1330c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cores/esp32/esp32-hal-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
#include "esp32/rom/rtc.h"
#elif CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/rom/rtc.h"
#include "driver/temp_sensor.h"
#elif CONFIG_IDF_TARGET_ESP32C3
#include "esp32c3/rom/rtc.h"
#include "driver/temp_sensor.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
Expand All @@ -51,12 +53,25 @@

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

float temperatureRead()
{
return (temprature_sens_read() - 32) / 1.8;
}
#else
float temperatureRead()
{
float result = NAN;
temp_sensor_config_t tsens = TSENS_CONFIG_DEFAULT();
temp_sensor_set_config(tsens);
temp_sensor_start();
temp_sensor_read_celsius(&result);
temp_sensor_stop();
return result;
}
#endif

void __yield()
{
Expand Down

0 comments on commit 9f1330c

Please sign in to comment.