Skip to content

Commit

Permalink
lib: dk_buttons_and_lets: Remove DK_LIBRARY_BUTTON_NO_ISR
Browse files Browse the repository at this point in the history
The nRF54L15PDK is no longer supported.

Signed-off-by: Carles Cufi <[email protected]>
  • Loading branch information
carlescufi committed Nov 20, 2024
1 parent cde2597 commit 4c9fd9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 50 deletions.
24 changes: 0 additions & 24 deletions lib/dk_buttons_and_leds/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,12 @@ if DK_LIBRARY

config DK_LIBRARY_BUTTON_SCAN_INTERVAL
int "Scanning interval of buttons in milliseconds"
default 50 if DK_LIBRARY_BUTTON_NO_ISR
default 10

config DK_LIBRARY_DYNAMIC_BUTTON_HANDLERS
bool "Enable the runtime assignable button handler API"
default y

config DK_LIBRARY_BUTTON_NO_ISR
bool "Poll buttons unconditionally (no interrupts) [EXPERIMENTAL]"
# Workaround for buttons on nRF54L15 PDK in revision 0.2.x.
default y if BOARD_NRF54L15PDK_NRF54L15_CPUAPP && (BOARD_REVISION = "0.2.0" || BOARD_REVISION = "0.2.1")
select EXPERIMENTAL
help
With this option disabled, the module periodically scans all the
available buttons until no button is pressed. If no button is
pressed, the module uses GPIO interrupts to detect the first button
press. On the first button press, the module switches back to
periodically scanning buttons.

Enable this option to avoid relying on GPIO interrupts at all and
to unconditionally scan all buttons periodically. Please note that
the constant scanning activity increases the overall power
consumption of the system.

For example, in case the application uses Button 3 or 4, the option
must be set for the nRF54L15 PDK (PCA10156) revisions
v0.2.0 AA0-ES2, v0.2.0 AA0-ES3, and v0.2.1 AB0-ES5.
These versions of the PDK have Buttons 3 and 4 connected to
the GPIO port which does not support interrupts.

module = DK_LIBRARY
module-str = DK library
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
Expand Down
47 changes: 21 additions & 26 deletions lib/dk_buttons_and_leds/dk_buttons_and_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ static void buttons_scan_fn(struct k_work *work)
static bool initial_run = true;
uint32_t button_scan;

__ASSERT_NO_MSG(!IS_ENABLED(CONFIG_DK_LIBRARY_BUTTON_NO_ISR) || !irq_enabled);

if (!IS_ENABLED(CONFIG_DK_LIBRARY_BUTTON_NO_ISR) && irq_enabled) {
if (irq_enabled) {
/* Disable GPIO interrupts for edge triggered devices.
* Devices that are configured with active high interrupts are already disabled.
*/
Expand Down Expand Up @@ -159,7 +157,7 @@ static void buttons_scan_fn(struct k_work *work)

last_button_scan = button_scan;

if (IS_ENABLED(CONFIG_DK_LIBRARY_BUTTON_NO_ISR) || (button_scan != 0)) {
if (button_scan != 0) {
k_work_reschedule(&buttons_scan,
K_MSEC(CONFIG_DK_LIBRARY_BUTTON_SCAN_INTERVAL));
} else {
Expand Down Expand Up @@ -238,6 +236,7 @@ static void button_pressed(const struct device *gpio_dev, struct gpio_callback *

int dk_buttons_init(button_handler_t button_handler)
{
uint32_t pin_mask = 0;
int err;

button_handler_cb = button_handler;
Expand All @@ -259,31 +258,27 @@ int dk_buttons_init(button_handler_t button_handler)
}
}

if (!IS_ENABLED(CONFIG_DK_LIBRARY_BUTTON_NO_ISR)) {
uint32_t pin_mask = 0;

for (size_t i = 0; i < ARRAY_SIZE(buttons); i++) {
/* Module starts in scanning mode and will switch to
* callback mode if no button is pressed.
*/
err = gpio_pin_interrupt_configure_dt(&buttons[i],
GPIO_INT_DISABLE);
if (err) {
LOG_ERR("Cannot disable callbacks()");
return err;
}

pin_mask |= BIT(buttons[i].pin);
for (size_t i = 0; i < ARRAY_SIZE(buttons); i++) {
/* Module starts in scanning mode and will switch to
* callback mode if no button is pressed.
*/
err = gpio_pin_interrupt_configure_dt(&buttons[i],
GPIO_INT_DISABLE);
if (err) {
LOG_ERR("Cannot disable callbacks()");
return err;
}

gpio_init_callback(&gpio_cb, button_pressed, pin_mask);
pin_mask |= BIT(buttons[i].pin);
}

for (size_t i = 0; i < ARRAY_SIZE(buttons); i++) {
err = gpio_add_callback(buttons[i].port, &gpio_cb);
if (err) {
LOG_ERR("Cannot add callback");
return err;
}
gpio_init_callback(&gpio_cb, button_pressed, pin_mask);

for (size_t i = 0; i < ARRAY_SIZE(buttons); i++) {
err = gpio_add_callback(buttons[i].port, &gpio_cb);
if (err) {
LOG_ERR("Cannot add callback");
return err;
}
}

Expand Down

0 comments on commit 4c9fd9e

Please sign in to comment.