Hi.
I want to modify the "nPM1300 One Button" example.
I need the Ship mode to be activated after pressing and holding the SHPHLD button for longer than 3 seconds. The Ship mode should activate before I release the SHPHLD button.
I plan to implement this function using the nRF52 timer, but for some reason the function regulator_parent_ship_mode() is not executed inside the timer function (timer0_handler).
#include <zephyr/drivers/mfd/npm1300.h> #include <zephyr/drivers/regulator.h> static const struct device *pmic = DEVICE_DT_GET(DT_NODELABEL(npm1300_ek_pmic)); static const struct device *regulators = DEVICE_DT_GET(DT_NODELABEL(npm1300_ek_regulators)); static int press_t; static void timer0_handler(struct k_timer *dummy) { /*Interrupt Context - System Timer ISR */ press_t = k_uptime_get() - press_t; LOG_INF("timer0_handler function started. Press_time = %d", press_t); if (vbus_connected) { LOG_INF("Ship mode entry not possible with USB connected\n"); } else { LOG_INF("SHIP MODE"); regulator_parent_ship_mode(regulators); } } K_TIMER_DEFINE(timer0, timer0_handler, NULL); static void event_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { if (pins & BIT(NPM1300_EVENT_SHIPHOLD_PRESS)) { LOG_INF("SHPHLD press"); press_t = k_uptime_get(); /* start timer */ k_timer_start(&timer0, K_MSEC(3000), K_NO_WAIT); } if (pins & BIT(NPM1300_EVENT_SHIPHOLD_RELEASE)) { LOG_INF("SHPHLD release"); /* stop timer */ k_timer_stop(&timer0); } if (pins & BIT(NPM1300_EVENT_VBUS_DETECTED)) { LOG_INF("Vbus connected\n"); vbus_connected = true; } if (pins & BIT(NPM1300_EVENT_VBUS_REMOVED)) { LOG_INF("Vbus removed\n"); vbus_connected = false; } } bool configure_events(void) ... int main(void) { LOG_INF("PMIC device ok"); while (1) { led_on(leds, 2U); k_msleep(1000); led_off(leds, 2U); k_msleep(1000); fuel_gauge_update(charger); } }
The result of the program is on the screenshot -->
As you can see, the program executes the code inside the function timer0_handler, but for some reason it does not switch to the Ship mode and continues to execute the code in the main function.
Please tell me why this is happening and where I am making a mistake?
Thank you.