Skip to content

Commit

Permalink
ports/esp32: Make LAN.active() idempotent.
Browse files Browse the repository at this point in the history
Signed-off-by: Elvis Pfutzenreuter <epxx@epxx.co>
  • Loading branch information
elvis-epx committed May 22, 2024
1 parent cfd5a8e commit 0719c98
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ports/esp32/network_lan.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,15 @@ static mp_obj_t lan_active(size_t n_args, const mp_obj_t *args) {
if (n_args > 1) {
if (mp_obj_is_true(args[1])) {
esp_netif_set_hostname(self->base.netif, mod_network_hostname_data);
self->base.active = (esp_eth_start(self->eth_handle) == ESP_OK);
if (!self->base.active) {
esp_err_t res = esp_eth_start(self->eth_handle);
self->base.active = (res == ESP_OK);
if (!self->base.active && res != ESP_ERR_INVALID_STATE) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("ethernet enable failed"));
}
} else {
self->base.active = !(esp_eth_stop(self->eth_handle) == ESP_OK);
if (self->base.active) {
esp_err_t res = esp_eth_stop(self->eth_handle);
self->base.active = !(res == ESP_OK);
if (self->base.active && res != ESP_ERR_INVALID_STATE) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("ethernet disable failed"));
}
}
Expand Down

0 comments on commit 0719c98

Please sign in to comment.