Update repo

This commit is contained in:
hangpersonal committed 2026-10-06 23:54:07 -07:00
1 parent d229fd964d
commit ff59d1588c
2 files changed
+30 -6

No files matched your search

@@ -8,7 +8,9 @@
gpio_keys {
compatible = "gpio-keys";
debounce-interval-ms = <30>;
/* <node_label>: <node_name> {}; */
user_button0: button {
label = "Button";
gpios = <&gpioc 13 GPIO_ACTIVE_HIGH>;
+28 -6
View File
@@ -10,9 +10,14 @@
#error "Board does not define alias sw0. Add a boad overlay"
#endif
const struct gpio_dt_spec led =
GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
static const struct gpio_dt_spec button =
GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
bool led_on;
static struct gpio_callback button_cb;
static void button_isr(const struct device *port,
@@ -30,15 +35,36 @@ static void button_isr(const struct device *port,
printk("[IRQ] Button state: %s\r\n", v ? "ACTIVE" : "INVACTIVE");
}
led_on = !led_on;
gpio_pin_set_dt(&led, (int)led_on);
}
int main(void) {
if(!device_is_ready(button.port)) {
int ret;
if (!device_is_ready(led.port) || !device_is_ready(button.port)) {
printk("GPIO device not ready\n");
return 0;
}
if(gpio_pin_configure_dt(&button, GPIO_INPUT) != 0) {
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_INACTIVE);
if (ret != 0) {
printk("Failed to configure LED: %d\n", ret);
return 0;
}
ret = gpio_pin_configure_dt(&button, GPIO_INPUT);
if (ret != 0) {
printk("Failed to configure button: %d\n", ret);
return 0;
}
// gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_BOTH)
ret = gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_TO_ACTIVE);
if (ret != 0) {
printk("Failed to configure interrupt: %d\n", ret);
return 0;
}
@@ -46,10 +72,6 @@ int main(void) {
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) {