esp32,esp8266: Add support to set/get power saving mode of WLAN.

For esp32 and esp8266 this commit adds:
- a 'pm' option to WLAN.config() to set/get the wifi power saving mode; and
- PM_NONE, PM_PERFORMANCE and PM_POWERSAVE constants to the WLAN class.

This API should be general enough to use with all WLAN drivers.

Documentation is also added.
This commit is contained in:
glenn20
2022-08-25 16:55:57 +10:00
committed by Damien George
parent 786013d467
commit 1093dea709
3 changed files with 44 additions and 0 deletions

View File

@@ -419,6 +419,10 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
system_phy_set_max_tpw(power);
break;
}
case MP_QSTR_pm: {
wifi_set_sleep_type(mp_obj_get_int(kwargs->table[i].value));
break;
}
default:
goto unknown;
}
@@ -486,6 +490,10 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
val = mp_obj_new_int(wifi_get_phy_mode());
break;
}
case MP_QSTR_pm: {
val = MP_OBJ_NEW_SMALL_INT(wifi_get_sleep_type());
break;
}
default:
goto unknown;
}
@@ -511,6 +519,11 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&esp_isconnected_obj) },
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&esp_config_obj) },
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
// Constants
{ MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(NONE_SLEEP_T) },
{ MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(MODEM_SLEEP_T) },
{ MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(LIGHT_SLEEP_T) },
};
STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);