diff --git a/boards/shields/npm1300_ek/doc/index.rst b/boards/shields/npm1300_ek/doc/index.rst index 816c31a5fff..5193523dde8 100644 --- a/boards/shields/npm1300_ek/doc/index.rst +++ b/boards/shields/npm1300_ek/doc/index.rst @@ -22,10 +22,5 @@ Usage ***** The shield can be used in any application by setting ``--shield npm1300_ek`` -when invoking ``west build``. You can check :zephyr:code-sample:`npm1300_ek` for a +when invoking ``west build``. You can check :zephyr:code-sample:`npm13xx_ek` for a comprehensive sample. - -References -********** - -TBC diff --git a/boards/shields/npm1304_ek/Kconfig.shield b/boards/shields/npm1304_ek/Kconfig.shield new file mode 100644 index 00000000000..d86b2525d1c --- /dev/null +++ b/boards/shields/npm1304_ek/Kconfig.shield @@ -0,0 +1,5 @@ +# Copyright (c) 2025 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SHIELD_NPM1304_EK + def_bool $(shields_list_contains,npm1304_ek) diff --git a/boards/shields/npm1304_ek/doc/index.rst b/boards/shields/npm1304_ek/doc/index.rst new file mode 100644 index 00000000000..2c47ed1ffd6 --- /dev/null +++ b/boards/shields/npm1304_ek/doc/index.rst @@ -0,0 +1,30 @@ +.. _npm1304_ek: + +nPM1304 EK +########## + +Overview +******** + +The nPM1304 EK lets you test different functions and features of the nPM1304 +Power Management Integrated Circuit (PMIC). + +Requirements +************ + +The nPM1304 EK board is not a direct fit into an Arduino connector. However, +the Zephyr shield is expected to be connected to the Arduino shield connectors. +That is, you need to connect the I2C lines to the ``arduino_i2c`` bus. This allows to +use the shield with any host board that supports the Arduino connector. + +Usage +***** + +To use the shield in any application, build it with the following command: + +.. zephyr-app-commands:: + :board: your_board + :shield: npm1304_ek + :goals: build + +For a comprehensive sample, refer to :zephyr:code-sample:`npm13xx_ek`. diff --git a/boards/shields/npm1304_ek/npm1304_ek.overlay b/boards/shields/npm1304_ek/npm1304_ek.overlay new file mode 100644 index 00000000000..37e6961c5fd --- /dev/null +++ b/boards/shields/npm1304_ek/npm1304_ek.overlay @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2025 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +&arduino_i2c { + npm1304_ek_pmic: pmic@6b { + compatible = "nordic,npm1304"; + reg = <0x6b>; + + npm1304_ek_gpio: gpio-controller { + compatible = "nordic,npm1304-gpio"; + gpio-controller; + #gpio-cells = <2>; + ngpios = <5>; + }; + + npm1304_ek_regulators: regulators { + compatible = "nordic,npm1304-regulator"; + + /* limits are set to min/max allowed values */ + npm1304_ek_buck1: BUCK1 { + regulator-min-microvolt = <1000000>; + regulator-max-microvolt = <3300000>; + }; + + npm1304_ek_buck2: BUCK2 { + regulator-min-microvolt = <1000000>; + regulator-max-microvolt = <3300000>; + }; + + npm1304_ek_ldo1: LDO1 { + regulator-min-microvolt = <1000000>; + regulator-max-microvolt = <3300000>; + }; + + npm1304_ek_ldo2: LDO2 { + regulator-min-microvolt = <1000000>; + regulator-max-microvolt = <3300000>; + }; + }; + + npm1304_ek_charger: charger { + compatible = "nordic,npm1304-charger"; + term-microvolt = <4150000>; + term-warm-microvolt = <4000000>; + current-microamp = <4000>; + vbus-limit-microamp = <500000>; + thermistor-ohms = <10000>; + thermistor-beta = <3380>; + charging-enable; + }; + + npm1304_ek_buttons: buttons { + compatible = "gpio-keys"; + + pmic_button0: pmic_button_0 { + gpios = <&npm1304_ek_gpio 0 GPIO_ACTIVE_LOW>; + label = "Pmic button switch 0"; + zephyr,code = ; + }; + + pmic_button1: pmic_button_1 { + gpios = <&npm1304_ek_gpio 1 GPIO_ACTIVE_LOW>; + label = "Pmic button switch 1"; + zephyr,code = ; + }; + + pmic_button2: pmic_button_2 { + gpios = <&npm1304_ek_gpio 2 GPIO_ACTIVE_LOW>; + label = "Pmic button switch 2"; + zephyr,code = ; + }; + }; + + npm1304_ek_leds: leds { + compatible = "nordic,npm1304-led"; + nordic,led0-mode = "error"; + nordic,led1-mode = "charging"; + nordic,led2-mode = "host"; + }; + }; +}; diff --git a/boards/shields/npm1304_ek/shield.yml b/boards/shields/npm1304_ek/shield.yml new file mode 100644 index 00000000000..88e19fb84be --- /dev/null +++ b/boards/shields/npm1304_ek/shield.yml @@ -0,0 +1,11 @@ +shield: + name: npm1304_ek + full_name: nPM1304 EK + vendor: nordic + supported_features: + - mfd + - input + - gpio + - led + - regulator + - sensor diff --git a/doc/_scripts/redirects.py b/doc/_scripts/redirects.py index 1c1e9e29942..ba7525fbdb0 100644 --- a/doc/_scripts/redirects.py +++ b/doc/_scripts/redirects.py @@ -302,6 +302,7 @@ ('samples/sensor/max44009/README', 'samples/sensor/light_polling/README'), ('samples/sensor/wsen_hids/README', 'samples/sensor/sensor'), ('samples/sensor/wsen_itds/README', 'samples/sensor/sensor'), + ('samples/shields/npm1300_ek/doc/index', 'samples/shields/npm13xx_ek/doc/index'), ('samples/subsys/video/capture/README', 'samples/drivers/video/capture/README'), ('samples/subsys/video/tcpserversink/README', 'samples/drivers/video/tcpserversink/README'), ('samples/subsys/video/video', 'samples/drivers/video/video'), diff --git a/samples/shields/npm1300_ek/CMakeLists.txt b/samples/shields/npm1300_ek/CMakeLists.txt deleted file mode 100644 index 09e4de1cc52..00000000000 --- a/samples/shields/npm1300_ek/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (c) 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -set(SHIELD npm1300_ek) - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(npm1300_ek) -target_sources(app PRIVATE src/main.c) diff --git a/samples/shields/npm1300_ek/doc/index.rst b/samples/shields/npm1300_ek/doc/index.rst deleted file mode 100644 index be2e8db34cf..00000000000 --- a/samples/shields/npm1300_ek/doc/index.rst +++ /dev/null @@ -1,71 +0,0 @@ -.. zephyr:code-sample:: npm1300_ek - :name: nPM1300 EK - - Interact with the nPM1300 PMIC using the shell interface. - -Overview -******** - -This sample is provided for evaluation of the :ref:`npm1300_ek`. -The sample provides a shell interface to support the features of the -nPM1300 PMIC, including: - -- Regulators (BUCK1/2, LDO1/2) -- GPIO - -Requirements -************ - -The shield needs to be wired to a host board supporting the Arduino connector. - -Examples and images to follow - -Building and Running -******************** - -The sample is designed so that it can run on any platform. For example, when -building for the nRF52 DK, the following command can be used: - -.. zephyr-app-commands:: - :zephyr-app: samples/shields/npm1300_ek - :board: nrf52dk/nrf52832 - :goals: build - :compact: - -Note that this sample automatically sets ``SHIELD`` to ``npm1300_ek``. Once -flashed, you should boot into the shell interface. The ``regulator`` command is -provided to test the PMIC. Below you can find details for each subcommand. - -Regulators -========== - -The ``regulator`` shell interface provides several subcommand to test -the regulators embedded in the PMIC. Below you can find some command examples. - -.. code-block:: bash - - # list all the supported voltages by BUCK1 - regulator vlist BUCK1 - 1.000 V - 1.100 V - ... - -.. code-block:: bash - - # enable BUCK2 - regulator enable BUCK2 - # disable BUCK2 - regulator disable BUCK2 - -.. code-block:: bash - - # set BUCK2 voltage to exactly 2V - regulator vset BUCK2 2V - # obtain the actual BUCK1 configured voltage - regulator vget BUCK1 - 1.800 V - # set BUCK1 voltage to a value between 2.35V and 2.45V - regulator set BUCK1 2.35V 2.45V - # obtain the actual BUCK1 configured voltage - regulator get BUCK1 - 2.400 V diff --git a/samples/shields/npm1300_ek/sample.yaml b/samples/shields/npm1300_ek/sample.yaml deleted file mode 100644 index de89e80d79e..00000000000 --- a/samples/shields/npm1300_ek/sample.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -sample: - name: nPM1300 EK -tests: - sample.shields.npm1300_ek: - platform_allow: nrf52dk/nrf52832 - harness: shield - tags: shield - extra_args: SHIELD=npm1300_ek - depends_on: arduino_i2c diff --git a/samples/shields/npm13xx_ek/CMakeLists.txt b/samples/shields/npm13xx_ek/CMakeLists.txt new file mode 100644 index 00000000000..f3432a12e0b --- /dev/null +++ b/samples/shields/npm13xx_ek/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +if(SHIELD STREQUAL "npm1300_ek") + set(EXTRA_DTC_OVERLAY_FILE npm1300.overlay) +elseif(SHIELD STREQUAL "npm1304_ek") + set(EXTRA_DTC_OVERLAY_FILE npm1304.overlay) +else() + message(FATAL_ERROR "either npm1300_ek or npm1304_ek must be selected with --shield") +endif() + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(npm13xx_ek) +target_sources(app PRIVATE src/main.c) diff --git a/samples/shields/npm13xx_ek/boards/nrf52dk_nrf52832.overlay b/samples/shields/npm13xx_ek/boards/nrf52dk_nrf52832.overlay new file mode 100644 index 00000000000..14a68cf7912 --- /dev/null +++ b/samples/shields/npm13xx_ek/boards/nrf52dk_nrf52832.overlay @@ -0,0 +1,10 @@ +/* + * Copyright (C) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +&i2c0_default { + group1 { + bias-pull-up; + }; +}; diff --git a/samples/shields/npm13xx_ek/doc/index.rst b/samples/shields/npm13xx_ek/doc/index.rst new file mode 100644 index 00000000000..892e5f45a65 --- /dev/null +++ b/samples/shields/npm13xx_ek/doc/index.rst @@ -0,0 +1,110 @@ +.. zephyr:code-sample:: npm13xx_ek + :name: nPM13xx EK + + Interact with an nPM1300 or nPM1304 PMIC using the shell interface and buttons. + +Overview +******** + +This sample is provided for evaluation of :ref:`npm1300_ek` and :ref:`npm1304_ek`. The sample +demonstrates use of Dynamic Voltage Scaling (DVS) regulator API feature which allows to switch +between chosen voltage levels or regulator modes by toggling configured GPIOs with a single +regulator API call. + +It also provides a shell interface to support the features of the nPM1300 and nPM1304 PMICs, +including: + +- Regulators (BUCK1/2, LDO1/2) +- GPIO + +Requirements +************ + +The shield needs to be wired to a host board featuring the Arduino I2C connector. PMIC's GPIO3 acts +as an interrupt output, pins GPIO1 and GPIO2 are configured to control regulator modes (controlled +by the MCU software through DVS). + +In addition, PMIC's VDDIO pin should be connected to an appropriate voltage reference. + +E.g. for an nRF52 Series DK the wiring is as follows: + + +------------------+-------+-------+-------+-------+-------+-------+-----+ + | nPM13xx EK pins | SDA | SCL | GPIO1 | GPIO2 | GPIO3 | VDDIO | GND | + +------------------+-------+-------+-------+-------+-------+-------+-----+ + | nRF52 DK pins | P0.26 | P0.27 | P0.17 | P0.18 | P0.22 | VDD | GND | + +------------------+-------+-------+-------+-------+-------+-------+-----+ + +Building and Running +******************** + +The sample is designed so that it can run on any platform (references to host GPIOs connected to +the nPM13xx EK need to be updated in the ``npm13xx.overlay`` files to reflect chosen HW). + +For example, when building for the nRF52 DK and the nPM1300 EK, the following command can be used: + +.. zephyr-app-commands:: + :zephyr-app: samples/shields/npm13xx_ek + :board: nrf52dk/nrf52832 + :shield: npm1300_ek + :goals: build + :compact: + +Testing +******* + +After flashing the sample FW, you need to connect to the shell interface, where in case of +successful initialization you will see the nPM13xx PMIC status messages containing charger status +and battery voltage, current and temperature. Pressing and releasing the SHPHLD button on the EK +will generate interrupts and these events will also be printed in the shell. + +Pressing a dedicated button on the host DK (Button 1 on an nRF52 Series DK) will cycle DVS states. + + +-------------------------------------+----------------+---------------+---------------+ + | **DVS state** (GPIO1 | GPIO2 level) | **BUCK2 mode** | **LDO1 mode** | **LDO2 mode** | + +-------------------------------------+----------------+---------------+---------------+ + | **0** (HIGH | HIGH) | OFF | OFF | OFF | + +-------------------------------------+----------------+---------------+---------------+ + | **1** (LOW | HIGH) | ON retention | OFF | OFF | + +-------------------------------------+----------------+---------------+---------------+ + | **2** (HIGH | LOW) | OFF | ON | ON | + +-------------------------------------+----------------+---------------+---------------+ + | **3** (LOW | LOW) | ON PWM | ON | ON | + +-------------------------------------+----------------+---------------+---------------+ + +.. note:: + On an nRF52 Series DK, DVS pins are also used for the onboard LED1 and LED2, so you can observe + the DVS state pins visually: an LED lights up when the respective pin is LOW + +Regulators +********** + +The ``regulator`` shell interface provides several subcommand to test +the regulators embedded in the PMIC. Below you can find some command examples. + +.. code-block:: console + + # list all the supported voltages by BUCK1 + uart:~$ regulator vlist BUCK1 + 1.000 V + 1.100 V + ... + +.. code-block:: console + + # enable BUCK2 + uart:~$ regulator enable BUCK2 + # disable BUCK2 + uart:~$ regulator disable BUCK2 + +.. code-block:: console + + # set BUCK2 voltage to exactly 2V + uart:~$ regulator vset BUCK2 2V + # obtain the actual BUCK1 configured voltage + uart:~$ regulator vget BUCK1 + 1.800 V + # set BUCK1 voltage to a value between 2.35V and 2.45V + uart:~$ regulator set BUCK1 2.35V 2.45V + # obtain the actual BUCK1 configured voltage + uart:~$ regulator get BUCK1 + 2.400 V diff --git a/samples/shields/npm1300_ek/nrf52dk_nrf52832.overlay b/samples/shields/npm13xx_ek/npm1300.overlay similarity index 88% rename from samples/shields/npm1300_ek/nrf52dk_nrf52832.overlay rename to samples/shields/npm13xx_ek/npm1300.overlay index e4f2cca20ce..408c1b8715d 100644 --- a/samples/shields/npm1300_ek/nrf52dk_nrf52832.overlay +++ b/samples/shields/npm13xx_ek/npm1300.overlay @@ -1,12 +1,7 @@ /* - * Copyright (C) 2023 Nordic Semiconductor ASA + * Copyright (C) 2025 Nordic Semiconductor ASA * SPDX-License-Identifier: Apache-2.0 */ - &i2c0_default { - group1 { - bias-pull-up; - }; -}; &npm1300_ek_regulators { dvs-gpios = <&gpio0 17 GPIO_ACTIVE_LOW>, diff --git a/samples/shields/npm13xx_ek/npm1304.overlay b/samples/shields/npm13xx_ek/npm1304.overlay new file mode 100644 index 00000000000..010c7d4897a --- /dev/null +++ b/samples/shields/npm13xx_ek/npm1304.overlay @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2025 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +&npm1304_ek_regulators { + dvs-gpios = <&gpio0 17 GPIO_ACTIVE_LOW>, + <&gpio0 18 GPIO_ACTIVE_LOW>; +}; + +&npm1304_ek_buck1 { + regulator-init-microvolt = <2000000>; +}; + +&npm1304_ek_buck2 { + regulator-init-microvolt = <3300000>; + retention-microvolt = <2500000>; + enable-gpio-config = <1 GPIO_ACTIVE_LOW>; + retention-gpio-config = <2 GPIO_ACTIVE_HIGH>; + pwm-gpio-config = <2 GPIO_ACTIVE_LOW>; +}; + +&npm1304_ek_ldo1 { + regulator-initial-mode = ; + enable-gpio-config = <2 GPIO_ACTIVE_LOW>; +}; + +&npm1304_ek_ldo2 { + regulator-initial-mode = ; + enable-gpio-config = <2 GPIO_ACTIVE_LOW>; +}; + +&npm1304_ek_pmic { + host-int-gpios = <&gpio0 22 0>; + pmic-int-pin = <3>; +}; diff --git a/samples/shields/npm1300_ek/prj.conf b/samples/shields/npm13xx_ek/prj.conf similarity index 100% rename from samples/shields/npm1300_ek/prj.conf rename to samples/shields/npm13xx_ek/prj.conf diff --git a/samples/shields/npm13xx_ek/sample.yaml b/samples/shields/npm13xx_ek/sample.yaml new file mode 100644 index 00000000000..98c68d54e32 --- /dev/null +++ b/samples/shields/npm13xx_ek/sample.yaml @@ -0,0 +1,17 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +sample: + name: nPM13xx EK +common: + platform_allow: nrf52dk/nrf52832 + depends_on: arduino_i2c + tags: + - shield + - regulator + - sensor +tests: + sample.shields.npm1300_ek: + extra_args: SHIELD=npm1300_ek + sample.shields.npm1304_ek: + extra_args: SHIELD=npm1304_ek diff --git a/samples/shields/npm1300_ek/src/main.c b/samples/shields/npm13xx_ek/src/main.c similarity index 81% rename from samples/shields/npm1300_ek/src/main.c rename to samples/shields/npm13xx_ek/src/main.c index 9ecffb69e21..0473c566235 100644 --- a/samples/shields/npm1300_ek/src/main.c +++ b/samples/shields/npm13xx_ek/src/main.c @@ -19,15 +19,25 @@ #define SLEEP_TIME_MS 100 #define UPDATE_TIME_MS 2000 +#if CONFIG_SHIELD_NPM1300_EK +#define SHIELD_LABEL(component) DT_NODELABEL(npm1300_ek_ ## component) +#elif CONFIG_SHIELD_NPM1304_EK +#define SHIELD_LABEL(component) DT_NODELABEL(npm1304_ek_ ## component) +#else +#error "either npm1300_ek or npm1304_ek shield should be selected" +#endif + +#define NPM13XX_DEVICE(dev) DEVICE_DT_GET(SHIELD_LABEL(dev)) + static const struct gpio_dt_spec button1 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios); -static const struct device *regulators = DEVICE_DT_GET(DT_NODELABEL(npm1300_ek_regulators)); +static const struct device *regulators = NPM13XX_DEVICE(regulators); -static const struct device *charger = DEVICE_DT_GET(DT_NODELABEL(npm1300_ek_charger)); +static const struct device *charger = NPM13XX_DEVICE(charger); -static const struct device *leds = DEVICE_DT_GET(DT_NODELABEL(npm1300_ek_leds)); +static const struct device *leds = NPM13XX_DEVICE(leds); -static const struct device *pmic = DEVICE_DT_GET(DT_NODELABEL(npm1300_ek_pmic)); +static const struct device *pmic = NPM13XX_DEVICE(pmic); void configure_ui(void) { @@ -53,9 +63,14 @@ void configure_ui(void) } } -static void event_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) +static void event_callback(const struct device *dev, struct gpio_callback *cb, uint32_t events) { - printk("Event detected\n"); + if (events & BIT(NPM13XX_EVENT_SHIPHOLD_PRESS)) { + printk("SHPHLD pressed\n"); + } + if (events & BIT(NPM13XX_EVENT_SHIPHOLD_RELEASE)) { + printk("SHPHLD released\n"); + } } void configure_events(void) @@ -68,7 +83,8 @@ void configure_events(void) /* Setup callback for shiphold button press */ static struct gpio_callback event_cb; - gpio_init_callback(&event_cb, event_callback, BIT(NPM13XX_EVENT_SHIPHOLD_PRESS)); + gpio_init_callback(&event_cb, event_callback, BIT(NPM13XX_EVENT_SHIPHOLD_PRESS) | + BIT(NPM13XX_EVENT_SHIPHOLD_RELEASE)); mfd_npm13xx_add_callback(pmic, &event_cb); }