0
0
Fork 0

feat: Change LED behavior

This commit is contained in:
windowsair 2022-01-18 20:48:16 +08:00
parent 79e6de3828
commit 2c4f61007f
3 changed files with 34 additions and 18 deletions

View File

@ -220,7 +220,7 @@ __STATIC_INLINE uint8_t DAP_GetSerNumString(char *str)
// LED_BUILTIN // LED_BUILTIN
#define PIN_LED_CONNECTED 2 #define PIN_LED_CONNECTED 2
// LED_BUILTIN // 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) __STATIC_INLINE void LED_RUNNING_OUT(uint32_t bit)
{ {
if (bit) // if (bit)
{ // {
//set bit // //set bit
GPIO.out_w1ts |= (0x1 << PIN_LED_RUNNING); // GPIO.out_w1ts |= (0x1 << PIN_LED_RUNNING);
} // }
else // else
{ // {
//reset bit // //reset bit
GPIO.out_w1tc |= (0x1 << PIN_LED_RUNNING); // 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) #if (!defined USE_UART_BRIDGE || USE_UART_BRIDGE == 0)
GPIO_FUNCTION_SET(PIN_LED_CONNECTED); GPIO_FUNCTION_SET(PIN_LED_CONNECTED);
#endif #endif
GPIO_FUNCTION_SET(PIN_LED_RUNNING); // GPIO_FUNCTION_SET(PIN_LED_RUNNING);
// Configure: LED as output (turned off) // Configure: LED as output (turned off)
#if (!defined USE_UART_BRIDGE || USE_UART_BRIDGE == 0) #if (!defined USE_UART_BRIDGE || USE_UART_BRIDGE == 0)
GPIO_SET_DIRECTION_NORMAL_OUT(PIN_LED_CONNECTED); GPIO_SET_DIRECTION_NORMAL_OUT(PIN_LED_CONNECTED);
#endif #endif
GPIO_SET_DIRECTION_NORMAL_OUT(PIN_LED_RUNNING); // GPIO_SET_DIRECTION_NORMAL_OUT(PIN_LED_RUNNING);
LED_CONNECTED_OUT(0); LED_CONNECTED_OUT(0);
LED_RUNNING_OUT(0); LED_RUNNING_OUT(0);

View File

@ -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) // static void GPIO_SET_DIRECTION_NORMAL_IN(int io_num)
// { // {
// GPIO.enable_w1tc |= (0x1 << io_num); // GPIO.enable_w1tc |= (0x1 << io_num);

View File

@ -4,6 +4,8 @@
#include "main/wifi_configuration.h" #include "main/wifi_configuration.h"
#include "components/DAP/include/gpio_op.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "freertos/event_groups.h" #include "freertos/event_groups.h"
@ -11,12 +13,8 @@
#include "esp_wifi.h" #include "esp_wifi.h"
#include "esp_event_loop.h" #include "esp_event_loop.h"
#include "esp_log.h" #include "esp_log.h"
// #include "nvs_flash.h"
// #include "lwip/err.h" #define PIN_LED_WIFI_STATUS 15
// #include "lwip/sockets.h"
// #include "lwip/sys.h"
// #include <lwip/netdb.h>
static EventGroupHandle_t wifi_event_group; static EventGroupHandle_t wifi_event_group;
static int ssid_index = 0; static int ssid_index = 0;
@ -43,10 +41,14 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) {
#endif #endif
break; break;
case SYSTEM_EVENT_STA_GOT_IP: case SYSTEM_EVENT_STA_GOT_IP:
GPIO_SET_LEVEL_HIGH(PIN_LED_WIFI_STATUS);
xEventGroupSetBits(wifi_event_group, IPV4_GOTIP_BIT); 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)); os_printf("SYSTEM EVENT STA GOT IP : %s\r\n", ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
break; break;
case SYSTEM_EVENT_STA_DISCONNECTED: case SYSTEM_EVENT_STA_DISCONNECTED:
GPIO_SET_LEVEL_LOW(PIN_LED_WIFI_STATUS);
os_printf("Disconnect reason : %d\r\n", (int)info->disconnected.reason); os_printf("Disconnect reason : %d\r\n", (int)info->disconnected.reason);
if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) {
/*Switch to 802.11 bgn mode */ /*Switch to 802.11 bgn mode */
@ -104,6 +106,9 @@ static void wait_for_ip() {
} }
void wifi_init(void) { void wifi_init(void) {
GPIO_FUNCTION_SET(PIN_LED_WIFI_STATUS);
GPIO_SET_DIRECTION_NORMAL_OUT(PIN_LED_WIFI_STATUS);
tcpip_adapter_init(); tcpip_adapter_init();
#if (USE_STATIC_IP == 1) #if (USE_STATIC_IP == 1)