First commit
This commit is contained in:
17
drivers/button/button.c
Normal file
17
drivers/button/button.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "button.h"
|
||||
#include <zephyr/sys/printk.h>
|
||||
|
||||
#define BUTTON_NODE DT_NODELABEL(button0)
|
||||
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET(BUTTON_NODE, gpios);
|
||||
|
||||
void button_init(void) {
|
||||
if (!device_is_ready(button.port)) {
|
||||
printk("Button device not ready\n");
|
||||
return;
|
||||
}
|
||||
gpio_pin_configure_dt(&button, GPIO_INPUT);
|
||||
}
|
||||
|
||||
int button_read(void) {
|
||||
return gpio_pin_get_dt(&button);
|
||||
}
|
||||
9
drivers/button/button.h
Normal file
9
drivers/button/button.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef BUTTON_H
|
||||
#define BUTTON_H
|
||||
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
void button_init(void);
|
||||
int button_read(void);
|
||||
|
||||
#endif // BUTTON_H
|
||||
Reference in New Issue
Block a user