[go: nahoru, domu]

Skip to content

Commit

Permalink
Get thermal info from S3 if no LM75A (ExpressLRS#2463)
Browse files Browse the repository at this point in the history
* Get thermal info from S3 if no LM75A

* Fixes as per review plus some bonus cleanup
  • Loading branch information
pkendall64 committed Feb 2, 2024
1 parent 701818d commit 65fe200
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/include/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

#ifndef HAS_THERMAL
#define OPT_HAS_THERMAL false
#define OPT_HAS_THERMAL_LM75A false
#elif !defined(OPT_HAS_THERMAL)
#define OPT_HAS_THERMAL true
#endif
Expand Down
17 changes: 9 additions & 8 deletions src/lib/THERMAL/devThermal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,27 @@ uint32_t get_rpm();
static void initialize()
{
#if defined(HAS_THERMAL)
#if defined(PLATFORM_ESP32_S3)
thermal.init();
#else
if (OPT_HAS_THERMAL_LM75A && GPIO_PIN_SCL != UNDEF_PIN && GPIO_PIN_SDA != UNDEF_PIN)
{
thermal.init();
}
#endif
#endif
if (GPIO_PIN_FAN_EN != UNDEF_PIN)
{
pinMode(GPIO_PIN_FAN_EN, OUTPUT);
}
}

#if defined(HAS_THERMAL)
static void timeoutThermal()
{
#if defined(HAS_THERMAL)
#if !defined(PLATFORM_ESP32_S3)
if(OPT_HAS_THERMAL_LM75A)
#endif
{
thermal.handle();
#ifdef HAS_SMART_FAN
Expand All @@ -90,8 +96,8 @@ static void timeoutThermal()
}
#endif
}
}
#endif
}

#if defined(PLATFORM_ESP32)
static void setFanSpeed()
Expand Down Expand Up @@ -258,12 +264,7 @@ static int event()

static int timeout()
{
#if defined(HAS_THERMAL)
if (OPT_HAS_THERMAL_LM75A && GPIO_PIN_SCL != UNDEF_PIN && GPIO_PIN_SDA != UNDEF_PIN)
{
timeoutThermal();
}
#endif
timeoutThermal();
timeoutFan();
timeoutTacho();
return THERMAL_DURATION;
Expand Down
60 changes: 40 additions & 20 deletions src/lib/THERMAL/thermal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
#include "lm75a.h"
LM75A lm75a;
#endif
#if defined(PLATFORM_ESP32_S3)
#include "driver/temp_sensor.h"
#endif

uint8_t thermal_threshold_data[] = {
static const uint8_t thermal_threshold_data[] = {
THERMAL_FAN_DEFAULT_HIGH_THRESHOLD,
THERMAL_FAN_DEFAULT_LOW_THRESHOLD,
THERMAL_FAN_ALWAYS_ON_HIGH_THRESHOLD,
Expand All @@ -16,25 +19,34 @@ uint8_t thermal_threshold_data[] = {
THERMAL_FAN_OFF_LOW_THRESHOLD
};

int thermal_status = THERMAL_STATUS_FAIL;
static Thermal_Status_t thermal_status = THERMAL_STATUS_FAIL;

void Thermal::init()
{
int status = -1;
#ifdef HAS_THERMAL_LM75A
status = lm75a.init();
#endif
if(status == -1)
if (OPT_HAS_THERMAL_LM75A)
{
ERRLN("Thermal failed!");
status = lm75a.init();
}
else
#if defined(PLATFORM_ESP32_S3)
if (status == -1)
{
DBGLN("Thermal OK!");
temp_value = 0;
thermal_status = THERMAL_STATUS_NORMAL;
update_threshold(0);
temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT();
temp_sensor.dac_offset = TSENS_DAC_L2; //TSENS_DAC_L2 is default L4(-40℃ ~ 20℃), L2(-10℃ ~ 80℃) L1(20℃ ~ 100℃) L0(50℃ ~ 125℃)
temp_sensor_set_config(temp_sensor);
temp_sensor_start();
}
#else
if (status == -1)
{
ERRLN("Thermal failed!");
return;
}
#endif
DBGLN("Thermal OK!");
temp_value = 0;
thermal_status = THERMAL_STATUS_NORMAL;
update_threshold(0);
}

void Thermal::handle()
Expand All @@ -49,8 +61,15 @@ uint8_t Thermal::read_temp()
ERRLN("thermal not ready!");
return 0;
}
#ifdef HAS_THERMAL_LM75A
return lm75a.read_lm75a();
if (OPT_HAS_THERMAL_LM75A)
{
return lm75a.read_lm75a();
}

#if defined(PLATFORM_ESP32_S3)
float result = 0;
temp_sensor_read_celsius(&result);
return static_cast<int>(result);
#else
return 0;
#endif
Expand All @@ -69,17 +88,18 @@ void Thermal::update_threshold(int index)
ERRLN("thermal not ready!");
return;
}
int size = sizeof(thermal_threshold_data)/sizeof(thermal_threshold_data[0]);
constexpr int size = sizeof(thermal_threshold_data)/sizeof(thermal_threshold_data[0]);
if(index > size/2)
{
ERRLN("thermal index out of range!");
return;
}
uint8_t high = thermal_threshold_data[2*index];
uint8_t low = thermal_threshold_data[2*index+1];
#ifdef HAS_THERMAL_LM75A
lm75a.update_lm75a_threshold(high, low);
#endif
if (OPT_HAS_THERMAL_LM75A)
{
const uint8_t high = thermal_threshold_data[2*index];
const uint8_t low = thermal_threshold_data[2*index+1];
lm75a.update_lm75a_threshold(high, low);
}
}

#endif

0 comments on commit 65fe200

Please sign in to comment.