From 06765ccfa68ce439919d8279665a7ee4d7f304ec Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 5 Oct 2023 14:49:49 -0400 Subject: [PATCH] RP2040 now builds --- ports/espressif/bindings/espnow/Peers.c | 4 ++-- ports/raspberrypi/audio_dma.c | 2 +- ports/raspberrypi/bindings/picodvi/Framebuffer.c | 2 +- ports/raspberrypi/common-hal/countio/Counter.c | 2 +- ports/raspberrypi/common-hal/rp2pio/StateMachine.c | 4 +++- ports/raspberrypi/mpconfigport.h | 7 +++++++ shared-bindings/usb/core/__init__.c | 3 +-- shared-bindings/usb/core/__init__.h | 11 +++++++++-- shared-bindings/usb_host/Port.c | 1 + shared-module/usb/utf16le.c | 2 +- 10 files changed, 27 insertions(+), 11 deletions(-) diff --git a/ports/espressif/bindings/espnow/Peers.c b/ports/espressif/bindings/espnow/Peers.c index a2bfcd255f..debc8948aa 100644 --- a/ports/espressif/bindings/espnow/Peers.c +++ b/ports/espressif/bindings/espnow/Peers.c @@ -126,10 +126,10 @@ espnow_peers_obj_t *espnow_peers_new(void) { MP_DEFINE_CONST_OBJ_TYPE( espnow_peers_type, MP_QSTR_Peers, - MP_TYPE_FLAG_NONE, + MP_TYPE_FLAG_ITER_IS_GETITER, print, espnow_peers_print, locals_dict, &espnow_peers_locals_dict, unary_op, espnow_peers_unary_op, subscr, espnow_peers_subscr, - getiter, espnow_peers_getiter + iter, espnow_peers_getiter ); diff --git a/ports/raspberrypi/audio_dma.c b/ports/raspberrypi/audio_dma.c index 8ea58acc3c..aead44d8b4 100644 --- a/ports/raspberrypi/audio_dma.c +++ b/ports/raspberrypi/audio_dma.c @@ -487,5 +487,5 @@ void isr_dma_0(void) { } } -MP_REGISTER_ROOT_POINTER(mp_obj_t playing_audio[NUM_DMA_CHANNELS]); +MP_REGISTER_ROOT_POINTER(mp_obj_t playing_audio[enum_NUM_DMA_CHANNELS]); #endif diff --git a/ports/raspberrypi/bindings/picodvi/Framebuffer.c b/ports/raspberrypi/bindings/picodvi/Framebuffer.c index 31fbea7efd..c327ce284d 100644 --- a/ports/raspberrypi/bindings/picodvi/Framebuffer.c +++ b/ports/raspberrypi/bindings/picodvi/Framebuffer.c @@ -255,5 +255,5 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &picodvi_framebuffer_locals_dict, make_new, picodvi_framebuffer_make_new, buffer, common_hal_picodvi_framebuffer_get_buffer, - protocol, &picodvi_framebuffer_proto, + protocol, &picodvi_framebuffer_proto ); diff --git a/ports/raspberrypi/common-hal/countio/Counter.c b/ports/raspberrypi/common-hal/countio/Counter.c index a6c98f113f..c68bc62945 100644 --- a/ports/raspberrypi/common-hal/countio/Counter.c +++ b/ports/raspberrypi/common-hal/countio/Counter.c @@ -112,4 +112,4 @@ void counter_interrupt_handler(void) { } } -MP_REGISTER_ROOT_POINTER(mp_obj_t counting[NUM_PWM_SLICES]); +MP_REGISTER_ROOT_POINTER(mp_obj_t counting[enum_NUM_PWM_SLICES]); diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index 573996a269..7e3be9d3e3 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -1099,4 +1099,6 @@ int common_hal_rp2pio_statemachine_get_pending(rp2pio_statemachine_obj_t *self) return self->pending_buffers; } -MP_REGISTER_ROOT_POINTER(mp_obj_t background_pio[NUM_DMA_CHANNELS]); +// Use a compile-time constant for MP_REGISTER_POINTER so the preprocessor will +// not split the expansion across multiple lines. +MP_REGISTER_ROOT_POINTER(mp_obj_t background_pio[enum_NUM_DMA_CHANNELS]); diff --git a/ports/raspberrypi/mpconfigport.h b/ports/raspberrypi/mpconfigport.h index 0c5f2d3402..743f7fe2f6 100644 --- a/ports/raspberrypi/mpconfigport.h +++ b/ports/raspberrypi/mpconfigport.h @@ -68,5 +68,12 @@ extern critical_section_t background_queue_lock; #define CALLBACK_CRITICAL_BEGIN (critical_section_enter_blocking(&background_queue_lock)) #define CALLBACK_CRITICAL_END (critical_section_exit(&background_queue_lock)) +// Turn some macros into compile-time constants, using enum. +// Some nested macros expand across multiple lines, which is not +// handled by the MP_REGISTER_ROOT_POINTER processing in makeqstrdefs.py. +enum { + enum_NUM_DMA_CHANNELS = NUM_DMA_CHANNELS, + enum_NUM_PWM_SLICES = NUM_PWM_SLICES, +}; #endif // __INCLUDED_MPCONFIGPORT_H diff --git a/shared-bindings/usb/core/__init__.c b/shared-bindings/usb/core/__init__.c index 03609a5a3c..0212ae8f30 100644 --- a/shared-bindings/usb/core/__init__.c +++ b/shared-bindings/usb/core/__init__.c @@ -130,8 +130,7 @@ MP_DEFINE_CONST_OBJ_TYPE( usb_core_devices_type, MP_QSTR_USBDevices, MP_TYPE_FLAG_ITER_IS_ITERNEXT, - getiter, mp_identity_getiter, - iternext, usb_core_devices_iternext + iter, usb_core_devices_iternext ); STATIC mp_obj_t usb_core_find(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { diff --git a/shared-bindings/usb/core/__init__.h b/shared-bindings/usb/core/__init__.h index 2067c4cd18..aa36754651 100644 --- a/shared-bindings/usb/core/__init__.h +++ b/shared-bindings/usb/core/__init__.h @@ -34,7 +34,7 @@ extern const mp_obj_module_t usb_core_module; void usb_core_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind); -#define MP_DEFINE_USB_CORE_EXCEPTION(exc_name, base_name) \ +/*#define MP_DEFINE_USB_CORE_EXCEPTION(exc_name, base_name) \ const mp_obj_type_t mp_type_usb_core_##exc_name = { \ { &mp_type_type }, \ .name = MP_QSTR_##exc_name, \ @@ -42,7 +42,14 @@ void usb_core_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_k .make_new = mp_obj_exception_make_new, \ .attr = mp_obj_exception_attr, \ .parent = &mp_type_##base_name, \ - }; + };*/ +#define MP_DEFINE_USB_CORE_EXCEPTION(exc_name, base_name) \ + MP_DEFINE_CONST_OBJ_TYPE(mp_type_usb_core_##exc_name, MP_QSTR_##exc_name, MP_TYPE_FLAG_NONE, \ + make_new, mp_obj_exception_make_new, \ + print, usb_core_exception_print, \ + attr, mp_obj_exception_attr, \ + parent, &mp_type_##base_name \ + ); extern const mp_obj_type_t mp_type_usb_core_USBError; extern const mp_obj_type_t mp_type_usb_core_USBTimeoutError; diff --git a/shared-bindings/usb_host/Port.c b/shared-bindings/usb_host/Port.c index afe1d6daa8..64f08869b7 100644 --- a/shared-bindings/usb_host/Port.c +++ b/shared-bindings/usb_host/Port.c @@ -72,6 +72,7 @@ STATIC MP_DEFINE_CONST_DICT(usb_host_port_locals_dict, usb_host_port_locals_dict MP_DEFINE_CONST_OBJ_TYPE( usb_host_port_type, MP_QSTR_Port, + MP_TYPE_FLAG_NONE, make_new, usb_host_port_make_new, locals_dict, &usb_host_port_locals_dict ); diff --git a/shared-module/usb/utf16le.c b/shared-module/usb/utf16le.c index 2b55dc6bab..10152a2a7d 100644 --- a/shared-module/usb/utf16le.c +++ b/shared-module/usb/utf16le.c @@ -70,5 +70,5 @@ mp_obj_t utf16le_to_string(const uint16_t *buf, size_t utf16_len) { vstr_init(&vstr, utf16_len); utf16_str utf = {buf, utf16_len}; _convert_utf16le_to_utf8(&vstr, &utf); - return mp_obj_new_str_from_vstr(&mp_type_str, &vstr); + return mp_obj_new_str_from_vstr(&vstr); }