Hello:
I created an app.overlay.
Here it is:
/ {
aliases {
fra_sw = &fra_sw0;
};
fra_sw0: fra_sw0 {
gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "FRA_SWITCH";
};
};
The build returned the following error:
C:/ncs/v3.2.1/zephyr/include/zephyr/device.h:96:41: error: '__device_dts_ord_DT_N_S_fra_sw0_P_gpios_IDX_0_PH_ORD' undeclared here (not in a function)
96 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
I did a lot of research on the internet and created the app.overlay below:
/ {
aliases {
frasw = &fra_sw0;
};
fra_buttons {
compatible = "gpio-keys";
fra_sw0: fra_sw0 {
gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "FRA_SWITCH";
};
};
};
The build returned no errors.
Questions:
- What is the function of the instructions?
fra_buttons {
compatible = "gpio-keys";?
- Is there another way to create the app.overlay, or is the method that didn't produce an error the correct one?
main.c is below:
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/printk.h>
#define SW_NODE DT_ALIAS(frasw)
#if !DT_NODE_HAS_STATUS(SW_NODE, okay)
#error "Alias 'frasw' not defined in the devicetree overlay."
#endif
static const struct gpio_dt_spec sw = GPIO_DT_SPEC_GET(SW_NODE, gpios);
static struct gpio_callback sw_cb;
static void sw_pressed_isr(const struct device *dev,
struct gpio_callback *cb,
uint32_t pins)
{
ARG_UNUSED(dev);
ARG_UNUSED(cb);
ARG_UNUSED(pins);
printk("FRA: Switch pressed!\n");
}
int main(void)
{
int ret;
if (!device_is_ready(sw.port)) {
printk("ERROR: GPIO device not ready\n");
return 0;
}
ret = gpio_pin_configure_dt(&sw, GPIO_INPUT);
if (ret) {
printk("ERROR: gpio_pin_configure_dt failed (%d)\n", ret);
return 0;
}
ret = gpio_pin_interrupt_configure_dt(&sw, GPIO_INT_EDGE_TO_ACTIVE);
if (ret) {
printk("ERROR: gpio_pin_interrupt_configure_dt failed (%d)\n", ret);
return 0;
}
gpio_init_callback(&sw_cb, sw_pressed_isr, BIT(sw.pin));
gpio_add_callback(sw.port, &sw_cb);
printk("FRA: Switch test started on P0.%02d (ACTIVE_LOW, pull-up).\n", sw.pin);
while (1) {
k_sleep(K_SECONDS(1));
}
}
Best Regards
Luiz Miranda