Skip to content

Commit c5b8401

Browse files
committed
First crack at native wifi API
1 parent 837abd6 commit c5b8401

19 files changed

Lines changed: 753 additions & 11 deletions

ports/esp32s2/Makefile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ INC += -Iesp-idf/components/freertos/xtensa/include
7878
INC += -Iesp-idf/components/esp32s2/include
7979
INC += -Iesp-idf/components/xtensa/esp32s2/include
8080
INC += -Iesp-idf/components/esp_common/include
81+
INC += -Iesp-idf/components/esp_event/include
82+
INC += -Iesp-idf/components/esp_netif/include
8183
INC += -Iesp-idf/components/esp_ringbuf/include
8284
INC += -Iesp-idf/components/esp_rom/include
85+
INC += -Iesp-idf/components/esp_wifi/include
8386
INC += -Iesp-idf/components/xtensa/include
8487
INC += -Iesp-idf/components/esp_timer/include
8588
INC += -Iesp-idf/components/soc/include
@@ -129,7 +132,7 @@ LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/esp32s2 \
129132
-Tesp32s2.rom.newlib-data.ld \
130133
-Tesp32s2.rom.newlib-funcs.ld \
131134
-Tesp32s2.rom.spiflash.ld
132-
LIBS := -lgcc -lc
135+
LIBS := -lgcc -lc -lstdc++
133136

134137
#
135138

@@ -238,20 +241,25 @@ $(BUILD)/esp-idf/partition_table/partition-table.bin: $(BUILD)/esp-idf/config/sd
238241

239242
# run menuconfig
240243
menuconfig: $(BUILD)/esp-idf/config
241-
ninja -C $(BUILD)/esp-idf menuconfig
242-
diff --old-line-format= --unchanged-line-format= sdkconfig.defaults $(BUILD)/esp-idf/sdkconfig > boards/$(BOARD)/sdkconfig || true
244+
$(Q)ninja -C $(BUILD)/esp-idf menuconfig
245+
$(Q)diff --old-line-format= --unchanged-line-format= sdkconfig.defaults $(BUILD)/esp-idf/sdkconfig > boards/$(BOARD)/sdkconfig || true
243246

244247
# qstr builds include headers so we need to make sure they are up to date
245248
$(HEADER_BUILD)/qstr.i.last: | $(BUILD)/esp-idf/config/sdkconfig.h
246249

247250
# Order here matters
248-
ESP_IDF_COMPONENTS_LINK = freertos log esp_system esp32s2 bootloader_support pthread esp_timer vfs spi_flash app_update esp_common esp32s2 heap newlib driver xtensa soc esp_ringbuf #
251+
ESP_IDF_COMPONENTS_LINK = freertos log esp_system esp32s2 bootloader_support pthread esp_timer vfs spi_flash app_update esp_common esp32s2 heap newlib driver xtensa soc esp_ringbuf esp_wifi esp_event wpa_supplicant mbedtls efuse nvs_flash
249252

250253
ESP_IDF_COMPONENTS_INCLUDE = driver freertos log soc
251254

252255
INC += $(foreach component, $(ESP_IDF_COMPONENTS_INCLUDE), -Iesp-idf/components/$(component)/include)
253256

254257
ESP_IDF_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a)
258+
ESP_IDF_WIFI_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_WIFI_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a)
259+
260+
MBEDTLS_COMPONENTS_LINK = crypto tls x509
261+
MBEDTLS_COMPONENTS_LINK_EXPANDED = $(foreach component, $(MBEDTLS_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/mbedtls/mbedtls/library/libmbed$(component).a)
262+
255263
BINARY_BLOBS = esp-idf/components/xtensa/esp32s2/libhal.a
256264
BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a librtc.a libsmartconfig.a libphy.a
257265
BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/esp32s2/, $(BINARY_WIFI_BLOBS))
@@ -265,18 +273,23 @@ all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
265273

266274
.PHONY: esp-idf-stamp
267275
esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h
268-
ninja -C $(BUILD)/esp-idf \
276+
$(Q)ninja -C $(BUILD)/esp-idf \
269277
bootloader/bootloader.bin \
270278
esp-idf/bootloader_support/libbootloader_support.a \
271279
esp-idf/esp32s2/ld/esp32s2.project.ld \
280+
esp-idf/esp_event/libesp_event.a \
272281
esp-idf/esp_system/libesp_system.a \
282+
esp-idf/esp_wifi/libesp_wifi.a \
283+
esp-idf/nvs_flash/libnvs_flash.a \
284+
esp-idf/wpa_supplicant/libwpa_supplicant.a \
285+
esp-idf/mbedtls/libmbedtls.a \
273286
esp-idf/freertos/libfreertos.a \
274287
esp-idf/log/liblog.a \
275288
esp-idf/xtensa/libxtensa.a
276289

277290
$(BUILD)/firmware.elf: $(OBJ) | esp-idf-stamp
278291
$(STEPECHO) "LINK $@"
279-
$(Q)$(CC) -o $@ $(LDFLAGS) $^ $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) build-$(BOARD)/esp-idf/esp-idf/newlib/libnewlib.a -u newlib_include_pthread_impl -Wl,--start-group $(LIBS) -Wl,--end-group
292+
$(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) $(MBEDTLS_COMPONENTS_LINK_EXPANDED) build-$(BOARD)/esp-idf/esp-idf/newlib/libnewlib.a -Wl,--end-group -u newlib_include_pthread_impl -Wl,--start-group $(LIBS) -Wl,--end-group build-$(BOARD)/esp-idf/esp-idf/pthread/libpthread.a -u __cxx_fatal_exception
280293
# $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(BUILD)/esp-idf/esp-idf/esp32s2/esp32s2_out.ld
281294

282295
$(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "shared-bindings/wifi/Network.h"
28+
29+
mp_obj_t common_hal_wifi_network_get_ssid(wifi_network_obj_t *self) {
30+
return mp_const_none;
31+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_NETWORK_H
28+
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_NETWORK_H
29+
30+
#include "py/obj.h"
31+
32+
typedef struct {
33+
mp_obj_base_t base;
34+
// Stores no state currently.
35+
} wifi_network_obj_t;
36+
37+
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_NETWORK_H
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "shared-bindings/wifi/Radio.h"
28+
29+
bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self) {
30+
return true;
31+
}
32+
33+
void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) {
34+
35+
}
36+
37+
mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) {
38+
return mp_const_none;
39+
}
40+
41+
mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
42+
return mp_const_none;
43+
}
44+
45+
void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) {
46+
47+
}
48+
49+
bool common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t* ssid, size_t ssid_len, uint8_t* password, size_t password_len, mp_float_t timeout) {
50+
return false;
51+
}
52+
53+
mp_obj_t common_hal_wifi_radio_get_ip_address(wifi_radio_obj_t *self) {
54+
return mp_const_none;
55+
}
56+
57+
mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address) {
58+
return 0;
59+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_RADIO_H
28+
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_RADIO_H
29+
30+
#include "py/obj.h"
31+
32+
typedef struct {
33+
mp_obj_base_t base;
34+
// Stores no state currently.
35+
} wifi_radio_obj_t;
36+
37+
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_RADIO_H
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "shared-bindings/wifi/Radio.h"
28+
29+
#include "py/runtime.h"
30+
31+
#include "esp-idf/components/esp_wifi/include/esp_wifi.h"
32+
33+
wifi_radio_obj_t common_hal_wifi_radio_obj;
34+
35+
void common_hal_wifi_init(void) {
36+
common_hal_wifi_radio_obj.base.type = &wifi_radio_type;
37+
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
38+
39+
esp_err_t result = esp_wifi_init(&config);
40+
if (result == ESP_ERR_NO_MEM) {
41+
mp_raise_msg(&mp_type_MemoryError, translate("Failed to allocate Wifi memory"));
42+
} else if (result != ESP_OK) {
43+
// handle this
44+
}
45+
}
46+
47+
void wifi_reset(void) {
48+
esp_wifi_deinit();
49+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI___INIT___H
28+
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI___INIT___H
29+
30+
#include "py/obj.h"
31+
32+
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI___INIT___H

ports/esp32s2/mpconfigport.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ CIRCUITPY_RANDOM = 0 # Requires OS
2929
CIRCUITPY_USB_MIDI = 0 # Requires USB
3030
CIRCUITPY_ULAB = 0 # No requirements, but takes extra flash
3131

32+
CIRCUITPY_WIFI = 1
33+
3234
CIRCUITPY_MODULE ?= none

ports/esp32s2/sdkconfig.defaults

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP=y
279279
#
280280
# Ethernet
281281
#
282-
CONFIG_ETH_ENABLED=y
283-
CONFIG_ETH_USE_SPI_ETHERNET=y
284-
# CONFIG_ETH_SPI_ETHERNET_DM9051 is not set
282+
# CONFIG_ETH_USE_SPI_ETHERNET is not set
285283
# CONFIG_ETH_USE_OPENETH is not set
286284
# end of Ethernet
287285

@@ -299,7 +297,7 @@ CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y
299297
CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL=120
300298
CONFIG_ESP_NETIF_TCPIP_LWIP=y
301299
# CONFIG_ESP_NETIF_LOOPBACK is not set
302-
CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=y
300+
# CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER is not set
303301
# end of ESP NETIF Adapter
304302

305303
#

0 commit comments

Comments
 (0)