Update repo
This commit is contained in:
1 parent
7c6fbea774
commit
0afe39c8fe
10 files changed
+324
No files matched your search
@@ -0,0 +1,66 @@
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/uart.h>
|
||||
#include <zephyr/drivers/adc.h>
|
||||
|
||||
|
||||
#if !DT_NODE_HAS_STATUS(DT_ALIAS(sw0), okay)
|
||||
#error "Board does not define alias sw0. Add a boad overlay"
|
||||
#endif
|
||||
|
||||
static const struct gpio_dt_spec button =
|
||||
GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
|
||||
|
||||
static struct gpio_callback button_cb;
|
||||
|
||||
|
||||
static void button_isr(const struct device *port,
|
||||
struct gpio_callback *cb,
|
||||
gpio_port_pins_t pins)
|
||||
{
|
||||
ARG_UNUSED(port);
|
||||
ARG_UNUSED(pins);
|
||||
ARG_UNUSED(cb);
|
||||
|
||||
// Do something
|
||||
int v = gpio_pin_get_dt(&button);
|
||||
|
||||
if(v >= 0) {
|
||||
printk("[IRQ] Button state: %s\r\n", v ? "ACTIVE" : "INVACTIVE");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if(!device_is_ready(button.port)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(gpio_pin_configure_dt(&button, GPIO_INPUT) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Set up callback and register it
|
||||
gpio_init_callback(&button_cb, button_isr, BIT(button.pin));
|
||||
gpio_add_callback(button.port, &button_cb);
|
||||
|
||||
|
||||
if(gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_BOTH) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
printk("\r\n[EXTI] Button pin interrupt is ready. Press button\r\n");
|
||||
|
||||
while (1) {
|
||||
|
||||
k_sleep(K_FOREVER);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user