工程路径:
zephyr\samples\hello_world
需要修改的文件
1. overlay文件
/ {
buttons {
compatible = "gpio-keys";
/*p0.23*/
M_BUTTON1: m_button1 {
gpios = <&gpio0 23 (GPIO_PULL_UP|GPIO_ACTIVE_LOW)>;
label = "M_BUTTON1";
};
/*p1.06 端口1模式下面需要切换到secure mode 否则会出现不起作用*/
/* https://devzone.nordicsemi.com/f/nordic-q-a/68786/p1-04-configuration-on-nrf5340 */
M_BUTTON2: m_button2 {
gpios = <&gpio1 6 (GPIO_PULL_UP|GPIO_ACTIVE_LOW)>;
label = "M_BUTTON2";
};
};
};
2.prj.conf
CONFIG_GPIO=y
3.main.c
#include <drivers/gpio.h>
#include <hal/nrf_gpio.h>
#define BUTTON_1_PORT DT_GPIO_LABEL(DT_NODELABEL(m_button1), gpios)
#define BUTTON_1_PIN DT_GPIO_PIN(DT_NODELABEL(m_button1), gpios)
#define BUTTON_1_FLAGS DT_GPIO_FL