diff --git a/boards/xtensa/esp32/common/include/esp32_board_wlan.h b/boards/xtensa/esp32/common/include/esp32_board_wlan.h new file mode 100644 index 00000000000..4a8c7cf5a8f --- /dev/null +++ b/boards/xtensa/esp32/common/include/esp32_board_wlan.h @@ -0,0 +1,73 @@ +/**************************************************************************** + * boards/xtensa/esp32/common/include/esp32_board_wlan.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_WLAN_H +#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_WLAN_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef CONFIG_ESP32_WIRELESS + +/**************************************************************************** + * Name: board_wlan_init + * + * Description: + * Configure the wireless subsystem. + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +int board_wlan_init(void); + +#endif /* CONFIG_ESP32_WIRELESS */ + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_WLAN_H */ diff --git a/boards/xtensa/esp32/common/src/Make.defs b/boards/xtensa/esp32/common/src/Make.defs index b43c960e36b..c7df4327482 100644 --- a/boards/xtensa/esp32/common/src/Make.defs +++ b/boards/xtensa/esp32/common/src/Make.defs @@ -30,6 +30,10 @@ ifeq ($(CONFIG_I2C_DRIVER),y) CSRCS += esp32_board_i2c.c endif +ifeq ($(CONFIG_ESP32_WIRELESS),y) + CSRCS += esp32_board_wlan.c +endif + ifeq ($(CONFIG_SENSORS_BMP180),y) CSRCS += esp32_bmp180.c endif diff --git a/boards/xtensa/esp32/common/src/esp32_board_wlan.c b/boards/xtensa/esp32/common/src/esp32_board_wlan.c new file mode 100644 index 00000000000..76362d3f41e --- /dev/null +++ b/boards/xtensa/esp32/common/src/esp32_board_wlan.c @@ -0,0 +1,124 @@ +/**************************************************************************** + * boards/xtensa/esp32/common/src/esp32_board_wlan.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "esp32_spiflash.h" +#include "esp32_wlan.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifdef CONFIG_ESP32_WIFI_SAVE_PARAM +static int esp32_init_wifi_storage(void) +{ + int ret; + const char *path = "/dev/mtdblock1"; + FAR struct mtd_dev_s *mtd_part; + + mtd_part = esp32_spiflash_alloc_mtdpart(); + if (!mtd_part) + { + syslog(LOG_ERR, "ERROR: Failed to alloc MTD partition of SPI Flash\n"); + return -1; + } + + ret = register_mtddriver(path, mtd_part, 0777, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to regitser MTD: %d\n", ret); + return -1; + } + + ret = nx_mount(path, CONFIG_ESP32_WIFI_FS_MOUNTPT, "spiffs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount the FS volume: %d\n", ret); + return ret; + } + + return 0; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_wlan_init + * + * Description: + * Configure the wireless subsystem. + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +int board_wlan_init(void) +{ + int ret = OK; + +#ifdef CONFIG_ESP32_WIFI_SAVE_PARAM + ret = esp32_init_wifi_storage(); + if (ret) + { + syslog(LOG_ERR, "ERROR: Failed to initialize WiFi storage\n"); + return ret; + } +#endif + +#ifdef ESP32_WLAN_HAS_STA + ret = esp32_wlan_sta_initialize(); + if (ret) + { + syslog(LOG_ERR, "ERROR: Failed to initialize WiFi station\n"); + return ret; + } +#endif + +#ifdef ESP32_WLAN_HAS_SOFTAP + ret = esp32_wlan_softap_initialize(); + if (ret) + { + syslog(LOG_ERR, "ERROR: Failed to initialize WiFi softAP\n"); + return ret; + } +#endif + + return ret; +} + diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c index e740e5b8976..a000a8d4143 100644 --- a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c @@ -39,7 +39,6 @@ #include #include -#include "esp32_wlan.h" #include "esp32_spiflash.h" #include "esp32_partition.h" @@ -63,6 +62,10 @@ # include "esp32_board_wdt.h" #endif +#ifdef CONFIG_ESP32_WIRELESS +# include "esp32_board_wlan.h" +#endif + #ifdef CONFIG_ESP32_AES_ACCELERATOR # include "esp32_aes.h" #endif @@ -95,38 +98,6 @@ * ****************************************************************************/ -#ifdef CONFIG_ESP32_WIFI_SAVE_PARAM -static int esp32_init_wifi_storage(void) -{ - int ret; - const char *path = "/dev/mtdblock1"; - FAR struct mtd_dev_s *mtd_part; - - mtd_part = esp32_spiflash_alloc_mtdpart(); - if (!mtd_part) - { - syslog(LOG_ERR, "ERROR: Failed to alloc MTD partition of SPI Flash\n"); - return -1; - } - - ret = register_mtddriver(path, mtd_part, 0777, NULL); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: Failed to regitser MTD: %d\n", ret); - return -1; - } - - ret = nx_mount(path, CONFIG_ESP32_WIFI_FS_MOUNTPT, "spiffs", 0, NULL); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: Failed to mount the FS volume: %d\n", ret); - return ret; - } - - return 0; -} -#endif - int esp32_bringup(void) { int ret; @@ -212,38 +183,15 @@ int esp32_bringup(void) #endif #ifdef CONFIG_ESP32_WIRELESS - -#ifdef CONFIG_ESP32_WIFI_SAVE_PARAM - ret = esp32_init_wifi_storage(); - if (ret) + ret = board_wlan_init(); + if (ret < 0) { - syslog(LOG_ERR, "ERROR: Failed to initialize WiFi storage\n"); + syslog(LOG_ERR, "ERROR: Failed to initialize wireless subsystem=%d\n", + ret); return ret; } #endif -#ifdef CONFIG_NET -#ifdef ESP32_WLAN_HAS_STA - ret = esp32_wlan_sta_initialize(); - if (ret) - { - syslog(LOG_ERR, "ERROR: Failed to initialize WiFi station\n"); - return ret; - } -#endif - -#ifdef ESP32_WLAN_HAS_SOFTAP - ret = esp32_wlan_softap_initialize(); - if (ret) - { - syslog(LOG_ERR, "ERROR: Failed to initialize WiFi softAP\n"); - return ret; - } -#endif -#endif - -#endif - /* First, register the timer drivers and let timer 1 for oneshot * if it is enabled. */ diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c index 5f74cc38b44..048d346915d 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c @@ -39,7 +39,6 @@ #include #include -#include "esp32_wlan.h" #include "esp32_spiflash.h" #include "esp32_partition.h" @@ -59,6 +58,10 @@ # include "esp32_board_wdt.h" #endif +#ifdef CONFIG_ESP32_WIRELESS +# include "esp32_board_wlan.h" +#endif + #ifdef CONFIG_BUTTONS # include #endif @@ -87,38 +90,6 @@ * ****************************************************************************/ -#ifdef CONFIG_ESP32_WIFI_SAVE_PARAM -static int esp32_init_wifi_storage(void) -{ - int ret; - const char *path = "/dev/mtdblock1"; - FAR struct mtd_dev_s *mtd_part; - - mtd_part = esp32_spiflash_alloc_mtdpart(); - if (!mtd_part) - { - syslog(LOG_ERR, "ERROR: Failed to alloc MTD partition of SPI Flash\n"); - return -1; - } - - ret = register_mtddriver(path, mtd_part, 0777, NULL); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: Failed to regitser MTD: %d\n", ret); - return -1; - } - - ret = nx_mount(path, CONFIG_ESP32_WIFI_FS_MOUNTPT, "spiffs", 0, NULL); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: Failed to mount the FS volume: %d\n", ret); - return ret; - } - - return 0; -} -#endif - int esp32_bringup(void) { int ret; @@ -187,38 +158,15 @@ int esp32_bringup(void) #endif #ifdef CONFIG_ESP32_WIRELESS - -#ifdef CONFIG_ESP32_WIFI_SAVE_PARAM - ret = esp32_init_wifi_storage(); - if (ret) + ret = board_wlan_init(); + if (ret < 0) { - syslog(LOG_ERR, "ERROR: Failed to initialize WiFi storage\n"); + syslog(LOG_ERR, "ERROR: Failed to initialize wireless subsystem=%d\n", + ret); return ret; } #endif -#ifdef CONFIG_NET -#ifdef ESP32_WLAN_HAS_STA - ret = esp32_wlan_sta_initialize(); - if (ret) - { - syslog(LOG_ERR, "ERROR: Failed to initialize WiFi station\n"); - return ret; - } -#endif - -#ifdef ESP32_WLAN_HAS_SOFTAP - ret = esp32_wlan_softap_initialize(); - if (ret) - { - syslog(LOG_ERR, "ERROR: Failed to initialize WiFi softAP\n"); - return ret; - } -#endif -#endif - -#endif - /* First, register the timer drivers and let timer 1 for oneshot * if it is enabled. */ diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c index 9385dc3e239..21e6dedb12f 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c @@ -40,7 +40,6 @@ #include #include -#include "esp32_wlan.h" #include "esp32_spiflash.h" #include "esp32_partition.h" @@ -60,6 +59,10 @@ # include "esp32_board_wdt.h" #endif +#ifdef CONFIG_ESP32_WIRELESS +# include "esp32_board_wlan.h" +#endif + #ifdef CONFIG_ESP32_I2C # include "esp32_board_i2c.h" #endif @@ -96,38 +99,6 @@ * ****************************************************************************/ -#ifdef CONFIG_ESP32_WIFI_SAVE_PARAM -static int esp32_init_wifi_storage(void) -{ - int ret; - const char *path = "/dev/mtdblock1"; - FAR struct mtd_dev_s *mtd_part; - - mtd_part = esp32_spiflash_alloc_mtdpart(); - if (!mtd_part) - { - syslog(LOG_ERR, "ERROR: Failed to alloc MTD partition of SPI Flash\n"); - return -1; - } - - ret = register_mtddriver(path, mtd_part, 0777, NULL); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: Failed to regitser MTD: %d\n", ret); - return -1; - } - - ret = nx_mount(path, CONFIG_ESP32_WIFI_FS_MOUNTPT, "spiffs", 0, NULL); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: Failed to mount the FS volume: %d\n", ret); - return ret; - } - - return 0; -} -#endif - int esp32_bringup(void) { int ret; @@ -196,38 +167,15 @@ int esp32_bringup(void) #endif #ifdef CONFIG_ESP32_WIRELESS - -#ifdef CONFIG_ESP32_WIFI_SAVE_PARAM - ret = esp32_init_wifi_storage(); - if (ret) + ret = board_wlan_init(); + if (ret < 0) { - syslog(LOG_ERR, "ERROR: Failed to initialize WiFi storage\n"); + syslog(LOG_ERR, "ERROR: Failed to initialize wireless subsystem=%d\n", + ret); return ret; } #endif -#ifdef CONFIG_NET -#ifdef ESP32_WLAN_HAS_STA - ret = esp32_wlan_sta_initialize(); - if (ret) - { - syslog(LOG_ERR, "ERROR: Failed to initialize WiFi station\n"); - return ret; - } -#endif - -#ifdef ESP32_WLAN_HAS_SOFTAP - ret = esp32_wlan_softap_initialize(); - if (ret) - { - syslog(LOG_ERR, "ERROR: Failed to initialize WiFi softAP\n"); - return ret; - } -#endif -#endif - -#endif - /* First, register the timer drivers and let timer 1 for oneshot * if it is enabled. */ @@ -244,7 +192,7 @@ int esp32_bringup(void) } #endif -#if defined(CONFIG_ESP32_TIMER1) && !defined(CONFIG_ONESHOT) +#if defined(CONFIG_ESP32_TIMER1) && !defined(CONFIG_ONESHOT) ret = esp32_timer_initialize("/dev/timer1", TIMER1); if (ret < 0) { @@ -266,7 +214,7 @@ int esp32_bringup(void) } #endif -#ifdef CONFIG_ESP32_TIMER3 +#ifdef CONFIG_ESP32_TIMER3 ret = esp32_timer_initialize("/dev/timer3", TIMER3); if (ret < 0) {