added external reset callback for use with gpio extender;

fix some issues in web server
This commit is contained in:
Bogdan Pilyugin 2022-10-06 14:22:22 +02:00
parent 53e16bcacb
commit cc7ba0a36e
4 changed files with 494 additions and 481 deletions

View File

@ -113,4 +113,6 @@ esp_err_t StartOTA(void);
void StartSystemTimer(void); void StartSystemTimer(void);
uint32_t GetUpTime(void); uint32_t GetUpTime(void);
void RegEthReset(void (*eth_rst)(uint8_t level));
#endif /* MAIN_INCLUDE_NETTRANSPORT_H_ */ #endif /* MAIN_INCLUDE_NETTRANSPORT_H_ */

View File

@ -19,8 +19,6 @@
* Description: * Description:
*/ */
#include "SystemConfiguration.h" #include "SystemConfiguration.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -37,9 +35,14 @@
#endif #endif
static const char *TAG = "EthTransport"; static const char *TAG = "EthTransport";
static bool isEthConn = false; static bool isEthConn = false;
static void (*eth_reset)(uint8_t level) = NULL;
void RegEthReset(void (*eth_rst)(uint8_t level))
{
eth_reset = eth_rst;
}
#if CONFIG_USE_SPI_ETHERNET #if CONFIG_USE_SPI_ETHERNET
esp_netif_t *eth_netif_spi[CONFIG_SPI_ETHERNETS_NUM] = { NULL }; esp_netif_t *eth_netif_spi[CONFIG_SPI_ETHERNETS_NUM] = { NULL };
@ -66,8 +69,6 @@ esp_netif_t* GetETHNetifAdapter(void)
#endif #endif
bool isETHConnected(void) bool isETHConnected(void)
{ {
return isEthConn; return isEthConn;
@ -122,7 +123,6 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
isEthConn = true; isEthConn = true;
} }
static void eth_init(void *pvParameter) static void eth_init(void *pvParameter)
{ {
#if CONFIG_USE_INTERNAL_ETHERNET #if CONFIG_USE_INTERNAL_ETHERNET
@ -161,13 +161,29 @@ static void eth_init(void *pvParameter)
#if CONFIG_USE_SPI_ETHERNET #if CONFIG_USE_SPI_ETHERNET
//Reset ethernet SPI device //Reset ethernet SPI device
#if CONFIG_ETH_SPI_PHY_RST0_GPIO >=0
gpio_set_level(CONFIG_ETH_SPI_PHY_RST0_GPIO, 0); gpio_set_level(CONFIG_ETH_SPI_PHY_RST0_GPIO, 0);
vTaskDelay(pdMS_TO_TICKS(10)); vTaskDelay(pdMS_TO_TICKS(10));
gpio_set_level(CONFIG_ETH_SPI_PHY_RST0_GPIO, 1); gpio_set_level(CONFIG_ETH_SPI_PHY_RST0_GPIO, 1);
vTaskDelay(pdMS_TO_TICKS(10)); vTaskDelay(pdMS_TO_TICKS(10));
#else
if (eth_reset)
{
eth_reset(0);
vTaskDelay(pdMS_TO_TICKS(10));
eth_reset(1);
vTaskDelay(pdMS_TO_TICKS(10));
}
else
{
ESP_LOGE(TAG, "ethernet chip reset pin not defined");
ESP_ERROR_CHECK(1);
}
#endif
// Create instance(s) of esp-netif for SPI Ethernet(s) // Create instance(s) of esp-netif for SPI Ethernet(s)
esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH(); esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH()
;
esp_netif_config_t cfg_spi = { esp_netif_config_t cfg_spi = {
.base = &esp_netif_config, .base = &esp_netif_config,
.stack = ESP_NETIF_NETSTACK_DEFAULT_ETH .stack = ESP_NETIF_NETSTACK_DEFAULT_ETH
@ -330,10 +346,8 @@ static void eth_init(void *pvParameter)
vTaskDelete(NULL); vTaskDelete(NULL);
} }
void EthStart(void) void EthStart(void)
{ {
xTaskCreate(eth_init, "EthInitTask", 1024 * 4, (void*) 0, 3, NULL); xTaskCreate(eth_init, "EthInitTask", 1024 * 4, (void*) 0, 3, NULL);
} }

View File

@ -291,10 +291,7 @@ static esp_err_t GETHandler(httpd_req_t *req)
file = espfs_fopen(fs, filepath); file = espfs_fopen(fs, filepath);
if (!file) if (!file)
{ {
ESP_LOGE(TAG, "Failed to read existing file : %s", filepath); httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "File not found");
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR,
"Failed to read existing file");
return ESP_FAIL; return ESP_FAIL;
} }
//get file info //get file info

View File

@ -169,7 +169,7 @@ if(GetSysConf()->wifiSettings.Flags1.bIsAP)
static void InitSysIO(void) static void InitSysIO(void)
{ {
#if (FUNCTIONAL_BUTTON_GPIO >= 0) #if (MAIN_FUNCTIONAL_BUTTON_GPIO >= 0)
gpio_pad_select_gpio(MAIN_FUNCTIONAL_BUTTON_GPIO); gpio_pad_select_gpio(MAIN_FUNCTIONAL_BUTTON_GPIO);
gpio_set_direction(MAIN_FUNCTIONAL_BUTTON_GPIO, GPIO_MODE_INPUT); gpio_set_direction(MAIN_FUNCTIONAL_BUTTON_GPIO, GPIO_MODE_INPUT);
gpio_set_pull_mode(MAIN_FUNCTIONAL_BUTTON_GPIO, GPIO_PULLUP_ONLY); gpio_set_pull_mode(MAIN_FUNCTIONAL_BUTTON_GPIO, GPIO_PULLUP_ONLY);