Skip to content

Commit d1cd096

Browse files
authored
Merge pull request #7358 from dhalbert/read-only-mac-address-rp2040
Read only mac address rp2040
2 parents 637d47b + 03b43b7 commit d1cd096

File tree

9 files changed

+58
-22
lines changed

9 files changed

+58
-22
lines changed

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@
310310
[submodule "ports/espressif/esp32-camera"]
311311
path = ports/espressif/esp32-camera
312312
url = https://github.com/adafruit/esp32-camera/
313+
branch = circuitpython
313314
[submodule "ports/raspberrypi/lib/cyw43-driver"]
314315
path = ports/raspberrypi/lib/cyw43-driver
315316
url = https://github.com/adafruit/cyw43-driver.git

locale/circuitpython.pot

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ msgstr ""
124124
msgid "%q is %q"
125125
msgstr ""
126126

127+
#: ports/raspberrypi/common-hal/wifi/Radio.c
128+
msgid "%q is read-only for this board"
129+
msgstr ""
130+
127131
#: py/argcheck.c shared-bindings/usb_hid/Device.c
128132
msgid "%q length must be %d"
129133
msgstr ""
@@ -298,7 +302,7 @@ msgstr ""
298302
msgid "'%s' object doesn't support item deletion"
299303
msgstr ""
300304

301-
#: ports/raspberrypi/common-hal/wifi/Radio.c py/runtime.c
305+
#: py/runtime.c
302306
msgid "'%s' object has no attribute '%q'"
303307
msgstr ""
304308

@@ -1856,18 +1860,14 @@ msgid "Random number generation error"
18561860
msgstr ""
18571861

18581862
#: shared-bindings/memorymonitor/AllocationSize.c
1859-
#: shared-bindings/pulseio/PulseIn.c
1863+
#: shared-bindings/pulseio/PulseIn.c shared-module/displayio/Bitmap.c
18601864
msgid "Read-only"
18611865
msgstr ""
18621866

18631867
#: extmod/vfs_fat.c py/moduerrno.c
18641868
msgid "Read-only filesystem"
18651869
msgstr ""
18661870

1867-
#: shared-module/displayio/Bitmap.c
1868-
msgid "Read-only object"
1869-
msgstr ""
1870-
18711871
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
18721872
msgid "Received response was invalid"
18731873
msgstr ""
@@ -2710,6 +2710,10 @@ msgstr ""
27102710
msgid "can't set attribute"
27112711
msgstr ""
27122712

2713+
#: py/runtime.c
2714+
msgid "can't set attribute '%q'"
2715+
msgstr ""
2716+
27132717
#: py/emitnative.c
27142718
msgid "can't store '%q'"
27152719
msgstr ""
@@ -3071,10 +3075,6 @@ msgstr ""
30713075
msgid "format requires a dict"
30723076
msgstr ""
30733077

3074-
#: shared-bindings/microcontroller/Processor.c
3075-
msgid "frequency is read-only for this board"
3076-
msgstr ""
3077-
30783078
#: py/objdeque.c
30793079
msgid "full"
30803080
msgstr ""

ports/raspberrypi/common-hal/wifi/Radio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ static inline void nw_put_le32(uint8_t *buf, uint32_t x) {
6464
buf[3] = x >> 24;
6565
}
6666

67-
NORETURN static void ro_attribute(int attr) {
68-
mp_raise_msg_varg(&mp_type_AttributeError, MP_ERROR_TEXT("'%s' object has no attribute '%q'"), "Radio", attr);
67+
NORETURN static void ro_attribute(qstr attr) {
68+
mp_raise_NotImplementedError_varg(translate("%q is read-only for this board"), attr);
6969
}
7070

7171
bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self) {

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_msg(&mp_type_NotImplementedError,translate("frequency is read-only for this board"));
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

shared-module/displayio/Bitmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t
117117

118118
void displayio_bitmap_set_dirty_area(displayio_bitmap_t *self, const displayio_area_t *dirty_area) {
119119
if (self->read_only) {
120-
mp_raise_RuntimeError(translate("Read-only object"));
120+
mp_raise_RuntimeError(translate("Read-only"));
121121
}
122122

123123
displayio_area_t area = *dirty_area;

0 commit comments

Comments
 (0)