samples: blinky: update to use new GPIO API
Update gpio_pin_configure() to take into account GPIO flags defined by the devicetree. Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
This commit is contained in:
parent
30a97ce28e
commit
ebc5bc62b0
1 changed files with 20 additions and 12 deletions
|
@ -8,25 +8,33 @@
|
|||
#include <device.h>
|
||||
#include <drivers/gpio.h>
|
||||
|
||||
#define LED_PORT DT_ALIAS_LED0_GPIOS_CONTROLLER
|
||||
#define LED DT_ALIAS_LED0_GPIOS_PIN
|
||||
|
||||
/* 1000 msec = 1 sec */
|
||||
#define SLEEP_TIME 1000
|
||||
#define SLEEP_TIME_MS 1000
|
||||
|
||||
#ifndef DT_ALIAS_LED0_GPIOS_FLAGS
|
||||
#define DT_ALIAS_LED0_GPIOS_FLAGS 0
|
||||
#endif
|
||||
|
||||
void main(void)
|
||||
{
|
||||
u32_t cnt = 0;
|
||||
struct device *dev;
|
||||
bool led_is_on = false;
|
||||
int ret;
|
||||
|
||||
dev = device_get_binding(LED_PORT);
|
||||
/* Set LED pin as output */
|
||||
gpio_pin_configure(dev, LED, GPIO_DIR_OUT);
|
||||
dev = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER);
|
||||
if (dev == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
ret = gpio_pin_configure(dev, DT_ALIAS_LED0_GPIOS_PIN, GPIO_OUTPUT |
|
||||
DT_ALIAS_LED0_GPIOS_FLAGS);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
/* Set pin to HIGH/LOW every 1 second */
|
||||
gpio_pin_write(dev, LED, cnt % 2);
|
||||
cnt++;
|
||||
k_sleep(SLEEP_TIME);
|
||||
gpio_pin_set(dev, DT_ALIAS_LED0_GPIOS_PIN, (int)led_is_on);
|
||||
led_is_on = !led_is_on;
|
||||
k_sleep(SLEEP_TIME_MS);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue