/
Controlling nPM1300 LEDs

Controlling nPM1300 LEDs

1. Overview

This application note describes how to configure nPM1300 LEDs in Zephyr BSP and use it in the user application.

2. Configuring nPM1300 LEDs in Zephyr BSP

The nPM1300 LEDs device is declared in nrf9151som_nrf9151_ns.dts as a child node of the npm1300_pmic device:

npm1300_pmic: pmic@6b { compatible = "nordic,npm1300"; ... npm1300_leds: npm1300_leds { compatible = "nordic,npm1300-led"; nordic,led0-mode = "host"; nordic,led1-mode = "host"; nordic,led2-mode = "host"; }; ... };

The devicetree node configures the following parameters:

Parameter

Value

Description

Parameter

Value

Description

compatible

"nordic,npm1300-led"

Enables the led_npm1300.c driver and associates it with the device.

nordic,led0-mode

"host"

LED <0|1|2> mode

nordic,led1-mode

"host"

nordic,led2-mode

"host"

3. Controlling nPM1300 LEDs in User Application

3.1. nPM1300 LEDs C-binding API

The Customized Asset Tracker v2 application makes use of the Zephyr LED API to control nPM1300 LEDs:

Function

Description

Comments

int led_on (const struct device *dev, uint32_t led);

Turn on the LED.

dev - LED device

led - LED number

Returns zero on success, otherwise a negative error code is returned.

int led_off (const struct device *dev, uint32_t led);

Turn off the LED.

dev - LED device

led - LED number

Returns zero on success, otherwise a negative error code is returned.

3.2. nPM1300 LEDs Shell Commands

The Customized Asset Tracker v2 application provides a set of Zephyr shell commands for nPM1300 LEDs:

Command

Parameters

Comments

led on

npm1300_leds <0|1>

Turn the LED on.

led off

npm1300_leds <0|1>

Turn the LED off.

4. Validating nPM1300 LED Operations

  1. Turn on the Charging LED and verify that the green LED has been turned on:

    uart:~$ led on npm1300_leds 0 npm1300_leds: turning on LED 0
  2. Turn on the Charging LED and verify that the green LED has been turned off:

    uart:~$ led off npm1300_leds 0 npm1300_leds: turning off LED 0
  3. Turn on the Error LED and verify that the red LED has been turned on:

    uart:~$ led on npm1300_leds 1 npm1300_leds: turning on LED 1
  4. Turn on the Error LED and verify that the red LED has been turned off:

    uart:~$ led off npm1300_leds 1 npm1300_leds: turning off LED 1

Related content