Update repo

This commit is contained in:
hangpersonal committed 2026-09-21 22:29:53 -07:00
1 parent 7c6fbea774
commit 0afe39c8fe
10 files changed
+324

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.20.0)
# Locate the Zephyr build system as a CMake package
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
# Project name
project(button_exti_irq)
# Add source files belong to this application
target_sources(app PRIVATE src/main.c)
@@ -0,0 +1,33 @@
/ {
aliases {
led0 = &red_led;
led1 = &blue_led;
led2 = &green_led;
sw0 = &user_button0;
};
gpio_keys {
compatible = "gpio-keys";
user_button0: button {
label = "Button";
gpios = <&gpioc 13 GPIO_ACTIVE_HIGH>;
zephyr,code = <INPUT_KEY_0>;
};
};
};
&adc1{
pinctrl-0 = <&adc1_in1_pa1 &adc1_in4_pa4 &adc1_in8_pb0>;
pinctrl-names = "default";
st,adc-prescaler = <4>;
status = "okay";
};
/*---Uncomment this block ONLY if your build complains the labels are undeclared---
&pinctrl{
adc1_in1_pa1: adc1_in1_pa1 { pinmux = <STM32_PINMUX('A', 1, ANALOG)>; }
adc1_in4_pa4: adc1_in4_pa4 { pinmux = <STM32_PINMUX('A', 4, ANALOG)>; }
adc1_in8_pb0: adc1_in8_pb0 { pinmux = <STM32_PINMUX('B', 0, ANALOG)>; }
}
*/
@@ -0,0 +1,24 @@
/ {
aliases {
led0 = &red_led_5;
led1 = &blue_led_6;
led2 = &green_led_4;
led3 = &orange_led_3;
sw0 = &user_button;
};
};
&adc1{
pinctrl-0 = <&adc1_in1_pa1 &adc1_in4_pa4 &adc1_in8_pb0>;
pinctrl-names = "default";
st,adc-prescaler = <4>;
status = "okay";
};
/*---Uncomment this block ONLY if your build complains the labels are undeclared---
&pinctrl{
adc1_in1_pa1: adc1_in1_pa1 { pinmux = <STM32_PINMUX('A', 1, ANALOG)>; }
adc1_in4_pa4: adc1_in4_pa4 { pinmux = <STM32_PINMUX('A', 4, ANALOG)>; }
adc1_in8_pb0: adc1_in8_pb0 { pinmux = <STM32_PINMUX('B', 0, ANALOG)>; }
}
*/
+7
View File
@@ -0,0 +1,7 @@
CONFIG_GPIO=y
CONFIG_CONSOLE=y
CONFIG_PRINTK=y
CONFIG_SERIAL=y
CONFIG_ADC=y
CONFIG_UART_INTERRUPT_DRIVEN=y
+66
View File
@@ -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;
}