Set cyw43 power management as needed, default to disabled
.. the value actually needs to be enforced each time the STA or AP is enabled, because internally there's a call to cyw43_wifi_pm with the library's defaut power management value, not ours. Add a getter, though it only returns our idea of what the power management register is set to, it doesn't read out from the actual hardware, sadly.
This commit is contained in:
parent
943b992bfc
commit
d3e85d165e
@ -31,6 +31,14 @@
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "bindings/cyw43/__init__.h"
|
||||
|
||||
|
||||
static int power_management_value = PM_DISABLED;
|
||||
|
||||
void bindings_cyw43_wifi_enforce_pm() {
|
||||
cyw43_wifi_pm(&cyw43_state, power_management_value);
|
||||
}
|
||||
|
||||
//| class CywPin:
|
||||
//| """A class that represents a GPIO pin attached to the wifi chip.
|
||||
//|
|
||||
@ -55,7 +63,7 @@ const mp_obj_type_t cyw43_pin_type = {
|
||||
//| PM_PERFORMANCE: int
|
||||
//| """Performance power management mode where more power is used to increase performance"""
|
||||
//| PM_DISABLED: int
|
||||
//| """Disable power management and always use highest power mode"""
|
||||
//| """Disable power management and always use highest power mode. CircuitPython sets this value at reset time, because it provides the best reliability."""
|
||||
//|
|
||||
//| def set_power_management(value: int) -> None:
|
||||
//| """Set the power management register
|
||||
@ -88,11 +96,20 @@ const mp_obj_type_t cyw43_pin_type = {
|
||||
//|
|
||||
STATIC mp_obj_t cyw43_set_power_management(const mp_obj_t value_in) {
|
||||
mp_int_t value = mp_obj_get_int(value_in);
|
||||
cyw43_wifi_pm(&cyw43_state, value);
|
||||
power_management_value = value;
|
||||
bindings_cyw43_wifi_enforce_pm();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(cyw43_set_power_management_obj, cyw43_set_power_management);
|
||||
|
||||
//| def get_power_management() -> int:
|
||||
//| """Retrieve the power management register"""
|
||||
//|
|
||||
STATIC mp_obj_t cyw43_get_power_management() {
|
||||
return mp_obj_new_int(power_management_value);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(cyw43_get_power_management_obj, cyw43_get_power_management);
|
||||
|
||||
const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj) {
|
||||
if (!mp_obj_is_type(obj, &mcu_pin_type) && !mp_obj_is_type(obj, &cyw43_pin_type)) {
|
||||
mp_raise_TypeError_varg(translate("Expected a %q or %q"), mcu_pin_type.name, cyw43_pin_type.name);
|
||||
@ -110,6 +127,7 @@ STATIC const mp_rom_map_elem_t cyw43_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cyw43) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_CywPin), MP_ROM_QSTR(MP_QSTR_CywPin) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_power_management), &cyw43_set_power_management_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_power_management), &cyw43_get_power_management_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PM_STANDARD), MP_ROM_INT(PM_STANDARD) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PM_AGGRESSIVE), MP_ROM_INT(PM_AGGRESSIVE) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(PM_PERFORMANCE) },
|
||||
|
@ -28,6 +28,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
|
||||
extern const mp_obj_type_t cyw43_pin_type;
|
||||
const mcu_pin_obj_t *validate_obj_is_free_pin_including_cyw43(mp_obj_t obj);
|
||||
@ -48,3 +49,5 @@ const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj);
|
||||
#define PM_PERFORMANCE CONSTANT_CYW43_PM_VALUE(CYW43_PM2_POWERSAVE_MODE, 20, 1, 1, 1)
|
||||
// The 0xa11140 magic value
|
||||
#define PM_DISABLED CONSTANT_CYW43_PM_VALUE(CYW43_NO_POWERSAVE_MODE, 200, 1, 1, 10)
|
||||
|
||||
extern void bindings_cyw43_wifi_enforce_pm(void);
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
#include "py/gc.h"
|
||||
#include "py/runtime.h"
|
||||
#include "bindings/cyw43/__init__.h"
|
||||
#include "shared-bindings/ipaddress/IPv4Address.h"
|
||||
#include "shared-bindings/wifi/ScannedNetworks.h"
|
||||
#include "shared-bindings/wifi/AuthMode.h"
|
||||
@ -152,6 +153,7 @@ void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) {
|
||||
|
||||
void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self) {
|
||||
cyw43_arch_enable_sta_mode();
|
||||
bindings_cyw43_wifi_enforce_pm();
|
||||
}
|
||||
|
||||
void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) {
|
||||
@ -159,6 +161,7 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) {
|
||||
|
||||
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) {
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
bindings_cyw43_wifi_enforce_pm();
|
||||
}
|
||||
|
||||
void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self) {
|
||||
@ -173,6 +176,7 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
|
||||
// TODO use connect_async so we can service bg tasks & check for ctrl-c during
|
||||
// connect
|
||||
int result = cyw43_arch_wifi_connect_timeout_ms((const char *)ssid, (const char *)password, CYW43_AUTH_WPA2_AES_PSK, timeout_ms);
|
||||
bindings_cyw43_wifi_enforce_pm();
|
||||
switch (result) {
|
||||
case 0:
|
||||
return WIFI_RADIO_ERROR_NONE;
|
||||
|
Loading…
Reference in New Issue
Block a user