Skip to content

Commit 37fd328

Browse files
committed
Merge branch 'feature/new_crosstool_2019r2' into 'master'
Support IDF V4.0 See merge request adf/esp-adf-internal!399
2 parents 75c059f + 9c06d63 commit 37fd328

File tree

9 files changed

+329
-132
lines changed

9 files changed

+329
-132
lines changed

components/audio_board/lyrat_v4_3/board_def.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifndef _AUDIO_BOARD_DEFINITION_H_
2626
#define _AUDIO_BOARD_DEFINITION_H_
2727

28+
#include "driver/touch_pad.h"
29+
2830
#define SDCARD_OPEN_FILE_NUM_MAX 5
2931
#define SDCARD_INTR_GPIO GPIO_NUM_34
3032

components/bluetooth_service/a2dp_stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static void bt_avrc_ct_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *
292292
break;
293293
}
294294
case ESP_AVRC_CT_CHANGE_NOTIFY_EVT: {
295-
ESP_LOGD(TAG, "AVRC event notification: %d, param: %d", rc->change_ntf.event_id, rc->change_ntf.event_parameter);
295+
// ESP_LOGD(TAG, "AVRC event notification: %u, param: %u", rc->change_ntf.event_id, rc->change_ntf.event_parameter);
296296
break;
297297
}
298298
case ESP_AVRC_CT_REMOTE_FEATURES_EVT: {

components/bluetooth_service/bluetooth_service.c

Lines changed: 113 additions & 89 deletions
Large diffs are not rendered by default.

components/esp_peripherals/esp_peripherals.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "freertos/task.h"
2929
#include "freertos/event_groups.h"
3030
#include "rom/queue.h"
31+
#include "driver/gpio.h"
3132
#include "esp_log.h"
3233
#include "audio_event_iface.h"
3334
#include "audio_mutex.h"

components/esp_peripherals/lib/touch/touch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
#include "esp_log.h"
3333
#include "driver/gpio.h"
34+
#include "driver/touch_pad.h"
3435
#include "rom/queue.h"
3536
#include "touch.h"
3637

37-
3838
#define TOUCHPAD_TRIGGER_THRESHOLD 100
3939
#define TOUCHPAD_FILTER_PERIOD (30)
4040
#define TOUCHPAD_READ_INTERVAL_MS (TOUCHPAD_FILTER_PERIOD*4)

components/esp_peripherals/periph_spiffs.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include "board.h"
3939
#include "periph_spiffs.h"
4040

41-
static const char* TAG = "PERIPH_SPIFFS";
41+
static const char *TAG = "PERIPH_SPIFFS";
4242

4343
#define VALIDATE_SPIFFS(periph, ret) if (!(periph && esp_periph_get_id(periph) == PERIPH_ID_SPIFFS)) { \
4444
ESP_LOGE(TAG, "Invalid SPIFFS periph, at line %d", __LINE__);\
@@ -80,7 +80,7 @@ static esp_err_t _spiffs_destroy(esp_periph_handle_t self)
8080

8181
periph_spiffs_t *spiffs = esp_periph_get_data(self);
8282
free(spiffs->root);
83-
if(spiffs->partition_label != NULL) {
83+
if (spiffs->partition_label != NULL) {
8484
free(spiffs->partition_label);
8585
}
8686
free(spiffs);
@@ -94,10 +94,10 @@ esp_err_t periph_spiffs_mount(esp_periph_handle_t periph)
9494
periph_spiffs_t *spiffs = esp_periph_get_data(periph);
9595

9696
esp_vfs_spiffs_conf_t conf = {
97-
.base_path = spiffs->root,
98-
.partition_label = spiffs->partition_label,
99-
.max_files = spiffs->max_files,
100-
.format_if_mount_failed = spiffs->format_if_mount_failed
97+
.base_path = spiffs->root,
98+
.partition_label = spiffs->partition_label,
99+
.max_files = spiffs->max_files,
100+
.format_if_mount_failed = spiffs->format_if_mount_failed
101101
};
102102

103103
// Use settings defined above to initialize and mount SPIFFS filesystem.
@@ -112,7 +112,7 @@ esp_err_t periph_spiffs_mount(esp_periph_handle_t periph)
112112
} else {
113113
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%d)", ret);
114114
}
115-
return NULL;
115+
return ESP_FAIL;
116116
}
117117

118118
if (ret == ESP_OK) {
@@ -141,7 +141,7 @@ esp_err_t periph_spiffs_unmount(esp_periph_handle_t periph)
141141
{
142142
VALIDATE_SPIFFS(periph, ESP_FAIL);
143143
periph_spiffs_t *spiffs = esp_periph_get_data(periph);
144-
144+
145145
int ret = esp_vfs_spiffs_unregister(spiffs->partition_label);
146146
if (ret == ESP_OK) {
147147
ESP_LOGD(TAG, "Unmount SPIFFS success");
@@ -156,7 +156,7 @@ esp_err_t periph_spiffs_unmount(esp_periph_handle_t periph)
156156
return ESP_OK;
157157
}
158158

159-
esp_periph_handle_t periph_spiffs_init(periph_spiffs_cfg_t* spiffs_cfg)
159+
esp_periph_handle_t periph_spiffs_init(periph_spiffs_cfg_t *spiffs_cfg)
160160
{
161161
esp_periph_handle_t periph = esp_periph_create(PERIPH_ID_SPIFFS, "periph_spiffs");
162162
AUDIO_MEM_CHECK(TAG, periph, return NULL);

components/esp_peripherals/periph_wifi.c

Lines changed: 144 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,39 @@
2222
*
2323
*/
2424

25-
#include <stdlib.h>
2625
#include <stdio.h>
26+
#include <stdlib.h>
2727
#include <string.h>
28+
2829
#include "freertos/FreeRTOS.h"
29-
#include "freertos/task.h"
3030
#include "freertos/queue.h"
31-
#include "soc/soc.h"
31+
#include "freertos/task.h"
3232
#include "soc/rtc_cntl_reg.h"
3333
#include "soc/sens_reg.h"
34-
#include "esp_wifi.h"
34+
#include "soc/soc.h"
35+
3536
#include "esp_event_loop.h"
3637
#include "esp_log.h"
3738
#include "esp_smartconfig.h"
3839
#include "esp_system.h"
40+
#include "esp_wifi.h"
41+
3942
#include "board.h"
40-
#include "periph_wifi.h"
4143
#include "esp_peripherals.h"
44+
#include "periph_wifi.h"
4245
#include "wifibleconfig.h"
4346

47+
#if __has_include("esp_idf_version.h")
48+
#include "esp_idf_version.h"
49+
#endif
50+
4451
static const char *TAG = "PERIPH_WIFI";
4552

46-
#define VALIDATE_WIFI(periph, ret) if (!(periph && esp_periph_get_id(periph) == PERIPH_ID_WIFI)) { \
47-
ESP_LOGE(TAG, "Invalid WIFI periph, at line %d", __LINE__);\
48-
return ret;\
49-
}
53+
#define VALIDATE_WIFI(periph, ret) \
54+
if (!(periph && esp_periph_get_id(periph) == PERIPH_ID_WIFI)) { \
55+
ESP_LOGE(TAG, "Invalid WIFI periph, at line %d", __LINE__); \
56+
return ret; \
57+
}
5058

5159
#define DEFAULT_RECONNECT_TIMEOUT_MS (1000)
5260

@@ -85,7 +93,7 @@ esp_err_t periph_wifi_wait_for_connected(esp_periph_handle_t periph, TickType_t
8593
return ESP_OK;
8694
}
8795
#ifdef CONFIG_BLUEDROID_ENABLED
88-
if(periph_wifi->config_mode == WIFI_CONFIG_BLUEFI) {
96+
if (periph_wifi->config_mode == WIFI_CONFIG_BLUEFI) {
8997
ble_config_stop();
9098
}
9199
#endif
@@ -99,6 +107,60 @@ periph_wifi_state_t periph_wifi_is_connected(esp_periph_handle_t periph)
99107
return wifi->wifi_state;
100108
}
101109

110+
#if defined(ESP_IDF_VERSION)
111+
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0))
112+
static void _wifi_smartconfig_event_callback(void *arg, esp_event_base_t event_base,
113+
int32_t event_id, void *event_data)
114+
{
115+
wifi_config_t sta_conf;
116+
periph_wifi_handle_t periph_wifi = (periph_wifi_handle_t)esp_periph_get_data(g_periph);
117+
switch (event_id) {
118+
case SC_EVENT_SCAN_DONE:
119+
ESP_LOGD(TAG, "SC_EVENT_SCAN_DONE");
120+
break;
121+
122+
case SC_EVENT_FOUND_CHANNEL:
123+
ESP_LOGD(TAG, "SC_EVENT_FOUND_CHANNEL");
124+
break;
125+
126+
case SC_EVENT_GOT_SSID_PSWD:
127+
ESP_LOGE(TAG, "SC_EVENT_GOT_SSID_PSWD");
128+
smartconfig_event_got_ssid_pswd_t *evt = (smartconfig_event_got_ssid_pswd_t *)event_data;
129+
memset(&sta_conf, 0x00, sizeof(sta_conf));
130+
memcpy(sta_conf.sta.ssid, evt->ssid, sizeof(sta_conf.sta.ssid));
131+
memcpy(sta_conf.sta.password, evt->password, sizeof(sta_conf.sta.password));
132+
sta_conf.sta.bssid_set = evt->bssid_set;
133+
if (sta_conf.sta.bssid_set == true) {
134+
memcpy(sta_conf.sta.bssid, evt->bssid, sizeof(sta_conf.sta.bssid));
135+
}
136+
ESP_LOGE(TAG, "SSID=%s, PASS=%s", sta_conf.sta.ssid, sta_conf.sta.password);
137+
138+
esp_wifi_disconnect();
139+
140+
if (esp_wifi_set_config(WIFI_IF_STA, &sta_conf) != ESP_OK) {
141+
periph_wifi->wifi_state = PERIPH_WIFI_CONFIG_ERROR;
142+
xEventGroupSetBits(periph_wifi->state_event, SMARTCONFIG_ERROR_BIT);
143+
}
144+
if (esp_wifi_connect() != ESP_OK) {
145+
periph_wifi->wifi_state = PERIPH_WIFI_CONFIG_ERROR;
146+
xEventGroupSetBits(periph_wifi->state_event, SMARTCONFIG_ERROR_BIT);
147+
esp_periph_send_event(g_periph, PERIPH_WIFI_CONFIG_ERROR, NULL, 0);
148+
break;
149+
}
150+
break;
151+
152+
case SC_EVENT_SEND_ACK_DONE:
153+
ESP_LOGE(TAG, "SC_EVENT_SEND_ACK_DONE");
154+
155+
periph_wifi->wifi_state = PERIPH_WIFI_CONFIG_DONE;
156+
esp_periph_send_event(g_periph, PERIPH_WIFI_CONFIG_DONE, NULL, 0);
157+
xEventGroupSetBits(periph_wifi->state_event, SMARTCONFIG_DONE_BIT);
158+
esp_smartconfig_stop();
159+
break;
160+
}
161+
}
162+
#endif
163+
#else
102164
static void _wifi_smartconfig_event_callback(smartconfig_status_t status, void *pdata)
103165
{
104166
wifi_config_t sta_conf;
@@ -141,7 +203,7 @@ static void _wifi_smartconfig_event_callback(smartconfig_status_t status, void *
141203
ESP_LOGE(TAG, "SC_STATUS_LINK_OVER");
142204

143205
if (pdata != NULL) {
144-
char phone_ip[4] = {0};
206+
char phone_ip[4] = { 0 };
145207
memcpy(phone_ip, (const void *)pdata, 4);
146208
ESP_LOGD(TAG, "Phone ip: %d.%d.%d.%d", phone_ip[0], phone_ip[1], phone_ip[2], phone_ip[3]);
147209
periph_wifi->wifi_state = PERIPH_WIFI_CONFIG_DONE;
@@ -156,6 +218,7 @@ static void _wifi_smartconfig_event_callback(smartconfig_status_t status, void *
156218
break;
157219
}
158220
}
221+
#endif
159222

160223
esp_err_t periph_wifi_wait_for_disconnected(esp_periph_handle_t periph, TickType_t tick_to_wait)
161224
{
@@ -168,7 +231,6 @@ esp_err_t periph_wifi_wait_for_disconnected(esp_periph_handle_t periph, TickType
168231
return ESP_FAIL;
169232
}
170233

171-
172234
esp_err_t periph_wifi_config_start(esp_periph_handle_t periph, periph_wifi_config_mode_t mode)
173235
{
174236
VALIDATE_WIFI(periph, ESP_FAIL);
@@ -187,7 +249,15 @@ esp_err_t periph_wifi_config_start(esp_periph_handle_t periph, periph_wifi_confi
187249
// esp_wifi_start();
188250
err |= esp_smartconfig_set_type(mode);
189251
err |= esp_smartconfig_fast_mode(true);
252+
#if defined(ESP_IDF_VERSION)
253+
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0))
254+
smartconfig_start_config_t cfg = SMARTCONFIG_START_CONFIG_DEFAULT();
255+
err |= esp_smartconfig_start(&cfg);
256+
esp_event_handler_register(SC_EVENT, ESP_EVENT_ANY_ID, &_wifi_smartconfig_event_callback, NULL);
257+
#endif
258+
#else
190259
err |= esp_smartconfig_start(_wifi_smartconfig_event_callback, 0);
260+
#endif
191261
xEventGroupClearBits(periph_wifi->state_event, SMARTCONFIG_DONE_BIT);
192262
xEventGroupClearBits(periph_wifi->state_event, SMARTCONFIG_ERROR_BIT);
193263

@@ -209,7 +279,7 @@ esp_err_t periph_wifi_config_wait_done(esp_periph_handle_t periph, TickType_t ti
209279
VALIDATE_WIFI(periph, ESP_FAIL);
210280
periph_wifi_handle_t periph_wifi = (periph_wifi_handle_t)esp_periph_get_data(periph);
211281
EventBits_t wificonfig_bit = xEventGroupWaitBits(periph_wifi->state_event,
212-
SMARTCONFIG_DONE_BIT | SMARTCONFIG_ERROR_BIT, false, true, tick_to_wait);
282+
SMARTCONFIG_DONE_BIT | SMARTCONFIG_ERROR_BIT, false, true, tick_to_wait);
213283

214284
if (wificonfig_bit & SMARTCONFIG_DONE_BIT) {
215285
return ESP_OK;
@@ -223,11 +293,55 @@ esp_err_t periph_wifi_config_wait_done(esp_periph_handle_t periph, TickType_t ti
223293

224294
static void wifi_reconnect_timer(xTimerHandle tmr)
225295
{
226-
esp_periph_handle_t periph = (esp_periph_handle_t) pvTimerGetTimerID(tmr);
296+
esp_periph_handle_t periph = (esp_periph_handle_t)pvTimerGetTimerID(tmr);
227297
esp_periph_stop_timer(periph);
228298
esp_wifi_connect();
229299
}
230300

301+
#if defined(ESP_IDF_VERSION)
302+
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0))
303+
static void _wifi_event_callback(void *arg, esp_event_base_t event_base,
304+
int32_t event_id, void *event_data)
305+
{
306+
esp_periph_handle_t self = (esp_periph_handle_t)arg;
307+
periph_wifi_handle_t periph_wifi = (periph_wifi_handle_t)esp_periph_get_data(self);
308+
309+
switch (event_id) {
310+
case WIFI_EVENT_STA_START:
311+
periph_wifi->wifi_state = PERIPH_WIFI_CONNECTING;
312+
esp_wifi_connect();
313+
break;
314+
case IP_EVENT_STA_GOT_IP:
315+
periph_wifi->wifi_state = PERIPH_WIFI_CONNECTED;
316+
xEventGroupClearBits(periph_wifi->state_event, DISCONNECTED_BIT);
317+
esp_periph_send_event(self, PERIPH_WIFI_CONNECTED, NULL, 0);
318+
xEventGroupSetBits(periph_wifi->state_event, CONNECTED_BIT);
319+
wifi_config_t w_config;
320+
memset(&w_config, 0x00, sizeof(wifi_config_t));
321+
esp_wifi_get_config(WIFI_IF_STA, &w_config);
322+
strcpy(periph_wifi->ssid, (char *)w_config.sta.ssid);
323+
break;
324+
case WIFI_EVENT_STA_DISCONNECTED:
325+
periph_wifi->wifi_state = PERIPH_WIFI_DISCONNECTED;
326+
xEventGroupClearBits(periph_wifi->state_event, CONNECTED_BIT);
327+
xEventGroupSetBits(periph_wifi->state_event, DISCONNECTED_BIT);
328+
esp_periph_send_event(self, PERIPH_WIFI_DISCONNECTED, NULL, 0);
329+
330+
ESP_LOGW(TAG, "Wi-Fi disconnected from SSID %s, auto-reconnect %s, reconnect after %d ms",
331+
periph_wifi->ssid,
332+
periph_wifi->disable_auto_reconnect == 0 ? "enabled" : "disabled",
333+
periph_wifi->reconnect_timeout_ms);
334+
if (periph_wifi->disable_auto_reconnect) {
335+
break;
336+
}
337+
esp_periph_start_timer(self, periph_wifi->reconnect_timeout_ms / portTICK_RATE_MS, wifi_reconnect_timer);
338+
break;
339+
default:
340+
break;
341+
}
342+
}
343+
#endif
344+
#else
231345
static esp_err_t _wifi_event_callback(void *ctx, system_event_t *event)
232346
{
233347
esp_periph_handle_t self = (esp_periph_handle_t)ctx;
@@ -257,9 +371,9 @@ static esp_err_t _wifi_event_callback(void *ctx, system_event_t *event)
257371
esp_periph_send_event(self, PERIPH_WIFI_DISCONNECTED, NULL, 0);
258372

259373
ESP_LOGW(TAG, "Wi-Fi disconnected from SSID %s, auto-reconnect %s, reconnect after %d ms",
260-
periph_wifi->ssid,
261-
periph_wifi->disable_auto_reconnect == 0 ? "enabled" : "disabled",
262-
periph_wifi->reconnect_timeout_ms);
374+
periph_wifi->ssid,
375+
periph_wifi->disable_auto_reconnect == 0 ? "enabled" : "disabled",
376+
periph_wifi->reconnect_timeout_ms);
263377
if (periph_wifi->disable_auto_reconnect) {
264378
break;
265379
}
@@ -270,6 +384,7 @@ static esp_err_t _wifi_event_callback(void *ctx, system_event_t *event)
270384
}
271385
return ESP_OK;
272386
}
387+
#endif
273388

274389
static esp_err_t _wifi_run(esp_periph_handle_t self, audio_event_iface_msg_t *msg)
275390
{
@@ -287,14 +402,22 @@ static esp_err_t _wifi_init(esp_periph_handle_t self)
287402
return ESP_FAIL;
288403
}
289404

290-
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
291-
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
292-
405+
#if defined(ESP_IDF_VERSION)
406+
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0))
407+
ESP_ERROR_CHECK(esp_event_loop_create_default());
408+
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &_wifi_event_callback, self));
409+
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &_wifi_event_callback, self));
410+
#endif
411+
#else
293412
if (esp_event_loop_get_queue() == NULL) {
294413
ESP_ERROR_CHECK(esp_event_loop_init(_wifi_event_callback, self));
295414
} else {
296415
esp_event_loop_set_cb(_wifi_event_callback, self);
297416
}
417+
#endif
418+
419+
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
420+
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
298421

299422
memset(&wifi_config, 0x00, sizeof(wifi_config_t));
300423
if (periph_wifi->ssid) {
@@ -338,14 +461,7 @@ esp_periph_handle_t periph_wifi_init(periph_wifi_cfg_t *config)
338461
{
339462
esp_periph_handle_t periph = NULL;
340463
periph_wifi_handle_t periph_wifi = NULL;
341-
bool _success =
342-
(
343-
(periph = esp_periph_create(PERIPH_ID_WIFI, "periph_wifi")) &&
344-
(periph_wifi = calloc(1, sizeof(struct periph_wifi))) &&
345-
(periph_wifi->state_event = xEventGroupCreate()) &&
346-
(config->ssid ? (bool)(periph_wifi->ssid = strdup(config->ssid)) : true) &&
347-
(config->password ? (bool)(periph_wifi->password = strdup(config->password)) : true)
348-
);
464+
bool _success = ((periph = esp_periph_create(PERIPH_ID_WIFI, "periph_wifi")) && (periph_wifi = calloc(1, sizeof(struct periph_wifi))) && (periph_wifi->state_event = xEventGroupCreate()) && (config->ssid ? (bool)(periph_wifi->ssid = strdup(config->ssid)) : true) && (config->password ? (bool)(periph_wifi->password = strdup(config->password)) : true));
349465

350466
AUDIO_MEM_CHECK(TAG, _success, goto _periph_wifi_init_failed);
351467

0 commit comments

Comments
 (0)