From 2c4f61007fbb7b67e1949407b7f5ce3ec7169975 Mon Sep 17 00:00:00 2001 From: windowsair Date: Tue, 18 Jan 2022 20:48:16 +0800 Subject: [PATCH] feat: Change LED behavior --- components/DAP/config/DAP_config.h | 26 +++++++++++++------------- components/DAP/include/gpio_op.h | 11 +++++++++++ main/wifi_handle.c | 15 ++++++++++----- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/components/DAP/config/DAP_config.h b/components/DAP/config/DAP_config.h index ec67197..b9d571b 100644 --- a/components/DAP/config/DAP_config.h +++ b/components/DAP/config/DAP_config.h @@ -220,7 +220,7 @@ __STATIC_INLINE uint8_t DAP_GetSerNumString(char *str) // LED_BUILTIN #define PIN_LED_CONNECTED 2 // LED_BUILTIN -#define PIN_LED_RUNNING 15 +#define PIN_LED_RUNNING _ // won't be used //************************************************************************************************** /** @@ -641,16 +641,16 @@ __STATIC_INLINE void LED_CONNECTED_OUT(uint32_t bit) */ __STATIC_INLINE void LED_RUNNING_OUT(uint32_t bit) { - if (bit) - { - //set bit - GPIO.out_w1ts |= (0x1 << PIN_LED_RUNNING); - } - else - { - //reset bit - GPIO.out_w1tc |= (0x1 << PIN_LED_RUNNING); - } + // if (bit) + // { + // //set bit + // GPIO.out_w1ts |= (0x1 << PIN_LED_RUNNING); + // } + // else + // { + // //reset bit + // GPIO.out_w1tc |= (0x1 << PIN_LED_RUNNING); + // } } ///@} @@ -706,14 +706,14 @@ __STATIC_INLINE void DAP_SETUP(void) #if (!defined USE_UART_BRIDGE || USE_UART_BRIDGE == 0) GPIO_FUNCTION_SET(PIN_LED_CONNECTED); #endif - GPIO_FUNCTION_SET(PIN_LED_RUNNING); + // GPIO_FUNCTION_SET(PIN_LED_RUNNING); // Configure: LED as output (turned off) #if (!defined USE_UART_BRIDGE || USE_UART_BRIDGE == 0) GPIO_SET_DIRECTION_NORMAL_OUT(PIN_LED_CONNECTED); #endif - GPIO_SET_DIRECTION_NORMAL_OUT(PIN_LED_RUNNING); + // GPIO_SET_DIRECTION_NORMAL_OUT(PIN_LED_RUNNING); LED_CONNECTED_OUT(0); LED_RUNNING_OUT(0); diff --git a/components/DAP/include/gpio_op.h b/components/DAP/include/gpio_op.h index 48888cf..6c11bd3 100644 --- a/components/DAP/include/gpio_op.h +++ b/components/DAP/include/gpio_op.h @@ -37,6 +37,17 @@ static void GPIO_SET_DIRECTION_NORMAL_OUT(int io_num) } +__STATIC_INLINE void GPIO_SET_LEVEL_HIGH(int io_num) +{ + GPIO.out_w1ts |= (0x1 << io_num); + +} + +__STATIC_INLINE void GPIO_SET_LEVEL_LOW(int io_num) +{ + GPIO.out_w1tc |= (0x1 << io_num); +} + // static void GPIO_SET_DIRECTION_NORMAL_IN(int io_num) // { // GPIO.enable_w1tc |= (0x1 << io_num); diff --git a/main/wifi_handle.c b/main/wifi_handle.c index 351444f..a1ad7ab 100644 --- a/main/wifi_handle.c +++ b/main/wifi_handle.c @@ -4,6 +4,8 @@ #include "main/wifi_configuration.h" +#include "components/DAP/include/gpio_op.h" + #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/event_groups.h" @@ -11,12 +13,8 @@ #include "esp_wifi.h" #include "esp_event_loop.h" #include "esp_log.h" -// #include "nvs_flash.h" -// #include "lwip/err.h" -// #include "lwip/sockets.h" -// #include "lwip/sys.h" -// #include +#define PIN_LED_WIFI_STATUS 15 static EventGroupHandle_t wifi_event_group; static int ssid_index = 0; @@ -43,10 +41,14 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) { #endif break; case SYSTEM_EVENT_STA_GOT_IP: + GPIO_SET_LEVEL_HIGH(PIN_LED_WIFI_STATUS); + xEventGroupSetBits(wifi_event_group, IPV4_GOTIP_BIT); os_printf("SYSTEM EVENT STA GOT IP : %s\r\n", ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip)); break; case SYSTEM_EVENT_STA_DISCONNECTED: + GPIO_SET_LEVEL_LOW(PIN_LED_WIFI_STATUS); + os_printf("Disconnect reason : %d\r\n", (int)info->disconnected.reason); if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { /*Switch to 802.11 bgn mode */ @@ -104,6 +106,9 @@ static void wait_for_ip() { } void wifi_init(void) { + GPIO_FUNCTION_SET(PIN_LED_WIFI_STATUS); + GPIO_SET_DIRECTION_NORMAL_OUT(PIN_LED_WIFI_STATUS); + tcpip_adapter_init(); #if (USE_STATIC_IP == 1)