Skip to content

Commit

Permalink
samples: canbus: convert to new GPIO API
Browse files Browse the repository at this point in the history
Use the new API to control the button and LEDS.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
  • Loading branch information
pabigot committed Jan 26, 2020
1 parent 603cef7 commit 73d24e3
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions samples/subsys/canbus/canopen/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ static struct gpio_callback button_callback;

struct led_indicator {
struct device *dev;
u32_t pin;
u32_t flags;
gpio_pin_t pin;
};

static struct led_indicator led_green;
Expand All @@ -68,11 +67,7 @@ static void led_callback(bool value, void *arg)
return;
}

if ((led->flags & GPIO_INT_ACTIVE_HIGH) == GPIO_INT_ACTIVE_LOW) {
drive = !drive;
}

gpio_pin_write(led->dev, led->pin, drive);
gpio_pin_set(led->dev, led->pin, drive);
}

/**
Expand All @@ -88,17 +83,19 @@ static void config_leds(CO_NMT_t *nmt)
#ifdef LED_GREEN_PORT
led_green.dev = device_get_binding(LED_GREEN_PORT);
led_green.pin = LED_GREEN_PIN;
led_green.flags = LED_GREEN_FLAGS;
if (led_green.dev) {
gpio_pin_configure(led_green.dev, LED_GREEN_PIN, GPIO_DIR_OUT);
gpio_pin_configure(led_green.dev, LED_GREEN_PIN,
GPIO_OUTPUT_INACTIVE
| LED_GREEN_FLAGS);
}
#endif /* LED_GREEN_PORT */
#ifdef LED_RED_PORT
led_red.dev = device_get_binding(LED_RED_PORT);
led_red.pin = LED_RED_PIN;
led_red.flags = LED_RED_FLAGS;
if (led_red.dev) {
gpio_pin_configure(led_red.dev, LED_RED_PIN, GPIO_DIR_OUT);
gpio_pin_configure(led_red.dev, LED_RED_PIN,
GPIO_OUTPUT_INACTIVE
| LED_RED_FLAGS);
}
#endif /* LED_RED_PORT */

Expand Down Expand Up @@ -175,9 +172,8 @@ static void config_button(void)
return;
}

err = gpio_pin_configure(dev, BUTTON_PIN, GPIO_DIR_IN |
GPIO_INT_DEBOUNCE | GPIO_INT |
GPIO_INT_EDGE | BUTTON_FLAGS);
err = gpio_pin_configure(dev, BUTTON_PIN,
GPIO_INPUT | BUTTON_FLAGS);

gpio_init_callback(&button_callback, button_isr_callback,
BIT(BUTTON_PIN));
Expand All @@ -188,7 +184,8 @@ static void config_button(void)
return;
}

err = gpio_pin_enable_callback(dev, BUTTON_PIN);
err = gpio_pin_interrupt_configure(dev, BUTTON_PIN,
GPIO_INT_EDGE_TO_ACTIVE);
if (err) {
LOG_ERR("failed to enable button callback");
return;
Expand Down

0 comments on commit 73d24e3

Please sign in to comment.