Improve cyw43.set_power_management documentation

.. and provide 4 preset values
This commit is contained in:
Jeff Epler 2022-09-30 14:17:46 -05:00
parent f9e655da47
commit 943b992bfc
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
2 changed files with 52 additions and 5 deletions

View File

@ -31,7 +31,6 @@
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "bindings/cyw43/__init__.h"
//| class CywPin:
//| """A class that represents a GPIO pin attached to the wifi chip.
//|
@ -49,14 +48,42 @@ const mp_obj_type_t cyw43_pin_type = {
)
};
//| PM_STANDARD: int
//| """The standard power management mode"""
//| PM_AGGRESSIVE: int
//| """Aggressive power management mode for optimial power usage at the cost of performance"""
//| 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"""
//|
//| def set_power_management(value: int) -> None:
//| """Set the power management register
//|
//| According to Raspberry Pi documentation, the value 0xa11140
//| increases responsiveness at the cost of higher power usage.
//| For transmitter power, see ``wifi.Radio.txpower``.
//| This controls software power saving features inside the cyw43 chip.
//| it does not control transmitter power.
//|
//| Besides this value, there appears to be no other public documentation
//| of the values that can be used.
//| The value is interpreted as a 24-bit hexadecimal number of the form
//| ``0x00adbrrm``.
//|
//| The low 4 bits, ``m``, are the power management mode:
//| * 0: disabled
//| * 1: aggressive power saving which reduces wifi throughput
//| * 2: Power saving with High througput
//|
//| The next 8 bits, ``r``, specify "the maximum time to wait before going back to sleep" for power management mode 2. The units of ``r`` are 10ms.
//|
//| The next 4 bits, ``b``, are the "wake period is measured in beacon periods".
//|
//| The next 4 bits, ``d``, specify the "wake interval measured in DTIMs. If this is set to 0, the wake interval is measured in beacon periods".
//|
//| The top 4 bits, ``a``, specifies the "wake interval sent to the access point"
//|
//| Several ``PM_`` constants gathered from various sources are included
//| in this module. According to Raspberry Pi documentation, the value 0xa11140
//| (called `cyw43.PM_DISABLED` here) increases responsiveness at the cost of higher power
//| usage.
//| """
//|
STATIC mp_obj_t cyw43_set_power_management(const mp_obj_t value_in) {
@ -83,6 +110,10 @@ 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_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) },
{ MP_ROM_QSTR(MP_QSTR_PM_DISABLED), MP_ROM_INT(PM_DISABLED) },
};
STATIC MP_DEFINE_CONST_DICT(cyw43_module_globals, cyw43_module_globals_table);

View File

@ -32,3 +32,19 @@
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);
const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj);
#define CONSTANT_CYW43_PM_VALUE(pm_mode, pm2_sleep_ret_ms, li_beacon_period, li_dtim_period, li_assoc) \
(li_assoc << 20 | /* listen interval sent to ap */ \
li_dtim_period << 16 | \
li_beacon_period << 12 | \
(pm2_sleep_ret_ms / 10) << 4 | /* cyw43_ll_wifi_pm multiplies this by 10 */ \
pm_mode /* CYW43_PM2_POWERSAVE_MODE etc */)
// CYW43_DEFAULT_PM (except a compile-time constant)
#define PM_STANDARD CONSTANT_CYW43_PM_VALUE(CYW43_PM2_POWERSAVE_MODE, 200, 1, 1, 10)
// CYW43_AGGRESSIVE_PM (except a compile-time constant)
#define PM_AGGRESSIVE CONSTANT_CYW43_PM_VALUE(CYW43_PM2_POWERSAVE_MODE, 2000, 1, 1, 10)
// CYW43_PERFORMANCE_PM (except a compile-time constant)
#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)