feat(wifi): Add wifi APIs according to IDF

This commit is contained in:
Zhang Jun Hao
2018-06-23 18:23:34 +08:00
parent 5d31b02f9b
commit ffe1e5c9cd
8 changed files with 1247 additions and 1734 deletions

View File

@ -0,0 +1,44 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed 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.
#include "esp_libc.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_socket.h"
#include "net/sockio.h"
/**
* @brief Init WiFi
* Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
* WiFi NVS structure etc, this WiFi also start WiFi task
*
* @attention 1. This API must be called before all other WiFi API can be called
* @attention 2. Always use WIFI_INIT_CONFIG_DEFAULT macro to init the config to default values, this can
* guarantee all the fields got correct value when more fields are added into wifi_init_config_t
* in future release. If you want to set your owner initial values, overwrite the default values
* which are set by WIFI_INIT_CONFIG_DEFAULT, please be notified that the field 'magic' of
* wifi_init_config_t should always be WIFI_INIT_CONFIG_MAGIC!
*
* @param config pointer to WiFi init configuration structure; can point to a temporary variable.
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_NO_MEM: out of memory
* - others: refer to error code esp_err.h
*/
esp_err_t esp_wifi_init(const wifi_init_config_t *config)
{
esp_event_set_default_wifi_handlers();
return esp_wifi_init_internal(config);
}

View File

@ -22,6 +22,8 @@
#include "freertos/semphr.h"
#include "freertos/timers.h"
#include "nvs.h"
#if defined(CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL) || defined(CONFIG_NEWLIB_LIBRARY_LEVEL_NANO)
#include "esp_newlib.h"
#endif
@ -42,7 +44,6 @@ static void *task_create_wrapper(void *task_func, const char *name, uint32_t sta
{
portBASE_TYPE ret;
xTaskHandle handle;
ret = xTaskCreate(task_func, name, stack_depth, param, prio, &handle);
return ret == pdPASS ? handle : NULL;
@ -311,6 +312,8 @@ static int32_t rand_wrapper(void)
}
wifi_osi_funcs_t s_wifi_osi_funcs = {
.version = ESP_WIFI_OS_ADAPTER_VERSION,
.enter_critical = enter_critical_wrapper,
.exit_critical = exit_critical_wrapper,
@ -365,4 +368,19 @@ wifi_osi_funcs_t s_wifi_osi_funcs = {
.srand = srand_wrapper,
.rand = rand_wrapper,
};
.nvs_set_i8 = nvs_set_i8,
.nvs_get_i8 = nvs_get_i8,
.nvs_set_u8 = nvs_set_u8,
.nvs_get_u8 = nvs_get_u8,
.nvs_set_u16 = nvs_set_u16,
.nvs_get_u16 = nvs_get_u16,
.nvs_open = nvs_open,
.nvs_close = nvs_close,
.nvs_commit = nvs_commit,
.nvs_set_blob = nvs_set_blob,
.nvs_get_blob = nvs_get_blob,
.nvs_erase_key = nvs_erase_key,
.magic = ESP_WIFI_OS_ADAPTER_MAGIC,
};