complete rework for microcontroller.cpu.frequency and wifi.radio MAC addresses

This commit is contained in:
Dan Halbert 2023-01-02 11:45:58 -05:00
parent 2da4e06890
commit 03b43b7b3f
6 changed files with 48 additions and 10 deletions

View File

@ -125,7 +125,6 @@ msgid "%q is %q"
msgstr ""
#: ports/raspberrypi/common-hal/wifi/Radio.c
#: shared-bindings/microcontroller/Processor.c
msgid "%q is read-only for this board"
msgstr ""
@ -2711,6 +2710,10 @@ msgstr ""
msgid "can't set attribute"
msgstr ""
#: py/runtime.c
msgid "can't set attribute '%q'"
msgstr ""
#: py/emitnative.c
msgid "can't store '%q'"
msgstr ""

View File

@ -2,6 +2,9 @@
LONGINT_IMPL = MPZ
CIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE ?= 1
# CYW43 support does not provide settable MAC addresses for station or AP.
CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS = 0
CIRCUITPY_ALARM ?= 1
CIRCUITPY_RP2PIO ?= 1

View File

@ -538,6 +538,9 @@ CFLAGS += -DCIRCUITPY_WIFI=$(CIRCUITPY_WIFI)
CIRCUITPY_WEB_WORKFLOW ?= $(CIRCUITPY_WIFI)
CFLAGS += -DCIRCUITPY_WEB_WORKFLOW=$(CIRCUITPY_WEB_WORKFLOW)
CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS?= 1
CFLAGS += -DCIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS=$(CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS)
# tinyusb port tailored configuration
CIRCUITPY_TUSB_MEM_ALIGN ?= 4
CFLAGS += -DCIRCUITPY_TUSB_MEM_ALIGN=$(CIRCUITPY_TUSB_MEM_ALIGN)

View File

@ -1247,8 +1247,8 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
mp_raise_AttributeError(MP_ERROR_TEXT("no such attribute"));
#else
mp_raise_msg_varg(&mp_type_AttributeError,
MP_ERROR_TEXT("'%s' object has no attribute '%q'"),
mp_obj_get_type_str(base), attr);
MP_ERROR_TEXT("can't set attribute '%q'"),
attr);
#endif
}

View File

@ -65,19 +65,21 @@
//| ...
//| frequency: int
//| """The CPU operating frequency in Hertz. (read-only)"""
//| """The CPU operating frequency in Hertz.
//|
//| **Limitations:** Setting the ``frequency`` is possible only on some i.MX boards.
//| On most boards, ``frequency`` is read-only.
//| """
#if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY
STATIC mp_obj_t mcu_processor_set_frequency(mp_obj_t self, mp_obj_t freq) {
#if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY
uint32_t value_of_freq = (uint32_t)mp_arg_validate_int_min(mp_obj_get_int(freq), 0, MP_QSTR_frequency);
common_hal_mcu_processor_set_frequency(self, value_of_freq);
#else
mp_raise_NotImplementedError_varg(translate("%q is read-only for this board"), MP_QSTR_frequency);
#endif
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(mcu_processor_set_frequency_obj, mcu_processor_set_frequency);
#endif
STATIC mp_obj_t mcu_processor_get_frequency(mp_obj_t self) {
@ -86,9 +88,14 @@ STATIC mp_obj_t mcu_processor_get_frequency(mp_obj_t self) {
MP_DEFINE_CONST_FUN_OBJ_1(mcu_processor_get_frequency_obj, mcu_processor_get_frequency);
#if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY
MP_PROPERTY_GETSET(mcu_processor_frequency_obj,
(mp_obj_t)&mcu_processor_get_frequency_obj,
(mp_obj_t)&mcu_processor_set_frequency_obj);
#else
MP_PROPERTY_GETTER(mcu_processor_frequency_obj,
(mp_obj_t)&mcu_processor_get_frequency_obj);
#endif
//| reset_reason: microcontroller.ResetReason
//| """The reason the microcontroller started up from reset state."""

View File

@ -139,13 +139,19 @@ MP_PROPERTY_GETSET(wifi_radio_hostname_obj,
//| mac_address: ReadableBuffer
//| """MAC address for the station. When the address is altered after interface is connected
//| the changes would only be reflected once the interface reconnects."""
//| the changes would only be reflected once the interface reconnects.
//|
//| **Limitations:** Not settable on RP2040 CYW43 boards, such as Pi Pico W.
//| """
STATIC mp_obj_t _wifi_radio_get_mac_address(mp_obj_t self_in) {
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_FROM_PTR(common_hal_wifi_radio_get_mac_address(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_mac_address_obj, _wifi_radio_get_mac_address);
#if CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS
STATIC mp_obj_t wifi_radio_set_mac_address(mp_obj_t self_in, mp_obj_t mac_address_in) {
mp_buffer_info_t mac_address;
mp_get_buffer_raise(mac_address_in, &mac_address, MP_BUFFER_READ);
@ -160,10 +166,16 @@ STATIC mp_obj_t wifi_radio_set_mac_address(mp_obj_t self_in, mp_obj_t mac_addres
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(wifi_radio_set_mac_address_obj, wifi_radio_set_mac_address);
#endif
#if CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS
MP_PROPERTY_GETSET(wifi_radio_mac_address_obj,
(mp_obj_t)&wifi_radio_get_mac_address_obj,
(mp_obj_t)&wifi_radio_set_mac_address_obj);
#else
MP_PROPERTY_GETTER(wifi_radio_mac_address_obj,
(mp_obj_t)&wifi_radio_get_mac_address_obj);
#endif
//| tx_power: float
//| """Wifi transmission power, in dBm."""
@ -187,13 +199,17 @@ MP_PROPERTY_GETSET(wifi_radio_tx_power_obj,
//| mac_address_ap: ReadableBuffer
//| """MAC address for the AP. When the address is altered after interface is started
//| the changes would only be reflected once the interface restarts."""
//| the changes would only be reflected once the interface restarts.
//|
//| **Limitations:** Not settable on RP2040 CYW43 boards, such as Pi Pico W.
//| """
STATIC mp_obj_t wifi_radio_get_mac_address_ap(mp_obj_t self_in) {
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_FROM_PTR(common_hal_wifi_radio_get_mac_address_ap(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_mac_address_ap_obj, wifi_radio_get_mac_address_ap);
#if CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS
STATIC mp_obj_t wifi_radio_set_mac_address_ap(mp_obj_t self_in, mp_obj_t mac_address_in) {
mp_buffer_info_t mac_address;
mp_get_buffer_raise(mac_address_in, &mac_address, MP_BUFFER_READ);
@ -208,10 +224,16 @@ STATIC mp_obj_t wifi_radio_set_mac_address_ap(mp_obj_t self_in, mp_obj_t mac_add
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(wifi_radio_set_mac_address_ap_obj, wifi_radio_set_mac_address_ap);
#endif
#if CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS
MP_PROPERTY_GETSET(wifi_radio_mac_address_ap_obj,
(mp_obj_t)&wifi_radio_get_mac_address_ap_obj,
(mp_obj_t)&wifi_radio_set_mac_address_ap_obj);
#else
MP_PROPERTY_GETTER(wifi_radio_mac_address_ap_obj,
(mp_obj_t)&wifi_radio_get_mac_address_ap_obj);
#endif
//| def start_scanning_networks(
//| self, *, start_channel: int = 1, stop_channel: int = 11