[nrf52] disable USB if not configured by esphome to save power (#19493)

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
tomaszduda23
2026-09-23 14:48:39 +02:00
committed by GitHub
co-authored by pre-commit-ci-lite[bot]
parent 3da7533159
commit 26abc1325e
2 changed files with 12 additions and 1 deletions
+8
View File
@@ -428,6 +428,10 @@ async def to_code(config: ConfigType) -> None:
)
zephyr_add_prj_conf("REBOOT", True)
# some boards enable USB by default.
# disable it to prevent extra current consumption.
zephyr_add_prj_conf("USB_DEVICE_STACK", False, False)
@coroutine_with_priority(CoroPriority.DIAGNOSTICS)
async def _dfu_to_code(dfu_config):
@@ -436,6 +440,10 @@ async def _dfu_to_code(dfu_config):
if CONF_RESET_PIN in dfu_config:
pin = await cg.gpio_pin_expression(dfu_config[CONF_RESET_PIN])
cg.add(var.set_reset_pin(pin))
# DFU uses cdc rate callback to enter bootloader which was disabled explicitly to save power.
zephyr_add_prj_conf("USB_DEVICE_STACK", True)
zephyr_add_prj_conf("USB_CDC_ACM", True)
zephyr_add_prj_conf("CDC_ACM_DTE_RATE_CALLBACK_SUPPORT", True)
await cg.register_component(var, dfu_config)
+4 -1
View File
@@ -176,7 +176,10 @@ def zephyr_to_code(config: ConfigType) -> None:
@coroutine_with_priority(CoroPriority.FINAL)
async def _cdc_acm_to_code(config: ConfigType) -> None:
if "CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT" in zephyr_data()[KEY_PRJ_CONF][""]:
need_cdc_cb = zephyr_data()[KEY_PRJ_CONF][""].get(
"CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT", (False,)
)[0]
if need_cdc_cb:
var = cg.new_Pvariable(config[CONF_CDC_ACM])
await cg.register_component(var, {})