This commit is contained in:
parent
22d036515c
commit
555419f701
@ -1,3 +1,30 @@
|
|||||||
|
#include <zephyr/device.h>
|
||||||
|
#include <zephyr/drivers/gpio.h>
|
||||||
|
#include <zephyr/sys/util.h>
|
||||||
|
#include <zephyr/sys/printk.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#define SLEEP_TIME_MS 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get button configuration from the devicetree sw0 alias. This is mandatory.
|
||||||
|
*/
|
||||||
|
#define SW0_NODE DT_ALIAS(sw0)
|
||||||
|
#if !DT_NODE_HAS_STATUS(SW0_NODE, okay)
|
||||||
|
#error "Unsupported board: sw0 devicetree alias is not defined"
|
||||||
|
#endif
|
||||||
|
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,
|
||||||
|
{0});
|
||||||
|
static struct gpio_callback button_cb_data;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The led0 devicetree alias is optional. If present, we'll use it
|
||||||
|
* to turn on the LED whenever the button is pressed.
|
||||||
|
*/
|
||||||
|
static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,
|
||||||
|
{0});
|
||||||
|
|
||||||
|
|
||||||
void button_pressed(const struct device *dev, struct gpio_callback *cb,
|
void button_pressed(const struct device *dev, struct gpio_callback *cb,
|
||||||
uint32_t pins)
|
uint32_t pins)
|
||||||
{
|
{
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
#include <zephyr/device.h>
|
|
||||||
#include <zephyr/drivers/gpio.h>
|
|
||||||
#include <zephyr/sys/util.h>
|
|
||||||
#include <zephyr/sys/printk.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#define SLEEP_TIME_MS 1
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get button configuration from the devicetree sw0 alias. This is mandatory.
|
|
||||||
*/
|
|
||||||
#define SW0_NODE DT_ALIAS(sw0)
|
|
||||||
#if !DT_NODE_HAS_STATUS(SW0_NODE, okay)
|
|
||||||
#error "Unsupported board: sw0 devicetree alias is not defined"
|
|
||||||
#endif
|
|
||||||
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,
|
|
||||||
{0});
|
|
||||||
static struct gpio_callback button_cb_data;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The led0 devicetree alias is optional. If present, we'll use it
|
|
||||||
* to turn on the LED whenever the button is pressed.
|
|
||||||
*/
|
|
||||||
static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,
|
|
||||||
{0});
|
|
@ -1,3 +1,12 @@
|
|||||||
|
/* --------- */
|
||||||
|
/* LED */
|
||||||
|
/* --------- */
|
||||||
|
|
||||||
|
/* Imports / Declarations */
|
||||||
|
#include <zephyr/drivers/gpio.h>
|
||||||
|
#define LED0_NODE DT_ALIAS(led0)
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
int blink_led(void) {
|
int blink_led(void) {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -19,3 +28,14 @@ int blink_led(void) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Example:
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
blink_led();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*/
|
@ -1,2 +0,0 @@
|
|||||||
#include <zephyr/drivers/gpio.h>
|
|
||||||
#define LED0_NODE DT_ALIAS(led0)
|
|
Loading…
Reference in New Issue
Block a user