59 lines
1.3 KiB
C
59 lines
1.3 KiB
C
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "freertos/queue.h"
|
|
#include "driver/gpio.h"
|
|
|
|
#include "main.h"
|
|
#include "pumps.h"
|
|
#include "ble.h"
|
|
|
|
#define GPIO_USER_BUTTON (19)
|
|
|
|
static void IRAM_ATTR gpio_isr_handler(void* arg) {
|
|
uint32_t gpio_num = (uint32_t) arg;
|
|
|
|
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
|
|
}
|
|
|
|
static void gpio_task(void* arg) {
|
|
uint32_t io_num;
|
|
uint8_t on = 1;
|
|
uint8_t off = 0;
|
|
|
|
for(;;) {
|
|
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
|
|
uint8_t level = gpio_get_level(io_num);
|
|
printf("GPIO[%d] intr, val: %d\n", io_num, level);
|
|
|
|
pumps_run();
|
|
|
|
ble_send_notification((void*)&on, 1);
|
|
|
|
// just a wee debounce
|
|
vTaskDelay(500 / portTICK_PERIOD_MS);
|
|
|
|
ble_send_notification((void*)&off, 1);
|
|
|
|
xQueueReset(gpio_evt_queue);
|
|
}
|
|
}
|
|
}
|
|
|
|
void user_button_init() {
|
|
gpio_config_t io_conf;
|
|
|
|
io_conf.intr_type = GPIO_PIN_INTR_NEGEDGE;
|
|
io_conf.mode = GPIO_MODE_INPUT;
|
|
io_conf.pin_bit_mask = (1ULL << GPIO_USER_BUTTON);
|
|
io_conf.pull_down_en = 0;
|
|
io_conf.pull_up_en = 1;
|
|
|
|
gpio_config(&io_conf);
|
|
|
|
gpio_evt_queue = xQueueCreate(1, sizeof(uint32_t));
|
|
xTaskCreate(gpio_task, "gpio_task", 4096, NULL, 10, NULL);
|
|
|
|
gpio_install_isr_service(0);
|
|
gpio_isr_handler_add(GPIO_USER_BUTTON, gpio_isr_handler, (void*) 0);
|
|
}
|