Skip to content

Commit

Permalink
Merge pull request #7358 from dhalbert/read-only-mac-address-rp2040
Browse files Browse the repository at this point in the history
Read only mac address rp2040
  • Loading branch information
dhalbert committed Jan 2, 2023
2 parents 637d47b + 03b43b7 commit d1cd096
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
[submodule "ports/espressif/esp32-camera"]
path = ports/espressif/esp32-camera
url = https://github.com/adafruit/esp32-camera/
branch = circuitpython
[submodule "ports/raspberrypi/lib/cyw43-driver"]
path = ports/raspberrypi/lib/cyw43-driver
url = https://github.com/adafruit/cyw43-driver.git
Expand Down
20 changes: 10 additions & 10 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ msgstr ""
msgid "%q is %q"
msgstr ""

#: ports/raspberrypi/common-hal/wifi/Radio.c
msgid "%q is read-only for this board"
msgstr ""

#: py/argcheck.c shared-bindings/usb_hid/Device.c
msgid "%q length must be %d"
msgstr ""
Expand Down Expand Up @@ -298,7 +302,7 @@ msgstr ""
msgid "'%s' object doesn't support item deletion"
msgstr ""

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

Expand Down Expand Up @@ -1856,18 +1860,14 @@ msgid "Random number generation error"
msgstr ""

#: shared-bindings/memorymonitor/AllocationSize.c
#: shared-bindings/pulseio/PulseIn.c
#: shared-bindings/pulseio/PulseIn.c shared-module/displayio/Bitmap.c
msgid "Read-only"
msgstr ""

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

#: shared-module/displayio/Bitmap.c
msgid "Read-only object"
msgstr ""

#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
msgid "Received response was invalid"
msgstr ""
Expand Down Expand Up @@ -2710,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 ""
Expand Down Expand Up @@ -3071,10 +3075,6 @@ msgstr ""
msgid "format requires a dict"
msgstr ""

#: shared-bindings/microcontroller/Processor.c
msgid "frequency is read-only for this board"
msgstr ""

#: py/objdeque.c
msgid "full"
msgstr ""
Expand Down
4 changes: 2 additions & 2 deletions ports/raspberrypi/common-hal/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ static inline void nw_put_le32(uint8_t *buf, uint32_t x) {
buf[3] = x >> 24;
}

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

bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self) {
Expand Down
3 changes: 3 additions & 0 deletions ports/raspberrypi/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions py/circuitpy_mpconfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions py/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
17 changes: 12 additions & 5 deletions shared-bindings/microcontroller/Processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_msg(&mp_type_NotImplementedError,translate("frequency is read-only for this board"));
#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) {
Expand All @@ -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."""
Expand Down
26 changes: 24 additions & 2 deletions shared-bindings/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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."""
Expand All @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion shared-module/displayio/Bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t

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

displayio_area_t area = *dirty_area;
Expand Down

0 comments on commit d1cd096

Please sign in to comment.