Skip to content

Commit 03b43b7

Browse files
committed
complete rework for microcontroller.cpu.frequency and wifi.radio MAC addresses
1 parent 2da4e06 commit 03b43b7

File tree

6 files changed

+48
-10
lines changed

6 files changed

+48
-10
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ msgid "%q is %q"
125125
msgstr ""
126126

127127
#: ports/raspberrypi/common-hal/wifi/Radio.c
128-
#: shared-bindings/microcontroller/Processor.c
129128
msgid "%q is read-only for this board"
130129
msgstr ""
131130

@@ -2711,6 +2710,10 @@ msgstr ""
27112710
msgid "can't set attribute"
27122711
msgstr ""
27132712

2713+
#: py/runtime.c
2714+
msgid "can't set attribute '%q'"
2715+
msgstr ""
2716+
27142717
#: py/emitnative.c
27152718
msgid "can't store '%q'"
27162719
msgstr ""

ports/raspberrypi/mpconfigport.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
LONGINT_IMPL = MPZ
33

44
CIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE ?= 1
5+
# CYW43 support does not provide settable MAC addresses for station or AP.
6+
CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS = 0
7+
58
CIRCUITPY_ALARM ?= 1
69

710
CIRCUITPY_RP2PIO ?= 1

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ CFLAGS += -DCIRCUITPY_WIFI=$(CIRCUITPY_WIFI)
538538
CIRCUITPY_WEB_WORKFLOW ?= $(CIRCUITPY_WIFI)
539539
CFLAGS += -DCIRCUITPY_WEB_WORKFLOW=$(CIRCUITPY_WEB_WORKFLOW)
540540

541+
CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS?= 1
542+
CFLAGS += -DCIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS=$(CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS)
543+
541544
# tinyusb port tailored configuration
542545
CIRCUITPY_TUSB_MEM_ALIGN ?= 4
543546
CFLAGS += -DCIRCUITPY_TUSB_MEM_ALIGN=$(CIRCUITPY_TUSB_MEM_ALIGN)

py/runtime.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,8 +1247,8 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
12471247
mp_raise_AttributeError(MP_ERROR_TEXT("no such attribute"));
12481248
#else
12491249
mp_raise_msg_varg(&mp_type_AttributeError,
1250-
MP_ERROR_TEXT("'%s' object has no attribute '%q'"),
1251-
mp_obj_get_type_str(base), attr);
1250+
MP_ERROR_TEXT("can't set attribute '%q'"),
1251+
attr);
12521252
#endif
12531253
}
12541254

shared-bindings/microcontroller/Processor.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,21 @@
6565
//| ...
6666

6767
//| frequency: int
68-
//| """The CPU operating frequency in Hertz. (read-only)"""
68+
//| """The CPU operating frequency in Hertz.
69+
//|
70+
//| **Limitations:** Setting the ``frequency`` is possible only on some i.MX boards.
71+
//| On most boards, ``frequency`` is read-only.
72+
//| """
6973

74+
#if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY
7075
STATIC mp_obj_t mcu_processor_set_frequency(mp_obj_t self, mp_obj_t freq) {
71-
#if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY
7276
uint32_t value_of_freq = (uint32_t)mp_arg_validate_int_min(mp_obj_get_int(freq), 0, MP_QSTR_frequency);
7377
common_hal_mcu_processor_set_frequency(self, value_of_freq);
74-
#else
75-
mp_raise_NotImplementedError_varg(translate("%q is read-only for this board"), MP_QSTR_frequency);
76-
#endif
7778
return mp_const_none;
7879
}
7980

8081
MP_DEFINE_CONST_FUN_OBJ_2(mcu_processor_set_frequency_obj, mcu_processor_set_frequency);
82+
#endif
8183

8284

8385
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) {
8688

8789
MP_DEFINE_CONST_FUN_OBJ_1(mcu_processor_get_frequency_obj, mcu_processor_get_frequency);
8890

91+
#if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY
8992
MP_PROPERTY_GETSET(mcu_processor_frequency_obj,
9093
(mp_obj_t)&mcu_processor_get_frequency_obj,
9194
(mp_obj_t)&mcu_processor_set_frequency_obj);
95+
#else
96+
MP_PROPERTY_GETTER(mcu_processor_frequency_obj,
97+
(mp_obj_t)&mcu_processor_get_frequency_obj);
98+
#endif
9299

93100
//| reset_reason: microcontroller.ResetReason
94101
//| """The reason the microcontroller started up from reset state."""

shared-bindings/wifi/Radio.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,19 @@ MP_PROPERTY_GETSET(wifi_radio_hostname_obj,
139139

140140
//| mac_address: ReadableBuffer
141141
//| """MAC address for the station. When the address is altered after interface is connected
142-
//| the changes would only be reflected once the interface reconnects."""
142+
//| the changes would only be reflected once the interface reconnects.
143+
//|
144+
//| **Limitations:** Not settable on RP2040 CYW43 boards, such as Pi Pico W.
145+
//| """
146+
147+
143148
STATIC mp_obj_t _wifi_radio_get_mac_address(mp_obj_t self_in) {
144149
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
145150
return MP_OBJ_FROM_PTR(common_hal_wifi_radio_get_mac_address(self));
146151
}
147152
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_mac_address_obj, _wifi_radio_get_mac_address);
148153

154+
#if CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS
149155
STATIC mp_obj_t wifi_radio_set_mac_address(mp_obj_t self_in, mp_obj_t mac_address_in) {
150156
mp_buffer_info_t mac_address;
151157
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
160166
return mp_const_none;
161167
}
162168
MP_DEFINE_CONST_FUN_OBJ_2(wifi_radio_set_mac_address_obj, wifi_radio_set_mac_address);
169+
#endif
163170

171+
#if CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS
164172
MP_PROPERTY_GETSET(wifi_radio_mac_address_obj,
165173
(mp_obj_t)&wifi_radio_get_mac_address_obj,
166174
(mp_obj_t)&wifi_radio_set_mac_address_obj);
175+
#else
176+
MP_PROPERTY_GETTER(wifi_radio_mac_address_obj,
177+
(mp_obj_t)&wifi_radio_get_mac_address_obj);
178+
#endif
167179

168180
//| tx_power: float
169181
//| """Wifi transmission power, in dBm."""
@@ -187,13 +199,17 @@ MP_PROPERTY_GETSET(wifi_radio_tx_power_obj,
187199

188200
//| mac_address_ap: ReadableBuffer
189201
//| """MAC address for the AP. When the address is altered after interface is started
190-
//| the changes would only be reflected once the interface restarts."""
202+
//| the changes would only be reflected once the interface restarts.
203+
//|
204+
//| **Limitations:** Not settable on RP2040 CYW43 boards, such as Pi Pico W.
205+
//| """
191206
STATIC mp_obj_t wifi_radio_get_mac_address_ap(mp_obj_t self_in) {
192207
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
193208
return MP_OBJ_FROM_PTR(common_hal_wifi_radio_get_mac_address_ap(self));
194209
}
195210
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_mac_address_ap_obj, wifi_radio_get_mac_address_ap);
196211

212+
#if CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS
197213
STATIC mp_obj_t wifi_radio_set_mac_address_ap(mp_obj_t self_in, mp_obj_t mac_address_in) {
198214
mp_buffer_info_t mac_address;
199215
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
208224
return mp_const_none;
209225
}
210226
MP_DEFINE_CONST_FUN_OBJ_2(wifi_radio_set_mac_address_ap_obj, wifi_radio_set_mac_address_ap);
227+
#endif
211228

229+
#if CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS
212230
MP_PROPERTY_GETSET(wifi_radio_mac_address_ap_obj,
213231
(mp_obj_t)&wifi_radio_get_mac_address_ap_obj,
214232
(mp_obj_t)&wifi_radio_set_mac_address_ap_obj);
233+
#else
234+
MP_PROPERTY_GETTER(wifi_radio_mac_address_ap_obj,
235+
(mp_obj_t)&wifi_radio_get_mac_address_ap_obj);
236+
#endif
215237

216238
//| def start_scanning_networks(
217239
//| self, *, start_channel: int = 1, stop_channel: int = 11

0 commit comments

Comments
 (0)