|
@@ -46,6 +46,7 @@ Contains the freeRTOS task and all necessary support
|
|
|
#include "tcpip_adapter.h"
|
|
|
// IDF-V4++ #include "esp_netif.h"
|
|
|
#include "esp_event.h"
|
|
|
+#include "esp_eth.h"
|
|
|
#include "esp_wifi.h"
|
|
|
#include "esp_wifi_types.h"
|
|
|
#include "esp_log.h"
|
|
@@ -67,6 +68,7 @@ Contains the freeRTOS task and all necessary support
|
|
|
|
|
|
#include "http_server_handlers.h"
|
|
|
#include "monitor.h"
|
|
|
+#include "accessors.h"
|
|
|
#include "globdefs.h"
|
|
|
|
|
|
|
|
@@ -264,6 +266,35 @@ void wifi_manager_reboot(reboot_type_t rtype){
|
|
|
//xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_WIFI_DISCONNECT_BIT); TODO: delete
|
|
|
}
|
|
|
|
|
|
+/** Event handler for Ethernet events */
|
|
|
+static void eth_event_handler(void *arg, esp_event_base_t event_base,
|
|
|
+ int32_t event_id, void *event_data)
|
|
|
+{
|
|
|
+ uint8_t mac_addr[6] = {0};
|
|
|
+ /* we can get the ethernet driver handle from event data */
|
|
|
+ esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;
|
|
|
+
|
|
|
+ switch (event_id) {
|
|
|
+ case ETHERNET_EVENT_CONNECTED:
|
|
|
+ esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
|
|
|
+ ESP_LOGI(TAG, "Ethernet Link Up");
|
|
|
+ ESP_LOGI(TAG, "Ethernet HW Addr %02x:%02x:%02x:%02x:%02x:%02x",
|
|
|
+ mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
|
|
|
+ break;
|
|
|
+ case ETHERNET_EVENT_DISCONNECTED:
|
|
|
+ ESP_LOGI(TAG, "Ethernet Link Down");
|
|
|
+ break;
|
|
|
+ case ETHERNET_EVENT_START:
|
|
|
+ ESP_LOGI(TAG, "Ethernet Started");
|
|
|
+ break;
|
|
|
+ case ETHERNET_EVENT_STOP:
|
|
|
+ ESP_LOGI(TAG, "Ethernet Stopped");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void wifi_manager_init_wifi(){
|
|
|
/* event handler and event group for the wifi driver */
|
|
|
ESP_LOGD(TAG, "Initializing wifi. Creating event group");
|
|
@@ -285,6 +316,32 @@ void wifi_manager_init_wifi(){
|
|
|
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_NULL) );
|
|
|
ESP_LOGD(TAG, "Initializing wifi. Starting wifi");
|
|
|
ESP_ERROR_CHECK( esp_wifi_start() );
|
|
|
+
|
|
|
+ //ETH
|
|
|
+
|
|
|
+ eth_config_t const *eth = config_eth_get( );
|
|
|
+ ESP_LOGE(TAG, "ETH MDC %d", eth->mdc);
|
|
|
+ ESP_LOGE(TAG, "ETH MDIO %d", eth->mdio);
|
|
|
+ ESP_LOGE(TAG, "ETH RST %d", eth->rst);
|
|
|
+
|
|
|
+ ESP_ERROR_CHECK(tcpip_adapter_set_default_eth_handlers());
|
|
|
+ ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, NULL));
|
|
|
+
|
|
|
+ eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
|
|
+ eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
|
|
+ phy_config.phy_addr = 1;
|
|
|
+ phy_config.reset_gpio_num = eth->rst;
|
|
|
+
|
|
|
+ mac_config.smi_mdc_gpio_num = eth->mdc;
|
|
|
+ mac_config.smi_mdio_gpio_num = eth->mdio;
|
|
|
+ esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);
|
|
|
+ esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config);
|
|
|
+
|
|
|
+ esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
|
|
+ esp_eth_handle_t eth_handle = NULL;
|
|
|
+ ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
|
|
+ ESP_ERROR_CHECK(esp_eth_start(eth_handle));
|
|
|
+ //END_ETH
|
|
|
|
|
|
taskYIELD();
|
|
|
ESP_LOGD(TAG, "Initializing wifi. done");
|
|
@@ -934,6 +991,7 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
|
|
|
break;
|
|
|
case IP_EVENT_ETH_GOT_IP:
|
|
|
ESP_LOGD(TAG, "IP_EVENT_ETH_GOT_IP");
|
|
|
+ wifi_manager_send_message(EVENT_ETH_GOT_IP, NULL);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
@@ -1324,6 +1382,7 @@ void wifi_manager( void * pvParameters ){
|
|
|
|
|
|
case ORDER_CONNECT_STA:
|
|
|
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - Begin");
|
|
|
+ break; // DOBREAK;
|
|
|
|
|
|
/* very important: precise that this connection attempt is specifically requested.
|
|
|
* Param in that case is a boolean indicating if the request was made automatically
|
|
@@ -1575,6 +1634,13 @@ void wifi_manager( void * pvParameters ){
|
|
|
if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL);
|
|
|
break;
|
|
|
|
|
|
+
|
|
|
+ case EVENT_ETH_GOT_IP:
|
|
|
+ ESP_LOGD(TAG, "MESSAGE: EVENT_ETH_GOT_IP");
|
|
|
+ /* callback */
|
|
|
+ if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL);
|
|
|
+ break;
|
|
|
+
|
|
|
case EVENT_STA_GOT_IP:
|
|
|
ESP_LOGD(TAG, "MESSAGE: EVENT_STA_GOT_IP");
|
|
|
|