mirror of
https://github.com/esphome/esphome.git
synced 2026-05-30 15:28:34 +08:00
[internal_temperature] Add support for LN882X (Lightning LN882H) (#15370)
Co-authored-by: Bl00d-B0b <Bl00d-B0b@users.noreply.github.com> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
committed by
GitHub
parent
dae8ea1b04
commit
ae9068a4c4
@@ -0,0 +1,24 @@
|
||||
#ifdef USE_LN882X
|
||||
|
||||
#include "internal_temperature.h"
|
||||
|
||||
extern "C" {
|
||||
uint16_t hal_adc_get_data(uint32_t adc_base, uint32_t ch);
|
||||
}
|
||||
|
||||
namespace esphome::internal_temperature {
|
||||
|
||||
void InternalTemperatureSensor::update() {
|
||||
static constexpr uint32_t ADC_BASE = 0x40000800U;
|
||||
static constexpr uint32_t ADC_CH0 = 1U;
|
||||
static constexpr uint16_t ADC_MASK = 0xFFF;
|
||||
static constexpr float ADC_TEMP_SCALE = 2.54f;
|
||||
static constexpr float ADC_TEMP_OFFSET = 278.15f;
|
||||
uint16_t raw = hal_adc_get_data(ADC_BASE, ADC_CH0);
|
||||
float temperature = (raw & ADC_MASK) / ADC_TEMP_SCALE - ADC_TEMP_OFFSET;
|
||||
this->publish_state(temperature);
|
||||
}
|
||||
|
||||
} // namespace esphome::internal_temperature
|
||||
|
||||
#endif // USE_LN882X
|
||||
@@ -8,6 +8,7 @@ from esphome.const import (
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
PLATFORM_BK72XX,
|
||||
PLATFORM_ESP32,
|
||||
PLATFORM_LN882X,
|
||||
PLATFORM_NRF52,
|
||||
PLATFORM_RP2040,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
@@ -30,7 +31,15 @@ CONFIG_SCHEMA = cv.All(
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
).extend(cv.polling_component_schema("60s")),
|
||||
cv.only_on([PLATFORM_ESP32, PLATFORM_RP2040, PLATFORM_BK72XX, PLATFORM_NRF52]),
|
||||
cv.only_on(
|
||||
[
|
||||
PLATFORM_ESP32,
|
||||
PLATFORM_RP2040,
|
||||
PLATFORM_BK72XX,
|
||||
PLATFORM_NRF52,
|
||||
PLATFORM_LN882X,
|
||||
]
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -53,6 +62,9 @@ FILTER_SOURCE_FILES = filter_source_files_from_platform(
|
||||
"internal_temperature_bk72xx.cpp": {
|
||||
PlatformFramework.BK72XX_ARDUINO,
|
||||
},
|
||||
"internal_temperature_ln882x.cpp": {
|
||||
PlatformFramework.LN882X_ARDUINO,
|
||||
},
|
||||
"internal_temperature_zephyr.cpp": {PlatformFramework.NRF52_ZEPHYR},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<<: !include common.yaml
|
||||
Reference in New Issue
Block a user