Commit 8386a499 authored by Tomasz Bursztyka's avatar Tomasz Bursztyka Committed by Anas Nashif
Browse files

samples: Using new GPIO API callbacks



Adapting GPIO samples to use the new callback format.

Change-Id: I944dce4faeeee30117edbd7a065e40caa0b7ed66
Signed-off-by: default avatarTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
parent 62fcd4ca
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <misc/util.h>

#if defined(CONFIG_STDOUT_CONSOLE)
#include <stdio.h>
@@ -36,11 +37,14 @@
#define EDGE    (GPIO_INT_EDGE | GPIO_INT_ACTIVE_LOW)


void button_pressed(struct device *gpiob, uint32_t pin)
void button_pressed(struct device *gpiob,
		    struct gpio_callback *cb, uint32_t pins)
{
	PRINT("Button pressed at %d\n", sys_tick_get_32());
}

static struct gpio_callback gpio_cb;

void main(void)
{
	struct device *gpiob;
@@ -51,7 +55,10 @@ void main(void)
			GPIO_DIR_IN | GPIO_INT
			| EDGE
			| PULL_UP);
	gpio_set_callback(gpiob, button_pressed);

	gpio_init_callback(&gpio_cb, button_pressed, BIT(PIN));

	gpio_add_callback(gpiob, &gpio_cb);
	gpio_pin_enable_callback(gpiob, PIN);

	while (1) {
+9 −3
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@
#include <device.h>
#include <gpio.h>
#include <sys_clock.h>
#include <misc/util.h>

#define SLEEPTICKS	SECONDS(1)

@@ -152,11 +153,14 @@
#error "Unsupported GPIO driver"
#endif

void gpio_callback(struct device *port, uint32_t pin)
void gpio_callback(struct device *port,
		   struct gpio_callback *cb, uint32_t pins)
{
	PRINT(GPIO_NAME "%d triggered\n", pin);
	PRINT(GPIO_NAME "%d triggered\n", GPIO_INT_PIN);
}

static struct gpio_callback gpio_cb;

void main(void)
{
	struct nano_timer timer;
@@ -186,7 +190,9 @@ void main(void)
		PRINT("Error configuring " GPIO_NAME "%d!\n", GPIO_INT_PIN);
	}

	ret = gpio_set_callback(gpio_dev, gpio_callback);
	gpio_init_callback(&gpio_cb, gpio_callback, BIT(GPIO_INT_PIN));

	ret = gpio_add_callback(gpio_dev, &gpio_cb);
	if (ret) {
		PRINT("Cannot setup callback!\n");
	}