#include "resets.h" #include "gpio.h" #include "uart.h" #include "stdio.h" #define KEY_PIN (24) #define LED_PIN (25) int main(void) { reset_unreset_blocks_wait(RESETS_BLOCK_IO_BANK0 | RESETS_BLOCK_UART0); gpio_init(0, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* UART_TX pin */ gpio_init(1, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* UART_RX pin */ uart_init(uart0_hw, 6 * 1000 * 1000, UART_DATABITS_8 | UART_PARITY_NONE | UART_STOPBITS_1); printf("gpio_key example\r\n"); gpio_init(LED_PIN, GPIO_FUNC_NULL | GPIO_OVER_OUT_HIGH | GPIO_OVER_OE_ENABLE | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* LED pin */ gpio_init(KEY_PIN, GPIO_FUNC_NULL | GPIO_PULL_UP | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* KEY pin */ while (1) { if (gpio_read(KEY_PIN)) { /* read pin status as 1: release key */ gpio_clear(LED_PIN); /* low level for turn off LED */ } else { /* read pin status as 0: press key */ gpio_set(LED_PIN); /* high level for turn on LED */ } } return 0; }