This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 5eca74f254c8d32847179f6ebbd5a6e4b588bec0 Author: raiden00pl <[email protected]> AuthorDate: Sat Jun 13 08:53:52 2026 +0200 boards/thingy53: Add the nPM1100 charger. Register the nPM1100 charge status driver as /dev/charge0, with CHG on P1.00 and ERR on P1.01. Assisted-by: Claude:claude-fable-5-1 Signed-off-by: raiden00pl <[email protected]> --- .../platforms/arm/nrf53/boards/thingy53/index.rst | 2 +- boards/arm/nrf53/thingy53/src/CMakeLists.txt | 4 + boards/arm/nrf53/thingy53/src/Make.defs | 4 + boards/arm/nrf53/thingy53/src/nrf53_bringup.c | 10 +++ boards/arm/nrf53/thingy53/src/nrf53_npm1100.c | 96 ++++++++++++++++++++++ boards/arm/nrf53/thingy53/src/thingy53.h | 12 +++ 6 files changed, 127 insertions(+), 1 deletion(-) diff --git a/Documentation/platforms/arm/nrf53/boards/thingy53/index.rst b/Documentation/platforms/arm/nrf53/boards/thingy53/index.rst index 534f828653f..bf257743aea 100644 --- a/Documentation/platforms/arm/nrf53/boards/thingy53/index.rst +++ b/Documentation/platforms/arm/nrf53/boards/thingy53/index.rst @@ -19,7 +19,7 @@ Buttons Yes LEDs No NFC No MX25R6435F No Dual line SPI -PMIC No +PMIC Yes nPM1100 CHG/ERR status Battery monitoring No Buzzer No PDM microphone (VM3011) No diff --git a/boards/arm/nrf53/thingy53/src/CMakeLists.txt b/boards/arm/nrf53/thingy53/src/CMakeLists.txt index 6343b3aae82..5934b2f91da 100644 --- a/boards/arm/nrf53/thingy53/src/CMakeLists.txt +++ b/boards/arm/nrf53/thingy53/src/CMakeLists.txt @@ -54,6 +54,10 @@ if(CONFIG_ADC) list(APPEND SRCS nrf53_adc.c) endif() +if(CONFIG_NPM1100) + list(APPEND SRCS nrf53_npm1100.c) +endif() + target_sources(board PRIVATE ${SRCS}) if(CONFIG_ARCH_BOARD_COMMON) diff --git a/boards/arm/nrf53/thingy53/src/Make.defs b/boards/arm/nrf53/thingy53/src/Make.defs index 9ad5518bfd7..fc3f9bfbffc 100644 --- a/boards/arm/nrf53/thingy53/src/Make.defs +++ b/boards/arm/nrf53/thingy53/src/Make.defs @@ -54,6 +54,10 @@ ifeq ($(CONFIG_ADC),y) CSRCS += nrf53_adc.c endif +ifeq ($(CONFIG_NPM1100),y) +CSRCS += nrf53_npm1100.c +endif + DEPPATH += --dep-path board VPATH += :board CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board diff --git a/boards/arm/nrf53/thingy53/src/nrf53_bringup.c b/boards/arm/nrf53/thingy53/src/nrf53_bringup.c index 0ce83f60cca..0bb6aa270b3 100644 --- a/boards/arm/nrf53/thingy53/src/nrf53_bringup.c +++ b/boards/arm/nrf53/thingy53/src/nrf53_bringup.c @@ -261,6 +261,16 @@ int nrf53_bringup(void) } #endif +#ifdef CONFIG_NPM1100 + /* Register the nPM1100 PMIC charge-status driver */ + + ret = nrf53_npm1100_init(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nrf53_npm1100_init failed: %d\n", ret); + } +#endif + /* Initialize on-board sensors */ ret = nrf53_sensors_init(); diff --git a/boards/arm/nrf53/thingy53/src/nrf53_npm1100.c b/boards/arm/nrf53/thingy53/src/nrf53_npm1100.c new file mode 100644 index 00000000000..434d88be96e --- /dev/null +++ b/boards/arm/nrf53/thingy53/src/nrf53_npm1100.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * boards/arm/nrf53/thingy53/src/nrf53_npm1100.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/power/battery_charger.h> +#include <nuttx/power/npm1100.h> + +#include "nrf53_gpio.h" +#include "thingy53.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* The nPM1100 CHG and ERR status pins are open-drain, active-low. Configure + * them as inputs with a pull-up and report the raw pin level; the nPM1100 + * driver applies the active-low semantics. + */ + +static bool nrf53_npm1100_read_chg(void) +{ + return nrf53_gpio_read(GPIO_NPM1100_CHG); +} + +static bool nrf53_npm1100_read_err(void) +{ + return nrf53_gpio_read(GPIO_NPM1100_ERR); +} + +static const struct npm1100_config_s g_npm1100_config = +{ + .read_chg = nrf53_npm1100_read_chg, + .read_err = nrf53_npm1100_read_err, +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_npm1100_init + * + * Description: + * Register the nPM1100 PMIC charge-status driver as /dev/charge0. + * + ****************************************************************************/ + +int nrf53_npm1100_init(void) +{ + FAR struct battery_charger_dev_s *charger; + int ret; + + nrf53_gpio_config(GPIO_NPM1100_CHG | GPIO_PULLUP); + nrf53_gpio_config(GPIO_NPM1100_ERR | GPIO_PULLUP); + + charger = npm1100_initialize(&g_npm1100_config); + if (charger == NULL) + { + return -ENODEV; + } + + ret = battery_charger_register("/dev/charge0", charger); + if (ret < 0) + { + baterr("ERROR: battery_charger_register failed: %d\n", ret); + } + + return ret; +} diff --git a/boards/arm/nrf53/thingy53/src/thingy53.h b/boards/arm/nrf53/thingy53/src/thingy53.h index 58bcc0d4bb9..7b8ab26b003 100644 --- a/boards/arm/nrf53/thingy53/src/thingy53.h +++ b/boards/arm/nrf53/thingy53/src/thingy53.h @@ -229,5 +229,17 @@ void nrf53_spidev_initialize(void); int nrf53_adc_setup(void); #endif +/**************************************************************************** + * Name: nrf53_npm1100_init + * + * Description: + * Register the nPM1100 PMIC charge-status driver as /dev/charge0. + * + ****************************************************************************/ + +#ifdef CONFIG_NPM1100 +int nrf53_npm1100_init(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_ARM_NRF53_THINGY53_SRC_THINGY53_H */
