/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "pico/cyw43_arch.h"
#define BUTTON1 3
#define BUTTON2 4
#define LED1 20
#define LED2 21
void gpio_callback(uint gpio, uint32_t events) {
switch (gpio) {
case BUTTON1:
printf("Button 1 was pressed.");
break;
case BUTTON2:
printf("Button 2 was pressed.");
break;
default:
break;
}
printf(" (GPIO %d)\n", gpio);
}
void init_gpio() {
gpio_init(BUTTON1);
gpio_init(BUTTON2);
gpio_set_dir(BUTTON1, GPIO_IN);
gpio_set_dir(BUTTON2, GPIO_IN);
gpio_pull_up(BUTTON1);
gpio_pull_up(BUTTON2);
}
int main() {
stdio_init_all();
init_gpio();
printf("Hello GPIO IRQ\n");
gpio_set_irq_enabled(BUTTON1, GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE, true);
gpio_set_irq_enabled(BUTTON2, GPIO_IRQ_EDGE_FALL, true);
gpio_set_irq_callback(&gpio_callback);
irq_set_enabled(IO_IRQ_BANK0, true);
while (1);
return 0;
}