mirror of
https://github.com/esphome/esphome.git
synced 2026-11-17 18:46:08 +00:00
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f8ee431fd | ||
|
|
373198978e | ||
|
|
9851b53fe2 | ||
|
|
0a39d4b42d | ||
|
|
2a0f332691 | ||
|
|
fe78f79469 | ||
|
|
480d2380ab | ||
|
|
51aae78e5d | ||
|
|
78a83b9bc5 | ||
|
|
eaa176767e | ||
|
|
b27b061438 | ||
|
|
7ddfbb6398 |
No files matched your search
@@ -515,12 +515,18 @@ void CC1101Component::dump_config() {
|
||||
}
|
||||
|
||||
void CC1101Component::begin_tx() {
|
||||
if (this->state_.PKT_FORMAT == static_cast<uint8_t>(PacketFormat::PACKET_FORMAT_FIFO)) {
|
||||
ESP_LOGW(TAG, "begin_tx is for async serial mode; use send_packet in packet mode");
|
||||
return;
|
||||
}
|
||||
this->wake_up();
|
||||
// Read the mode before the PKTCTRL0 write below overwrites it in state_
|
||||
const bool packet_mode = this->state_.PKT_FORMAT == static_cast<uint8_t>(PacketFormat::PACKET_FORMAT_FIFO);
|
||||
// Ensure Packet Format is 3 (Async Serial)
|
||||
this->write_(Register::PKTCTRL0, 0x32);
|
||||
ESP_LOGV(TAG, "Beginning TX sequence");
|
||||
if (this->gdo0_pin_ != nullptr) {
|
||||
// setup() only attaches the interrupt in packet mode. In async serial mode the pin may be
|
||||
// shared with remote_receiver, and detaching here would remove the receiver's interrupt.
|
||||
if (packet_mode) {
|
||||
this->gdo0_pin_->detach_interrupt();
|
||||
}
|
||||
this->gdo0_pin_->pin_mode(gpio::FLAG_OUTPUT);
|
||||
}
|
||||
// Transition through IDLE to bypass CCA (Clear Channel Assessment) which can
|
||||
|
||||
@@ -63,25 +63,13 @@ void CST816Touchscreen::update_touches() {
|
||||
uint8_t data[13];
|
||||
if (!this->status_comm_result(this->read_bytes(REG_STATUS, data, sizeof data)))
|
||||
return;
|
||||
|
||||
// The low nibble is the touch count. CST816/CST820 are single-touch;
|
||||
// CST826/CST836 can report two points, but this driver only reads the first
|
||||
// point. Some CST8xx controllers report an all-0xFF frame when idle or after
|
||||
// disabling auto-sleep: the count lands above two and the coordinates are
|
||||
// the 0xFFF sentinel, so both guards below reject it.
|
||||
uint8_t num_of_touches = low_nibble(data[REG_TOUCH_NUM]);
|
||||
uint8_t num_of_touches = data[REG_TOUCH_NUM] & 3;
|
||||
if (num_of_touches == 0) {
|
||||
return;
|
||||
}
|
||||
if (num_of_touches > 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t x = encode_uint16(low_nibble(data[REG_XPOS_HIGH]), data[REG_XPOS_LOW]);
|
||||
uint16_t y = encode_uint16(low_nibble(data[REG_YPOS_HIGH]), data[REG_YPOS_LOW]);
|
||||
if (x == 0x0FFF || y == 0x0FFF) {
|
||||
return;
|
||||
}
|
||||
ESP_LOGV(TAG, "Read touch %d/%d", x, y);
|
||||
this->add_raw_touch_position_(0, x, y);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,5 @@ FILTER_SOURCE_FILES = filter_source_files_from_platform(
|
||||
PlatformFramework.LN882X_ARDUINO,
|
||||
},
|
||||
"debug_zephyr.cpp": {PlatformFramework.NRF52_ZEPHYR},
|
||||
"debug_nrf52.cpp": {PlatformFramework.NRF52_ZEPHYR},
|
||||
"debug_nrf54l.cpp": {PlatformFramework.NRF52_ZEPHYR},
|
||||
}
|
||||
)
|
||||
@@ -1,380 +0,0 @@
|
||||
#include "debug_component.h"
|
||||
#ifdef USE_ZEPHYR
|
||||
#include <nrfx.h>
|
||||
#endif
|
||||
#if defined(USE_ZEPHYR) && !defined(NRF54L_SERIES)
|
||||
#include <cinttypes>
|
||||
#include <cstdint>
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include <hal/nrf_power.h>
|
||||
|
||||
#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0]
|
||||
|
||||
namespace esphome::debug {
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "debug");
|
||||
|
||||
// Check if an nRF peripheral's ENABLE register indicates it is enabled.
|
||||
// periph: peripheral register prefix (e.g. USBD, UARTE, SPI)
|
||||
// reg: register block pointer (e.g. NRF_USBD, NRF_UARTE0)
|
||||
#define NRF_PERIPH_ENABLED(periph, reg) \
|
||||
YESNO(((reg)->ENABLE & periph##_ENABLE_ENABLE_Msk) == (periph##_ENABLE_ENABLE_Enabled << periph##_ENABLE_ENABLE_Pos))
|
||||
|
||||
constexpr std::uintptr_t MBR_PARAM_PAGE_ADDR = 0xFFC;
|
||||
constexpr std::uintptr_t MBR_BOOTLOADER_ADDR = 0xFF8;
|
||||
|
||||
static inline uint32_t read_mem_u32(uintptr_t addr) {
|
||||
// NOLINTNEXTLINE(performance-no-int-to-ptr,clang-analyzer-core.FixedAddressDereference)
|
||||
return *reinterpret_cast<volatile uint32_t *>(addr);
|
||||
}
|
||||
|
||||
static inline uint8_t read_mem_u8(uintptr_t addr) {
|
||||
// NOLINTNEXTLINE(performance-no-int-to-ptr,clang-analyzer-core.FixedAddressDereference)
|
||||
return *reinterpret_cast<volatile uint8_t *>(addr);
|
||||
}
|
||||
|
||||
// defines from https://github.com/adafruit/Adafruit_nRF52_Bootloader which prints those information
|
||||
constexpr uint32_t SD_MAGIC_NUMBER = 0x51B1E5DB;
|
||||
constexpr uintptr_t MBR_SIZE = 0x1000;
|
||||
constexpr uintptr_t SOFTDEVICE_INFO_STRUCT_OFFSET = 0x2000;
|
||||
constexpr uintptr_t SD_ID_OFFSET = SOFTDEVICE_INFO_STRUCT_OFFSET + 0x10;
|
||||
constexpr uintptr_t SD_VERSION_OFFSET = SOFTDEVICE_INFO_STRUCT_OFFSET + 0x14;
|
||||
|
||||
static inline bool is_sd_present() {
|
||||
return read_mem_u32(SOFTDEVICE_INFO_STRUCT_OFFSET + MBR_SIZE + 4) == SD_MAGIC_NUMBER;
|
||||
}
|
||||
static inline uint32_t sd_id_get() {
|
||||
if (read_mem_u8(MBR_SIZE + SOFTDEVICE_INFO_STRUCT_OFFSET) > (SD_ID_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) {
|
||||
return read_mem_u32(MBR_SIZE + SD_ID_OFFSET);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static inline uint32_t sd_version_get() {
|
||||
if (read_mem_u8(MBR_SIZE + SOFTDEVICE_INFO_STRUCT_OFFSET) > (SD_VERSION_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) {
|
||||
return read_mem_u32(MBR_SIZE + SD_VERSION_OFFSET);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef ESPHOME_LOG_HAS_VERBOSE
|
||||
// NOLINTBEGIN(clang-analyzer-core.FixedAddressDereference) -- nRF peripheral registers are MMIO at fixed addresses
|
||||
static void log_peripherals_info() {
|
||||
// most peripherals are enabled only when in use so ESP_LOGV is enough
|
||||
ESP_LOGV(TAG, "Peripherals status:");
|
||||
ESP_LOGV(TAG, " USBD: %-3s| UARTE0: %-3s| UARTE1: %-3s| UART0: %-3s", //
|
||||
NRF_PERIPH_ENABLED(USBD, NRF_USBD), NRF_PERIPH_ENABLED(UARTE, NRF_UARTE0),
|
||||
NRF_PERIPH_ENABLED(UARTE, NRF_UARTE1), NRF_PERIPH_ENABLED(UART, NRF_UART0));
|
||||
ESP_LOGV(TAG, " TWIS0: %-3s| TWIS1: %-3s| TWIM0: %-3s| TWIM1: %-3s", //
|
||||
NRF_PERIPH_ENABLED(TWIS, NRF_TWIS0), NRF_PERIPH_ENABLED(TWIS, NRF_TWIS1),
|
||||
NRF_PERIPH_ENABLED(TWIM, NRF_TWIM0), NRF_PERIPH_ENABLED(TWIM, NRF_TWIM1));
|
||||
ESP_LOGV(TAG, " TWI0: %-3s| TWI1: %-3s| COMP: %-3s| CCM: %-3s", //
|
||||
NRF_PERIPH_ENABLED(TWI, NRF_TWI0), NRF_PERIPH_ENABLED(TWI, NRF_TWI1), NRF_PERIPH_ENABLED(COMP, NRF_COMP),
|
||||
NRF_PERIPH_ENABLED(CCM, NRF_CCM));
|
||||
ESP_LOGV(TAG, " PDM: %-3s| SPIS0: %-3s| SPIS1: %-3s| SPIS2: %-3s", //
|
||||
NRF_PERIPH_ENABLED(PDM, NRF_PDM), NRF_PERIPH_ENABLED(SPIS, NRF_SPIS0), NRF_PERIPH_ENABLED(SPIS, NRF_SPIS1),
|
||||
NRF_PERIPH_ENABLED(SPIS, NRF_SPIS2));
|
||||
ESP_LOGV(TAG, " SPIM0: %-3s| SPIM1: %-3s| SPIM2: %-3s| SPIM3: %-3s", //
|
||||
NRF_PERIPH_ENABLED(SPIM, NRF_SPIM0), NRF_PERIPH_ENABLED(SPIM, NRF_SPIM1),
|
||||
NRF_PERIPH_ENABLED(SPIM, NRF_SPIM2), NRF_PERIPH_ENABLED(SPIM, NRF_SPIM3));
|
||||
ESP_LOGV(TAG, " SPI0: %-3s| SPI1: %-3s| SPI2: %-3s| SAADC: %-3s", //
|
||||
NRF_PERIPH_ENABLED(SPI, NRF_SPI0), NRF_PERIPH_ENABLED(SPI, NRF_SPI1), NRF_PERIPH_ENABLED(SPI, NRF_SPI2),
|
||||
NRF_PERIPH_ENABLED(SAADC, NRF_SAADC));
|
||||
ESP_LOGV(TAG, " QSPI: %-3s| QDEC: %-3s| LPCOMP: %-3s| I2S: %-3s", //
|
||||
NRF_PERIPH_ENABLED(QSPI, NRF_QSPI), NRF_PERIPH_ENABLED(QDEC, NRF_QDEC),
|
||||
NRF_PERIPH_ENABLED(LPCOMP, NRF_LPCOMP), NRF_PERIPH_ENABLED(I2S, NRF_I2S));
|
||||
ESP_LOGV(TAG, " PWM0: %-3s| PWM1: %-3s| PWM2: %-3s| PWM3: %-3s", //
|
||||
NRF_PERIPH_ENABLED(PWM, NRF_PWM0), NRF_PERIPH_ENABLED(PWM, NRF_PWM1), NRF_PERIPH_ENABLED(PWM, NRF_PWM2),
|
||||
NRF_PERIPH_ENABLED(PWM, NRF_PWM3));
|
||||
ESP_LOGV(TAG, " AAR: %-3s| QSPI deep power-down:%-3s| CRYPTOCELL: %-3s", NRF_PERIPH_ENABLED(AAR, NRF_AAR),
|
||||
YESNO((NRF_QSPI->IFCONFIG0 & QSPI_IFCONFIG0_DPMENABLE_Msk) ==
|
||||
(QSPI_IFCONFIG0_DPMENABLE_Enable << QSPI_IFCONFIG0_DPMENABLE_Pos)),
|
||||
YESNO((NRF_CRYPTOCELL->ENABLE & CRYPTOCELL_ENABLE_ENABLE_Msk) ==
|
||||
(CRYPTOCELL_ENABLE_ENABLE_Enabled << CRYPTOCELL_ENABLE_ENABLE_Pos)));
|
||||
}
|
||||
// NOLINTEND(clang-analyzer-core.FixedAddressDereference)
|
||||
#endif
|
||||
|
||||
static const char *regout0_to_str(uint32_t value) {
|
||||
switch (value) {
|
||||
case (UICR_REGOUT0_VOUT_DEFAULT):
|
||||
return "1.8V (default)";
|
||||
case (UICR_REGOUT0_VOUT_1V8):
|
||||
return "1.8V";
|
||||
case (UICR_REGOUT0_VOUT_2V1):
|
||||
return "2.1V";
|
||||
case (UICR_REGOUT0_VOUT_2V4):
|
||||
return "2.4V";
|
||||
case (UICR_REGOUT0_VOUT_2V7):
|
||||
return "2.7V";
|
||||
case (UICR_REGOUT0_VOUT_3V0):
|
||||
return "3.0V";
|
||||
case (UICR_REGOUT0_VOUT_3V3):
|
||||
return "3.3V";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "???V";
|
||||
}
|
||||
|
||||
size_t DebugComponent::get_device_info_(std::span<char, DEVICE_INFO_BUFFER_SIZE> buffer, size_t pos) {
|
||||
constexpr size_t size = DEVICE_INFO_BUFFER_SIZE;
|
||||
char *buf = buffer.data();
|
||||
|
||||
// Main supply status
|
||||
// NOLINTNEXTLINE(clang-analyzer-core.FixedAddressDereference) -- NRF_POWER is MMIO at a fixed address
|
||||
auto regstatus = nrf_power_mainregstatus_get(NRF_POWER);
|
||||
const char *supply_status = (regstatus == NRF_POWER_MAINREGSTATUS_NORMAL) ? "Normal voltage." : "High voltage.";
|
||||
ESP_LOGD(TAG, "Main supply status: %s", supply_status);
|
||||
pos = buf_append_str(buf, size, pos, "|Main supply status: ");
|
||||
pos = buf_append_str(buf, size, pos, supply_status);
|
||||
|
||||
// Regulator stage 0
|
||||
if (nrf_power_mainregstatus_get(NRF_POWER) == NRF_POWER_MAINREGSTATUS_HIGH) {
|
||||
const char *reg0_type = nrf_power_dcdcen_vddh_get(NRF_POWER) ? "DC/DC" : "LDO";
|
||||
const char *reg0_voltage = regout0_to_str((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) >> UICR_REGOUT0_VOUT_Pos);
|
||||
ESP_LOGD(TAG, "Regulator stage 0: %s, %s", reg0_type, reg0_voltage);
|
||||
pos = buf_append_str(buf, size, pos, "|Regulator stage 0: ");
|
||||
pos = buf_append_str(buf, size, pos, reg0_type);
|
||||
pos = buf_append_str(buf, size, pos, ", ");
|
||||
pos = buf_append_str(buf, size, pos, reg0_voltage);
|
||||
#ifdef USE_NRF52_REG0_VOUT
|
||||
if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) >> UICR_REGOUT0_VOUT_Pos != USE_NRF52_REG0_VOUT) {
|
||||
ESP_LOGE(TAG, "Regulator stage 0: expected %s", regout0_to_str(USE_NRF52_REG0_VOUT));
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Regulator stage 0: disabled");
|
||||
pos = buf_append_str(buf, size, pos, "|Regulator stage 0: disabled");
|
||||
}
|
||||
|
||||
// Regulator stage 1
|
||||
const char *reg1_type = nrf_power_dcdcen_get(NRF_POWER) ? "DC/DC" : "LDO";
|
||||
ESP_LOGD(TAG, "Regulator stage 1: %s", reg1_type);
|
||||
pos = buf_append_str(buf, size, pos, "|Regulator stage 1: ");
|
||||
pos = buf_append_str(buf, size, pos, reg1_type);
|
||||
|
||||
// USB power state
|
||||
const char *usb_state;
|
||||
if (nrf_power_usbregstatus_vbusdet_get(NRF_POWER)) {
|
||||
usb_state = nrf_power_usbregstatus_outrdy_get(NRF_POWER) ? "ready" : "connected (regulator is not ready)";
|
||||
} else {
|
||||
usb_state = "disconnected";
|
||||
}
|
||||
ESP_LOGD(TAG, "USB power state: %s", usb_state);
|
||||
pos = buf_append_str(buf, size, pos, "|USB power state: ");
|
||||
pos = buf_append_str(buf, size, pos, usb_state);
|
||||
|
||||
// Power-fail comparator
|
||||
bool enabled;
|
||||
nrf_power_pof_thr_t pof_thr = nrf_power_pofcon_get(NRF_POWER, &enabled);
|
||||
if (enabled) {
|
||||
const char *pof_voltage;
|
||||
switch (pof_thr) {
|
||||
case POWER_POFCON_THRESHOLD_V17:
|
||||
pof_voltage = "1.7V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V18:
|
||||
pof_voltage = "1.8V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V19:
|
||||
pof_voltage = "1.9V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V20:
|
||||
pof_voltage = "2.0V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V21:
|
||||
pof_voltage = "2.1V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V22:
|
||||
pof_voltage = "2.2V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V23:
|
||||
pof_voltage = "2.3V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V24:
|
||||
pof_voltage = "2.4V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V25:
|
||||
pof_voltage = "2.5V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V26:
|
||||
pof_voltage = "2.6V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V27:
|
||||
pof_voltage = "2.7V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V28:
|
||||
pof_voltage = "2.8V";
|
||||
break;
|
||||
default:
|
||||
pof_voltage = "???V";
|
||||
break;
|
||||
}
|
||||
|
||||
if (nrf_power_mainregstatus_get(NRF_POWER) == NRF_POWER_MAINREGSTATUS_HIGH) {
|
||||
const char *vddh_voltage;
|
||||
switch (nrf_power_pofcon_vddh_get(NRF_POWER)) {
|
||||
case NRF_POWER_POFTHRVDDH_V27:
|
||||
vddh_voltage = "2.7V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V28:
|
||||
vddh_voltage = "2.8V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V29:
|
||||
vddh_voltage = "2.9V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V30:
|
||||
vddh_voltage = "3.0V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V31:
|
||||
vddh_voltage = "3.1V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V32:
|
||||
vddh_voltage = "3.2V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V33:
|
||||
vddh_voltage = "3.3V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V34:
|
||||
vddh_voltage = "3.4V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V35:
|
||||
vddh_voltage = "3.5V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V36:
|
||||
vddh_voltage = "3.6V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V37:
|
||||
vddh_voltage = "3.7V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V38:
|
||||
vddh_voltage = "3.8V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V39:
|
||||
vddh_voltage = "3.9V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V40:
|
||||
vddh_voltage = "4.0V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V41:
|
||||
vddh_voltage = "4.1V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V42:
|
||||
vddh_voltage = "4.2V";
|
||||
break;
|
||||
default:
|
||||
vddh_voltage = "???V";
|
||||
break;
|
||||
}
|
||||
ESP_LOGD(TAG, "Power-fail comparator: %s, VDDH: %s", pof_voltage, vddh_voltage);
|
||||
pos = buf_append_str(buf, size, pos, "|Power-fail comparator: ");
|
||||
pos = buf_append_str(buf, size, pos, pof_voltage);
|
||||
pos = buf_append_str(buf, size, pos, ", VDDH: ");
|
||||
pos = buf_append_str(buf, size, pos, vddh_voltage);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Power-fail comparator: %s", pof_voltage);
|
||||
pos = buf_append_str(buf, size, pos, "|Power-fail comparator: ");
|
||||
pos = buf_append_str(buf, size, pos, pof_voltage);
|
||||
}
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Power-fail comparator: disabled");
|
||||
pos = buf_append_str(buf, size, pos, "|Power-fail comparator: disabled");
|
||||
}
|
||||
|
||||
auto package = [](uint32_t value) {
|
||||
switch (value) {
|
||||
case 0x2004:
|
||||
return "QIxx - 7x7 73-pin aQFN";
|
||||
case 0x2000:
|
||||
return "QFxx - 6x6 48-pin QFN";
|
||||
case 0x2005:
|
||||
return "CKxx - 3.544 x 3.607 WLCSP";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "Unspecified";
|
||||
};
|
||||
|
||||
char mac_pretty[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
|
||||
get_mac_address_pretty_into_buffer(mac_pretty);
|
||||
ESP_LOGD(TAG,
|
||||
"nRF debug info:\n"
|
||||
" Code page size: %u, code size: %u, device id: 0x%08x%08x\n"
|
||||
" Encryption root: 0x%08x%08x%08x%08x, Identity Root: 0x%08x%08x%08x%08x\n"
|
||||
" Device address type: %s, address: %s\n"
|
||||
" Part code: nRF%x, version: %c%c%c%c, package: %s\n"
|
||||
" RAM: %ukB, Flash: %ukB, production test: %sdone",
|
||||
NRF_FICR->CODEPAGESIZE, NRF_FICR->CODESIZE, NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0], NRF_FICR->ER[0],
|
||||
NRF_FICR->ER[1], NRF_FICR->ER[2], NRF_FICR->ER[3], NRF_FICR->IR[0], NRF_FICR->IR[1], NRF_FICR->IR[2],
|
||||
NRF_FICR->IR[3], (NRF_FICR->DEVICEADDRTYPE & 0x1 ? LOG_STR_LITERAL("Random") : LOG_STR_LITERAL("Public")),
|
||||
mac_pretty, NRF_FICR->INFO.PART, NRF_FICR->INFO.VARIANT >> 24 & 0xFF, NRF_FICR->INFO.VARIANT >> 16 & 0xFF,
|
||||
NRF_FICR->INFO.VARIANT >> 8 & 0xFF, NRF_FICR->INFO.VARIANT & 0xFF, package(NRF_FICR->INFO.PACKAGE),
|
||||
NRF_FICR->INFO.RAM, NRF_FICR->INFO.FLASH,
|
||||
(NRF_FICR->PRODTEST[0] == 0xBB42319F ? LOG_STR_LITERAL("") : LOG_STR_LITERAL("not ")));
|
||||
bool n_reset_enabled = NRF_UICR->PSELRESET[0] == NRF_UICR->PSELRESET[1] &&
|
||||
(NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) == UICR_PSELRESET_CONNECT_Connected
|
||||
<< UICR_PSELRESET_CONNECT_Pos;
|
||||
ESP_LOGD(
|
||||
TAG, " GPIO as NFC pins: %s, GPIO as nRESET pin: %s",
|
||||
YESNO((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)),
|
||||
YESNO(n_reset_enabled));
|
||||
if (n_reset_enabled) {
|
||||
uint8_t port = (NRF_UICR->PSELRESET[0] & UICR_PSELRESET_PORT_Msk) >> UICR_PSELRESET_PORT_Pos;
|
||||
uint8_t pin = (NRF_UICR->PSELRESET[0] & UICR_PSELRESET_PIN_Msk) >> UICR_PSELRESET_PIN_Pos;
|
||||
ESP_LOGD(TAG, " nRESET port P%u.%02u", port, pin);
|
||||
}
|
||||
#ifdef USE_BOOTLOADER_MCUBOOT
|
||||
ESP_LOGD(TAG, " Bootloader: mcuboot");
|
||||
#else
|
||||
ESP_LOGD(TAG, " Bootloader: Adafruit, version %u.%u.%u", (BOOTLOADER_VERSION_REGISTER >> 16) & 0xFF,
|
||||
(BOOTLOADER_VERSION_REGISTER >> 8) & 0xFF, BOOTLOADER_VERSION_REGISTER & 0xFF);
|
||||
ESP_LOGD(TAG, " MBR bootloader addr 0x%08x, UICR bootloader addr 0x%08x", read_mem_u32(MBR_BOOTLOADER_ADDR),
|
||||
NRF_UICR->NRFFW[0]);
|
||||
ESP_LOGD(TAG, " MBR param page addr 0x%08x, UICR param page addr 0x%08x", read_mem_u32(MBR_PARAM_PAGE_ADDR),
|
||||
NRF_UICR->NRFFW[1]);
|
||||
if (is_sd_present()) {
|
||||
uint32_t const sd_id = sd_id_get();
|
||||
uint32_t const sd_version = sd_version_get();
|
||||
|
||||
uint32_t ver[3];
|
||||
ver[0] = sd_version / 1000000;
|
||||
ver[1] = (sd_version - ver[0] * 1000000) / 1000;
|
||||
ver[2] = (sd_version - ver[0] * 1000000 - ver[1] * 1000);
|
||||
|
||||
ESP_LOGD(TAG, " SoftDevice: S%u %u.%u.%u", sd_id, ver[0], ver[1], ver[2]);
|
||||
#ifdef USE_SOFTDEVICE_ID
|
||||
#ifdef USE_SOFTDEVICE_VERSION
|
||||
if (USE_SOFTDEVICE_ID != sd_id || USE_SOFTDEVICE_VERSION != ver[0]) {
|
||||
ESP_LOGE(TAG, "Built for SoftDevice S%u %u.x.y. It may crash due to mismatch of bootloader version.",
|
||||
USE_SOFTDEVICE_ID, USE_SOFTDEVICE_VERSION);
|
||||
}
|
||||
#else
|
||||
if (USE_SOFTDEVICE_ID != sd_id) {
|
||||
ESP_LOGE(TAG, "Built for SoftDevice S%u. It may crash due to mismatch of bootloader version.", USE_SOFTDEVICE_ID);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
// 13 words of 8 hex digits, separated by spaces
|
||||
char uicr_buf[13 * 9];
|
||||
auto uicr = [&uicr_buf](volatile uint32_t *data, uint8_t size) {
|
||||
size_t len = 0;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
len = buf_append_printf(uicr_buf, sizeof(uicr_buf), len, i > 0 ? " %08" PRIX32 : "%08" PRIX32, data[i]);
|
||||
}
|
||||
return uicr_buf;
|
||||
};
|
||||
ESP_LOGD(TAG, " NRFFW %s", uicr(NRF_UICR->NRFFW, 13));
|
||||
ESP_LOGD(TAG, " NRFHW %s", uicr(NRF_UICR->NRFHW, 12));
|
||||
#ifdef ESPHOME_LOG_HAS_VERBOSE
|
||||
log_peripherals_info();
|
||||
#endif
|
||||
return pos;
|
||||
}
|
||||
|
||||
#undef NRF_PERIPH_ENABLED
|
||||
|
||||
} // namespace esphome::debug
|
||||
#endif
|
||||
@@ -1,113 +0,0 @@
|
||||
#include "debug_component.h"
|
||||
#ifdef USE_ZEPHYR
|
||||
#include <nrfx.h>
|
||||
#endif
|
||||
#if defined(USE_ZEPHYR) && defined(NRF54L_SERIES)
|
||||
#include <cinttypes>
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome::debug {
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "debug");
|
||||
|
||||
// Check if an nRF peripheral's ENABLE register indicates it is enabled.
|
||||
// periph: peripheral register prefix (e.g. USBD, UARTE, SPI)
|
||||
// reg: register block pointer (e.g. NRF_USBD, NRF_UARTE0)
|
||||
#define NRF_PERIPH_ENABLED(periph, reg) \
|
||||
YESNO(((reg)->ENABLE & periph##_ENABLE_ENABLE_Msk) == (periph##_ENABLE_ENABLE_Enabled << periph##_ENABLE_ENABLE_Pos))
|
||||
|
||||
#ifdef ESPHOME_LOG_HAS_VERBOSE
|
||||
// NOLINTBEGIN(clang-analyzer-core.FixedAddressDereference) -- nRF peripheral registers are MMIO at fixed addresses
|
||||
static void log_peripherals_info() {
|
||||
// most peripherals are enabled only when in use so ESP_LOGV is enough
|
||||
// UARTE, SPIM, SPIS, TWIM and TWIS with the same number share one instance
|
||||
ESP_LOGV(TAG, "Peripherals status:");
|
||||
ESP_LOGV(TAG, " UARTE00: %-3s| UARTE20: %-3s| UARTE21: %-3s| UARTE22: %-3s| UARTE30: %-3s", //
|
||||
NRF_PERIPH_ENABLED(UARTE, NRF_UARTE00), NRF_PERIPH_ENABLED(UARTE, NRF_UARTE20),
|
||||
NRF_PERIPH_ENABLED(UARTE, NRF_UARTE21), NRF_PERIPH_ENABLED(UARTE, NRF_UARTE22),
|
||||
NRF_PERIPH_ENABLED(UARTE, NRF_UARTE30));
|
||||
ESP_LOGV(TAG, " SPIM00: %-3s| SPIM20: %-3s| SPIM21: %-3s| SPIM22: %-3s| SPIM30: %-3s", //
|
||||
NRF_PERIPH_ENABLED(SPIM, NRF_SPIM00), NRF_PERIPH_ENABLED(SPIM, NRF_SPIM20),
|
||||
NRF_PERIPH_ENABLED(SPIM, NRF_SPIM21), NRF_PERIPH_ENABLED(SPIM, NRF_SPIM22),
|
||||
NRF_PERIPH_ENABLED(SPIM, NRF_SPIM30));
|
||||
ESP_LOGV(TAG, " SPIS00: %-3s| SPIS20: %-3s| SPIS21: %-3s| SPIS22: %-3s| SPIS30: %-3s", //
|
||||
NRF_PERIPH_ENABLED(SPIS, NRF_SPIS00), NRF_PERIPH_ENABLED(SPIS, NRF_SPIS20),
|
||||
NRF_PERIPH_ENABLED(SPIS, NRF_SPIS21), NRF_PERIPH_ENABLED(SPIS, NRF_SPIS22),
|
||||
NRF_PERIPH_ENABLED(SPIS, NRF_SPIS30));
|
||||
ESP_LOGV(TAG, " TWIM20: %-3s| TWIM21: %-3s| TWIM22: %-3s| TWIM30: %-3s", //
|
||||
NRF_PERIPH_ENABLED(TWIM, NRF_TWIM20), NRF_PERIPH_ENABLED(TWIM, NRF_TWIM21),
|
||||
NRF_PERIPH_ENABLED(TWIM, NRF_TWIM22), NRF_PERIPH_ENABLED(TWIM, NRF_TWIM30));
|
||||
ESP_LOGV(TAG, " TWIS20: %-3s| TWIS21: %-3s| TWIS22: %-3s| TWIS30: %-3s", //
|
||||
NRF_PERIPH_ENABLED(TWIS, NRF_TWIS20), NRF_PERIPH_ENABLED(TWIS, NRF_TWIS21),
|
||||
NRF_PERIPH_ENABLED(TWIS, NRF_TWIS22), NRF_PERIPH_ENABLED(TWIS, NRF_TWIS30));
|
||||
ESP_LOGV(TAG, " PWM20: %-3s| PWM21: %-3s| PWM22: %-3s| SAADC: %-3s", //
|
||||
NRF_PERIPH_ENABLED(PWM, NRF_PWM20), NRF_PERIPH_ENABLED(PWM, NRF_PWM21), NRF_PERIPH_ENABLED(PWM, NRF_PWM22),
|
||||
NRF_PERIPH_ENABLED(SAADC, NRF_SAADC));
|
||||
ESP_LOGV(TAG, " PDM20: %-3s| PDM21: %-3s| QDEC20: %-3s| QDEC21: %-3s", //
|
||||
NRF_PERIPH_ENABLED(PDM, NRF_PDM20), NRF_PERIPH_ENABLED(PDM, NRF_PDM21), NRF_PERIPH_ENABLED(QDEC, NRF_QDEC20),
|
||||
NRF_PERIPH_ENABLED(QDEC, NRF_QDEC21));
|
||||
ESP_LOGV(TAG, " COMP: %-3s| LPCOMP: %-3s| AAR00: %-3s| CCM00: %-3s", //
|
||||
NRF_PERIPH_ENABLED(COMP, NRF_COMP), NRF_PERIPH_ENABLED(LPCOMP, NRF_LPCOMP),
|
||||
NRF_PERIPH_ENABLED(AAR, NRF_AAR00), NRF_PERIPH_ENABLED(CCM, NRF_CCM00));
|
||||
}
|
||||
// NOLINTEND(clang-analyzer-core.FixedAddressDereference)
|
||||
#endif
|
||||
|
||||
// NOLINTBEGIN(clang-analyzer-core.FixedAddressDereference) -- nRF registers are MMIO at fixed addresses
|
||||
size_t DebugComponent::get_device_info_(std::span<char, DEVICE_INFO_BUFFER_SIZE> buffer, size_t pos) {
|
||||
constexpr size_t size = DEVICE_INFO_BUFFER_SIZE;
|
||||
char *buf = buffer.data();
|
||||
|
||||
// Main regulator
|
||||
const char *reg_type = (NRF_REGULATORS->VREGMAIN.DCDCEN & REGULATORS_VREGMAIN_DCDCEN_VAL_Msk) ==
|
||||
(REGULATORS_VREGMAIN_DCDCEN_VAL_Enabled << REGULATORS_VREGMAIN_DCDCEN_VAL_Pos)
|
||||
? "DC/DC"
|
||||
: "LDO";
|
||||
ESP_LOGD(TAG, "Main regulator: %s", reg_type);
|
||||
pos = buf_append_str(buf, size, pos, "|Main regulator: ");
|
||||
pos = buf_append_str(buf, size, pos, reg_type);
|
||||
|
||||
// Power-fail comparator, the threshold goes from 1.7V up in 0.1V steps
|
||||
const uint32_t pofcon = NRF_REGULATORS->POFCON;
|
||||
if ((pofcon & REGULATORS_POFCON_POF_Msk) == (REGULATORS_POFCON_POF_Enabled << REGULATORS_POFCON_POF_Pos)) {
|
||||
const uint32_t decivolts = 17 + ((pofcon & REGULATORS_POFCON_THRESHOLD_Msk) >> REGULATORS_POFCON_THRESHOLD_Pos);
|
||||
ESP_LOGD(TAG, "Power-fail comparator: %" PRIu32 ".%" PRIu32 "V", decivolts / 10, decivolts % 10);
|
||||
pos = buf_append_printf(buf, size, pos, "|Power-fail comparator: %" PRIu32 ".%" PRIu32 "V", decivolts / 10,
|
||||
decivolts % 10);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Power-fail comparator: disabled");
|
||||
pos = buf_append_str(buf, size, pos, "|Power-fail comparator: disabled");
|
||||
}
|
||||
|
||||
char mac_pretty[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
|
||||
get_mac_address_pretty_into_buffer(mac_pretty);
|
||||
const uint32_t variant = NRF_FICR->INFO.VARIANT;
|
||||
ESP_LOGD(TAG,
|
||||
"nRF debug info:\n"
|
||||
" Device id: 0x%08" PRIx32 "%08" PRIx32 "\n"
|
||||
" Encryption root: 0x%08" PRIx32 "%08" PRIx32 "%08" PRIx32 "%08" PRIx32 ", Identity Root: 0x%08" PRIx32
|
||||
"%08" PRIx32 "%08" PRIx32 "%08" PRIx32 "\n"
|
||||
" Device address type: %s, address: %s\n"
|
||||
" Part code: 0x%" PRIx32 ", version: %c%c%c%c, package: 0x%" PRIx32 "\n"
|
||||
" RAM: %" PRIu32 "kB, RRAM: %" PRIu32 "kB",
|
||||
NRF_FICR->INFO.DEVICEID[1], NRF_FICR->INFO.DEVICEID[0], NRF_FICR->ER[0], NRF_FICR->ER[1], NRF_FICR->ER[2],
|
||||
NRF_FICR->ER[3], NRF_FICR->IR[0], NRF_FICR->IR[1], NRF_FICR->IR[2], NRF_FICR->IR[3],
|
||||
(NRF_FICR->DEVICEADDRTYPE & 0x1 ? LOG_STR_LITERAL("Random") : LOG_STR_LITERAL("Public")), mac_pretty,
|
||||
NRF_FICR->INFO.PART, static_cast<char>(variant >> 24 & 0xFF), static_cast<char>(variant >> 16 & 0xFF),
|
||||
static_cast<char>(variant >> 8 & 0xFF), static_cast<char>(variant & 0xFF), NRF_FICR->INFO.PACKAGE,
|
||||
NRF_FICR->INFO.RAM, NRF_FICR->INFO.RRAM);
|
||||
#ifdef USE_BOOTLOADER_MCUBOOT
|
||||
ESP_LOGD(TAG, " Bootloader: mcuboot");
|
||||
#endif
|
||||
#ifdef ESPHOME_LOG_HAS_VERBOSE
|
||||
log_peripherals_info();
|
||||
#endif
|
||||
return pos;
|
||||
}
|
||||
// NOLINTEND(clang-analyzer-core.FixedAddressDereference)
|
||||
|
||||
#undef NRF_PERIPH_ENABLED
|
||||
|
||||
} // namespace esphome::debug
|
||||
#endif
|
||||
@@ -2,14 +2,55 @@
|
||||
#ifdef USE_ZEPHYR
|
||||
#include <cinttypes>
|
||||
#include <climits>
|
||||
#include "esphome/core/alloc_helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include <esphome/components/zephyr/reset_reason.h>
|
||||
#include <zephyr/drivers/hwinfo.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <hal/nrf_power.h>
|
||||
#include <cstdint>
|
||||
#include <zephyr/storage/flash_map.h>
|
||||
|
||||
#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0]
|
||||
|
||||
namespace esphome::debug {
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "debug");
|
||||
constexpr std::uintptr_t MBR_PARAM_PAGE_ADDR = 0xFFC;
|
||||
constexpr std::uintptr_t MBR_BOOTLOADER_ADDR = 0xFF8;
|
||||
|
||||
static inline uint32_t read_mem_u32(uintptr_t addr) {
|
||||
// NOLINTNEXTLINE(performance-no-int-to-ptr,clang-analyzer-core.FixedAddressDereference)
|
||||
return *reinterpret_cast<volatile uint32_t *>(addr);
|
||||
}
|
||||
|
||||
static inline uint8_t read_mem_u8(uintptr_t addr) {
|
||||
// NOLINTNEXTLINE(performance-no-int-to-ptr,clang-analyzer-core.FixedAddressDereference)
|
||||
return *reinterpret_cast<volatile uint8_t *>(addr);
|
||||
}
|
||||
|
||||
// defines from https://github.com/adafruit/Adafruit_nRF52_Bootloader which prints those information
|
||||
constexpr uint32_t SD_MAGIC_NUMBER = 0x51B1E5DB;
|
||||
constexpr uintptr_t MBR_SIZE = 0x1000;
|
||||
constexpr uintptr_t SOFTDEVICE_INFO_STRUCT_OFFSET = 0x2000;
|
||||
constexpr uintptr_t SD_ID_OFFSET = SOFTDEVICE_INFO_STRUCT_OFFSET + 0x10;
|
||||
constexpr uintptr_t SD_VERSION_OFFSET = SOFTDEVICE_INFO_STRUCT_OFFSET + 0x14;
|
||||
|
||||
static inline bool is_sd_present() {
|
||||
return read_mem_u32(SOFTDEVICE_INFO_STRUCT_OFFSET + MBR_SIZE + 4) == SD_MAGIC_NUMBER;
|
||||
}
|
||||
static inline uint32_t sd_id_get() {
|
||||
if (read_mem_u8(MBR_SIZE + SOFTDEVICE_INFO_STRUCT_OFFSET) > (SD_ID_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) {
|
||||
return read_mem_u32(MBR_SIZE + SD_ID_OFFSET);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static inline uint32_t sd_version_get() {
|
||||
if (read_mem_u8(MBR_SIZE + SOFTDEVICE_INFO_STRUCT_OFFSET) > (SD_VERSION_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) {
|
||||
return read_mem_u32(MBR_SIZE + SD_VERSION_OFFSET);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *DebugComponent::get_reset_reason_(std::span<char, RESET_REASON_BUFFER_SIZE> buffer) {
|
||||
const char *buf = zephyr::get_reset_reason(buffer);
|
||||
@@ -55,6 +96,329 @@ void DebugComponent::log_partition_info_() {
|
||||
flash_area_foreach(fa_cb, nullptr);
|
||||
}
|
||||
|
||||
#ifdef ESPHOME_LOG_HAS_VERBOSE
|
||||
// Check if an nRF peripheral's ENABLE register indicates it is enabled.
|
||||
// periph: peripheral register prefix (e.g. USBD, UARTE, SPI)
|
||||
// reg: register block pointer (e.g. NRF_USBD, NRF_UARTE0)
|
||||
#define NRF_PERIPH_ENABLED(periph, reg) \
|
||||
YESNO(((reg)->ENABLE & periph##_ENABLE_ENABLE_Msk) == (periph##_ENABLE_ENABLE_Enabled << periph##_ENABLE_ENABLE_Pos))
|
||||
|
||||
// NOLINTBEGIN(clang-analyzer-core.FixedAddressDereference) -- nRF peripheral registers are MMIO at fixed addresses
|
||||
static void log_peripherals_info() {
|
||||
// most peripherals are enabled only when in use so ESP_LOGV is enough
|
||||
ESP_LOGV(TAG, "Peripherals status:");
|
||||
ESP_LOGV(TAG, " USBD: %-3s| UARTE0: %-3s| UARTE1: %-3s| UART0: %-3s", //
|
||||
NRF_PERIPH_ENABLED(USBD, NRF_USBD), NRF_PERIPH_ENABLED(UARTE, NRF_UARTE0),
|
||||
NRF_PERIPH_ENABLED(UARTE, NRF_UARTE1), NRF_PERIPH_ENABLED(UART, NRF_UART0));
|
||||
ESP_LOGV(TAG, " TWIS0: %-3s| TWIS1: %-3s| TWIM0: %-3s| TWIM1: %-3s", //
|
||||
NRF_PERIPH_ENABLED(TWIS, NRF_TWIS0), NRF_PERIPH_ENABLED(TWIS, NRF_TWIS1),
|
||||
NRF_PERIPH_ENABLED(TWIM, NRF_TWIM0), NRF_PERIPH_ENABLED(TWIM, NRF_TWIM1));
|
||||
ESP_LOGV(TAG, " TWI0: %-3s| TWI1: %-3s| COMP: %-3s| CCM: %-3s", //
|
||||
NRF_PERIPH_ENABLED(TWI, NRF_TWI0), NRF_PERIPH_ENABLED(TWI, NRF_TWI1), NRF_PERIPH_ENABLED(COMP, NRF_COMP),
|
||||
NRF_PERIPH_ENABLED(CCM, NRF_CCM));
|
||||
ESP_LOGV(TAG, " PDM: %-3s| SPIS0: %-3s| SPIS1: %-3s| SPIS2: %-3s", //
|
||||
NRF_PERIPH_ENABLED(PDM, NRF_PDM), NRF_PERIPH_ENABLED(SPIS, NRF_SPIS0), NRF_PERIPH_ENABLED(SPIS, NRF_SPIS1),
|
||||
NRF_PERIPH_ENABLED(SPIS, NRF_SPIS2));
|
||||
ESP_LOGV(TAG, " SPIM0: %-3s| SPIM1: %-3s| SPIM2: %-3s| SPIM3: %-3s", //
|
||||
NRF_PERIPH_ENABLED(SPIM, NRF_SPIM0), NRF_PERIPH_ENABLED(SPIM, NRF_SPIM1),
|
||||
NRF_PERIPH_ENABLED(SPIM, NRF_SPIM2), NRF_PERIPH_ENABLED(SPIM, NRF_SPIM3));
|
||||
ESP_LOGV(TAG, " SPI0: %-3s| SPI1: %-3s| SPI2: %-3s| SAADC: %-3s", //
|
||||
NRF_PERIPH_ENABLED(SPI, NRF_SPI0), NRF_PERIPH_ENABLED(SPI, NRF_SPI1), NRF_PERIPH_ENABLED(SPI, NRF_SPI2),
|
||||
NRF_PERIPH_ENABLED(SAADC, NRF_SAADC));
|
||||
ESP_LOGV(TAG, " QSPI: %-3s| QDEC: %-3s| LPCOMP: %-3s| I2S: %-3s", //
|
||||
NRF_PERIPH_ENABLED(QSPI, NRF_QSPI), NRF_PERIPH_ENABLED(QDEC, NRF_QDEC),
|
||||
NRF_PERIPH_ENABLED(LPCOMP, NRF_LPCOMP), NRF_PERIPH_ENABLED(I2S, NRF_I2S));
|
||||
ESP_LOGV(TAG, " PWM0: %-3s| PWM1: %-3s| PWM2: %-3s| PWM3: %-3s", //
|
||||
NRF_PERIPH_ENABLED(PWM, NRF_PWM0), NRF_PERIPH_ENABLED(PWM, NRF_PWM1), NRF_PERIPH_ENABLED(PWM, NRF_PWM2),
|
||||
NRF_PERIPH_ENABLED(PWM, NRF_PWM3));
|
||||
ESP_LOGV(TAG, " AAR: %-3s| QSPI deep power-down:%-3s| CRYPTOCELL: %-3s", NRF_PERIPH_ENABLED(AAR, NRF_AAR),
|
||||
YESNO((NRF_QSPI->IFCONFIG0 & QSPI_IFCONFIG0_DPMENABLE_Msk) ==
|
||||
(QSPI_IFCONFIG0_DPMENABLE_Enable << QSPI_IFCONFIG0_DPMENABLE_Pos)),
|
||||
YESNO((NRF_CRYPTOCELL->ENABLE & CRYPTOCELL_ENABLE_ENABLE_Msk) ==
|
||||
(CRYPTOCELL_ENABLE_ENABLE_Enabled << CRYPTOCELL_ENABLE_ENABLE_Pos)));
|
||||
}
|
||||
// NOLINTEND(clang-analyzer-core.FixedAddressDereference)
|
||||
#undef NRF_PERIPH_ENABLED
|
||||
#endif
|
||||
|
||||
static const char *regout0_to_str(uint32_t value) {
|
||||
switch (value) {
|
||||
case (UICR_REGOUT0_VOUT_DEFAULT):
|
||||
return "1.8V (default)";
|
||||
case (UICR_REGOUT0_VOUT_1V8):
|
||||
return "1.8V";
|
||||
case (UICR_REGOUT0_VOUT_2V1):
|
||||
return "2.1V";
|
||||
case (UICR_REGOUT0_VOUT_2V4):
|
||||
return "2.4V";
|
||||
case (UICR_REGOUT0_VOUT_2V7):
|
||||
return "2.7V";
|
||||
case (UICR_REGOUT0_VOUT_3V0):
|
||||
return "3.0V";
|
||||
case (UICR_REGOUT0_VOUT_3V3):
|
||||
return "3.3V";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "???V";
|
||||
}
|
||||
|
||||
size_t DebugComponent::get_device_info_(std::span<char, DEVICE_INFO_BUFFER_SIZE> buffer, size_t pos) {
|
||||
constexpr size_t size = DEVICE_INFO_BUFFER_SIZE;
|
||||
char *buf = buffer.data();
|
||||
|
||||
// Main supply status
|
||||
// NOLINTNEXTLINE(clang-analyzer-core.FixedAddressDereference) -- NRF_POWER is MMIO at a fixed address
|
||||
auto regstatus = nrf_power_mainregstatus_get(NRF_POWER);
|
||||
const char *supply_status = (regstatus == NRF_POWER_MAINREGSTATUS_NORMAL) ? "Normal voltage." : "High voltage.";
|
||||
ESP_LOGD(TAG, "Main supply status: %s", supply_status);
|
||||
pos = buf_append_str(buf, size, pos, "|Main supply status: ");
|
||||
pos = buf_append_str(buf, size, pos, supply_status);
|
||||
|
||||
// Regulator stage 0
|
||||
if (nrf_power_mainregstatus_get(NRF_POWER) == NRF_POWER_MAINREGSTATUS_HIGH) {
|
||||
const char *reg0_type = nrf_power_dcdcen_vddh_get(NRF_POWER) ? "DC/DC" : "LDO";
|
||||
const char *reg0_voltage = regout0_to_str((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) >> UICR_REGOUT0_VOUT_Pos);
|
||||
ESP_LOGD(TAG, "Regulator stage 0: %s, %s", reg0_type, reg0_voltage);
|
||||
pos = buf_append_str(buf, size, pos, "|Regulator stage 0: ");
|
||||
pos = buf_append_str(buf, size, pos, reg0_type);
|
||||
pos = buf_append_str(buf, size, pos, ", ");
|
||||
pos = buf_append_str(buf, size, pos, reg0_voltage);
|
||||
#ifdef USE_NRF52_REG0_VOUT
|
||||
if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) >> UICR_REGOUT0_VOUT_Pos != USE_NRF52_REG0_VOUT) {
|
||||
ESP_LOGE(TAG, "Regulator stage 0: expected %s", regout0_to_str(USE_NRF52_REG0_VOUT));
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Regulator stage 0: disabled");
|
||||
pos = buf_append_str(buf, size, pos, "|Regulator stage 0: disabled");
|
||||
}
|
||||
|
||||
// Regulator stage 1
|
||||
const char *reg1_type = nrf_power_dcdcen_get(NRF_POWER) ? "DC/DC" : "LDO";
|
||||
ESP_LOGD(TAG, "Regulator stage 1: %s", reg1_type);
|
||||
pos = buf_append_str(buf, size, pos, "|Regulator stage 1: ");
|
||||
pos = buf_append_str(buf, size, pos, reg1_type);
|
||||
|
||||
// USB power state
|
||||
const char *usb_state;
|
||||
if (nrf_power_usbregstatus_vbusdet_get(NRF_POWER)) {
|
||||
usb_state = nrf_power_usbregstatus_outrdy_get(NRF_POWER) ? "ready" : "connected (regulator is not ready)";
|
||||
} else {
|
||||
usb_state = "disconnected";
|
||||
}
|
||||
ESP_LOGD(TAG, "USB power state: %s", usb_state);
|
||||
pos = buf_append_str(buf, size, pos, "|USB power state: ");
|
||||
pos = buf_append_str(buf, size, pos, usb_state);
|
||||
|
||||
// Power-fail comparator
|
||||
bool enabled;
|
||||
nrf_power_pof_thr_t pof_thr = nrf_power_pofcon_get(NRF_POWER, &enabled);
|
||||
if (enabled) {
|
||||
const char *pof_voltage;
|
||||
switch (pof_thr) {
|
||||
case POWER_POFCON_THRESHOLD_V17:
|
||||
pof_voltage = "1.7V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V18:
|
||||
pof_voltage = "1.8V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V19:
|
||||
pof_voltage = "1.9V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V20:
|
||||
pof_voltage = "2.0V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V21:
|
||||
pof_voltage = "2.1V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V22:
|
||||
pof_voltage = "2.2V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V23:
|
||||
pof_voltage = "2.3V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V24:
|
||||
pof_voltage = "2.4V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V25:
|
||||
pof_voltage = "2.5V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V26:
|
||||
pof_voltage = "2.6V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V27:
|
||||
pof_voltage = "2.7V";
|
||||
break;
|
||||
case POWER_POFCON_THRESHOLD_V28:
|
||||
pof_voltage = "2.8V";
|
||||
break;
|
||||
default:
|
||||
pof_voltage = "???V";
|
||||
break;
|
||||
}
|
||||
|
||||
if (nrf_power_mainregstatus_get(NRF_POWER) == NRF_POWER_MAINREGSTATUS_HIGH) {
|
||||
const char *vddh_voltage;
|
||||
switch (nrf_power_pofcon_vddh_get(NRF_POWER)) {
|
||||
case NRF_POWER_POFTHRVDDH_V27:
|
||||
vddh_voltage = "2.7V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V28:
|
||||
vddh_voltage = "2.8V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V29:
|
||||
vddh_voltage = "2.9V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V30:
|
||||
vddh_voltage = "3.0V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V31:
|
||||
vddh_voltage = "3.1V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V32:
|
||||
vddh_voltage = "3.2V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V33:
|
||||
vddh_voltage = "3.3V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V34:
|
||||
vddh_voltage = "3.4V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V35:
|
||||
vddh_voltage = "3.5V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V36:
|
||||
vddh_voltage = "3.6V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V37:
|
||||
vddh_voltage = "3.7V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V38:
|
||||
vddh_voltage = "3.8V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V39:
|
||||
vddh_voltage = "3.9V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V40:
|
||||
vddh_voltage = "4.0V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V41:
|
||||
vddh_voltage = "4.1V";
|
||||
break;
|
||||
case NRF_POWER_POFTHRVDDH_V42:
|
||||
vddh_voltage = "4.2V";
|
||||
break;
|
||||
default:
|
||||
vddh_voltage = "???V";
|
||||
break;
|
||||
}
|
||||
ESP_LOGD(TAG, "Power-fail comparator: %s, VDDH: %s", pof_voltage, vddh_voltage);
|
||||
pos = buf_append_str(buf, size, pos, "|Power-fail comparator: ");
|
||||
pos = buf_append_str(buf, size, pos, pof_voltage);
|
||||
pos = buf_append_str(buf, size, pos, ", VDDH: ");
|
||||
pos = buf_append_str(buf, size, pos, vddh_voltage);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Power-fail comparator: %s", pof_voltage);
|
||||
pos = buf_append_str(buf, size, pos, "|Power-fail comparator: ");
|
||||
pos = buf_append_str(buf, size, pos, pof_voltage);
|
||||
}
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Power-fail comparator: disabled");
|
||||
pos = buf_append_str(buf, size, pos, "|Power-fail comparator: disabled");
|
||||
}
|
||||
|
||||
auto package = [](uint32_t value) {
|
||||
switch (value) {
|
||||
case 0x2004:
|
||||
return "QIxx - 7x7 73-pin aQFN";
|
||||
case 0x2000:
|
||||
return "QFxx - 6x6 48-pin QFN";
|
||||
case 0x2005:
|
||||
return "CKxx - 3.544 x 3.607 WLCSP";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "Unspecified";
|
||||
};
|
||||
|
||||
char mac_pretty[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
|
||||
get_mac_address_pretty_into_buffer(mac_pretty);
|
||||
ESP_LOGD(TAG,
|
||||
"nRF debug info:\n"
|
||||
" Code page size: %u, code size: %u, device id: 0x%08x%08x\n"
|
||||
" Encryption root: 0x%08x%08x%08x%08x, Identity Root: 0x%08x%08x%08x%08x\n"
|
||||
" Device address type: %s, address: %s\n"
|
||||
" Part code: nRF%x, version: %c%c%c%c, package: %s\n"
|
||||
" RAM: %ukB, Flash: %ukB, production test: %sdone",
|
||||
NRF_FICR->CODEPAGESIZE, NRF_FICR->CODESIZE, NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0], NRF_FICR->ER[0],
|
||||
NRF_FICR->ER[1], NRF_FICR->ER[2], NRF_FICR->ER[3], NRF_FICR->IR[0], NRF_FICR->IR[1], NRF_FICR->IR[2],
|
||||
NRF_FICR->IR[3], (NRF_FICR->DEVICEADDRTYPE & 0x1 ? "Random" : "Public"), mac_pretty, NRF_FICR->INFO.PART,
|
||||
NRF_FICR->INFO.VARIANT >> 24 & 0xFF, NRF_FICR->INFO.VARIANT >> 16 & 0xFF, NRF_FICR->INFO.VARIANT >> 8 & 0xFF,
|
||||
NRF_FICR->INFO.VARIANT & 0xFF, package(NRF_FICR->INFO.PACKAGE), NRF_FICR->INFO.RAM, NRF_FICR->INFO.FLASH,
|
||||
(NRF_FICR->PRODTEST[0] == 0xBB42319F ? "" : "not "));
|
||||
bool n_reset_enabled = NRF_UICR->PSELRESET[0] == NRF_UICR->PSELRESET[1] &&
|
||||
(NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) == UICR_PSELRESET_CONNECT_Connected
|
||||
<< UICR_PSELRESET_CONNECT_Pos;
|
||||
ESP_LOGD(
|
||||
TAG, " GPIO as NFC pins: %s, GPIO as nRESET pin: %s",
|
||||
YESNO((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)),
|
||||
YESNO(n_reset_enabled));
|
||||
if (n_reset_enabled) {
|
||||
uint8_t port = (NRF_UICR->PSELRESET[0] & UICR_PSELRESET_PORT_Msk) >> UICR_PSELRESET_PORT_Pos;
|
||||
uint8_t pin = (NRF_UICR->PSELRESET[0] & UICR_PSELRESET_PIN_Msk) >> UICR_PSELRESET_PIN_Pos;
|
||||
ESP_LOGD(TAG, " nRESET port P%u.%02u", port, pin);
|
||||
}
|
||||
#ifdef USE_BOOTLOADER_MCUBOOT
|
||||
ESP_LOGD(TAG, " Bootloader: mcuboot");
|
||||
#else
|
||||
ESP_LOGD(TAG, " Bootloader: Adafruit, version %u.%u.%u", (BOOTLOADER_VERSION_REGISTER >> 16) & 0xFF,
|
||||
(BOOTLOADER_VERSION_REGISTER >> 8) & 0xFF, BOOTLOADER_VERSION_REGISTER & 0xFF);
|
||||
ESP_LOGD(TAG, " MBR bootloader addr 0x%08x, UICR bootloader addr 0x%08x", read_mem_u32(MBR_BOOTLOADER_ADDR),
|
||||
NRF_UICR->NRFFW[0]);
|
||||
ESP_LOGD(TAG, " MBR param page addr 0x%08x, UICR param page addr 0x%08x", read_mem_u32(MBR_PARAM_PAGE_ADDR),
|
||||
NRF_UICR->NRFFW[1]);
|
||||
if (is_sd_present()) {
|
||||
uint32_t const sd_id = sd_id_get();
|
||||
uint32_t const sd_version = sd_version_get();
|
||||
|
||||
uint32_t ver[3];
|
||||
ver[0] = sd_version / 1000000;
|
||||
ver[1] = (sd_version - ver[0] * 1000000) / 1000;
|
||||
ver[2] = (sd_version - ver[0] * 1000000 - ver[1] * 1000);
|
||||
|
||||
ESP_LOGD(TAG, " SoftDevice: S%u %u.%u.%u", sd_id, ver[0], ver[1], ver[2]);
|
||||
#ifdef USE_SOFTDEVICE_ID
|
||||
#ifdef USE_SOFTDEVICE_VERSION
|
||||
if (USE_SOFTDEVICE_ID != sd_id || USE_SOFTDEVICE_VERSION != ver[0]) {
|
||||
ESP_LOGE(TAG, "Built for SoftDevice S%u %u.x.y. It may crash due to mismatch of bootloader version.",
|
||||
USE_SOFTDEVICE_ID, USE_SOFTDEVICE_VERSION);
|
||||
}
|
||||
#else
|
||||
if (USE_SOFTDEVICE_ID != sd_id) {
|
||||
ESP_LOGE(TAG, "Built for SoftDevice S%u. It may crash due to mismatch of bootloader version.", USE_SOFTDEVICE_ID);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
// 13 words of 8 hex digits, separated by spaces
|
||||
char uicr_buf[13 * 9];
|
||||
auto uicr = [&uicr_buf](volatile uint32_t *data, uint8_t size) {
|
||||
size_t len = 0;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
len = buf_append_printf(uicr_buf, sizeof(uicr_buf), len, i > 0 ? " %08" PRIX32 : "%08" PRIX32, data[i]);
|
||||
}
|
||||
return uicr_buf;
|
||||
};
|
||||
ESP_LOGD(TAG, " NRFFW %s", uicr(NRF_UICR->NRFFW, 13));
|
||||
ESP_LOGD(TAG, " NRFHW %s", uicr(NRF_UICR->NRFHW, 12));
|
||||
#ifdef ESPHOME_LOG_HAS_VERBOSE
|
||||
log_peripherals_info();
|
||||
#endif
|
||||
return pos;
|
||||
}
|
||||
|
||||
// The Python side enables the statistics only for a verbose logger
|
||||
#ifdef CONFIG_SCHED_THREAD_USAGE_ANALYSIS
|
||||
static void log_thread_usage(const struct k_thread *thread, void *user_data) {
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
|
||||
namespace esphome::logger {
|
||||
|
||||
// Maximum header size: 35 bytes fixed + 32 bytes tag + 16 bytes thread name = 83 bytes (45 byte safety margin)
|
||||
// Space write_header() needs free. Without the tag the header takes at most 68 bytes (20 fixed, 48 for a thread name
|
||||
// of up to MAX_TAG_LENGTH); the tag gets the rest of the line's room minus that budget, so at least MAX_TAG_LENGTH
|
||||
// (on ESP8266 exactly MAX_TAG_LENGTH)
|
||||
static constexpr uint16_t MAX_HEADER_SIZE = 128;
|
||||
// Longest tag the header budget allows
|
||||
// Longest thread name in the header, and the shortest tag it always keeps
|
||||
static constexpr size_t MAX_TAG_LENGTH = 32;
|
||||
|
||||
// ANSI color code last digit (30-38 range, store only last digit to save RAM on ESP8266)
|
||||
@@ -42,15 +44,8 @@ struct LogBuffer {
|
||||
// Replaces the null terminator with a newline for console output.
|
||||
// Must be called after notify_listeners_() since listeners need null-terminated strings.
|
||||
// Console output uses length-based writes (buf.pos), so null terminator is not needed.
|
||||
void terminate_with_newline() {
|
||||
if (this->pos < this->size) {
|
||||
this->data[this->pos++] = '\n';
|
||||
} else if (this->size > 0) {
|
||||
// Buffer was full - replace last char with newline to ensure it's visible
|
||||
this->data[this->size - 1] = '\n';
|
||||
this->pos = this->size;
|
||||
}
|
||||
}
|
||||
// The body writers keep the terminator's byte inside the buffer, so the newline always fits
|
||||
void terminate_with_newline() { this->data[this->pos++] = '\n'; }
|
||||
void HOT write_header(uint8_t level, const char *tag, int line, const char *thread_name) {
|
||||
// Early return if insufficient space - intentionally don't update pos to prevent partial writes
|
||||
if (this->pos + MAX_HEADER_SIZE > this->size)
|
||||
@@ -75,7 +70,13 @@ struct LogBuffer {
|
||||
*p++ = '[';
|
||||
|
||||
// Copy tag
|
||||
p = copy_string(p, tag);
|
||||
#ifdef USE_ESP8266
|
||||
// ESP8266 has always cut tags at MAX_TAG_LENGTH, which leaves the message more of a short buffer
|
||||
p = copy_string(p, tag, MAX_TAG_LENGTH);
|
||||
#else
|
||||
// The early return above leaves at least MAX_HEADER_SIZE, so the tag keeps MAX_TAG_LENGTH or more
|
||||
p = copy_string(p, tag, this->remaining_() - (MAX_HEADER_SIZE - MAX_TAG_LENGTH));
|
||||
#endif
|
||||
|
||||
*p++ = ':';
|
||||
|
||||
@@ -93,7 +94,7 @@ struct LogBuffer {
|
||||
if (thread_name != nullptr) {
|
||||
p = write_ansi_color(p, 1); // Bold red for thread name
|
||||
*p++ = '[';
|
||||
p = copy_string(p, thread_name);
|
||||
p = copy_string(p, thread_name, MAX_TAG_LENGTH);
|
||||
*p++ = ']';
|
||||
p = write_ansi_color(p, level); // Restore original color
|
||||
}
|
||||
@@ -115,22 +116,27 @@ struct LogBuffer {
|
||||
}
|
||||
#endif
|
||||
// Writes a message that needs no formatting, truncated and stripped of trailing newlines as format_body() does
|
||||
void HOT write_unformatted_body(const char *text, size_t len) {
|
||||
if (!this->full_()) {
|
||||
const uint16_t limit = this->remaining_() - 1; // vsnprintf() keeps the last byte for the null terminator
|
||||
// Forced inline: as on dev, the per-line path keeps it in its caller instead of calling out on every line
|
||||
inline void HOT ESPHOME_ALWAYS_INLINE write_unformatted_body(const char *text, size_t len) {
|
||||
const int room = this->body_room_();
|
||||
if (room > 0) {
|
||||
const uint16_t limit = room - 1; // vsnprintf() keeps the last byte for the null terminator
|
||||
const uint16_t copy_len = (len < limit) ? static_cast<uint16_t>(len) : limit;
|
||||
memcpy(this->current_(), text, copy_len);
|
||||
this->pos += copy_len;
|
||||
this->strip_trailing_newlines_();
|
||||
this->write_ansi_reset_();
|
||||
}
|
||||
this->finalize_();
|
||||
}
|
||||
// write_unformatted_body() for a message in flash
|
||||
inline void HOT ESPHOME_ALWAYS_INLINE write_unformatted_body_p(ESPHOME_PGM_P text) {
|
||||
if (!this->full_()) {
|
||||
const int room = this->body_room_();
|
||||
if (room > 0) {
|
||||
char *const start = this->current_();
|
||||
this->pos = static_cast<uint16_t>(progmem_copy_str(start, start + this->remaining_() - 1, text) - this->data);
|
||||
this->pos = static_cast<uint16_t>(progmem_copy_str(start, start + room - 1, text) - this->data);
|
||||
this->strip_trailing_newlines_();
|
||||
this->write_ansi_reset_();
|
||||
}
|
||||
this->finalize_();
|
||||
}
|
||||
@@ -151,58 +157,59 @@ struct LogBuffer {
|
||||
*p++ = ' ';
|
||||
this->pos = static_cast<uint16_t>(p - this->data);
|
||||
}
|
||||
void write_body(const char *text, uint16_t text_length) {
|
||||
const uint16_t available = this->remaining_();
|
||||
const uint16_t copy_len = (text_length < available) ? text_length : available;
|
||||
if (copy_len > 0) {
|
||||
memcpy(this->current_(), text, copy_len);
|
||||
this->pos += copy_len;
|
||||
}
|
||||
this->finalize_();
|
||||
// Same as write_unformatted_body(), for the boot replay and the task log buffer
|
||||
#ifdef USE_ESP8266
|
||||
// No task log buffer here, so the boot replay is the only caller and takes it inline
|
||||
void write_body(const char *text, uint16_t text_length) { this->write_unformatted_body(text, text_length); }
|
||||
#else
|
||||
// One out-of-line copy shared by both callers
|
||||
void __attribute__((noinline)) write_body(const char *text, uint16_t text_length) {
|
||||
this->write_unformatted_body(text, text_length);
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool full_() const { return this->pos >= this->size; }
|
||||
uint16_t remaining_() const { return this->size - this->pos; }
|
||||
// Room for the body and its null terminator with the color reset behind it; 0 or less when there is none
|
||||
int body_room_() const { return this->remaining_() - ANSI_RESET_LEN; }
|
||||
char *current_() { return this->data + this->pos; }
|
||||
void finalize_() {
|
||||
this->write_ansi_reset_();
|
||||
// Null terminate
|
||||
this->data[this->full_() ? this->size - 1 : this->pos] = '\0';
|
||||
}
|
||||
// Write ANSI reset sequence inline ("\033[0m") - avoids write_() call overhead
|
||||
void write_ansi_reset_() {
|
||||
if (this->remaining_() >= ANSI_RESET_LEN) {
|
||||
char *p = this->current_();
|
||||
*p++ = '\033';
|
||||
*p++ = '[';
|
||||
*p++ = '0';
|
||||
*p++ = 'm';
|
||||
this->pos += ANSI_RESET_LEN;
|
||||
}
|
||||
// The body starts inside the buffer (write_header() needs MAX_HEADER_SIZE free) and the body writers keep a byte
|
||||
// for the terminator, so pos is inside the buffer here
|
||||
inline void ESPHOME_ALWAYS_INLINE finalize_() { this->data[this->pos] = '\0'; }
|
||||
// Write ANSI reset sequence inline ("\033[0m"); forced inline, since it runs on every log line
|
||||
// Callers have checked body_room_(), which keeps space for the reset and the terminator after it
|
||||
inline void ESPHOME_ALWAYS_INLINE write_ansi_reset_() {
|
||||
char *p = this->current_();
|
||||
*p++ = '\033';
|
||||
*p++ = '[';
|
||||
*p++ = '0';
|
||||
*p++ = 'm';
|
||||
this->pos += ANSI_RESET_LEN;
|
||||
}
|
||||
// Forced inline: an outlined copy slows every formatted line
|
||||
inline void ESPHOME_ALWAYS_INLINE strip_trailing_newlines_() {
|
||||
while (this->pos > 0 && this->data[this->pos - 1] == '\n')
|
||||
this->pos--;
|
||||
}
|
||||
void process_vsnprintf_result_(int ret) {
|
||||
if (ret < 0)
|
||||
return;
|
||||
const uint16_t rem = this->remaining_();
|
||||
this->pos += (ret >= rem) ? (rem - 1) : static_cast<uint16_t>(ret);
|
||||
this->strip_trailing_newlines_();
|
||||
void process_vsnprintf_result_(int ret, int room) {
|
||||
if (ret >= 0) {
|
||||
this->pos += (ret >= room) ? (room - 1) : ret;
|
||||
this->strip_trailing_newlines_();
|
||||
}
|
||||
this->write_ansi_reset_();
|
||||
}
|
||||
void format_vsnprintf_(const char *format, va_list args) {
|
||||
if (this->full_())
|
||||
const int room = this->body_room_();
|
||||
if (room <= 0)
|
||||
return;
|
||||
this->process_vsnprintf_result_(vsnprintf(this->current_(), this->remaining_(), format, args));
|
||||
this->process_vsnprintf_result_(vsnprintf(this->current_(), room, format, args), room);
|
||||
}
|
||||
#ifdef USE_ESP8266
|
||||
void format_vsnprintf_p_(PGM_P format, va_list args) {
|
||||
if (this->full_())
|
||||
const int room = this->body_room_();
|
||||
if (room <= 0)
|
||||
return;
|
||||
this->process_vsnprintf_result_(vsnprintf_P(this->current_(), this->remaining_(), format, args));
|
||||
this->process_vsnprintf_result_(vsnprintf_P(this->current_(), room, format, args), room);
|
||||
}
|
||||
#endif
|
||||
// Extract one decimal digit via subtraction (no division - important for ESP8266)
|
||||
@@ -230,17 +237,18 @@ struct LogBuffer {
|
||||
return p;
|
||||
}
|
||||
// Copies str unchecked and without its null terminator, so the caller reserves space; returns the new end
|
||||
static char *copy_string(char *p, const char *str) {
|
||||
// Copies at most max_len bytes, so the header stays within MAX_HEADER_SIZE and the body starts inside the buffer
|
||||
static char *copy_string(char *p, const char *str, size_t max_len) {
|
||||
#ifdef USE_ESP8266
|
||||
// Only ESP8266 caps the length; tags may be in PROGMEM, so read each byte once
|
||||
for (size_t i = 0; i < MAX_TAG_LENGTH; i++) {
|
||||
// Tags may be in PROGMEM, so read each byte once
|
||||
for (size_t i = 0; i < max_len; i++) {
|
||||
const char c = static_cast<char>(progmem_read_byte(reinterpret_cast<const uint8_t *>(str + i)));
|
||||
if (c == '\0')
|
||||
break;
|
||||
*p++ = c;
|
||||
}
|
||||
#else
|
||||
const size_t len = strlen(str);
|
||||
const size_t len = strnlen(str, max_len);
|
||||
memcpy(p, str, len); // NOLINT(bugprone-not-null-terminated-result) - the header is built piece by piece
|
||||
p += len;
|
||||
#endif
|
||||
|
||||
@@ -9,7 +9,7 @@ void HOT Logger::write_msg_(const char *msg, uint16_t len) {
|
||||
char buffer[TIMESTAMP_LEN + ESPHOME_LOGGER_TX_BUFFER_SIZE + HEADROOM];
|
||||
|
||||
time_t rawtime;
|
||||
::time(&rawtime);
|
||||
time(&rawtime);
|
||||
struct tm timeinfo;
|
||||
localtime_r(&rawtime, &timeinfo); // Thread-safe version
|
||||
size_t pos = strftime(buffer, TIMESTAMP_LEN + 1, "[%H:%M:%S]", &timeinfo);
|
||||
|
||||
@@ -323,17 +323,12 @@ bool MQTTClientComponent::can_proceed() {
|
||||
}
|
||||
|
||||
void MQTTClientComponent::start_dnslookup_() {
|
||||
this->status_set_warning();
|
||||
// No lookup can start before the network is up: there is no DNS server to ask yet.
|
||||
// Stay disconnected, and loop() calls this again.
|
||||
if (!network::is_connected())
|
||||
return;
|
||||
|
||||
for (auto &subscription : this->subscriptions_) {
|
||||
subscription.subscribed = false;
|
||||
subscription.resubscribe_timeout = 0;
|
||||
}
|
||||
|
||||
this->status_set_warning();
|
||||
this->dns_resolve_error_ = false;
|
||||
this->dns_resolved_ = false;
|
||||
ip_addr_t addr;
|
||||
@@ -363,13 +358,9 @@ void MQTTClientComponent::start_dnslookup_() {
|
||||
}
|
||||
default:
|
||||
case ERR_ARG: {
|
||||
// The lookup never started, so there is no answer to wait for; loop() tries again in 5 seconds
|
||||
// error
|
||||
ESP_LOGW(TAG, "Error resolving broker IP address: %d", err);
|
||||
this->state_ = MQTT_CLIENT_DISCONNECTED;
|
||||
this->disconnect_reason_ = MQTTClientDisconnectReason::DNS_RESOLVE_ERROR;
|
||||
this->on_disconnect_.call(MQTTClientDisconnectReason::DNS_RESOLVE_ERROR);
|
||||
this->connect_begin_ = millis();
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from collections.abc import Callable
|
||||
import logging
|
||||
|
||||
from esphome import automation
|
||||
import esphome.codegen as cg
|
||||
@@ -9,8 +8,6 @@ import esphome.config_validation as cv
|
||||
from esphome.const import CONF_DURATION, CONF_ID, CONF_MODE, CONF_VOLTAGE
|
||||
from esphome.types import ConfigType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CODEOWNERS = ["@tomaszduda23"]
|
||||
DEPENDENCIES = ["i2c"]
|
||||
DOMAIN = "npm1300"
|
||||
@@ -45,18 +42,20 @@ NPM1300_CHILD_SCHEMA = cv.Schema(
|
||||
{cv.GenerateID(CONF_NPM1300_ID): cv.use_id(NPM1300Component)}
|
||||
)
|
||||
|
||||
NPM1300Status = npm1300_ns.struct("NPM1300Status")
|
||||
# The status registers read on each update
|
||||
# Status registers read on each update: VBUSINSTATUS, BCHGCHARGESTATUS and BCHGERRREASON
|
||||
STATUS_PUBLISHER = cg.HubFunction(
|
||||
"status",
|
||||
cg.void,
|
||||
[(NPM1300Status.operator("const").operator("ref"), "status")],
|
||||
[
|
||||
(cg.uint8, "vbus_status"),
|
||||
(cg.uint8, "charge_status"),
|
||||
(cg.uint8, "error_reason"),
|
||||
],
|
||||
define="USE_NPM1300_STATUS_PUBLISHER",
|
||||
)
|
||||
STATUS = STATUS_PUBLISHER.param("status")
|
||||
VBUS_STATUS = STATUS.vbus
|
||||
CHARGE_STATUS = STATUS.charge
|
||||
ERROR_REASON = STATUS.error_reason
|
||||
VBUS_STATUS = STATUS_PUBLISHER.param("vbus_status")
|
||||
CHARGE_STATUS = STATUS_PUBLISHER.param("charge_status")
|
||||
ERROR_REASON = STATUS_PUBLISHER.param("error_reason")
|
||||
# The ADC results and the amperes per code of the battery current
|
||||
DATA_PUBLISHER = cg.HubFunction(
|
||||
"data",
|
||||
@@ -78,10 +77,7 @@ OUTPUTS = NPM1300Output.options(
|
||||
# Written for a field the YAML leaves out
|
||||
NPM1300_UNSET = 0xFF
|
||||
# ADCNTCRSEL codes, by kiloohms
|
||||
THERMISTOR_NONE = "none"
|
||||
THERMISTOR_RESISTANCES = {10: 1, 47: 2, 100: 3}
|
||||
# B25/50 of the thermistors the product specification lists for each resistance, by kiloohms
|
||||
THERMISTOR_BETAS = {10: 3380, 47: 4050, 100: 4250}
|
||||
LDO_MODES = {"load_switch": 0, "ldo": 1}
|
||||
TERMINATION_CURRENTS = {"10%": 0, "20%": 1}
|
||||
# BCHGVTRICKLESEL, by millivolts
|
||||
@@ -105,13 +101,14 @@ def _one_of_units(
|
||||
validator: Callable[[object], float],
|
||||
allowed: list[int],
|
||||
unit: str,
|
||||
scale: float = 1000,
|
||||
) -> Callable[[object], float]:
|
||||
"""Validate a quantity with `validator` and accept only the listed values, given in thousandths of `unit`."""
|
||||
"""Validate a quantity with `validator` and accept only the listed values, given in units * `scale`."""
|
||||
|
||||
def validate(value: object) -> float:
|
||||
value = validator(value)
|
||||
if _millis(value) not in allowed:
|
||||
options = ", ".join(f"{v / 1000:g}{unit}" for v in allowed)
|
||||
if round(value * scale) not in allowed:
|
||||
options = ", ".join(f"{v / scale:g}{unit}" for v in allowed)
|
||||
raise cv.Invalid(f"Must be one of {options}")
|
||||
return value
|
||||
|
||||
@@ -138,23 +135,6 @@ def _stepped(
|
||||
return validate
|
||||
|
||||
|
||||
def _thermistor_resistance(value: object) -> float | str:
|
||||
if isinstance(value, str) and value.lower() == THERMISTOR_NONE:
|
||||
return THERMISTOR_NONE
|
||||
value = cv.resistance(value)
|
||||
if round(value) not in (kilohms * 1000 for kilohms in THERMISTOR_RESISTANCES):
|
||||
options = ", ".join(f"{kilohms}kOhm" for kilohms in THERMISTOR_RESISTANCES)
|
||||
raise cv.Invalid(f"Must be one of {options} or {THERMISTOR_NONE}")
|
||||
return value
|
||||
|
||||
|
||||
def thermistor_beta(config: ConfigType) -> int:
|
||||
"""The B constant of the hub's thermistor: the configured one, or the one listed for its resistance."""
|
||||
if (beta := config.get(CONF_THERMISTOR_BETA)) is not None:
|
||||
return beta
|
||||
return THERMISTOR_BETAS[round(config[CONF_THERMISTOR_RESISTANCE] / 1000)]
|
||||
|
||||
|
||||
OUTPUT_VOLTAGE = _stepped(cv.voltage, 1000, 3300, 100, "V")
|
||||
VBUS_CURRENT_LIMIT = _stepped(cv.current, 100, 1500, 100, "A")
|
||||
|
||||
@@ -170,58 +150,15 @@ LDO_SCHEMA = BUCK_SCHEMA.extend(
|
||||
}
|
||||
)
|
||||
|
||||
WARM_TERMINATION_VOLTAGE_DEFAULT = 3.6
|
||||
|
||||
|
||||
def _warm_termination_default(config: ConfigType) -> ConfigType:
|
||||
"""Keep the default warm termination voltage at or below the termination voltage.
|
||||
|
||||
Warn when the default stays below a higher termination voltage.
|
||||
"""
|
||||
if (
|
||||
not isinstance(config, dict)
|
||||
or CONF_WARM_TERMINATION_VOLTAGE in config
|
||||
or CONF_TERMINATION_VOLTAGE not in config
|
||||
):
|
||||
return config
|
||||
try:
|
||||
termination = cv.voltage(config[CONF_TERMINATION_VOLTAGE])
|
||||
except cv.Invalid:
|
||||
# The schema reports it
|
||||
return config
|
||||
if termination < WARM_TERMINATION_VOLTAGE_DEFAULT - 0.001:
|
||||
# A warm battery is never charged higher than a cool one
|
||||
return {
|
||||
**config,
|
||||
CONF_WARM_TERMINATION_VOLTAGE: config[CONF_TERMINATION_VOLTAGE],
|
||||
}
|
||||
if termination > WARM_TERMINATION_VOLTAGE_DEFAULT + 0.001:
|
||||
_LOGGER.warning(
|
||||
"npm1300 '%s' is not set, so a warm battery (45 °C to 60 °C by default) stops "
|
||||
"charging at %.2fV instead of the %.2fV of '%s'. Set '%s' to the value your "
|
||||
"battery allows when warm",
|
||||
CONF_WARM_TERMINATION_VOLTAGE,
|
||||
WARM_TERMINATION_VOLTAGE_DEFAULT,
|
||||
termination,
|
||||
CONF_TERMINATION_VOLTAGE,
|
||||
CONF_WARM_TERMINATION_VOLTAGE,
|
||||
)
|
||||
return config
|
||||
|
||||
|
||||
_CHARGER_SETTINGS_SCHEMA = cv.Schema(
|
||||
CHARGER_SCHEMA = cv.Schema(
|
||||
{
|
||||
# Defaults are the reset values of the product specification
|
||||
cv.Optional(CONF_CHARGE_CURRENT, default="32mA"): _stepped(
|
||||
cv.current, 32, 800, 2, "A"
|
||||
cv.Required(CONF_CHARGE_CURRENT): _stepped(cv.current, 32, 800, 2, "A"),
|
||||
cv.Optional(CONF_TERMINATION_VOLTAGE, default="4.2V"): _one_of_units(
|
||||
cv.voltage, TERMINATION_VOLTAGES, "V"
|
||||
),
|
||||
cv.Optional(CONF_TERMINATION_VOLTAGE, default="3.6V"): _one_of_units(
|
||||
cv.Optional(CONF_WARM_TERMINATION_VOLTAGE): _one_of_units(
|
||||
cv.voltage, TERMINATION_VOLTAGES, "V"
|
||||
),
|
||||
cv.Optional(
|
||||
CONF_WARM_TERMINATION_VOLTAGE,
|
||||
default=f"{WARM_TERMINATION_VOLTAGE_DEFAULT}V",
|
||||
): _one_of_units(cv.voltage, TERMINATION_VOLTAGES, "V"),
|
||||
cv.Optional(CONF_TERMINATION_CURRENT, default="10%"): cv.enum(
|
||||
TERMINATION_CURRENTS
|
||||
),
|
||||
@@ -232,37 +169,22 @@ _CHARGER_SETTINGS_SCHEMA = cv.Schema(
|
||||
cv.current, list(DISCHARGE_CURRENT_LIMITS), "A"
|
||||
),
|
||||
cv.Optional(CONF_RECHARGE, default=True): cv.boolean,
|
||||
cv.Optional(CONF_ENABLED, default=False): cv.boolean,
|
||||
cv.Optional(CONF_ENABLED, default=True): cv.boolean,
|
||||
}
|
||||
)
|
||||
CHARGER_SCHEMA = cv.All(_warm_termination_default, _CHARGER_SETTINGS_SCHEMA)
|
||||
|
||||
|
||||
def _check_thermistor(config: ConfigType) -> ConfigType:
|
||||
"""A wrong thermistor shifts the battery temperature the charger sees, so charging needs one chosen."""
|
||||
resistance = config.get(CONF_THERMISTOR_RESISTANCE)
|
||||
if CONF_CHARGER in config and resistance is None:
|
||||
raise cv.Invalid(
|
||||
f"'{CONF_THERMISTOR_RESISTANCE}' is required with '{CONF_CHARGER}': set the nominal "
|
||||
f"resistance of the battery thermistor, or '{THERMISTOR_NONE}'",
|
||||
path=[CONF_THERMISTOR_RESISTANCE],
|
||||
)
|
||||
if CONF_THERMISTOR_BETA in config and resistance in (None, THERMISTOR_NONE):
|
||||
raise cv.Invalid(
|
||||
f"'{CONF_THERMISTOR_BETA}' needs '{CONF_THERMISTOR_RESISTANCE}' set to the "
|
||||
"resistance of the thermistor",
|
||||
path=[CONF_THERMISTOR_BETA],
|
||||
)
|
||||
return config
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(NPM1300Component),
|
||||
cv.Optional(CONF_VBUS_CURRENT_LIMIT): VBUS_CURRENT_LIMIT,
|
||||
cv.Optional(CONF_THERMISTOR_RESISTANCE): _thermistor_resistance,
|
||||
cv.Optional(CONF_THERMISTOR_BETA): cv.int_range(min=1, max=65535),
|
||||
cv.Optional(CONF_THERMISTOR_RESISTANCE): _one_of_units(
|
||||
cv.resistance, list(THERMISTOR_RESISTANCES), "kOhm", scale=0.001
|
||||
),
|
||||
cv.Optional(CONF_THERMISTOR_BETA, default=3380): cv.int_range(
|
||||
min=1, max=65535
|
||||
),
|
||||
cv.Optional(CONF_CHARGER): CHARGER_SCHEMA,
|
||||
cv.Optional(CONF_BUCK1): BUCK_SCHEMA,
|
||||
cv.Optional(CONF_BUCK2): BUCK_SCHEMA,
|
||||
@@ -271,8 +193,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s"))
|
||||
.extend(i2c.i2c_device_schema(0x6B)),
|
||||
_check_thermistor,
|
||||
.extend(i2c.i2c_device_schema(0x6B))
|
||||
)
|
||||
|
||||
|
||||
@@ -287,7 +208,7 @@ def _vbus_current_limit_code(amps: float) -> int:
|
||||
|
||||
def _charger_config(config: ConfigType) -> cg.StructInitializer:
|
||||
termination = _termination_voltage_code(config[CONF_TERMINATION_VOLTAGE])
|
||||
warm = _termination_voltage_code(config[CONF_WARM_TERMINATION_VOLTAGE])
|
||||
warm = config.get(CONF_WARM_TERMINATION_VOLTAGE)
|
||||
return cg.StructInitializer(
|
||||
NPM1300ChargerConfig,
|
||||
("current", _millis(config[CONF_CHARGE_CURRENT]) // 2),
|
||||
@@ -296,7 +217,10 @@ def _charger_config(config: ConfigType) -> cg.StructInitializer:
|
||||
DISCHARGE_CURRENT_LIMITS[_millis(config[CONF_DISCHARGE_CURRENT_LIMIT])],
|
||||
),
|
||||
("termination_voltage", termination),
|
||||
("warm_termination_voltage", warm),
|
||||
(
|
||||
"warm_termination_voltage",
|
||||
termination if warm is None else _termination_voltage_code(warm),
|
||||
),
|
||||
("trickle_voltage", TRICKLE_VOLTAGES[_millis(config[CONF_TRICKLE_VOLTAGE])]),
|
||||
("termination_current", TERMINATION_CURRENTS[config[CONF_TERMINATION_CURRENT]]),
|
||||
("recharge", config[CONF_RECHARGE]),
|
||||
@@ -323,13 +247,6 @@ def _output_config(config: ConfigType | None) -> cg.StructInitializer:
|
||||
def _config(config: ConfigType) -> cg.StructInitializer:
|
||||
charger = config.get(CONF_CHARGER)
|
||||
resistance = config.get(CONF_THERMISTOR_RESISTANCE)
|
||||
if resistance is None:
|
||||
thermistor, beta = NPM1300_UNSET, 0
|
||||
elif resistance == THERMISTOR_NONE:
|
||||
thermistor, beta = 0, 0
|
||||
else:
|
||||
thermistor = THERMISTOR_RESISTANCES[round(resistance / 1000)]
|
||||
beta = thermistor_beta(config)
|
||||
return cg.StructInitializer(
|
||||
NPM1300Config,
|
||||
(
|
||||
@@ -337,8 +254,13 @@ def _config(config: ConfigType) -> cg.StructInitializer:
|
||||
cg.ArrayInitializer(*(_output_config(config.get(key)) for key in OUTPUTS)),
|
||||
),
|
||||
("charger", None if charger is None else _charger_config(charger)),
|
||||
("thermistor_beta", beta),
|
||||
("thermistor", thermistor),
|
||||
("thermistor_beta", config[CONF_THERMISTOR_BETA]),
|
||||
(
|
||||
"thermistor",
|
||||
NPM1300_UNSET
|
||||
if resistance is None
|
||||
else THERMISTOR_RESISTANCES[round(resistance / 1000)],
|
||||
),
|
||||
("charger_configured", charger is not None),
|
||||
)
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ static constexpr uint16_t REG_BCHG_VTERM = 0x030C;
|
||||
static constexpr uint16_t REG_BCHG_VTERM_R = 0x030D;
|
||||
static constexpr uint16_t REG_BCHG_VTRICKLE_SEL = 0x030E;
|
||||
static constexpr uint16_t REG_BCHG_ITERM_SEL = 0x030F;
|
||||
static constexpr uint16_t REG_BCHG_NTC_STATUS = 0x0332;
|
||||
static constexpr uint16_t REG_BCHG_CHARGE_STATUS = 0x0334;
|
||||
static constexpr uint16_t REG_BCHG_ERR_REASON = 0x0336;
|
||||
static constexpr uint16_t REG_BUCK1_ENA_SET = 0x0400;
|
||||
@@ -54,9 +53,6 @@ static constexpr uint16_t REG_SHIP_TASK_SHIP_MODE = 0x0B02;
|
||||
|
||||
// VBUSINSTATUS
|
||||
static constexpr uint8_t VBUS_PRESENT = 0x01;
|
||||
// NTCSTATUS
|
||||
static constexpr uint8_t NTC_STATUS_COLD = 0x01;
|
||||
static constexpr uint8_t NTC_STATUS_HOT = 0x08;
|
||||
// BCHGCHARGESTATUS; bit 0 (battery detected) is reserved since C00 silicon
|
||||
static constexpr uint8_t CHARGE_STATUS_COMPLETED = 0x02;
|
||||
static constexpr uint8_t CHARGE_STATUS_TRICKLE = 0x04;
|
||||
@@ -111,36 +107,26 @@ float ntc_temperature(uint16_t code, float inv_beta) {
|
||||
#endif
|
||||
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
PROGMEM_STRING_TABLE(ChargerStatusStrings, "Discharging", "Error", "Disabled", "Paused, PMIC Too Hot",
|
||||
"Charge Complete", "Trickle Charge", "Constant Current", "Constant Voltage",
|
||||
"Paused, Battery Too Cold", "Paused, Battery Too Hot", "Not Charging");
|
||||
static constexpr uint8_t CHARGER_STATUS_FIRST_BIT = 3;
|
||||
// BCHGCHARGESTATUS bits in order of priority, reported from string CHARGER_STATUS_FIRST_BIT on
|
||||
PROGMEM_STRING_TABLE(ChargerStatusStrings, "Error", "Paused, Die Too Hot", "Charge Complete", "Trickle Charge",
|
||||
"Constant Current", "Constant Voltage", "Discharging", "Not Charging");
|
||||
// BCHGCHARGESTATUS bits in order of priority; bit i is reported as string i + 1
|
||||
static const uint8_t CHARGER_STATUS_BITS[] PROGMEM = {CHARGE_STATUS_DIE_TEMP_HIGH, CHARGE_STATUS_COMPLETED,
|
||||
CHARGE_STATUS_TRICKLE, CHARGE_STATUS_CONSTANT_CURRENT,
|
||||
CHARGE_STATUS_CONSTANT_VOLTAGE};
|
||||
|
||||
static uint8_t charger_status_index(const NPM1300Status &status) {
|
||||
if ((status.vbus & VBUS_PRESENT) == 0)
|
||||
static uint8_t charger_status_index(uint8_t vbus_status, uint8_t charge_status, uint8_t error_reason) {
|
||||
if (error_reason != 0)
|
||||
return 0;
|
||||
if (status.error_reason != 0)
|
||||
return 1;
|
||||
if ((status.charger_enable & 1) == 0)
|
||||
return 2;
|
||||
for (size_t i = 0; i < sizeof(CHARGER_STATUS_BITS); i++) {
|
||||
if ((status.charge & progmem_read_byte(&CHARGER_STATUS_BITS[i])) != 0)
|
||||
return CHARGER_STATUS_FIRST_BIT + i;
|
||||
if ((charge_status & progmem_read_byte(&CHARGER_STATUS_BITS[i])) != 0)
|
||||
return i + 1;
|
||||
}
|
||||
// The charger stops without an error outside the cold and hot limits of the battery temperature
|
||||
if ((status.ntc & NTC_STATUS_COLD) != 0)
|
||||
return 8;
|
||||
if ((status.ntc & NTC_STATUS_HOT) != 0)
|
||||
return 9;
|
||||
return 10;
|
||||
return (vbus_status & VBUS_PRESENT) == 0 ? 6 : 7;
|
||||
}
|
||||
|
||||
void publish_charger_status(text_sensor::TextSensor *sensor, uint8_t &last, const NPM1300Status &status) {
|
||||
const uint8_t index = charger_status_index(status);
|
||||
void publish_charger_status(text_sensor::TextSensor *sensor, uint8_t &last, uint8_t vbus_status, uint8_t charge_status,
|
||||
uint8_t error_reason) {
|
||||
const uint8_t index = charger_status_index(vbus_status, charge_status, error_reason);
|
||||
if (index == last)
|
||||
return;
|
||||
last = index;
|
||||
@@ -212,7 +198,7 @@ bool NPM1300Component::configure_charger_(const NPM1300Config &config) {
|
||||
split_9bit(charger.discharge_limit, discharge);
|
||||
uint8_t disable = charger.recharge ? 0 : CHARGER_DISABLE_RECHARGE;
|
||||
// Without a thermistor the charger reports an NTC error and does not charge
|
||||
if (config.thermistor == 0 || config.thermistor == NPM1300_UNSET)
|
||||
if (config.thermistor == NPM1300_UNSET)
|
||||
disable |= CHARGER_DISABLE_NTC;
|
||||
const uint8_t enable = (CHARGER_DISABLE_RECHARGE | CHARGER_DISABLE_NTC) & ~disable;
|
||||
if (this->write_register16(REG_BCHG_ISET_MSB, current, sizeof(current)) != i2c::ERROR_OK ||
|
||||
@@ -306,40 +292,33 @@ void NPM1300Component::hibernate(uint32_t duration_ms) {
|
||||
}
|
||||
|
||||
void NPM1300Component::update() {
|
||||
NPM1300Status status;
|
||||
// NTCSTATUS, DIETEMPSTATUS and BCHGCHARGESTATUS
|
||||
uint8_t charger_status[3];
|
||||
if (!this->status_comm_check(this->read_byte_reg16(REG_VBUSIN_STATUS, &status.vbus) &&
|
||||
this->read_byte_reg16(REG_BCHG_ENABLE_SET, &status.charger_enable) &&
|
||||
this->read_register16(REG_BCHG_NTC_STATUS, charger_status, sizeof(charger_status)) ==
|
||||
i2c::ERROR_OK &&
|
||||
this->read_byte_reg16(REG_BCHG_ERR_REASON, &status.error_reason)))
|
||||
uint8_t vbus_status;
|
||||
uint8_t charge_status;
|
||||
uint8_t error_reason;
|
||||
if (!this->status_comm_check(this->read_byte_reg16(REG_VBUSIN_STATUS, &vbus_status) &&
|
||||
this->read_byte_reg16(REG_BCHG_CHARGE_STATUS, &charge_status) &&
|
||||
this->read_byte_reg16(REG_BCHG_ERR_REASON, &error_reason)))
|
||||
return;
|
||||
status.ntc = charger_status[0];
|
||||
status.charge = charger_status[2];
|
||||
// Without a thermistor the NTC pin is grounded and can read as a hot battery
|
||||
if (progmem_read_byte(&this->config_->thermistor) == 0)
|
||||
status.ntc = 0;
|
||||
|
||||
// The chip goes back to its default VBUS current limit whenever VBUS is removed
|
||||
const bool vbus_present = (status.vbus & VBUS_PRESENT) != 0;
|
||||
const bool vbus_present = (vbus_status & VBUS_PRESENT) != 0;
|
||||
if (vbus_present && !this->vbus_present_ && this->vbus_current_limit_ != NPM1300_UNSET &&
|
||||
!this->status_comm_check(this->apply_vbus_current_limit_()))
|
||||
return;
|
||||
this->vbus_present_ = vbus_present;
|
||||
|
||||
if (status.error_reason != this->last_error_reason_) {
|
||||
this->last_error_reason_ = status.error_reason;
|
||||
if (status.error_reason != 0) {
|
||||
ESP_LOGW(TAG, "Charger error, BCHGERRREASON 0x%02X", status.error_reason);
|
||||
if (error_reason != this->last_error_reason_) {
|
||||
this->last_error_reason_ = error_reason;
|
||||
if (error_reason != 0) {
|
||||
ESP_LOGW(TAG, "Charger error, BCHGERRREASON 0x%02X", error_reason);
|
||||
}
|
||||
}
|
||||
#ifdef USE_NPM1300_STATUS_PUBLISHER
|
||||
if (this->status_publisher_ != nullptr)
|
||||
this->status_publisher_(status);
|
||||
this->status_publisher_(vbus_status, charge_status, error_reason);
|
||||
#endif
|
||||
#ifdef USE_SWITCH
|
||||
if (!this->status_comm_check(this->publish_switches_(status)))
|
||||
if (!this->status_comm_check(this->publish_switches_()))
|
||||
return;
|
||||
#endif
|
||||
|
||||
@@ -369,10 +348,16 @@ void NPM1300Component::update() {
|
||||
}
|
||||
|
||||
#ifdef USE_SWITCH
|
||||
bool NPM1300Component::publish_switches_(const NPM1300Status &status) {
|
||||
PUBLISH_STATE(this->charger_switch_, (status.charger_enable & 1) != 0);
|
||||
bool NPM1300Component::publish_switches_() {
|
||||
uint8_t value;
|
||||
bool ok = true;
|
||||
if (this->charger_switch_ != nullptr) {
|
||||
if (this->read_byte_reg16(REG_BCHG_ENABLE_SET, &value)) {
|
||||
this->charger_switch_->publish_state((value & 1) != 0);
|
||||
} else {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
switch_::Switch *const bucks[2] = {this->buck1_switch_, this->buck2_switch_};
|
||||
if (bucks[0] != nullptr || bucks[1] != nullptr) {
|
||||
if (this->read_byte_reg16(REG_BUCK_STATUS, &value)) {
|
||||
@@ -476,9 +461,7 @@ void NPM1300Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, " Enabled at boot: %s", YESNO(output.enabled != 0));
|
||||
}
|
||||
}
|
||||
if (config.thermistor == 0) {
|
||||
ESP_LOGCONFIG(TAG, " Thermistor: none");
|
||||
} else if (config.thermistor != NPM1300_UNSET) {
|
||||
if (config.thermistor != NPM1300_UNSET) {
|
||||
ESP_LOGCONFIG(TAG, " Thermistor B constant: %u", config.thermistor_beta);
|
||||
}
|
||||
#ifdef USE_SENSOR
|
||||
|
||||
@@ -54,19 +54,10 @@ struct NPM1300Config {
|
||||
NPM1300OutputConfig outputs[NPM1300_OUTPUT_COUNT];
|
||||
NPM1300ChargerConfig charger; // only applied when charger_configured
|
||||
uint16_t thermistor_beta;
|
||||
uint8_t thermistor; // ADCNTCRSEL code: 0 for none, 1 for 10 kOhm, 2 for 47 kOhm, 3 for 100 kOhm, or NPM1300_UNSET
|
||||
uint8_t thermistor; // ADCNTCRSEL code: 1 for 10 kOhm, 2 for 47 kOhm, 3 for 100 kOhm, or NPM1300_UNSET
|
||||
bool charger_configured;
|
||||
};
|
||||
|
||||
/// The status registers read on every update
|
||||
struct NPM1300Status {
|
||||
uint8_t vbus; // VBUSINSTATUS
|
||||
uint8_t charger_enable; // BCHGENABLESET
|
||||
uint8_t ntc; // NTCSTATUS
|
||||
uint8_t charge; // BCHGCHARGESTATUS
|
||||
uint8_t error_reason; // BCHGERRREASON
|
||||
};
|
||||
|
||||
#ifdef USE_NPM1300_DATA_PUBLISHER
|
||||
/// The 10-bit ADC result whose high 8 bits are adc[msb] and low 2 bits are at `shift` in adc[lsbs]
|
||||
inline uint16_t adc_code(const uint8_t *adc, uint8_t msb, uint8_t lsbs, uint8_t shift) {
|
||||
@@ -77,7 +68,8 @@ float ntc_temperature(uint16_t code, float inv_beta);
|
||||
#endif
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
/// Publish the charger status text, only when it differs from `last`
|
||||
void publish_charger_status(text_sensor::TextSensor *sensor, uint8_t &last, const NPM1300Status &status);
|
||||
void publish_charger_status(text_sensor::TextSensor *sensor, uint8_t &last, uint8_t vbus_status, uint8_t charge_status,
|
||||
uint8_t error_reason);
|
||||
#endif
|
||||
|
||||
class NPM1300Component : public PollingComponent, public i2c::I2CDevice {
|
||||
@@ -103,7 +95,7 @@ class NPM1300Component : public PollingComponent, public i2c::I2CDevice {
|
||||
float get_setup_priority() const override { return setup_priority::BUS - 1.0f; }
|
||||
|
||||
#ifdef USE_NPM1300_STATUS_PUBLISHER
|
||||
HUB_PUBLISHER(status, const NPM1300Status &)
|
||||
HUB_PUBLISHER(status, uint8_t, uint8_t, uint8_t)
|
||||
#endif
|
||||
#ifdef USE_NPM1300_DATA_PUBLISHER
|
||||
HUB_PUBLISHER(data, const uint8_t *, float)
|
||||
@@ -136,7 +128,7 @@ class NPM1300Component : public PollingComponent, public i2c::I2CDevice {
|
||||
#endif
|
||||
#ifdef USE_SWITCH
|
||||
/// Returns false when a status read failed
|
||||
bool publish_switches_(const NPM1300Status &status);
|
||||
bool publish_switches_();
|
||||
#endif
|
||||
|
||||
const NPM1300Config *config_;
|
||||
|
||||
@@ -21,6 +21,7 @@ from esphome.types import ConfigType
|
||||
from . import (
|
||||
ADC,
|
||||
CONF_NPM1300_ID,
|
||||
CONF_THERMISTOR_BETA,
|
||||
CONF_THERMISTOR_RESISTANCE,
|
||||
CONF_VBUS_CURRENT_LIMIT,
|
||||
DATA_PUBLISHER,
|
||||
@@ -29,9 +30,7 @@ from . import (
|
||||
DUMP_TAG,
|
||||
IBAT_SCALE,
|
||||
NPM1300_CHILD_SCHEMA,
|
||||
THERMISTOR_NONE,
|
||||
npm1300_ns,
|
||||
thermistor_beta,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["npm1300"]
|
||||
@@ -110,10 +109,10 @@ def _final_validate(config: ConfigType) -> None:
|
||||
if CONF_BATTERY_TEMPERATURE not in config:
|
||||
return
|
||||
hub = fv.get_declaring_config(config[CONF_NPM1300_ID])
|
||||
if hub.get(CONF_THERMISTOR_RESISTANCE, THERMISTOR_NONE) == THERMISTOR_NONE:
|
||||
if CONF_THERMISTOR_RESISTANCE not in hub:
|
||||
raise cv.Invalid(
|
||||
f"'{CONF_BATTERY_TEMPERATURE}' needs '{CONF_THERMISTOR_RESISTANCE}' set to the "
|
||||
"nominal resistance of the battery thermistor on the npm1300 component",
|
||||
f"'{CONF_BATTERY_TEMPERATURE}' needs '{CONF_THERMISTOR_RESISTANCE}' "
|
||||
"set on the npm1300 component",
|
||||
path=[CONF_BATTERY_TEMPERATURE],
|
||||
)
|
||||
|
||||
@@ -146,7 +145,7 @@ async def to_code(config: ConfigType) -> None:
|
||||
if (var := await sensors(CONF_BATTERY_TEMPERATURE, None)) is not None:
|
||||
hub_config = next(c for c in CORE.config[DOMAIN] if c[CONF_ID] == hub_id)
|
||||
state = npm1300_ns.ntc_temperature(
|
||||
_adc(2, 5, 2), 1.0 / thermistor_beta(hub_config)
|
||||
_adc(2, 5, 2), 1.0 / hub_config[CONF_THERMISTOR_BETA]
|
||||
)
|
||||
_add_adc_sensor(hub, var, state, "Battery Temperature")
|
||||
await sensors(CONF_VBUS_CURRENT_LIMIT, hub.set_vbus_current_limit_sensor)
|
||||
@@ -15,7 +15,6 @@ from . import (
|
||||
CONF_THERMISTOR_RESISTANCE,
|
||||
NPM1300_CHILD_SCHEMA,
|
||||
OUTPUTS,
|
||||
THERMISTOR_NONE,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["npm1300"]
|
||||
@@ -45,18 +44,11 @@ def _final_validate(config: ConfigType) -> None:
|
||||
if CONF_CHARGER not in config:
|
||||
return
|
||||
hub = fv.get_declaring_config(config[CONF_NPM1300_ID])
|
||||
# A wrong thermistor shifts the battery temperature the charger sees
|
||||
if CONF_THERMISTOR_RESISTANCE not in hub:
|
||||
raise cv.Invalid(
|
||||
f"The '{CONF_CHARGER}' switch needs '{CONF_THERMISTOR_RESISTANCE}' on the npm1300 "
|
||||
f"component: the nominal resistance of the battery thermistor, or '{THERMISTOR_NONE}'",
|
||||
path=[CONF_CHARGER],
|
||||
)
|
||||
# Only the charger block turns off the NTC check, without which the charger never starts
|
||||
if CONF_CHARGER not in hub and hub[CONF_THERMISTOR_RESISTANCE] == THERMISTOR_NONE:
|
||||
if CONF_CHARGER not in hub and CONF_THERMISTOR_RESISTANCE not in hub:
|
||||
raise cv.Invalid(
|
||||
f"The '{CONF_CHARGER}' switch needs a '{CONF_CHARGER}' block when "
|
||||
f"'{CONF_THERMISTOR_RESISTANCE}' is '{THERMISTOR_NONE}'",
|
||||
f"The '{CONF_CHARGER}' switch needs a '{CONF_CHARGER}' block or "
|
||||
f"'{CONF_THERMISTOR_RESISTANCE}' on the npm1300 component",
|
||||
path=[CONF_CHARGER],
|
||||
)
|
||||
|
||||
|
||||
@@ -11,12 +11,14 @@ from esphome.cpp_generator import (
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from . import (
|
||||
CHARGE_STATUS,
|
||||
CONF_NPM1300_ID,
|
||||
DUMP,
|
||||
DUMP_TAG,
|
||||
ERROR_REASON,
|
||||
NPM1300_CHILD_SCHEMA,
|
||||
STATUS,
|
||||
STATUS_PUBLISHER,
|
||||
VBUS_STATUS,
|
||||
npm1300_ns,
|
||||
)
|
||||
|
||||
@@ -46,7 +48,9 @@ async def to_code(config: ConfigType) -> None:
|
||||
)
|
||||
STATUS_PUBLISHER.add(
|
||||
hub,
|
||||
npm1300_ns.publish_charger_status(parent_ref(var), last, STATUS),
|
||||
npm1300_ns.publish_charger_status(
|
||||
parent_ref(var), last, VBUS_STATUS, CHARGE_STATUS, ERROR_REASON
|
||||
),
|
||||
)
|
||||
DUMP.add(
|
||||
hub,
|
||||
|
||||
@@ -13,7 +13,6 @@ from esphome.build_helpers.ccache import resolve_ccache_path
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import network
|
||||
from esphome.components.zephyr import (
|
||||
PreferenceStorage,
|
||||
Section,
|
||||
add_extra_script,
|
||||
copy_files as zephyr_copy_files,
|
||||
@@ -107,7 +106,6 @@ from .const import (
|
||||
VARIANT_NRF52832,
|
||||
VARIANT_NRF52840,
|
||||
VARIANT_REGULATOR,
|
||||
VARIANTS_NRF54L,
|
||||
VARIANTS_WITHOUT_USB,
|
||||
)
|
||||
from .framework import (
|
||||
@@ -538,11 +536,6 @@ def _final_validate(config):
|
||||
FINAL_VALIDATE_SCHEMA = _final_validate
|
||||
|
||||
|
||||
def _preferences_storage(variant: str) -> PreferenceStorage:
|
||||
"""The storage for preferences: ZMS on the RRAM of the nRF54L, NVS on flash."""
|
||||
return "ZMS" if variant in VARIANTS_NRF54L else "NVS"
|
||||
|
||||
|
||||
@coroutine_with_priority(CoroPriority.PLATFORM)
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
"""Convert the configuration to code."""
|
||||
@@ -551,7 +544,7 @@ async def to_code(config: ConfigType) -> None:
|
||||
variant = get_nrf52_variant()
|
||||
cg.add_define("ESPHOME_VARIANT", variant)
|
||||
cg.add_build_flag(f"-DUSE_NRF52_VARIANT_{variant}")
|
||||
if variant in VARIANTS_NRF54L:
|
||||
if variant in (VARIANT_NRF54L15, VARIANT_NRF54LM20):
|
||||
# The entropy driver runs on the CRACEN crypto unit, which needs Nordic's PSA crypto
|
||||
include_west_project("mbedtls")
|
||||
include_west_project("oberon-psa-crypto")
|
||||
@@ -619,11 +612,11 @@ async def to_code(config: ConfigType) -> None:
|
||||
if config[KEY_BOOTLOADER] in ADAFRUIT_BOOTLOADERS:
|
||||
cg.add_define("USE_BOOTLOADER_ADAFRUIT")
|
||||
|
||||
zephyr_setup_preferences(_preferences_storage(variant))
|
||||
zephyr_setup_preferences()
|
||||
zephyr_to_code(config)
|
||||
|
||||
# The nRF54L has RRAM (cpuapp_rram) and no flash0 node
|
||||
if CORE.testing_mode and variant not in VARIANTS_NRF54L:
|
||||
if CORE.testing_mode and variant not in (VARIANT_NRF54L15, VARIANT_NRF54LM20):
|
||||
zephyr_add_overlay(
|
||||
f"""
|
||||
&flash0 {{
|
||||
|
||||
@@ -17,7 +17,6 @@ from .const import (
|
||||
VARIANT_NRF54LM20,
|
||||
VARIANT_NRF52832,
|
||||
VARIANT_NRF52840,
|
||||
VARIANTS_NRF54L,
|
||||
)
|
||||
from .framework import (
|
||||
check_and_install,
|
||||
@@ -146,7 +145,7 @@ def upload_using_cmsis_dap(unique_id: str | None = None) -> None:
|
||||
pyocd = [str(paths["python_executable"]), "-m", "pyocd"]
|
||||
probe = ["-t", target] + (["-u", unique_id] if unique_id else [])
|
||||
cmd = [*pyocd, "flash", "--no-wait", *probe, "-e", "sector"]
|
||||
if variant in VARIANTS_NRF54L:
|
||||
if variant in (VARIANT_NRF54L15, VARIANT_NRF54LM20):
|
||||
cmd += ["--script", str(_NRF54L_WATCHDOG_SCRIPT)]
|
||||
cmd += [str(image) for image in images]
|
||||
if not run_command_ok(cmd, env=env, stream_output=True):
|
||||
|
||||
@@ -41,8 +41,6 @@ VARIANT_I2C = {
|
||||
VARIANT_NRF54LM20: VariantI2C("i2c21", (1, 3)),
|
||||
}
|
||||
VARIANTS_WITHOUT_USB = frozenset({VARIANT_NRF52832, VARIANT_NRF54L15})
|
||||
# The nRF54L family: RRAM instead of flash, the CRACEN crypto unit and the wdt31 watchdog
|
||||
VARIANTS_NRF54L = frozenset({VARIANT_NRF54L15, VARIANT_NRF54LM20})
|
||||
# Devicetree label of the main regulator, reg1 on the others
|
||||
VARIANT_REGULATOR = {VARIANT_NRF52832: "reg"}
|
||||
VARIANT_FLASH_SIZE = {VARIANT_NRF52832: 0x80000, VARIANT_NRF52840: 0x100000}
|
||||
|
||||
@@ -15,9 +15,6 @@ namespace esphome::uart {
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "uart");
|
||||
|
||||
// GPIO32-47 (RP2350B) and GPIO64 (CYW43) are in no mask; a 32-bit shift by them is undefined.
|
||||
static constexpr bool pin_in_mask(uint8_t pin, uint32_t mask) { return pin < 32 && (mask & (1U << pin)) != 0; }
|
||||
|
||||
uint16_t RP2UartComponent::get_config() {
|
||||
uint16_t config = 0;
|
||||
|
||||
@@ -84,9 +81,9 @@ void RP2UartComponent::setup() {
|
||||
if (this->tx_pin_->is_inverted()) {
|
||||
ESP_LOGD(TAG, "An inverted TX pin %u can only be used with SerialPIO", this->tx_pin_->get_pin());
|
||||
} else {
|
||||
if (pin_in_mask(this->tx_pin_->get_pin(), valid_tx_uart_0)) {
|
||||
if (((1 << this->tx_pin_->get_pin()) & valid_tx_uart_0) != 0) {
|
||||
tx_hw = 0;
|
||||
} else if (pin_in_mask(this->tx_pin_->get_pin(), valid_tx_uart_1)) {
|
||||
} else if (((1 << this->tx_pin_->get_pin()) & valid_tx_uart_1) != 0) {
|
||||
tx_hw = 1;
|
||||
} else {
|
||||
ESP_LOGD(TAG, "TX pin %u can only be used with SerialPIO", this->tx_pin_->get_pin());
|
||||
@@ -98,9 +95,9 @@ void RP2UartComponent::setup() {
|
||||
if (this->rx_pin_->is_inverted()) {
|
||||
ESP_LOGD(TAG, "An inverted RX pin %u can only be used with SerialPIO", this->rx_pin_->get_pin());
|
||||
} else {
|
||||
if (pin_in_mask(this->rx_pin_->get_pin(), valid_rx_uart_0)) {
|
||||
if (((1 << this->rx_pin_->get_pin()) & valid_rx_uart_0) != 0) {
|
||||
rx_hw = 0;
|
||||
} else if (pin_in_mask(this->rx_pin_->get_pin(), valid_rx_uart_1)) {
|
||||
} else if (((1 << this->rx_pin_->get_pin()) & valid_rx_uart_1) != 0) {
|
||||
rx_hw = 1;
|
||||
} else {
|
||||
ESP_LOGD(TAG, "RX pin %u can only be used with SerialPIO", this->rx_pin_->get_pin());
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
import textwrap
|
||||
from typing import Literal, NamedTuple, TypedDict
|
||||
from typing import NamedTuple, TypedDict
|
||||
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
@@ -212,18 +212,10 @@ async def _cdc_acm_to_code() -> None:
|
||||
_cdc_acm_add_ports()
|
||||
|
||||
|
||||
PreferenceStorage = Literal["NVS", "ZMS"]
|
||||
|
||||
|
||||
def zephyr_setup_preferences(storage: PreferenceStorage = "NVS") -> None:
|
||||
"""Store preferences through the settings subsystem.
|
||||
|
||||
`storage` picks the Zephyr storage backend: NVS for flash, ZMS for RRAM and MRAM.
|
||||
"""
|
||||
def zephyr_setup_preferences() -> None:
|
||||
cg.add(zephyr_ns.setup_preferences())
|
||||
zephyr_add_prj_conf("SETTINGS", True)
|
||||
zephyr_add_prj_conf(storage, True)
|
||||
zephyr_add_prj_conf(f"SETTINGS_{storage}", True)
|
||||
zephyr_add_prj_conf("NVS", True)
|
||||
zephyr_add_prj_conf("FLASH_MAP", True)
|
||||
zephyr_add_prj_conf("FLASH", True)
|
||||
|
||||
|
||||
@@ -846,9 +846,7 @@ def convert_visual_temperatures(
|
||||
that needs ``full_config`` is left for final validation, which runs this again with it."""
|
||||
if (unit := entity_temperature_unit(config, full_config)) is None:
|
||||
return config
|
||||
# A platform entry that only holds nested entities has no visual section of its own
|
||||
if (visual := config.get(CONF_VISUAL)) is None:
|
||||
return config
|
||||
visual = config[CONF_VISUAL]
|
||||
convert_temperature_keys(visual, (CONF_MIN_TEMPERATURE, CONF_MAX_TEMPERATURE), unit)
|
||||
section = visual if delta_section is None else visual.get(delta_section)
|
||||
if section is not None:
|
||||
|
||||
@@ -222,20 +222,6 @@ def test_a_resolved_unit_waits_for_the_full_config() -> None:
|
||||
assert config[CONF_VISUAL][CONF_MIN_TEMPERATURE] == pytest.approx(59.0)
|
||||
|
||||
|
||||
def test_final_validate_skips_a_platform_that_only_holds_nested_climates() -> None:
|
||||
"""A hub platform may put each of its climates under a key of one platform entry."""
|
||||
nested = climate_schema(climate_ns.class_("NestedClimate", Climate))
|
||||
platform_schema = cv.Schema({cv.Optional("zone_1"): nested})
|
||||
config = platform_schema(
|
||||
{"zone_1": {CONF_NAME: "Zone 1", CONF_VISUAL: {CONF_MIN_TEMPERATURE: "50°F"}}}
|
||||
)
|
||||
# The platform entry itself is not a climate and has no visual section
|
||||
assert CONF_VISUAL not in config
|
||||
_final_validate([config])
|
||||
# The nested climate was converted by its own schema
|
||||
assert config["zone_1"][CONF_VISUAL][CONF_MIN_TEMPERATURE] == pytest.approx(10.0)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("use_fahrenheit", "cn105_lines"),
|
||||
[
|
||||
|
||||
@@ -8,16 +8,11 @@ from esphome.components.npm1300 import (
|
||||
CHARGER_SCHEMA,
|
||||
NPM1300_UNSET,
|
||||
OUTPUT_VOLTAGE,
|
||||
THERMISTOR_NONE,
|
||||
VBUS_CURRENT_LIMIT,
|
||||
_charger_config,
|
||||
_check_thermistor,
|
||||
_config,
|
||||
_output_config,
|
||||
_termination_voltage_code,
|
||||
_thermistor_resistance,
|
||||
_vbus_current_limit_code,
|
||||
thermistor_beta,
|
||||
)
|
||||
from esphome.const import CONF_MODE, CONF_VOLTAGE
|
||||
from esphome.cpp_generator import StructInitializer
|
||||
@@ -59,35 +54,10 @@ def test_termination_voltage_gap_rejected(voltage: str) -> None:
|
||||
CHARGER_SCHEMA({"charge_current": "100mA", "termination_voltage": voltage})
|
||||
|
||||
|
||||
def test_warm_termination_defaults_to_reset_value() -> None:
|
||||
def test_warm_termination_defaults_to_termination() -> None:
|
||||
fields = _charger({"charge_current": "100mA", "termination_voltage": "4.1V"})
|
||||
assert fields["termination_voltage"] == "6"
|
||||
assert fields["warm_termination_voltage"] == "2"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("config", "warns"),
|
||||
[
|
||||
({"termination_voltage": "4.2V"}, True),
|
||||
({"termination_voltage": "3.5V"}, False),
|
||||
({"termination_voltage": "3.6V"}, False),
|
||||
({}, False),
|
||||
({"termination_voltage": "4.2V", "warm_termination_voltage": "4.0V"}, False),
|
||||
],
|
||||
)
|
||||
def test_warm_termination_default_warning(
|
||||
config: ConfigType, warns: bool, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
CHARGER_SCHEMA(config)
|
||||
assert ("warm_termination_voltage" in caplog.text) is warns
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("termination", "code"), [("3.5V", "0"), ("3.55V", "1")])
|
||||
def test_warm_termination_default_not_above_termination(
|
||||
termination: str, code: str
|
||||
) -> None:
|
||||
fields = _charger({"termination_voltage": termination})
|
||||
assert fields["warm_termination_voltage"] == code
|
||||
assert fields["warm_termination_voltage"] == "6"
|
||||
|
||||
|
||||
def test_warm_termination_code() -> None:
|
||||
@@ -142,66 +112,3 @@ def test_vbus_current_limit_code(limit: str, code: int) -> None:
|
||||
def test_vbus_current_limit_rejected(limit: str) -> None:
|
||||
with pytest.raises(cv.Invalid):
|
||||
VBUS_CURRENT_LIMIT(limit)
|
||||
|
||||
|
||||
def test_charger_needs_thermistor() -> None:
|
||||
with pytest.raises(cv.Invalid, match="thermistor_resistance"):
|
||||
_check_thermistor({"charger": {}})
|
||||
config = {"charger": {}, "thermistor_resistance": THERMISTOR_NONE}
|
||||
assert _check_thermistor(config) is config
|
||||
|
||||
|
||||
@pytest.mark.parametrize("resistance", [None, THERMISTOR_NONE])
|
||||
def test_thermistor_beta_needs_resistance(resistance: str | None) -> None:
|
||||
config = {"thermistor_beta": 3380}
|
||||
if resistance is not None:
|
||||
config["thermistor_resistance"] = resistance
|
||||
with pytest.raises(cv.Invalid, match="thermistor_beta"):
|
||||
_check_thermistor(config)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("resistance", "beta"), [(10000.0, 3380), (47000.0, 4050), (100000.0, 4250)]
|
||||
)
|
||||
def test_thermistor_beta_default(resistance: float, beta: int) -> None:
|
||||
assert thermistor_beta({"thermistor_resistance": resistance}) == beta
|
||||
|
||||
|
||||
def test_thermistor_beta_configured() -> None:
|
||||
config = {"thermistor_resistance": 47000.0, "thermistor_beta": 3950}
|
||||
assert thermistor_beta(config) == 3950
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("resistance", "code", "beta"),
|
||||
[
|
||||
(None, str(NPM1300_UNSET), "0"),
|
||||
(THERMISTOR_NONE, "0", "0"),
|
||||
(100000.0, "3", "4250"),
|
||||
],
|
||||
)
|
||||
def test_config_thermistor(
|
||||
resistance: str | float | None, code: str, beta: str
|
||||
) -> None:
|
||||
config = {} if resistance is None else {"thermistor_resistance": resistance}
|
||||
fields = _fields(_config(config))
|
||||
assert fields["thermistor"] == code
|
||||
assert fields["thermistor_beta"] == beta
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "result"),
|
||||
[
|
||||
("10kOhm", 10000.0),
|
||||
("0.047MOhm", 47000.0),
|
||||
("100000", 100000.0),
|
||||
("None", "none"),
|
||||
],
|
||||
)
|
||||
def test_thermistor_resistance(value: str, result: float | str) -> None:
|
||||
assert _thermistor_resistance(value) == result
|
||||
|
||||
|
||||
def test_thermistor_resistance_rejected() -> None:
|
||||
with pytest.raises(cv.Invalid, match="10kOhm, 47kOhm, 100kOhm or none"):
|
||||
_thermistor_resistance("22kOhm")
|
||||
@@ -1,6 +0,0 @@
|
||||
from tests.testing_helpers import ComponentManifestOverride
|
||||
|
||||
|
||||
def override_manifest(manifest: ComponentManifestOverride) -> None:
|
||||
# touchscreen.h includes display.h
|
||||
manifest.dependencies = manifest.dependencies + ["display"]
|
||||
@@ -1,42 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "esphome/components/cst816/touchscreen/cst816_touchscreen.h"
|
||||
|
||||
namespace esphome::cst816::testing {
|
||||
|
||||
static constexpr uint8_t ADDRESS = 0x15;
|
||||
// The driver reads REG_STATUS onwards in one transfer: status, gesture, touch count, then two points.
|
||||
static constexpr size_t FRAME_SIZE = 13;
|
||||
|
||||
/// Serves one fixed status frame.
|
||||
class FrameBus final : public i2c::I2CBus {
|
||||
public:
|
||||
explicit FrameBus(std::array<uint8_t, FRAME_SIZE> frame) : frame_(frame) {}
|
||||
|
||||
i2c::ErrorCode write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count, uint8_t *read_buffer,
|
||||
size_t read_count) override {
|
||||
EXPECT_EQ(address, ADDRESS);
|
||||
for (size_t i = 0; i < read_count; i++)
|
||||
read_buffer[i] = i < FRAME_SIZE ? this->frame_[i] : 0;
|
||||
return i2c::ERROR_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::array<uint8_t, FRAME_SIZE> frame_;
|
||||
};
|
||||
|
||||
inline std::array<uint8_t, FRAME_SIZE> make_frame(uint8_t touch_num, uint16_t x = 0, uint16_t y = 0) {
|
||||
std::array<uint8_t, FRAME_SIZE> frame{};
|
||||
frame[REG_TOUCH_NUM] = touch_num;
|
||||
frame[REG_XPOS_HIGH] = (x >> 8) & 0x0F;
|
||||
frame[REG_XPOS_LOW] = x & 0xFF;
|
||||
frame[REG_YPOS_HIGH] = (y >> 8) & 0x0F;
|
||||
frame[REG_YPOS_LOW] = y & 0xFF;
|
||||
return frame;
|
||||
}
|
||||
|
||||
} // namespace esphome::cst816::testing
|
||||
@@ -1,88 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
namespace esphome::cst816::testing {
|
||||
|
||||
class CST816TouchscreenTest : public ::testing::Test {
|
||||
protected:
|
||||
void feed_(const std::array<uint8_t, FRAME_SIZE> &frame) {
|
||||
this->bus_ = std::make_unique<FrameBus>(frame);
|
||||
this->touchscreen_.set_i2c_bus(this->bus_.get());
|
||||
this->touchscreen_.set_i2c_address(ADDRESS);
|
||||
this->touchscreen_.update_touches();
|
||||
}
|
||||
|
||||
std::unique_ptr<FrameBus> bus_;
|
||||
CST816Touchscreen touchscreen_;
|
||||
};
|
||||
|
||||
// An idle frame reports 0xFF in the touch count byte and 0xFFF coordinates. Masking 0xFF to the
|
||||
// low two bits turns that into three touches at the maximum position, a phantom tap.
|
||||
TEST_F(CST816TouchscreenTest, IdleAllOnesFrameIsIgnored) {
|
||||
this->feed_(make_frame(0xFF, 0x0FFF, 0x0FFF));
|
||||
EXPECT_TRUE(this->touchscreen_.get_touches().empty());
|
||||
}
|
||||
|
||||
TEST_F(CST816TouchscreenTest, ZeroTouchCountIsIgnored) {
|
||||
this->feed_(make_frame(0));
|
||||
EXPECT_TRUE(this->touchscreen_.get_touches().empty());
|
||||
}
|
||||
|
||||
// Three is the boundary the guard rejects: the old mask turned a count of three into three
|
||||
// touches, so this is the value whose behaviour changes.
|
||||
TEST_F(CST816TouchscreenTest, TouchCountThreeIsIgnored) {
|
||||
this->feed_(make_frame(3, 100, 200));
|
||||
EXPECT_TRUE(this->touchscreen_.get_touches().empty());
|
||||
}
|
||||
|
||||
// The count is the whole low nibble, so 0x05 must not be masked down to one touch by a 0x03 mask.
|
||||
TEST_F(CST816TouchscreenTest, TouchCountFiveIsIgnored) {
|
||||
this->feed_(make_frame(0x05, 100, 200));
|
||||
EXPECT_TRUE(this->touchscreen_.get_touches().empty());
|
||||
}
|
||||
|
||||
TEST_F(CST816TouchscreenTest, SingleTouchIsReported) {
|
||||
this->feed_(make_frame(1, 300, 100));
|
||||
auto touches = this->touchscreen_.get_touches();
|
||||
ASSERT_EQ(touches.size(), 1u);
|
||||
EXPECT_EQ(touches[0].x_raw, 300);
|
||||
EXPECT_EQ(touches[0].y_raw, 100);
|
||||
}
|
||||
|
||||
// CST826/CST836 can report two points; the driver only consumes the first one.
|
||||
TEST_F(CST816TouchscreenTest, TwoPointFrameReportsFirstPoint) {
|
||||
this->feed_(make_frame(2, 300, 100));
|
||||
auto touches = this->touchscreen_.get_touches();
|
||||
ASSERT_EQ(touches.size(), 1u);
|
||||
EXPECT_EQ(touches[0].x_raw, 300);
|
||||
EXPECT_EQ(touches[0].y_raw, 100);
|
||||
}
|
||||
|
||||
TEST_F(CST816TouchscreenTest, SentinelPositionIsIgnored) {
|
||||
this->feed_(make_frame(1, 0x0FFF, 100));
|
||||
EXPECT_TRUE(this->touchscreen_.get_touches().empty());
|
||||
}
|
||||
|
||||
// The sentinel is checked on both axes; a valid X with Y=0xFFF is still an idle reading.
|
||||
TEST_F(CST816TouchscreenTest, SentinelYPositionIsIgnored) {
|
||||
this->feed_(make_frame(1, 100, 0x0FFF));
|
||||
EXPECT_TRUE(this->touchscreen_.get_touches().empty());
|
||||
}
|
||||
|
||||
// x_raw_max_/y_raw_max_ are calibration endpoints, not validity limits: the base class applies them
|
||||
// after swapping axes and clamps readings outside them. A touch beyond the calibrated maximum is
|
||||
// still a real touch and must reach the base class.
|
||||
TEST_F(CST816TouchscreenTest, CalibrationBoundsDoNotDropTouches) {
|
||||
this->touchscreen_.set_calibration(0, 240, 0, 320);
|
||||
this->touchscreen_.set_swap_xy(true);
|
||||
this->feed_(make_frame(1, 300, 100));
|
||||
auto touches = this->touchscreen_.get_touches();
|
||||
ASSERT_EQ(touches.size(), 1u);
|
||||
EXPECT_EQ(touches[0].x_raw, 100);
|
||||
EXPECT_EQ(touches[0].y_raw, 300);
|
||||
}
|
||||
|
||||
} // namespace esphome::cst816::testing
|
||||
@@ -1,2 +0,0 @@
|
||||
packages:
|
||||
debug: !include common.yaml
|
||||
@@ -1,2 +0,0 @@
|
||||
packages:
|
||||
debug: !include common.yaml
|
||||
@@ -0,0 +1,104 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdarg>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "esphome/components/logger/log_buffer.h"
|
||||
|
||||
namespace esphome::logger::testing {
|
||||
|
||||
static void format_into(LogBuffer &buf, const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
buf.format_body(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
// A cut line keeps its whole color reset, and the terminator is never counted in pos
|
||||
static void expect_reset_and_terminator(const LogBuffer &buf, uint16_t start) {
|
||||
ASSERT_LT(buf.pos, buf.size);
|
||||
EXPECT_EQ(buf.data[buf.pos], '\0');
|
||||
if (buf.size - start > LogBuffer::ANSI_RESET_LEN) {
|
||||
ASSERT_GE(buf.pos, start + LogBuffer::ANSI_RESET_LEN);
|
||||
EXPECT_EQ(memcmp(buf.data + buf.pos - LogBuffer::ANSI_RESET_LEN, "\033[0m", LogBuffer::ANSI_RESET_LEN), 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(LogBufferTest, CutLineKeepsColorResetAndTerminator) {
|
||||
constexpr uint16_t max_size = 48;
|
||||
const std::string text(max_size + 8, 'x');
|
||||
for (uint16_t size = 1; size <= max_size; size++) {
|
||||
for (uint16_t start = 0; start < size; start++) {
|
||||
for (size_t len = 0; len <= text.size(); len++) {
|
||||
SCOPED_TRACE(::testing::Message() << "size " << size << " start " << start << " text " << len);
|
||||
const std::string body = text.substr(0, len);
|
||||
char formatted[max_size], copied[max_size];
|
||||
memset(formatted, '#', sizeof(formatted));
|
||||
memset(copied, '#', sizeof(copied));
|
||||
LogBuffer a{formatted, size, start};
|
||||
format_into(a, "%s", body.c_str());
|
||||
expect_reset_and_terminator(a, start);
|
||||
LogBuffer b{copied, size, start};
|
||||
b.write_body(body.data(), static_cast<uint16_t>(len));
|
||||
expect_reset_and_terminator(b, start);
|
||||
EXPECT_EQ(a.pos, b.pos);
|
||||
// The text keeps every character that fits in front of the reset and the terminator
|
||||
const int room = size - start - LogBuffer::ANSI_RESET_LEN;
|
||||
const size_t kept = room > 0 ? std::min(len, static_cast<size_t>(room - 1)) : 0;
|
||||
EXPECT_EQ(a.pos, start + kept + (room > 0 ? LogBuffer::ANSI_RESET_LEN : 0));
|
||||
EXPECT_EQ(memcmp(formatted + start, text.data(), kept), 0);
|
||||
EXPECT_EQ(memcmp(copied + start, text.data(), kept), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(LogBufferTest, CutAfterNewlineDropsIt) {
|
||||
char formatted[16], copied[16];
|
||||
LogBuffer a{formatted, sizeof(formatted)};
|
||||
LogBuffer b{copied, sizeof(copied)};
|
||||
// 11 bytes of text fit in 16 after the reset and the terminator; the 11th is the newline
|
||||
format_into(a, "%s", "0123456789\nabc");
|
||||
b.write_body("0123456789\nabc", 14);
|
||||
EXPECT_EQ(std::string(formatted, a.pos), "0123456789\033[0m");
|
||||
EXPECT_EQ(std::string(copied, b.pos), "0123456789\033[0m");
|
||||
}
|
||||
|
||||
TEST(LogBufferTest, LineThatFitsIsUnchanged) {
|
||||
char data[64];
|
||||
LogBuffer buf{data, sizeof(data)};
|
||||
format_into(buf, "%s", "hello");
|
||||
EXPECT_EQ(std::string(data, buf.pos), "hello\033[0m");
|
||||
}
|
||||
|
||||
static std::string header_line(uint16_t size, const std::string &tag, const std::string &thread) {
|
||||
std::string data(size, '#');
|
||||
const std::string text(600, 'x');
|
||||
LogBuffer buf{data.data(), size};
|
||||
buf.write_header(ESPHOME_LOG_LEVEL_DEBUG, tag.c_str(), 123, thread.c_str());
|
||||
EXPECT_LT(buf.pos, size);
|
||||
format_into(buf, "%s", text.c_str());
|
||||
expect_reset_and_terminator(buf, 0);
|
||||
return data.substr(0, buf.pos);
|
||||
}
|
||||
|
||||
TEST(LogBufferTest, LongTagIsKeptWhenItFits) {
|
||||
const std::string tag(200, 't');
|
||||
const std::string line = header_line(512, tag, "main");
|
||||
EXPECT_NE(line.find("[" + tag + ":123]"), std::string::npos);
|
||||
}
|
||||
|
||||
TEST(LogBufferTest, LongTagAndThreadNameAreCutToTheRoomLeft) {
|
||||
// The smallest tx_buffer_size; an overlong tag or thread name must not push the header past the buffer
|
||||
constexpr uint16_t size = 160;
|
||||
constexpr size_t tag_room = size - (MAX_HEADER_SIZE - MAX_TAG_LENGTH);
|
||||
const std::string line = header_line(size, std::string(200, 't'), std::string(200, 'n'));
|
||||
EXPECT_NE(line.find("[" + std::string(tag_room, 't') + ":123]"), std::string::npos);
|
||||
EXPECT_EQ(line.find(std::string(tag_room + 1, 't')), std::string::npos);
|
||||
EXPECT_NE(line.find(std::string(MAX_TAG_LENGTH, 'n')), std::string::npos);
|
||||
EXPECT_EQ(line.find(std::string(MAX_TAG_LENGTH + 1, 'n')), std::string::npos);
|
||||
}
|
||||
|
||||
} // namespace esphome::logger::testing
|
||||
@@ -26,7 +26,8 @@ TEST(UnformattedLogTest, BodyMatchesFormattedBodyAtEverySize) {
|
||||
const char *texts[] = {"", "short", "ends with newlines\n\n", "\n", "a\nb", long_text.c_str()};
|
||||
constexpr uint16_t max_size = 48;
|
||||
for (uint16_t size = 1; size <= max_size; size++) {
|
||||
for (uint16_t start = 0; start <= size; start++) {
|
||||
// The header always leaves room for the terminator, so the body starts inside the buffer
|
||||
for (uint16_t start = 0; start < size; start++) {
|
||||
for (const char *text : texts) {
|
||||
SCOPED_TRACE(::testing::Message() << "size " << size << " start " << start << " text '" << text << "'");
|
||||
char formatted[max_size], unformatted[max_size], flash[max_size];
|
||||
@@ -46,7 +47,7 @@ TEST(UnformattedLogTest, BodyMatchesFormattedBodyAtEverySize) {
|
||||
ASSERT_EQ(a.pos, b.pos);
|
||||
ASSERT_EQ(a.pos, c.pos);
|
||||
// Up to and including the null terminator; vsnprintf() may leave bytes after it that nothing reads
|
||||
const size_t used = (a.pos < size) ? a.pos + 1 : size;
|
||||
const size_t used = a.pos + 1;
|
||||
ASSERT_EQ(memcmp(formatted, unformatted, used), 0);
|
||||
ASSERT_EQ(memcmp(formatted, flash, used), 0);
|
||||
}
|
||||
|
||||
@@ -1,38 +1,29 @@
|
||||
npm1300:
|
||||
- id: pmic
|
||||
i2c_id: i2c_bus
|
||||
vbus_current_limit: 500mA
|
||||
thermistor_resistance: 10kOhm
|
||||
thermistor_beta: 3380
|
||||
charger:
|
||||
charge_current: 150mA
|
||||
termination_voltage: 4.2V
|
||||
warm_termination_voltage: 4.0V
|
||||
termination_current: 20%
|
||||
trickle_voltage: 2.5V
|
||||
discharge_current_limit: 1000mA
|
||||
recharge: true
|
||||
buck2:
|
||||
voltage: 3.3V
|
||||
ldo1:
|
||||
voltage: 3.3V
|
||||
mode: ldo
|
||||
enabled: true
|
||||
ldo2:
|
||||
mode: load_switch
|
||||
enabled: false
|
||||
# A battery without a thermistor
|
||||
- id: pmic_no_ntc
|
||||
i2c_id: i2c_bus
|
||||
address: 0x6C
|
||||
thermistor_resistance: none
|
||||
charger:
|
||||
termination_voltage: 3.5V
|
||||
enabled: true
|
||||
id: pmic
|
||||
i2c_id: i2c_bus
|
||||
vbus_current_limit: 500mA
|
||||
thermistor_resistance: 10kOhm
|
||||
thermistor_beta: 3380
|
||||
charger:
|
||||
charge_current: 150mA
|
||||
termination_voltage: 4.2V
|
||||
warm_termination_voltage: 4.0V
|
||||
termination_current: 20%
|
||||
trickle_voltage: 2.5V
|
||||
discharge_current_limit: 1000mA
|
||||
recharge: true
|
||||
buck2:
|
||||
voltage: 3.3V
|
||||
ldo1:
|
||||
voltage: 3.3V
|
||||
mode: ldo
|
||||
enabled: true
|
||||
ldo2:
|
||||
mode: load_switch
|
||||
enabled: false
|
||||
|
||||
sensor:
|
||||
- platform: npm1300
|
||||
npm1300_id: pmic
|
||||
battery_voltage:
|
||||
name: Battery Voltage
|
||||
battery_current:
|
||||
@@ -50,7 +41,6 @@ sensor:
|
||||
|
||||
binary_sensor:
|
||||
- platform: npm1300
|
||||
npm1300_id: pmic
|
||||
vbus_present:
|
||||
name: VBUS Present
|
||||
vbus_current_limit_active:
|
||||
@@ -64,13 +54,11 @@ binary_sensor:
|
||||
|
||||
text_sensor:
|
||||
- platform: npm1300
|
||||
npm1300_id: pmic
|
||||
charger_status:
|
||||
name: Charger Status
|
||||
|
||||
switch:
|
||||
- platform: npm1300
|
||||
npm1300_id: pmic
|
||||
charger:
|
||||
name: Charger
|
||||
buck1:
|
||||
@@ -79,10 +67,6 @@ switch:
|
||||
name: LDO1
|
||||
ldo2:
|
||||
name: LDO2
|
||||
- platform: npm1300
|
||||
npm1300_id: pmic_no_ntc
|
||||
charger:
|
||||
name: Charger Without Thermistor
|
||||
|
||||
button:
|
||||
- platform: template
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
"""Each SoC variant stores preferences in the storage made for its memory."""
|
||||
|
||||
import pytest
|
||||
|
||||
from esphome.components import nrf52
|
||||
from esphome.components.nrf52.const import (
|
||||
VARIANT_NRF54L15,
|
||||
VARIANT_NRF54LM20,
|
||||
VARIANT_NRF51822,
|
||||
VARIANT_NRF52832,
|
||||
VARIANT_NRF52840,
|
||||
)
|
||||
from esphome.components.zephyr import zephyr_setup_preferences
|
||||
from esphome.components.zephyr.const import KEY_PRJ_CONF, KEY_ZEPHYR
|
||||
from esphome.core import CORE
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("variant", "storage", "other"),
|
||||
[
|
||||
(VARIANT_NRF54L15, "ZMS", "NVS"),
|
||||
(VARIANT_NRF54LM20, "ZMS", "NVS"),
|
||||
(VARIANT_NRF52840, "NVS", "ZMS"),
|
||||
(VARIANT_NRF52832, "NVS", "ZMS"),
|
||||
(VARIANT_NRF51822, "NVS", "ZMS"),
|
||||
],
|
||||
)
|
||||
def test_variant_picks_the_settings_backend(
|
||||
variant: str, storage: str, other: str
|
||||
) -> None:
|
||||
CORE.data[KEY_ZEPHYR] = {KEY_PRJ_CONF: {}}
|
||||
|
||||
zephyr_setup_preferences(nrf52._preferences_storage(variant))
|
||||
|
||||
prj_conf = CORE.data[KEY_ZEPHYR][KEY_PRJ_CONF][""]
|
||||
assert prj_conf[f"CONFIG_{storage}"] == (True, True)
|
||||
assert prj_conf[f"CONFIG_SETTINGS_{storage}"] == (True, True)
|
||||
assert f"CONFIG_{other}" not in prj_conf
|
||||
assert f"CONFIG_SETTINGS_{other}" not in prj_conf
|
||||
@@ -1550,15 +1550,6 @@ def test_convert_visual_temperatures(
|
||||
convert_visual_temperatures({"visual": {}}, delta_keys, delta_section)
|
||||
|
||||
|
||||
def test_convert_visual_temperatures_without_a_visual_section() -> None:
|
||||
"""A platform entry that only holds nested entities has no visual section and is left alone."""
|
||||
nested = {"visual": {"min_temperature": (50.0, "°F")}}
|
||||
config = {"zone_1": nested}
|
||||
|
||||
assert convert_visual_temperatures(config, ("step",)) is config
|
||||
assert nested["visual"]["min_temperature"] == (50.0, "°F")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_setup_entity_integrations_registers_mqtt_and_web_server(
|
||||
monkeypatch: pytest.MonkeyPatch, setup_test_environment: list[str]
|
||||
|
||||
@@ -1792,13 +1792,7 @@ def test_ccache_env_opt_in_without_binary(
|
||||
# Explicit IDF_CCACHE_ENABLE=1 forces it on; without a usable binary
|
||||
# IDF's CMake silently skips ccache, so this branch must say so out loud.
|
||||
p1, p2, p3 = _ccache_patches(tmp_path, None, tmp_path / "build")
|
||||
with (
|
||||
patch.dict("os.environ", {"IDF_CCACHE_ENABLE": "1"}, clear=True),
|
||||
patch("esphome.espidf.framework.shutil.which", return_value=None),
|
||||
p1,
|
||||
p2,
|
||||
p3,
|
||||
):
|
||||
with patch.dict("os.environ", {"IDF_CCACHE_ENABLE": "1"}, clear=True), p1, p2, p3:
|
||||
env = _ccache_env()
|
||||
assert env["IDF_CCACHE_ENABLE"] == "1"
|
||||
assert env["CCACHE_DIR"] == str(tmp_path / "tools" / "ccache")
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from esphome.components.zephyr import (
|
||||
zephyr_add_prj_conf,
|
||||
zephyr_add_prj_conf_min,
|
||||
zephyr_setup_preferences,
|
||||
)
|
||||
from esphome.components.zephyr import zephyr_add_prj_conf, zephyr_add_prj_conf_min
|
||||
from esphome.components.zephyr.const import KEY_PRJ_CONF, KEY_ZEPHYR
|
||||
from esphome.core import CORE
|
||||
|
||||
@@ -32,19 +28,3 @@ def test_largest_min_wins_in_any_order() -> None:
|
||||
zephyr_add_prj_conf_min("MAIN_STACK_SIZE", 4096)
|
||||
|
||||
assert _prj_conf()["CONFIG_MAIN_STACK_SIZE"] == (8192, True)
|
||||
|
||||
|
||||
def test_preferences_use_nvs_by_default() -> None:
|
||||
zephyr_setup_preferences()
|
||||
|
||||
assert _prj_conf()["CONFIG_NVS"] == (True, True)
|
||||
assert _prj_conf()["CONFIG_SETTINGS_NVS"] == (True, True)
|
||||
assert "CONFIG_ZMS" not in _prj_conf()
|
||||
|
||||
|
||||
def test_preferences_can_use_zms() -> None:
|
||||
zephyr_setup_preferences("ZMS")
|
||||
|
||||
assert _prj_conf()["CONFIG_ZMS"] == (True, True)
|
||||
assert _prj_conf()["CONFIG_SETTINGS_ZMS"] == (True, True)
|
||||
assert "CONFIG_NVS" not in _prj_conf()
|
||||
Reference in new issue
Block a user