From 3179db4ef4f423c77f2170034dcd3a1544b8336c Mon Sep 17 00:00:00 2001 From: Neradoc Date: Wed, 4 May 2022 01:49:51 +0200 Subject: [PATCH 1/9] move frozen adafruit_circuitplayground to express subdirectory --- .../boards/circuitplayground_express/mpconfigboard.mk | 2 +- .../boards/circuitplayground_express_crickit/mpconfigboard.mk | 2 +- .../boards/circuitplayground_express_displayio/mpconfigboard.mk | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk index 5311cdc1d4..b64fd2033d 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk @@ -19,7 +19,7 @@ CIRCUITPY_COUNTIO = 1 CIRCUITPY_BUSDEVICE = 1 # Include these Python libraries in firmware. -FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground/frozen_cpx FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk index 4d749d2134..975d892b9a 100644 --- a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk @@ -18,7 +18,7 @@ CIRCUITPY_KEYPAD = 0 CIRCUITPY_ONEWIREIO = 0 # Include these Python libraries in firmware. -FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground/frozen_cpx FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Crickit FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Motor diff --git a/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk index 0ae0c58b42..4338fe3e1e 100644 --- a/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk @@ -24,7 +24,7 @@ CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_PARALLELDISPLAY = 0 # Include these Python libraries in firmware. -FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground/frozen_cpx FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Thermistor From 2aea5ed7429b7788ba1a8300be29c76f23fb8c58 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Mon, 23 May 2022 22:12:40 +0200 Subject: [PATCH 2/9] update adafruit_circuitplayground to last release with frozen dir --- frozen/Adafruit_CircuitPython_CircuitPlayground | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frozen/Adafruit_CircuitPython_CircuitPlayground b/frozen/Adafruit_CircuitPython_CircuitPlayground index f82d3ef195..54b2fa03d8 160000 --- a/frozen/Adafruit_CircuitPython_CircuitPlayground +++ b/frozen/Adafruit_CircuitPython_CircuitPlayground @@ -1 +1 @@ -Subproject commit f82d3ef195256aa71d274a34ea25f760d7e651d1 +Subproject commit 54b2fa03d8af80562b77460841e63d47f12eee43 From 90fe20a15343b62e03fc8f8eee793b3a3ebab1e7 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Fri, 27 May 2022 15:33:54 -0500 Subject: [PATCH 3/9] Adding manual IP address set --- ports/espressif/common-hal/wifi/Radio.c | 19 +++++++++ ports/espressif/common-hal/wifi/__init__.c | 10 +++++ ports/espressif/common-hal/wifi/__init__.h | 2 + shared-bindings/wifi/Radio.c | 46 ++++++++++++++++++++++ shared-bindings/wifi/Radio.h | 5 +++ 5 files changed, 82 insertions(+) diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index 8ee1c80926..e43ce2fa51 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -398,6 +398,25 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self) { return common_hal_ipaddress_new_ipv4address(self->dns_info.ip.u_addr.ip4.addr); } +void common_hal_wifi_radio_start_dhcp_client(wifi_radio_obj_t *self) { + esp_netif_dhcpc_start(self->netif); +} + +void common_hal_wifi_radio_stop_dhcp_client(wifi_radio_obj_t *self) { + esp_netif_dhcpc_stop(self->netif); +} + +void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway) { + common_hal_wifi_radio_stop_dhcp_client(self); // Must stop DHCP to set a manual address + + esp_netif_ip_info_t ip_info; + ipaddress_ipaddress_to_esp_idf_ip4(ipv4, &ip_info.ip); + ipaddress_ipaddress_to_esp_idf_ip4(netmask, &ip_info.netmask); + ipaddress_ipaddress_to_esp_idf_ip4(gateway, &ip_info.gw); + + esp_netif_set_ip_info(self->netif, &ip_info); +} + mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout) { esp_ping_config_t ping_config = ESP_PING_DEFAULT_CONFIG(); ipaddress_ipaddress_to_esp_idf(ip_address, &ping_config.target_addr); diff --git a/ports/espressif/common-hal/wifi/__init__.c b/ports/espressif/common-hal/wifi/__init__.c index cb9b028aba..36cf27a69f 100644 --- a/ports/espressif/common-hal/wifi/__init__.c +++ b/ports/espressif/common-hal/wifi/__init__.c @@ -189,6 +189,16 @@ void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t *esp_ip_addre IP_ADDR4(esp_ip_address, bytes[0], bytes[1], bytes[2], bytes[3]); } +void ipaddress_ipaddress_to_esp_idf_ip4(mp_obj_t ip_address, esp_ip4_addr_t *esp_ip_address) { + if (!mp_obj_is_type(ip_address, &ipaddress_ipv4address_type)) { + mp_raise_ValueError(translate("Only IPv4 addresses supported")); + } + mp_obj_t packed = common_hal_ipaddress_ipv4address_get_packed(ip_address); + size_t len; + const char *bytes = mp_obj_str_get_data(packed, &len); + esp_netif_set_ip4_addr(esp_ip_address, bytes[0], bytes[1], bytes[2], bytes[3]); +} + void common_hal_wifi_gc_collect(void) { common_hal_wifi_radio_gc_collect(&common_hal_wifi_radio_obj); } diff --git a/ports/espressif/common-hal/wifi/__init__.h b/ports/espressif/common-hal/wifi/__init__.h index be91dca758..4258f1643f 100644 --- a/ports/espressif/common-hal/wifi/__init__.h +++ b/ports/espressif/common-hal/wifi/__init__.h @@ -30,9 +30,11 @@ #include "py/obj.h" #include "lwip/api.h" +#include "components/esp_wifi/include/esp_wifi.h" void wifi_reset(void); void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t *esp_ip_address); +void ipaddress_ipaddress_to_esp_idf_ip4(mp_obj_t ip_address, esp_ip4_addr_t *esp_ip_address); #endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WIFI___INIT___H diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index e79d7047b3..93c8009e50 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -414,6 +414,27 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_subnet_ap_obj, wifi_radio_get_ipv4 MP_PROPERTY_GETTER(wifi_radio_ipv4_subnet_ap_obj, (mp_obj_t)&wifi_radio_get_ipv4_subnet_ap_obj); +//| def set_ipv4_address(self, ipv4: ipaddress.IPv4Address, netmask: ipaddress.IPv4Address, gateway: ipaddress.IPv4Address) -> None: +//| """Sets the IP v4 address of the station. Must include the netmask and gateway. +//| Setting the address manually will stop the DHCP client.""" +//| ... +STATIC mp_obj_t wifi_radio_set_ipv4_address(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_ipv4, ARG_netmask, ARG_gateway }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_ipv4, MP_ARG_REQUIRED | MP_ARG_OBJ, }, + { MP_QSTR_netmask, MP_ARG_REQUIRED | MP_ARG_OBJ, }, + { MP_QSTR_gateway, MP_ARG_REQUIRED | MP_ARG_OBJ, }, + }; + + wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + common_hal_wifi_radio_set_ipv4_address(self, args[ARG_ipv4].u_obj, args[ARG_netmask].u_obj, args[ARG_gateway].u_obj); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_set_ipv4_address_obj, 4, wifi_radio_set_ipv4_address); + //| ipv4_address: Optional[ipaddress.IPv4Address] //| """IP v4 Address of the station when connected to an access point. None otherwise.""" //| @@ -459,6 +480,26 @@ STATIC mp_obj_t wifi_radio_get_ap_info(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_info_obj, wifi_radio_get_ap_info); +//| def wifi_radio_start_dhcp_client(self) -> None: +//| """Starts the DHCP client.""" +//| ... +//| +STATIC mp_obj_t wifi_radio_start_dhcp_client(mp_obj_t self) { + common_hal_wifi_radio_start_dhcp_client(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_start_dhcp_client_obj, wifi_radio_start_dhcp_client); + +//| def wifi_radio_stop_dhcp_client(self) -> None: +//| """Stops the DHCP client. Needed to assign a static IP address.""" +//| ... +//| +STATIC mp_obj_t wifi_radio_stop_dhcp_client(mp_obj_t self) { + common_hal_wifi_radio_stop_dhcp_client(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_dhcp_client_obj, wifi_radio_stop_dhcp_client); + MP_PROPERTY_GETTER(wifi_radio_ap_info_obj, (mp_obj_t)&wifi_radio_get_ap_info_obj); @@ -509,6 +550,9 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_start_ap), MP_ROM_PTR(&wifi_radio_start_ap_obj) }, { MP_ROM_QSTR(MP_QSTR_stop_ap), MP_ROM_PTR(&wifi_radio_stop_ap_obj) }, + { MP_ROM_QSTR(MP_QSTR_start_dhcp), MP_ROM_PTR(&wifi_radio_start_dhcp_client_obj) }, + { MP_ROM_QSTR(MP_QSTR_stop_dhcp), MP_ROM_PTR(&wifi_radio_stop_dhcp_client_obj) }, + { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) }, // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) }, @@ -521,6 +565,8 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ipv4_address), MP_ROM_PTR(&wifi_radio_ipv4_address_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_address_ap), MP_ROM_PTR(&wifi_radio_ipv4_address_ap_obj) }, + { MP_ROM_QSTR(MP_QSTR_set_ipv4_address), MP_ROM_PTR(&wifi_radio_set_ipv4_address_obj) }, + // { MP_ROM_QSTR(MP_QSTR_access_point_active), MP_ROM_PTR(&wifi_radio_access_point_active_obj) }, // { MP_ROM_QSTR(MP_QSTR_start_access_point), MP_ROM_PTR(&wifi_radio_start_access_point_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index cee9f6ef15..5590e17990 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -91,6 +91,9 @@ extern void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode, uint8_t max_connections); extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self); +extern void common_hal_wifi_radio_start_dhcp_client(wifi_radio_obj_t *self); +extern void common_hal_wifi_radio_stop_dhcp_client(wifi_radio_obj_t *self); + extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len); extern mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self); @@ -102,6 +105,8 @@ extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self) extern mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self); +extern void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway); + extern mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_RADIO_H From e8dd5d35d6d3549089212529563336a1eaa084a9 Mon Sep 17 00:00:00 2001 From: EmergReanimator Date: Sun, 29 May 2022 16:13:38 +0200 Subject: [PATCH 4/9] # WARNING: head commit changed in the meantime Fixed STM SPI frequency settings. Corrected default frequency settings in common_hal_busio_spi_construct. Fixed common_hal_busio_spi_get_frequency. --- ports/stm/common-hal/busio/SPI.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ports/stm/common-hal/busio/SPI.c b/ports/stm/common-hal/busio/SPI.c index f772cdeec0..a66a8dcb88 100644 --- a/ports/stm/common-hal/busio/SPI.c +++ b/ports/stm/common-hal/busio/SPI.c @@ -206,6 +206,10 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, spi_clock_enable(1 << (self->sck->periph_index - 1)); reserved_spi[self->sck->periph_index - 1] = true; + // Always start at 250khz which is what SD cards need. They are sensitive to + // SPI bus noise before they are put into SPI mode. + const uint32_t default_baudrate = 250000UL; + self->handle.Instance = SPIx; self->handle.Init.Mode = SPI_MODE_MASTER; // Direction change only required for RX-only, see RefMan RM0090:884 @@ -218,7 +222,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, self->handle.Init.CLKPolarity = SPI_POLARITY_LOW; self->handle.Init.CLKPhase = SPI_PHASE_1EDGE; self->handle.Init.NSS = SPI_NSS_SOFT; - self->handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256; + self->handle.Init.BaudRatePrescaler = stm32_baud_to_spi_div(default_baudrate, &self->prescaler, get_busclock(self->handle.Instance)); self->handle.Init.FirstBit = SPI_FIRSTBIT_MSB; self->handle.Init.TIMode = SPI_TIMODE_DISABLE; self->handle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; @@ -226,8 +230,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (HAL_SPI_Init(&self->handle) != HAL_OK) { mp_raise_ValueError(translate("SPI init error")); } - self->baudrate = (get_busclock(SPIx) / 16); - self->prescaler = 16; + self->baudrate = default_baudrate; + // self->prescaler = 16; // Initialised above by stm32_baud_to_spi_div self->half_duplex = half_duplex; self->polarity = 0; self->phase = 0; @@ -381,7 +385,7 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t *self) { // returns actual frequency - uint32_t result = HAL_RCC_GetPCLK2Freq() / self->prescaler; + uint32_t result = get_busclock(self->handle.Instance) / self->prescaler; return result; } From f0b387e882a85e9e0363f7f3776bb7e1e9f80f28 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 31 May 2022 16:13:15 +0200 Subject: [PATCH 5/9] fix autoapi bug ourselves for now --- conf.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/conf.py b/conf.py index c92e8bb719..145bed4d7b 100644 --- a/conf.py +++ b/conf.py @@ -33,6 +33,25 @@ from sphinx import addnodes tools_describe = str(pathlib.Path(__file__).parent / "tools/describe") +# Monkeypatch autoapi +def _format_args(args_info, include_annotations=True, ignore_self=None): + result = [] + + for i, (prefix, name, annotation, default) in enumerate(args_info): + if i == 0 and ignore_self is not None and name == ignore_self: + continue + formatted = "{}{}{}{}".format( + prefix or "", + name or "", + ": {}".format(annotation) if annotation and include_annotations else "", + (" = {}" if annotation else "={}").format(default) if default else "", + ) + result.append(formatted) + return ", ".join(result) + +import autoapi.mappers.python.objects as objects +objects._format_args = _format_args + # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. From 4f6d4e2284b4461a843c98b048f62b0681251fd6 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Tue, 31 May 2022 22:13:18 -0500 Subject: [PATCH 6/9] Doc fix and add set for DNS --- ports/espressif/common-hal/wifi/Radio.c | 6 ++++++ shared-bindings/wifi/Radio.c | 20 ++++++++++++++------ shared-bindings/wifi/Radio.h | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index e43ce2fa51..b6f8fc1058 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -398,6 +398,12 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self) { return common_hal_ipaddress_new_ipv4address(self->dns_info.ip.u_addr.ip4.addr); } +void common_hal_wifi_radio_set_ipv4_dns(wifi_radio_obj_t *self, mp_obj_t ipv4_dns_addr) { + esp_netif_dns_info_t dns_addr; + ipaddress_ipaddress_to_esp_idf_ip4(ipv4_dns_addr, &dns_addr.ip.u_addr.ip4); + esp_netif_set_dns_info(self->netif, ESP_NETIF_DNS_MAIN, &dns_addr); +} + void common_hal_wifi_radio_start_dhcp_client(wifi_radio_obj_t *self) { esp_netif_dhcpc_start(self->netif); } diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 93c8009e50..958164d74a 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -459,8 +459,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_address_ap_obj, wifi_radio_get_ipv MP_PROPERTY_GETTER(wifi_radio_ipv4_address_ap_obj, (mp_obj_t)&wifi_radio_get_ipv4_address_ap_obj); -//| ipv4_dns: Optional[ipaddress.IPv4Address] -//| """IP v4 Address of the DNS server in use when connected to an access point. None otherwise.""" +//| ipv4_dns: ipaddress.IPv4Address +//| """IP v4 Address of the DNS server to be used.""" //| STATIC mp_obj_t wifi_radio_get_ipv4_dns(mp_obj_t self) { return common_hal_wifi_radio_get_ipv4_dns(self); @@ -468,8 +468,16 @@ STATIC mp_obj_t wifi_radio_get_ipv4_dns(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_dns_obj, wifi_radio_get_ipv4_dns); -MP_PROPERTY_GETTER(wifi_radio_ipv4_dns_obj, - (mp_obj_t)&wifi_radio_get_ipv4_dns_obj); +STATIC mp_obj_t wifi_radio_set_ipv4_dns(mp_obj_t self, mp_obj_t ipv4_dns_addr) { + common_hal_wifi_radio_set_ipv4_dns(self, ipv4_dns_addr); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(wifi_radio_set_ipv4_dns_obj, wifi_radio_set_ipv4_dns); + +MP_PROPERTY_GETSET(wifi_radio_ipv4_dns_obj, + (mp_obj_t)&wifi_radio_get_ipv4_dns_obj, + (mp_obj_t)&wifi_radio_set_ipv4_dns_obj); //| ap_info: Optional[Network] //| """Network object containing BSSID, SSID, authmode, channel, country and RSSI when connected to an access point. None otherwise.""" @@ -480,7 +488,7 @@ STATIC mp_obj_t wifi_radio_get_ap_info(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_info_obj, wifi_radio_get_ap_info); -//| def wifi_radio_start_dhcp_client(self) -> None: +//| def start_dhcp(self) -> None: //| """Starts the DHCP client.""" //| ... //| @@ -490,7 +498,7 @@ STATIC mp_obj_t wifi_radio_start_dhcp_client(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_start_dhcp_client_obj, wifi_radio_start_dhcp_client); -//| def wifi_radio_stop_dhcp_client(self) -> None: +//| def stop_dhcp(self) -> None: //| """Stops the DHCP client. Needed to assign a static IP address.""" //| ... //| diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 5590e17990..208be8c44c 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -98,6 +98,7 @@ extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, extern mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self); +extern void common_hal_wifi_radio_set_ipv4_dns(wifi_radio_obj_t *self, mp_obj_t ipv4_dns_addr); extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway_ap(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self); From 40e890323b24038aaf98aa95935689ab28ed06f8 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Wed, 1 Jun 2022 20:13:51 -0500 Subject: [PATCH 7/9] Add DNS optional to set IP --- ports/espressif/common-hal/wifi/Radio.c | 6 +++++- shared-bindings/wifi/Radio.c | 9 +++++---- shared-bindings/wifi/Radio.h | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index b6f8fc1058..6451cb1414 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -412,7 +412,7 @@ void common_hal_wifi_radio_stop_dhcp_client(wifi_radio_obj_t *self) { esp_netif_dhcpc_stop(self->netif); } -void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway) { +void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway, mp_obj_t ipv4_dns) { common_hal_wifi_radio_stop_dhcp_client(self); // Must stop DHCP to set a manual address esp_netif_ip_info_t ip_info; @@ -421,6 +421,10 @@ void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv ipaddress_ipaddress_to_esp_idf_ip4(gateway, &ip_info.gw); esp_netif_set_ip_info(self->netif, &ip_info); + + if (ipv4_dns != MP_OBJ_NULL) { + common_hal_wifi_radio_set_ipv4_dns(self, ipv4_dns); + } } mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout) { diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 958164d74a..a0cf97c092 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -414,23 +414,24 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_subnet_ap_obj, wifi_radio_get_ipv4 MP_PROPERTY_GETTER(wifi_radio_ipv4_subnet_ap_obj, (mp_obj_t)&wifi_radio_get_ipv4_subnet_ap_obj); -//| def set_ipv4_address(self, ipv4: ipaddress.IPv4Address, netmask: ipaddress.IPv4Address, gateway: ipaddress.IPv4Address) -> None: -//| """Sets the IP v4 address of the station. Must include the netmask and gateway. +//| def set_ipv4_address(self, ipv4: ipaddress.IPv4Address, netmask: ipaddress.IPv4Address, gateway: ipaddress.IPv4Address, ipv4_dns: Optional[ipaddress.IPv4Address]) -> None: +//| """Sets the IP v4 address of the station. Must include the netmask and gateway. DNS address is optional. //| Setting the address manually will stop the DHCP client.""" //| ... STATIC mp_obj_t wifi_radio_set_ipv4_address(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_ipv4, ARG_netmask, ARG_gateway }; + enum { ARG_ipv4, ARG_netmask, ARG_gateway, ARG_ipv4_dns }; static const mp_arg_t allowed_args[] = { { MP_QSTR_ipv4, MP_ARG_REQUIRED | MP_ARG_OBJ, }, { MP_QSTR_netmask, MP_ARG_REQUIRED | MP_ARG_OBJ, }, { MP_QSTR_gateway, MP_ARG_REQUIRED | MP_ARG_OBJ, }, + { MP_QSTR_ipv4_dns, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - common_hal_wifi_radio_set_ipv4_address(self, args[ARG_ipv4].u_obj, args[ARG_netmask].u_obj, args[ARG_gateway].u_obj); + common_hal_wifi_radio_set_ipv4_address(self, args[ARG_ipv4].u_obj, args[ARG_netmask].u_obj, args[ARG_gateway].u_obj, args[ARG_ipv4_dns].u_obj); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_set_ipv4_address_obj, 4, wifi_radio_set_ipv4_address); diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 208be8c44c..09a66b2e63 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -106,7 +106,7 @@ extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self) extern mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self); -extern void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway); +extern void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway, mp_obj_t ipv4_dns_addr); extern mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout); From 4f27337207a74351a4d85016428df815896c0efa Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 2 Jun 2022 21:24:56 +0200 Subject: [PATCH 8/9] Only check the savings if a word occurs at least twice Profiling shows that `est_net_savings` is one of the highest costs of the whole process. Approximately, you can save storage only if a word appears more than once, and doing this greatly reduces the number of `est_net_savings` calls. Locally, it reduces the time for this specific build step by 50% on ports/unix coverage build, without affecting the size of the generated binary. --- py/makeqstrdata.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index 74ad78c47d..7222ded805 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -400,7 +400,8 @@ def compute_huffman_coding(translations, compression_filename): # words[] array. scores = sorted( - ((s, -est_net_savings(s, occ)) for (s, occ) in counter.items()), key=lambda x: x[1] + ((s, -est_net_savings(s, occ)) for (s, occ) in counter.items() if occ > 1), + key=lambda x: x[1], ) # Pick the one with the highest score. The score must be negative. From 1d0546da313b27cd33f4788c7e351917b1c1a496 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Thu, 2 Jun 2022 16:31:39 -0500 Subject: [PATCH 9/9] Made tcp set arguments keywords --- shared-bindings/wifi/Radio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index a0cf97c092..cb5090d0f4 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -414,17 +414,17 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_subnet_ap_obj, wifi_radio_get_ipv4 MP_PROPERTY_GETTER(wifi_radio_ipv4_subnet_ap_obj, (mp_obj_t)&wifi_radio_get_ipv4_subnet_ap_obj); -//| def set_ipv4_address(self, ipv4: ipaddress.IPv4Address, netmask: ipaddress.IPv4Address, gateway: ipaddress.IPv4Address, ipv4_dns: Optional[ipaddress.IPv4Address]) -> None: +//| def set_ipv4_address(self, *, ipv4: ipaddress.IPv4Address, netmask: ipaddress.IPv4Address, gateway: ipaddress.IPv4Address, ipv4_dns: Optional[ipaddress.IPv4Address]) -> None: //| """Sets the IP v4 address of the station. Must include the netmask and gateway. DNS address is optional. //| Setting the address manually will stop the DHCP client.""" //| ... STATIC mp_obj_t wifi_radio_set_ipv4_address(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_ipv4, ARG_netmask, ARG_gateway, ARG_ipv4_dns }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_ipv4, MP_ARG_REQUIRED | MP_ARG_OBJ, }, - { MP_QSTR_netmask, MP_ARG_REQUIRED | MP_ARG_OBJ, }, - { MP_QSTR_gateway, MP_ARG_REQUIRED | MP_ARG_OBJ, }, - { MP_QSTR_ipv4_dns, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_ipv4, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ, }, + { MP_QSTR_netmask, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ, }, + { MP_QSTR_gateway, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ, }, + { MP_QSTR_ipv4_dns, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, }; wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); @@ -434,7 +434,7 @@ STATIC mp_obj_t wifi_radio_set_ipv4_address(size_t n_args, const mp_obj_t *pos_a common_hal_wifi_radio_set_ipv4_address(self, args[ARG_ipv4].u_obj, args[ARG_netmask].u_obj, args[ARG_gateway].u_obj, args[ARG_ipv4_dns].u_obj); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_set_ipv4_address_obj, 4, wifi_radio_set_ipv4_address); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_set_ipv4_address_obj, 1, wifi_radio_set_ipv4_address); //| ipv4_address: Optional[ipaddress.IPv4Address] //| """IP v4 Address of the station when connected to an access point. None otherwise."""