Skip to content

Commit

Permalink
samples: shields: npm1300_ek: Added LED to example
Browse files Browse the repository at this point in the history
Updated shield sample to drive LED

Signed-off-by: Andy Sinclair <andy.sinclair@nordicsemi.no>
  • Loading branch information
aasinclair authored and fabiobaltieri committed Jun 23, 2023
1 parent 198d5b8 commit d79cf20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions samples/shields/npm1300_ek/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ CONFIG_LOG=y
CONFIG_GPIO=y
CONFIG_REGULATOR=y
CONFIG_SENSOR=y
CONFIG_LED=y
17 changes: 17 additions & 0 deletions samples/shields/npm1300_ek/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zephyr/drivers/regulator.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/drivers/sensor/npm1300_charger.h>
#include <zephyr/drivers/led.h>
#include <zephyr/dt-bindings/regulator/npm1300.h>
#include <zephyr/sys/printk.h>
#include <getopt.h>
Expand All @@ -23,6 +24,8 @@ static const struct device *regulators = DEVICE_DT_GET(DT_NODELABEL(npm1300_ek_r

static const struct device *charger = DEVICE_DT_GET(DT_NODELABEL(npm1300_ek_charger));

static const struct device *leds = DEVICE_DT_GET(DT_NODELABEL(npm1300_ek_leds));

void configure_ui(void)
{
int ret;
Expand All @@ -40,6 +43,11 @@ void configure_ui(void)
}

printk("Set up button at %s pin %d\n", button1.port->name, button1.pin);

if (!device_is_ready(leds)) {
printk("Error: led device is not ready\n");
return;
}
}

void read_sensors(void)
Expand Down Expand Up @@ -92,6 +100,15 @@ int main(void)
regulator_parent_dvs_state_set(regulators, dvs_state);
}

/* Update PMIC LED if button state has changed */
if (button_state != last_button) {
if (button_state) {
led_on(leds, 2U);
} else {
led_off(leds, 2U);
}
}

/* Read and display charger status */
static int count;

Expand Down

0 comments on commit d79cf20

Please sign in to comment.