From dd4d9120de275e83332a02d5924de62621a2a6f1 Mon Sep 17 00:00:00 2001 From: patrick Date: Wed, 31 May 2023 23:40:32 +1000 Subject: [PATCH 1/5] esp32/modesp32: Add temperature method for S2,C3 chips. Removed S3 as this is not available until idf>=4.4.2 Signed-off-by: Patrick Joy --- docs/library/esp32.rst | 10 ++++++++++ ports/esp32/modesp32.c | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/docs/library/esp32.rst b/docs/library/esp32.rst index d9241d545c46b..6fb3fd7491fb6 100644 --- a/docs/library/esp32.rst +++ b/docs/library/esp32.rst @@ -44,6 +44,16 @@ Functions Read the raw value of the internal temperature sensor, returning an integer. +.. Note:: + Only available on ESP32. + +.. function:: temperature() + + Read the value of the internal temperature sensor in celsius, returning a float. + +.. Note:: + Available on ESP32-S2, ESP32-S3 and ESP32-C3. + .. function:: hall_sensor() Read the raw value of the internal Hall sensor, returning an integer. diff --git a/ports/esp32/modesp32.c b/ports/esp32/modesp32.c index 7a436bf77cefb..7da0b41b650bb 100644 --- a/ports/esp32/modesp32.c +++ b/ports/esp32/modesp32.c @@ -178,6 +178,26 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp32_hall_sensor_obj, esp32_hall_sensor); #endif +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 + +#include "driver/temp_sensor.h" + +STATIC mp_obj_t esp32_temperature(void) { + + temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT(); + temp_sensor_get_config(&temp_sensor); + temp_sensor.dac_offset = TSENS_DAC_DEFAULT; // DEFAULT: range:-10℃ ~ 80℃, error < 1℃. + temp_sensor_set_config(temp_sensor); + temp_sensor_start(); + float tsens_out; + temp_sensor_read_celsius(&tsens_out); + temp_sensor_stop(); + + return mp_obj_new_float(tsens_out); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp32_temperature_obj, esp32_temperature); +#endif + STATIC mp_obj_t esp32_idf_heap_info(const mp_obj_t cap_in) { mp_int_t cap = mp_obj_get_int(cap_in); multi_heap_info_t info; @@ -212,6 +232,9 @@ STATIC const mp_rom_map_elem_t esp32_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_raw_temperature), MP_ROM_PTR(&esp32_raw_temperature_obj) }, { MP_ROM_QSTR(MP_QSTR_hall_sensor), MP_ROM_PTR(&esp32_hall_sensor_obj) }, #endif + #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 + { MP_ROM_QSTR(MP_QSTR_temperature), MP_ROM_PTR(&esp32_temperature_obj) }, + #endif { MP_ROM_QSTR(MP_QSTR_idf_heap_info), MP_ROM_PTR(&esp32_idf_heap_info_obj) }, { MP_ROM_QSTR(MP_QSTR_NVS), MP_ROM_PTR(&esp32_nvs_type) }, From 2029eac7a0cdcb313f15ba4522d12ed720e920e0 Mon Sep 17 00:00:00 2001 From: Patrick Joy Date: Thu, 1 Jun 2023 16:09:11 +1000 Subject: [PATCH 2/5] esp32/modesp32: Retrigger checks. Signed-off-by: Patrick Joy From 336f5d6e36e8e949d6014259b784f7e1287fedcd Mon Sep 17 00:00:00 2001 From: Patrick Joy Date: Fri, 2 Jun 2023 10:43:50 +1000 Subject: [PATCH 3/5] esp32/modesp32: Add temperature method for S2,C3 chips. Removed S3 as this is not available until idf>=4.4.2 Signed-off-by: Patrick Joy From f63b5927f38935305cea0ec8c4fb003241c4a486 Mon Sep 17 00:00:00 2001 From: Patrick Joy Date: Fri, 2 Jun 2023 10:55:53 +1000 Subject: [PATCH 4/5] esp32/modesp32: Add temperature method for S2,C3 chips. Documentation changes. Signed-off-by: Patrick Joy --- docs/library/esp32.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/library/esp32.rst b/docs/library/esp32.rst index 6fb3fd7491fb6..7d6e243c5f96e 100644 --- a/docs/library/esp32.rst +++ b/docs/library/esp32.rst @@ -52,7 +52,7 @@ Functions Read the value of the internal temperature sensor in celsius, returning a float. .. Note:: - Available on ESP32-S2, ESP32-S3 and ESP32-C3. + Available on ESP32-S2 and ESP32-C3. .. function:: hall_sensor() From c1adfe5d493403129c80c2b32ce724d904b9606b Mon Sep 17 00:00:00 2001 From: Patrick Joy Date: Fri, 30 Jun 2023 20:06:20 +1000 Subject: [PATCH 5/5] esp32/modesp32: Updated to idf v5.0.2. Signed-off-by: Patrick Joy --- docs/library/esp32.rst | 9 ++++++--- ports/esp32/modesp32.c | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/library/esp32.rst b/docs/library/esp32.rst index 7d6e243c5f96e..a1a87c07bd1e0 100644 --- a/docs/library/esp32.rst +++ b/docs/library/esp32.rst @@ -44,15 +44,18 @@ Functions Read the raw value of the internal temperature sensor, returning an integer. -.. Note:: - Only available on ESP32. + Only available on ESP32. .. function:: temperature() Read the value of the internal temperature sensor in celsius, returning a float. + Available on ESP32-S2, S3 and C3. + .. Note:: - Available on ESP32-S2 and ESP32-C3. + The temperature sensor is designed primarily to measure the temperature changes inside + the chip. The temperature value depends on factors like microcontroller clock frequency + or I/O load. Generally, the chip’s internal temperature might be higher than the ambient temperature. .. function:: hall_sensor() diff --git a/ports/esp32/modesp32.c b/ports/esp32/modesp32.c index 21507e214e0bb..56b6d2ddb020f 100644 --- a/ports/esp32/modesp32.c +++ b/ports/esp32/modesp32.c @@ -170,20 +170,20 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp32_raw_temperature_obj, esp32_raw_temperatur #endif -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 -#include "driver/temp_sensor.h" +#include "driver/temperature_sensor.h" STATIC mp_obj_t esp32_temperature(void) { - temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT(); - temp_sensor_get_config(&temp_sensor); - temp_sensor.dac_offset = TSENS_DAC_DEFAULT; // DEFAULT: range:-10℃ ~ 80℃, error < 1℃. - temp_sensor_set_config(temp_sensor); - temp_sensor_start(); + temperature_sensor_handle_t temp_sensor = NULL; + temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(0, 50); + temperature_sensor_install(&temp_sensor_config, &temp_sensor); + temperature_sensor_enable(temp_sensor); float tsens_out; - temp_sensor_read_celsius(&tsens_out); - temp_sensor_stop(); + temperature_sensor_get_celsius(temp_sensor, &tsens_out); + temperature_sensor_disable(temp_sensor); + temperature_sensor_uninstall(temp_sensor); return mp_obj_new_float(tsens_out); } @@ -223,7 +223,7 @@ STATIC const mp_rom_map_elem_t esp32_module_globals_table[] = { #if CONFIG_IDF_TARGET_ESP32 { MP_ROM_QSTR(MP_QSTR_raw_temperature), MP_ROM_PTR(&esp32_raw_temperature_obj) }, #endif - #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 + #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 { MP_ROM_QSTR(MP_QSTR_temperature), MP_ROM_PTR(&esp32_temperature_obj) }, #endif { MP_ROM_QSTR(MP_QSTR_idf_heap_info), MP_ROM_PTR(&esp32_idf_heap_info_obj) }, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy