Merge pull request #7358 from dhalbert/read-only-mac-address-rp2040

Read only mac address rp2040
This commit is contained in:
Dan Halbert 2023-01-02 13:23:28 -05:00 committed by GitHub
commit d1cd096813
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 58 additions and 22 deletions

1
.gitmodules vendored
View File

@ -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

View File

@ -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 ""
@ -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 ""
@ -1856,7 +1860,7 @@ 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 ""
@ -1864,10 +1868,6 @@ msgstr ""
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 ""
@ -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 ""
@ -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 ""

View File

@ -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) {

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_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) {
@ -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

View File

@ -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;