Skip to content

Commit 0b94638

Browse files
committed
Changes based on Dan's feedback
1 parent 5d8ac04 commit 0b94638

File tree

16 files changed

+78
-105
lines changed

16 files changed

+78
-105
lines changed

locale/circuitpython.pot

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-08-27 11:21-0400\n"
11+
"POT-Creation-Date: 2020-09-03 15:16-0700\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -1238,7 +1238,7 @@ msgid "Nordic Soft Device failure assertion."
12381238
msgstr ""
12391239

12401240
#: shared-bindings/ipaddress/IPv4Address.c shared-bindings/ipaddress/__init__.c
1241-
msgid "Not a valid IP string."
1241+
msgid "Not a valid IP string"
12421242
msgstr ""
12431243

12441244
#: ports/nrf/common-hal/_bleio/__init__.c
@@ -1282,7 +1282,7 @@ msgid ""
12821282
msgstr ""
12831283

12841284
#: shared-bindings/ipaddress/__init__.c
1285-
msgid "Only raw int supported for ip."
1285+
msgid "Only raw int supported for ip"
12861286
msgstr ""
12871287

12881288
#: shared-bindings/audiobusio/PDMIn.c
@@ -1365,10 +1365,6 @@ msgstr ""
13651365
msgid "Pull not used when direction is output."
13661366
msgstr ""
13671367

1368-
#: ports/stm/ref/pulseout-pre-timeralloc.c
1369-
msgid "PulseOut not supported on this chip"
1370-
msgstr ""
1371-
13721368
#: ports/stm/common-hal/os/__init__.c
13731369
msgid "RNG DeInit Error"
13741370
msgstr ""
@@ -1486,7 +1482,7 @@ msgid "Serializer in use"
14861482
msgstr ""
14871483

14881484
#: shared-bindings/ssl/SSLContext.c
1489-
msgid "Server side context cannot have hostname."
1485+
msgid "Server side context cannot have hostname"
14901486
msgstr ""
14911487

14921488
#: shared-bindings/nvm/ByteArray.c
@@ -1792,7 +1788,7 @@ msgid ""
17921788
msgstr ""
17931789

17941790
#: shared-bindings/wifi/Radio.c
1795-
msgid "WiFi password must be between 8 and 63 characters."
1791+
msgid "WiFi password must be between 8 and 63 characters"
17961792
msgstr ""
17971793

17981794
#: ports/nrf/common-hal/_bleio/PacketBuffer.c

ports/esp32s2/common-hal/socketpool/Socket.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ bool common_hal_socketpool_socket_connect(socketpool_socket_obj_t* self, const c
5555
if (err == ESP_ERR_MBEDTLS_SSL_SETUP_FAILED) {
5656
mp_raise_espidf_MemoryError();
5757
} else if (ESP_ERR_MBEDTLS_SSL_HANDSHAKE_FAILED) {
58-
// What should this error be?
5958
mp_raise_OSError_msg_varg(translate("Failed SSL handshake"));
6059
} else {
6160
mp_raise_OSError_msg_varg(translate("Unhandled ESP TLS error %d %d %x %d"), esp_tls_code, flags, err, result);
@@ -123,15 +122,9 @@ mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self,
123122
}
124123

125124
void common_hal_socketpool_socket_close(socketpool_socket_obj_t* self) {
126-
if (self->connected) {
127-
self->connected = false;
128-
}
125+
self->connected = false;
129126
if (self->tcp != NULL) {
130-
int status = esp_tls_conn_destroy(self->tcp);
131-
132-
if (status < 0) {
133-
// raise an error
134-
}
127+
esp_tls_conn_destroy(self->tcp);
135128
self->tcp = NULL;
136129
}
137130
}

ports/esp32s2/common-hal/socketpool/SocketPool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
void common_hal_socketpool_socketpool_construct(socketpool_socketpool_obj_t* self, mp_obj_t radio) {
3737
if (radio != MP_OBJ_FROM_PTR(&common_hal_wifi_radio_obj)) {
38-
mp_raise_ValueError(translate("SocketPool can only be used with wifi.radio."));
38+
mp_raise_ValueError(translate("SocketPool can only be used with wifi.radio"));
3939
}
4040
}
4141

@@ -63,7 +63,7 @@ socketpool_socket_obj_t* common_hal_socketpool_socket(socketpool_socketpool_obj_
6363

6464
if (socket_type == SOCK_DGRAM || socket_type == SOCK_RAW ||
6565
addr_family == AF_INET6 || ipproto == IPPROTO_IPV6) {
66-
mp_raise_NotImplementedError(translate("Only IPv4 SOCK_STREAM sockets supported."));
66+
mp_raise_NotImplementedError(translate("Only IPv4 SOCK_STREAM sockets supported"));
6767
}
6868

6969
int socknum = -1;

ports/esp32s2/common-hal/socketpool/__init__.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,3 @@
2323
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
* THE SOFTWARE.
2525
*/
26-
27-
#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_SOCKETPOOL___INIT___H
28-
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_SOCKETPOOL___INIT___H
29-
30-
31-
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_SOCKETPOOL___INIT___H

ports/esp32s2/common-hal/wifi/Radio.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) {
7373
}
7474
}
7575

76+
#define MAC_ADDRESS_LENGTH 6
77+
7678
mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) {
77-
uint8_t mac[6];
79+
uint8_t mac[MAC_ADDRESS_LENGTH];
7880
esp_wifi_get_mac(ESP_IF_WIFI_STA, mac);
79-
return mp_const_none;
81+
return mp_obj_new_bytes(mac, MAC_ADDRESS_LENGTH);
8082
}
8183

8284
mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
@@ -87,8 +89,8 @@ mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
8789
start_station(self);
8890

8991
wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t);
90-
self->current_scan = scan;
9192
scan->base.type = &wifi_scannednetworks_type;
93+
self->current_scan = scan;
9294
scan->start_channel = 1;
9395
scan->end_channel = 11;
9496
scan->radio_event_group = self->event_group_handle;
@@ -107,9 +109,7 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
107109
wifi_config_t* config = &self->sta_config;
108110
memcpy(&config->sta.ssid, ssid, ssid_len);
109111
config->sta.ssid[ssid_len] = 0;
110-
if (password_len > 0) {
111-
memcpy(&config->sta.password, password, password_len);
112-
}
112+
memcpy(&config->sta.password, password, password_len);
113113
config->sta.password[password_len] = 0;
114114
config->sta.channel = channel;
115115
esp_wifi_set_config(ESP_IF_WIFI_STA, config);
@@ -159,7 +159,7 @@ mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address,
159159

160160
uint32_t received = 0;
161161
uint32_t total_time_ms = 0;
162-
while (received == 0 && total_time_ms < timeout_ms) {
162+
while (received == 0 && total_time_ms < timeout_ms && !mp_hal_is_interrupted()) {
163163
RUN_BACKGROUND_TASKS;
164164
esp_ping_get_profile(ping, ESP_PING_PROF_DURATION, &total_time_ms, sizeof(total_time_ms));
165165
esp_ping_get_profile(ping, ESP_PING_PROF_REPLY, &received, sizeof(received));

ports/esp32s2/common-hal/wifi/ScannedNetworks.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ void wifi_scannednetworks_deinit(wifi_scannednetworks_obj_t* self) {
162162
if (self->scanning) {
163163
esp_wifi_scan_stop();
164164
if (wifi_scannednetworks_wait_for_scan(self)) {
165+
// Ignore the number of records since we're throwing them away.
165166
uint16_t number = 0;
166167
esp_wifi_scan_get_ap_records(&number, NULL);
167168
self->scanning = false;

ports/esp32s2/common-hal/wifi/__init__.c

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -44,51 +44,42 @@ static void event_handler(void* arg, esp_event_base_t event_base,
4444
int32_t event_id, void* event_data) {
4545
wifi_radio_obj_t* radio = arg;
4646
if (event_base == WIFI_EVENT) {
47-
if (event_id == WIFI_EVENT_SCAN_DONE) {
48-
xEventGroupSetBits(radio->event_group_handle, WIFI_SCAN_DONE_BIT);
49-
} else if (event_id == WIFI_EVENT_STA_START) {
50-
} else if (event_id == WIFI_EVENT_STA_STOP) {
51-
} else if (event_id == WIFI_EVENT_STA_CONNECTED) {
52-
ESP_EARLY_LOGW(TAG, "connected");
53-
} else if (event_id == WIFI_EVENT_STA_DISCONNECTED) {
54-
ESP_EARLY_LOGW(TAG, "disconnected");
55-
wifi_event_sta_disconnected_t* d = (wifi_event_sta_disconnected_t*) event_data;
56-
uint8_t reason = d->reason;
57-
ESP_EARLY_LOGW(TAG, "reason %d 0x%02x", reason, reason);
58-
if (radio->retries_left > 0 &&
59-
(reason == WIFI_REASON_AUTH_EXPIRE ||
60-
reason == WIFI_REASON_ASSOC_EXPIRE ||
61-
reason == WIFI_REASON_CONNECTION_FAIL ||
62-
reason == WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT)) {
63-
radio->retries_left--;
64-
ESP_EARLY_LOGI(TAG, "Retrying connect. %d retries remaining", radio->retries_left);
65-
esp_wifi_connect();
66-
return;
47+
switch (event_id) {
48+
case WIFI_EVENT_SCAN_DONE:
49+
xEventGroupSetBits(radio->event_group_handle, WIFI_SCAN_DONE_BIT);
50+
break;
51+
case WIFI_EVENT_STA_CONNECTED:
52+
ESP_EARLY_LOGW(TAG, "connected");
53+
break;
54+
case WIFI_EVENT_STA_DISCONNECTED: {
55+
ESP_EARLY_LOGW(TAG, "disconnected");
56+
wifi_event_sta_disconnected_t* d = (wifi_event_sta_disconnected_t*) event_data;
57+
uint8_t reason = d->reason;
58+
ESP_EARLY_LOGW(TAG, "reason %d 0x%02x", reason, reason);
59+
if (radio->retries_left > 0 &&
60+
(reason == WIFI_REASON_AUTH_EXPIRE ||
61+
reason == WIFI_REASON_ASSOC_EXPIRE ||
62+
reason == WIFI_REASON_CONNECTION_FAIL ||
63+
reason == WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT)) {
64+
radio->retries_left--;
65+
ESP_EARLY_LOGI(TAG, "Retrying connect. %d retries remaining", radio->retries_left);
66+
esp_wifi_connect();
67+
return;
68+
}
69+
70+
radio->last_disconnect_reason = reason;
71+
xEventGroupSetBits(radio->event_group_handle, WIFI_DISCONNECTED_BIT);
6772
}
6873

69-
radio->last_disconnect_reason = reason;
70-
xEventGroupSetBits(radio->event_group_handle, WIFI_DISCONNECTED_BIT);
71-
72-
// if (reason != WIFI_REASON_ASSOC_LEAVE) {
73-
// // reconnect
74-
// }
75-
} else if (event_id == WIFI_EVENT_STA_AUTHMODE_CHANGE) {
74+
// Cases to handle later.
75+
// case WIFI_EVENT_STA_START:
76+
// case WIFI_EVENT_STA_STOP:
77+
// case WIFI_EVENT_STA_AUTHMODE_CHANGE:
78+
default:
79+
break;
7680
}
7781
}
7882

79-
// esp_wifi_connect();
80-
// if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
81-
// esp_wifi_connect();
82-
// } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
83-
// if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
84-
// esp_wifi_connect();
85-
// s_retry_num++;
86-
// ESP_LOGI(TAG, "retry to connect to the AP");
87-
// } else {
88-
// xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
89-
// }
90-
// ESP_LOGI(TAG,"connect to the AP fail");
91-
// } else
9283
if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
9384
ESP_EARLY_LOGW(TAG, "got ip");
9485
radio->retries_left = radio->starting_retries;
@@ -100,7 +91,7 @@ static bool wifi_inited;
10091

10192
void common_hal_wifi_init(void) {
10293
wifi_inited = true;
103-
common_hal_wifi_radio_obj.base.type = &wifi_radio_type;
94+
common_hal_wifi_radio_obj.base.type = &wifi_radio_type;
10495

10596
ESP_ERROR_CHECK(esp_netif_init());
10697
ESP_ERROR_CHECK(esp_event_loop_create_default());
@@ -120,13 +111,13 @@ void common_hal_wifi_init(void) {
120111
self,
121112
&self->handler_instance_got_ip));
122113

123-
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
124-
esp_err_t result = esp_wifi_init(&config);
125-
if (result == ESP_ERR_NO_MEM) {
126-
mp_raise_msg(&mp_type_MemoryError, translate("Failed to allocate Wifi memory"));
127-
} else if (result != ESP_OK) {
128-
// handle this
129-
}
114+
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
115+
esp_err_t result = esp_wifi_init(&config);
116+
if (result == ESP_ERR_NO_MEM) {
117+
mp_raise_msg(&mp_type_MemoryError, translate("Failed to allocate Wifi memory"));
118+
} else if (result != ESP_OK) {
119+
mp_raise_RuntimeError(translate("Failed to init wifi"));
120+
}
130121
common_hal_wifi_radio_set_enabled(self, true);
131122
}
132123

@@ -135,14 +126,14 @@ void wifi_reset(void) {
135126
return;
136127
}
137128
wifi_radio_obj_t* radio = &common_hal_wifi_radio_obj;
138-
common_hal_wifi_radio_set_enabled(radio, false);
129+
common_hal_wifi_radio_set_enabled(radio, false);
139130
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(WIFI_EVENT,
140131
ESP_EVENT_ANY_ID,
141132
radio->handler_instance_all_wifi));
142133
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT,
143134
IP_EVENT_STA_GOT_IP,
144135
radio->handler_instance_got_ip));
145-
ESP_ERROR_CHECK(esp_wifi_deinit());
136+
ESP_ERROR_CHECK(esp_wifi_deinit());
146137
esp_netif_destroy(radio->netif);
147138
radio->netif = NULL;
148139
ESP_ERROR_CHECK(esp_netif_deinit());

ports/esp32s2/mpconfigport.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ CIRCUITPY_I2CPERIPHERAL = 0
2323
CIRCUITPY_ROTARYIO = 0
2424
CIRCUITPY_RTC = 0
2525
CIRCUITPY_NVM = 0
26-
CIRCUITPY_USB_MIDI = 0 # We don't have enough endpoints to include MIDI.
26+
# We don't have enough endpoints to include MIDI.
27+
CIRCUITPY_USB_MIDI = 0
2728
CIRCUITPY_WIFI = 1
2829
CIRCUITPY_ESPIDF = 1
2930

ports/esp32s2/partitions.csv

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# ESP-IDF Partition Table
22
# Name, Type, SubType, Offset, Size, Flags
3-
# bootloader.bin 0x1000
4-
# partition table 0x8000, 0xC00
5-
otadata, data, ota, 0xd000, 0x2000,
6-
phy_init, data, phy, 0xf000, 0x1000,
7-
ota_0, 0, ota_0, 0x10000, 0x160000,
8-
ota_1, 0, ota_1, 0x170000, 0x160000,
3+
# bootloader.bin,, 0x1000, 32K
4+
# partition table,, 0x8000, 4K
5+
nvs, data, nvs, 0x9000, 20K,
6+
otadata, data, ota, 0xe000, 8K,
7+
ota_0, 0, ota_0, 0x10000, 1408K,
8+
ota_1, 0, ota_1, 0x170000, 1408K,
99
uf2, app, factory,0x2d0000, 256K,
1010
user_fs, data, fat, 0x310000, 960K,

py/circuitpy_mpconfig.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
9595
CIRCUITPY_DISPLAYIO ?= $(CIRCUITPY_FULL_BUILD)
9696
CFLAGS += -DCIRCUITPY_DISPLAYIO=$(CIRCUITPY_DISPLAYIO)
9797

98-
# CIRCUITPY_ESPIDF is handled in the atmel-samd tree.
98+
# CIRCUITPY_ESPIDF is handled in the esp32s2 tree.
9999
# Only for ESP32S chips.
100100
# Assume not a ESP build.
101101
CIRCUITPY_ESPIDF ?= 0

shared-bindings/ipaddress/IPv4Address.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
//| """Encapsulates an IPv4 address."""
4040
//|
4141

42-
//| def __init__(self, address: Union[str, bytes]) -> None:
42+
//| def __init__(self, address: Union[int, str, bytes]) -> None:
4343
//| """Create a new IPv4Address object encapsulating the address value.
4444
//|
4545
//| The value itself can either be bytes or a string formatted address."""
@@ -64,7 +64,7 @@ STATIC mp_obj_t ipaddress_ipv4address_make_new(const mp_obj_type_t *type, size_t
6464
} else if (MP_OBJ_IS_STR(address)) {
6565
GET_STR_DATA_LEN(address, str_data, str_len);
6666
if (!ipaddress_parse_ipv4address((const char*) str_data, str_len, &value)) {
67-
mp_raise_ValueError(translate("Not a valid IP string."));
67+
mp_raise_ValueError(translate("Not a valid IP string"));
6868
}
6969
} else {
7070
mp_buffer_info_t buf_info;

shared-bindings/ipaddress/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ STATIC mp_obj_t ipaddress_ip_address(mp_obj_t ip_in) {
8888
} else if (MP_OBJ_IS_STR(ip_in)) {
8989
GET_STR_DATA_LEN(ip_in, str_data, str_len);
9090
if (!ipaddress_parse_ipv4address((const char*) str_data, str_len, &value)) {
91-
mp_raise_ValueError(translate("Not a valid IP string."));
91+
mp_raise_ValueError(translate("Not a valid IP string"));
9292
}
9393
} else {
94-
mp_raise_ValueError(translate("Only raw int supported for ip."));
94+
mp_raise_ValueError(translate("Only raw int supported for ip"));
9595
}
9696

9797
return common_hal_ipaddress_new_ipv4address(value);

shared-bindings/socketpool/SocketPool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ STATIC mp_obj_t socketpool_socketpool_make_new(const mp_obj_type_t *type, size_t
6161
}
6262

6363

64-
//| def socket(self, family: int, type: int, proto: int) -> None:
64+
//| def socket(self, family: int = AF_INET, type: int = SOCK_STREAM, proto: int = IPPROTO_TCP) -> None:
6565
//| """Create a new socket
6666
//|
6767
//| :param ~int family: AF_INET or AF_INET6

shared-bindings/ssl/SSLContext.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ STATIC mp_obj_t ssl_sslcontext_wrap_socket(size_t n_args, const mp_obj_t *pos_ar
7272
const char *server_hostname = mp_obj_str_get_str(args[ARG_server_hostname].u_obj);
7373
bool server_side = args[ARG_server_side].u_bool;
7474
if (server_side && server_hostname != NULL) {
75-
mp_raise_ValueError(translate("Server side context cannot have hostname."));
75+
mp_raise_ValueError(translate("Server side context cannot have hostname"));
7676
}
7777

7878
socketpool_socket_obj_t* sock = args[ARG_sock].u_obj;

0 commit comments

Comments
 (0)