diff --git a/include/user_button.h b/include/user_button.h new file mode 100644 index 0000000..f6d094a --- /dev/null +++ b/include/user_button.h @@ -0,0 +1,6 @@ +#ifndef __USER_BUTTON_H +#define __USER_BUTTON_H + +void user_button_init(); + +#endif diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index e60b552..cf5e47f 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -3,6 +3,7 @@ set(COMPONENT_SRCS "\ lorcomm.c\ ble.c\ console.c\ + user_button.c\ cmd_bw.c\ cmd_cr.c\ cmd_sf.c\ diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild new file mode 100644 index 0000000..6d54446 --- /dev/null +++ b/main/Kconfig.projbuild @@ -0,0 +1,44 @@ +menu "LoRComm Config" + menuconfig LORCOMM_GPS_ENABLED + bool "Enable GPS receiver" + help + Enables attached GPS receiver + + if LORCOMM_GPS_ENABLED + config LORCOMM_GPS_RX + int "GPS RX Pin" + default 13 + help + GPIO to receive data from GPS receiver + endif + + choice LORCOMM_BUTTON_ACTION + bool "User Button Action" + default LORCOMM_BUTTON_ACTION_HELO + help + Selection action to be performed when the user button + is pressed. + + config LORCOMM_BUTTON_ACTION_NONE + bool "Do nothing" + help + Do nothing + + config LORCOMM_BUTTON_ACTION_HELO + bool "Send HELO" + help + Send out a HELO packet and listen for response + + if LORCOMM_GPS_ENABLED + config LORCOMM_BUTTON_ACTION_GPS + bool "Send GPS" + help + Sends GPS coordinates and listens for ACK. + endif + endchoice + + config LORCOMM_BUTTON_ACTION_ENABLED + bool + default n if LORCOMM_BUTTON_ACTION_NONE + default y +endmenu diff --git a/main/main.c b/main/main.c index da77418..cc5b86e 100644 --- a/main/main.c +++ b/main/main.c @@ -14,6 +14,7 @@ #include "esp32-lora.h" #include "console.h" #include "ble.h" +#include "user_button.h" static const char *TAG = "loracom-main"; @@ -88,6 +89,10 @@ void app_main(void) { lora32_enable_continuous_rx(&lora); +#ifdef CONFIG_LORCOMM_BUTTON_ACTION_ENABLED + user_button_init(); +#endif + while(1) { vTaskDelay(1000 / portTICK_PERIOD_MS); } diff --git a/main/user_button.c b/main/user_button.c new file mode 100644 index 0000000..119392e --- /dev/null +++ b/main/user_button.c @@ -0,0 +1,39 @@ +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "driver/gpio.h" + +static xQueueHandle gpio_evt_queue = NULL; + +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_example(void* arg) { + uint32_t io_num; + for(;;) { + if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) { + printf("GPIO[%d] intr, val: %d\n", io_num, gpio_get_level(io_num)); + } + } +} + +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 = (1L << 0); + io_conf.pull_down_en = 0; + io_conf.pull_up_en = 0; + + gpio_config(&io_conf); + + gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t)); + xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL); + + gpio_install_isr_service(0); + gpio_isr_handler_add(0, gpio_isr_handler, (void*) 0); +}