SHOW:
|
|
- or go back to the newest paste.
| 1 | #include "driver/gpio.h" | |
| 2 | #include "button.h" | |
| 3 | ||
| 4 | #define GPIO_BUTTON GPIO_NUM_1 | |
| 5 | ||
| 6 | void button_init(void) | |
| 7 | {
| |
| 8 | gpio_config_t io_config ={};
| |
| 9 | io_config.pin_bit_mask= 1ULL << GPIO_BUTTON; | |
| 10 | io_config.mode = GPIO_MODE_INPUT; | |
| 11 | io_config.pull_up_en = GPIO_PULLUP_ENABLED; | |
| 12 | io_config.pulldown_en = GPIO_PULLDOWN_DISABLE; | |
| 13 | io_config.intr_type = GPIO_INTR_DISABLE; | |
| 14 | gpio_config(&io_conf); | |
| 15 | } | |
| 16 | ||
| 17 | button_state_t button_get(void) | |
| 18 | {
| |
| 19 | uint8_t pin_level; | |
| 20 | pin_level = gpio_get_level(GPIO_BUTTON); | |
| 21 | if(pin_level ==1) | |
| 22 | {
| |
| 23 | button_state_t state = BUTTON_PRESSED; | |
| 24 | return state; | |
| 25 | } | |
| 26 | button_state_t state = BUTTON_RELEASED; | |
| 27 | return state; | |
| 28 | } |