From 057b4e10a776bbb594b014e1cb39a0f731f72062 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Feb 2023 17:28:10 +1100 Subject: [PATCH 01/50] codal_app: Update codal-microbit-v2 to v0.2.48. Changes to codal-core: - add support for dynamic pins on peripherals - add function to generate dynamic runtime component IDs - add sample rate support to the stream classes - ensure AnimatedDisplay::waitForFreeDisplay() is free of race conditions Changes to codal-microbit-v2: - add SET_SOFTDEVICE_PRESENT option - use DEVICE_BLE in codal.json to enable/disable BLE - improve temporal response of SoundOutputPin::setAnalogValue() - introduce convenience functions for playing SoundExpressions - Introduce egress double buffering onto SoundEmojiSynth - introduce audio output isplaying() Charges to codal-nrf52: - add support for dynamic pins on peripherals - add sample rate support to the ADC Signed-off-by: Damien George --- src/codal_app/codal.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codal_app/codal.json b/src/codal_app/codal.json index 2b8048b..35d131c 100644 --- a/src/codal_app/codal.json +++ b/src/codal_app/codal.json @@ -2,7 +2,7 @@ "target": { "name": "codal-microbit-v2", "url": "https://github.com/lancaster-university/codal-microbit-v2", - "branch": "v0.2.43", + "branch": "v0.2.48", "type": "git", "test_ignore": true } , From ee7574116b627bb53bfcab0b19a507b525507951 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Feb 2023 18:12:23 +1100 Subject: [PATCH 02/50] codal_app/microbithal: Use i2c.redirect method to reconfig pins. Fixes issue #112. Signed-off-by: Damien George --- src/codal_app/microbithal.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/codal_app/microbithal.cpp b/src/codal_app/microbithal.cpp index d032ba3..1b778f7 100644 --- a/src/codal_app/microbithal.cpp +++ b/src/codal_app/microbithal.cpp @@ -215,10 +215,13 @@ void microbit_hal_pin_write_ws2812(int pin, const uint8_t *buf, size_t len) { } int microbit_hal_i2c_init(int scl, int sda, int freq) { - // TODO set pins - int ret = uBit.i2c.setFrequency(freq); + int ret = uBit.i2c.redirect(*pin_obj[sda], *pin_obj[scl]); if (ret != DEVICE_OK) { - return ret;; + return ret; + } + ret = uBit.i2c.setFrequency(freq); + if (ret != DEVICE_OK) { + return ret; } return 0; } From 3af0abd392fd2e325c5e824a2ffb508088ac849a Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Feb 2023 18:12:58 +1100 Subject: [PATCH 03/50] codal_app/microbithal: Use spi.redirect method to reconfig pins. Fixes issue #111. Signed-off-by: Damien George --- src/codal_app/microbithal.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/codal_app/microbithal.cpp b/src/codal_app/microbithal.cpp index 1b778f7..efcb56f 100644 --- a/src/codal_app/microbithal.cpp +++ b/src/codal_app/microbithal.cpp @@ -258,11 +258,16 @@ int microbit_hal_uart_init(int tx, int rx, int baudrate, int bits, int parity, i static NRF52SPI *spi = NULL; int microbit_hal_spi_init(int sclk, int mosi, int miso, int frequency, int bits, int mode) { - if (spi != NULL) { - delete spi; + int ret; + if (spi == NULL) { + spi = new NRF52SPI(*pin_obj[mosi], *pin_obj[miso], *pin_obj[sclk], NRF_SPIM2); + } else { + ret = spi->redirect(*pin_obj[mosi], *pin_obj[miso], *pin_obj[sclk]); + if (ret != DEVICE_OK) { + return ret; + } } - spi = new NRF52SPI(*pin_obj[mosi], *pin_obj[miso], *pin_obj[sclk], NRF_SPIM2); - int ret = spi->setFrequency(frequency); + ret = spi->setFrequency(frequency); if (ret != DEVICE_OK) { return ret; } From bbc70b674d1bfe054ffc1f086ca4d804ae45197d Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Feb 2023 18:24:35 +1100 Subject: [PATCH 04/50] codal_app: Use uBit.io.logo instead of uBit.io.face. The uBit.io.face object is a (deprecated) reference to uBit.io.logo. Signed-off-by: Damien George --- src/codal_app/microbithal.cpp | 6 +++--- src/codal_app/microbithal.h | 2 +- src/codal_port/microbit_pin.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/codal_app/microbithal.cpp b/src/codal_app/microbithal.cpp index efcb56f..06ad832 100644 --- a/src/codal_app/microbithal.cpp +++ b/src/codal_app/microbithal.cpp @@ -50,7 +50,7 @@ NRF52Pin *const pin_obj[] = { &uBit.io.P16, &uBit.io.P19, // external I2C SCL &uBit.io.P20, // external I2C SDA - &uBit.io.face, + &uBit.io.logo, &uBit.io.speaker, &uBit.io.runmic, &uBit.io.microphone, @@ -203,8 +203,8 @@ void microbit_hal_pin_write_analog_u10(int pin, int value) { } int microbit_hal_pin_is_touched(int pin) { - if (pin == MICROBIT_HAL_PIN_FACE) { - // For touch on the face/logo, delegate to the TouchButton instance. + if (pin == MICROBIT_HAL_PIN_LOGO) { + // For touch on the logo pin, delegate to the TouchButton instance. return uBit.logo.buttonActive(); } return pin_obj[pin]->isTouched(); diff --git a/src/codal_app/microbithal.h b/src/codal_app/microbithal.h index fa9fe5c..7744821 100644 --- a/src/codal_app/microbithal.h +++ b/src/codal_app/microbithal.h @@ -59,7 +59,7 @@ extern "C" { #define MICROBIT_HAL_PIN_P16 (16) #define MICROBIT_HAL_PIN_P19 (17) #define MICROBIT_HAL_PIN_P20 (18) -#define MICROBIT_HAL_PIN_FACE (19) +#define MICROBIT_HAL_PIN_LOGO (19) #define MICROBIT_HAL_PIN_SPEAKER (20) #define MICROBIT_HAL_PIN_USB_TX (30) #define MICROBIT_HAL_PIN_USB_RX (31) diff --git a/src/codal_port/microbit_pin.c b/src/codal_port/microbit_pin.c index 2b807a4..e3d2d6e 100644 --- a/src/codal_port/microbit_pin.c +++ b/src/codal_port/microbit_pin.c @@ -48,7 +48,7 @@ const microbit_pin_obj_t microbit_p16_obj = {{µbit_dig_pin_type}, 16, MICR const microbit_pin_obj_t microbit_p19_obj = {{µbit_dig_pin_type}, 19, MICROBIT_HAL_PIN_P19, MODE_I2C}; const microbit_pin_obj_t microbit_p20_obj = {{µbit_dig_pin_type}, 20, MICROBIT_HAL_PIN_P20, MODE_I2C}; -const microbit_pin_obj_t microbit_pin_logo_obj = {{µbit_touch_only_pin_type}, 30, MICROBIT_HAL_PIN_FACE, MODE_UNUSED}; +const microbit_pin_obj_t microbit_pin_logo_obj = {{µbit_touch_only_pin_type}, 30, MICROBIT_HAL_PIN_LOGO, MODE_UNUSED}; const microbit_pin_obj_t microbit_pin_speaker_obj = {{µbit_dig_pin_type}, 31, MICROBIT_HAL_PIN_SPEAKER, MODE_UNUSED}; static mp_obj_t microbit_pin_get_mode_func(mp_obj_t self_in) { From a5dd649283ad6c232e5f924af3b24242f58e3bbc Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 27 Mar 2023 11:54:50 +1100 Subject: [PATCH 05/50] codal_port/microbit_display: Stop animations when calling clear(). Following the semantics of micro:bit v1. Fixes issue #150. Signed-off-by: Damien George --- src/codal_port/drv_display.c | 2 ++ src/codal_port/microbit_display.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/codal_port/drv_display.c b/src/codal_port/drv_display.c index db700d8..f03874a 100644 --- a/src/codal_port/drv_display.c +++ b/src/codal_port/drv_display.c @@ -142,6 +142,8 @@ void microbit_display_update(void) { } void microbit_display_clear(void) { + // Reset repeat state, cancel animation and clear screen. + // The actual screen clearing will be done by microbit_display_update. wakeup_event = false; async_mode = ASYNC_MODE_CLEAR; async_tick = async_delay - MILLISECONDS_PER_MACRO_TICK; diff --git a/src/codal_port/microbit_display.c b/src/codal_port/microbit_display.c index fb41017..b094948 100644 --- a/src/codal_port/microbit_display.c +++ b/src/codal_port/microbit_display.c @@ -163,7 +163,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(microbit_display_read_light_level_obj, microbit_displa mp_obj_t microbit_display_clear_func(mp_obj_t self) { (void)self; - microbit_hal_display_clear(); + microbit_display_clear(); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_1(microbit_display_clear_obj, microbit_display_clear_func); From 5177bdc96df45266f344b2813f2f4d94891c7928 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 27 Mar 2023 11:56:11 +1100 Subject: [PATCH 06/50] codal_app/microbithal: Remove now-unused microbit_hal_display_clear. Signed-off-by: Damien George --- src/codal_app/microbithal.cpp | 4 ---- src/codal_app/microbithal.h | 1 - 2 files changed, 5 deletions(-) diff --git a/src/codal_app/microbithal.cpp b/src/codal_app/microbithal.cpp index 06ad832..249606b 100644 --- a/src/codal_app/microbithal.cpp +++ b/src/codal_app/microbithal.cpp @@ -319,10 +319,6 @@ void microbit_hal_display_enable(int value) { } } -void microbit_hal_display_clear(void) { - uBit.display.clear(); -} - int microbit_hal_display_get_pixel(int x, int y) { uint32_t pixel = uBit.display.image.getPixelValue(x, y); if (pixel == 255) { diff --git a/src/codal_app/microbithal.h b/src/codal_app/microbithal.h index 7744821..e8840dc 100644 --- a/src/codal_app/microbithal.h +++ b/src/codal_app/microbithal.h @@ -138,7 +138,6 @@ int microbit_hal_spi_transfer(size_t len, const uint8_t *src, uint8_t *dest); int microbit_hal_button_state(int button, int *was_pressed, int *num_presses); void microbit_hal_display_enable(int value); -void microbit_hal_display_clear(void); int microbit_hal_display_get_pixel(int x, int y); void microbit_hal_display_set_pixel(int x, int y, int bright); int microbit_hal_display_read_light_level(void); From d66bf2c6ff9e75ed9b2cf52ed3b362bafdae46cb Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 8 May 2023 19:50:26 +1000 Subject: [PATCH 07/50] src/addlayouttable.py: Allow map entries to start with 0x20. More recent versions of gcc will emit lines that start with 0x20, instead of the (64-bit) long form 0x000...020. Signed-off-by: Damien George --- src/addlayouttable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addlayouttable.py b/src/addlayouttable.py index 3e32ab1..d625b82 100755 --- a/src/addlayouttable.py +++ b/src/addlayouttable.py @@ -124,7 +124,7 @@ def parse_map_file(filename, symbols): line = line.strip() if line == "Linker script and memory map": parse_symbols = True - elif parse_symbols and line.startswith("0x00"): + elif parse_symbols and line.startswith(("0x00", "0x20")): line = line.split() if len(line) >= 2 and line[1] in symbols: symbols[line[1]] = int(line[0], 16) From 9e9832930646dfa0f599d709f87d1f23c4dd66f6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 15 May 2023 16:59:50 +1000 Subject: [PATCH 08/50] src/addlayouttable.py: Print total size of each section. Signed-off-by: Damien George --- src/addlayouttable.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/addlayouttable.py b/src/addlayouttable.py index d625b82..4e7fe1e 100755 --- a/src/addlayouttable.py +++ b/src/addlayouttable.py @@ -228,11 +228,11 @@ def main(): # Print information. if args.output is not sys.stdout: - fmt = "{:13} 0x{:05x}..0x{:05x}" - print(fmt.format("SoftDevice", sd_start, sd_end)) - print(fmt.format("MicroPython", mp_start, mp_end)) - print(fmt.format("Layout table", layout_addr, layout_addr + len(layout.data))) - print(fmt.format("Filesystem", fs_start, fs_end)) + fmt = "{:13} 0x{:05x}..0x{:05x} {:6} bytes" + print(fmt.format("SoftDevice", sd_start, sd_end, sd_end - sd_start)) + print(fmt.format("MicroPython", mp_start, mp_end, mp_end - mp_start)) + print(fmt.format("Layout table", layout_addr, layout_addr + len(layout.data), len(layout.data))) + print(fmt.format("Filesystem", fs_start, fs_end, fs_end - fs_start)) # Output the new firmware as a hex file. output_firmware(args.output, firmware, layout_addr, layout.data) From 618fafd8c014f93c13408973e92b3ca5894269e6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 15 May 2023 17:00:14 +1000 Subject: [PATCH 09/50] codal_port/Makefile: Suppress dangling ptr warning from stackctrl.c. Signed-off-by: Damien George --- src/codal_port/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/codal_port/Makefile b/src/codal_port/Makefile index 5f07b38..d5d616e 100644 --- a/src/codal_port/Makefile +++ b/src/codal_port/Makefile @@ -131,6 +131,9 @@ $(MBIT_VER_FILE): FORCE $(PYTHON) $(TOP)/py/makeversionhdr.py $(MBIT_VER_FILE).pre $(CAT) $(MBIT_VER_FILE).pre | $(SED) s/MICROPY_/MICROBIT_/ > $(MBIT_VER_FILE) +# Suppress warnings bulding stackctrl.c (fixed post v1.20.0). +$(BUILD)/py/stackctrl.o: CWARN += -Wno-dangling-pointer + # Suppress warnings from SAM library. $(BUILD)/$(abspath $(LOCAL_LIB_DIR))/sam/sam.o: CWARN += -Wno-array-bounds From 16fe526d88175ab79a21cba8cc449ffea190f8d3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 15 May 2023 16:48:14 +1000 Subject: [PATCH 10/50] lib/micropython: Update micropython submodule to v1.20.0. Signed-off-by: Damien George --- lib/micropython | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/micropython b/lib/micropython index da4b38e..294baf5 160000 --- a/lib/micropython +++ b/lib/micropython @@ -1 +1 @@ -Subproject commit da4b38e7562dfa451917f9d7f344a7f26de8c7bd +Subproject commit 294baf52b346e400e2255c6c1e82af5b978b18f7 From 5176ffd761ecdcce9836f9a7e1f835710fb9e85c Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 15 May 2023 16:49:35 +1000 Subject: [PATCH 11/50] codal_port: Update to build with latest micropython. Signed-off-by: Damien George --- .gitignore | 1 - src/codal.patch | 2 +- src/codal_port/Makefile | 11 ++-- src/codal_port/drv_display.c | 2 + src/codal_port/drv_radio.c | 2 + src/codal_port/drv_softtimer.c | 2 + src/codal_port/iters.c | 12 ++--- src/codal_port/microbit_accelerometer.c | 11 ++-- src/codal_port/microbit_button.c | 11 ++-- src/codal_port/microbit_compass.c | 11 ++-- src/codal_port/microbit_display.c | 12 ++--- src/codal_port/microbit_i2c.c | 13 ++--- src/codal_port/microbit_image.c | 68 +++++++++++++------------ src/codal_port/microbit_microphone.c | 11 ++-- src/codal_port/microbit_pin.c | 44 ++++++++-------- src/codal_port/microbit_sound.c | 13 ++--- src/codal_port/microbit_soundeffect.c | 17 ++++--- src/codal_port/microbit_soundevent.c | 13 ++--- src/codal_port/microbit_speaker.c | 11 ++-- src/codal_port/microbit_spi.c | 13 ++--- src/codal_port/microbit_uart.c | 13 ++--- src/codal_port/microbitfs.c | 26 +++++----- src/codal_port/modantigravity.c | 2 + src/codal_port/modaudio.c | 25 +++++---- src/codal_port/modaudio.h | 1 + src/codal_port/modlog.c | 2 + src/codal_port/modlove.c | 2 + src/codal_port/modmachine.c | 2 + src/codal_port/modmicrobit.c | 16 +++--- src/codal_port/modmusic.c | 5 ++ src/codal_port/modos.c | 2 + src/codal_port/modpower.c | 2 + src/codal_port/modradio.c | 2 + src/codal_port/modspeech.c | 4 ++ src/codal_port/modthis.c | 2 + src/codal_port/modutime.c | 2 + src/codal_port/mpconfigport.h | 38 -------------- 37 files changed, 227 insertions(+), 199 deletions(-) diff --git a/.gitignore b/.gitignore index 9d5fcdd..c107393 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ src/build src/MICROBIT.hex src/codal_port/build -src/codal_port/libmicropython.a diff --git a/src/codal.patch b/src/codal.patch index 7bca328..6b6a65c 100644 --- a/src/codal.patch +++ b/src/codal.patch @@ -20,6 +20,6 @@ index b89e1d0..b53224b 100644 +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PROJECT_SOURCE_DIR}/../../src/codal_port/filesystem.ld") +add_library(micropython STATIC IMPORTED) +set_target_properties(micropython PROPERTIES -+ IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/../../src/codal_port/libmicropython.a" ++ IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/../../src/codal_port/build/libmicropython.a" +) +target_link_libraries("MICROBIT" micropython) diff --git a/src/codal_port/Makefile b/src/codal_port/Makefile index d5d616e..2d8d033 100644 --- a/src/codal_port/Makefile +++ b/src/codal_port/Makefile @@ -14,6 +14,13 @@ QSTR_DEFS = qstrdefsport.h # Include py core make definitions. include $(TOP)/py/py.mk +include $(TOP)/extmod/extmod.mk + +# The micropython-lib submodule is not needed by this project, but the MicroPython +# build system requires it if FROZEN_MANIFEST is set (which it is below). To avoid +# needing to check out the micropython-lib submodule, point MPY_LIB_DIR to a dummy +# location that has a README.md file. +MPY_LIB_DIR = $(TOP) MP_VER_FILE = $(HEADER_BUILD)/mpversion.h MBIT_VER_FILE = $(HEADER_BUILD)/microbitversion.h @@ -107,7 +114,7 @@ SRC_C += \ $(abspath $(LOCAL_LIB_DIR)/sam/debug.c) \ SRC_O += \ - shared/runtime/gchelper_m3.o \ + shared/runtime/gchelper_thumb2.o \ OBJ = $(PY_O) OBJ += $(addprefix $(BUILD)/, $(SRC_O)) @@ -138,5 +145,3 @@ $(BUILD)/py/stackctrl.o: CWARN += -Wno-dangling-pointer $(BUILD)/$(abspath $(LOCAL_LIB_DIR))/sam/sam.o: CWARN += -Wno-array-bounds include $(TOP)/py/mkrules.mk - -CLEAN_EXTRA += $(LIBMICROPYTHON) diff --git a/src/codal_port/drv_display.c b/src/codal_port/drv_display.c index f03874a..03823d1 100644 --- a/src/codal_port/drv_display.c +++ b/src/codal_port/drv_display.c @@ -192,3 +192,5 @@ void microbit_display_animate(mp_obj_t iterable, mp_int_t delay, bool clear, boo wait_for_event(); } } + +MP_REGISTER_ROOT_POINTER(void *display_data); diff --git a/src/codal_port/drv_radio.c b/src/codal_port/drv_radio.c index 1452ae1..ed8ef5b 100644 --- a/src/codal_port/drv_radio.c +++ b/src/codal_port/drv_radio.c @@ -283,3 +283,5 @@ void microbit_radio_pop(void) { // Re-enable the radio IRQ. NVIC_EnableIRQ(RADIO_IRQn); } + +MP_REGISTER_ROOT_POINTER(uint8_t *radio_buf); diff --git a/src/codal_port/drv_softtimer.c b/src/codal_port/drv_softtimer.c index e58ee26..6dfcafd 100644 --- a/src/codal_port/drv_softtimer.c +++ b/src/codal_port/drv_softtimer.c @@ -98,3 +98,5 @@ uint32_t microbit_soft_timer_get_ms_to_next_expiry(void) { } return dt; } + +MP_REGISTER_ROOT_POINTER(struct _microbit_soft_timer_entry_t *soft_timer_heap); diff --git a/src/codal_port/iters.c b/src/codal_port/iters.c index 8869307..dbfe306 100644 --- a/src/codal_port/iters.c +++ b/src/codal_port/iters.c @@ -42,12 +42,12 @@ static mp_obj_t microbit_repeat_iter_next(mp_obj_t iter_in) { return mp_obj_subscr(iter->iterable, MP_OBJ_NEW_SMALL_INT(iter->index), MP_OBJ_SENTINEL); } -const mp_obj_type_t microbit_repeat_iterator_type = { - .base = { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = microbit_repeat_iter_next, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + microbit_repeat_iterator_type, + MP_QSTR_iterator, + MP_TYPE_FLAG_ITER_IS_ITERNEXT, + iter, microbit_repeat_iter_next + ); mp_obj_t microbit_repeat_iterator(mp_obj_t iterable) { repeat_iterator_t *result = m_new_obj(repeat_iterator_t); diff --git a/src/codal_port/microbit_accelerometer.c b/src/codal_port/microbit_accelerometer.c index 761401b..dfd096b 100644 --- a/src/codal_port/microbit_accelerometer.c +++ b/src/codal_port/microbit_accelerometer.c @@ -199,11 +199,12 @@ STATIC const mp_rom_map_elem_t microbit_accelerometer_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_accelerometer_locals_dict, microbit_accelerometer_locals_dict_table); -const mp_obj_type_t microbit_accelerometer_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitAccelerometer, - .locals_dict = (mp_obj_dict_t *)µbit_accelerometer_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + microbit_accelerometer_type, + MP_QSTR_MicroBitAccelerometer, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_accelerometer_locals_dict + ); const microbit_accelerometer_obj_t microbit_accelerometer_obj = { { µbit_accelerometer_type }, diff --git a/src/codal_port/microbit_button.c b/src/codal_port/microbit_button.c index bbc6339..a62d778 100644 --- a/src/codal_port/microbit_button.c +++ b/src/codal_port/microbit_button.c @@ -64,11 +64,12 @@ STATIC const mp_map_elem_t microbit_button_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(microbit_button_locals_dict, microbit_button_locals_dict_table); -const mp_obj_type_t microbit_button_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitButton, - .locals_dict = (mp_obj_dict_t *)µbit_button_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_button_type, + MP_QSTR_MicroBitButton, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_button_locals_dict + ); const microbit_button_obj_t microbit_button_a_obj = { .base = { µbit_button_type }, diff --git a/src/codal_port/microbit_compass.c b/src/codal_port/microbit_compass.c index dab165a..469b963 100644 --- a/src/codal_port/microbit_compass.c +++ b/src/codal_port/microbit_compass.c @@ -100,11 +100,12 @@ STATIC const mp_rom_map_elem_t microbit_compass_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_compass_locals_dict, microbit_compass_locals_dict_table); -STATIC const mp_obj_type_t microbit_compass_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitCompass, - .locals_dict = (mp_obj_dict_t *)µbit_compass_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + microbit_compass_type, + MP_QSTR_MicroBitCompass, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_compass_locals_dict + ); const microbit_compass_obj_t microbit_compass_obj = { { µbit_compass_type }, diff --git a/src/codal_port/microbit_display.c b/src/codal_port/microbit_display.c index b094948..27c5f8f 100644 --- a/src/codal_port/microbit_display.c +++ b/src/codal_port/microbit_display.c @@ -210,14 +210,14 @@ STATIC const mp_rom_map_elem_t microbit_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_is_on), MP_ROM_PTR(µbit_display_is_on_obj) }, { MP_ROM_QSTR(MP_QSTR_read_light_level),MP_ROM_PTR(µbit_display_read_light_level_obj) }, }; - STATIC MP_DEFINE_CONST_DICT(microbit_display_locals_dict, microbit_display_locals_dict_table); -STATIC const mp_obj_type_t microbit_display_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitDisplay, - .locals_dict = (mp_obj_dict_t*)µbit_display_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + microbit_display_type, + MP_QSTR_MicroBitDisplay, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_display_locals_dict + ); microbit_display_obj_t microbit_display_obj = { .base = {µbit_display_type}, diff --git a/src/codal_port/microbit_i2c.c b/src/codal_port/microbit_i2c.c index 9f64104..90b007e 100644 --- a/src/codal_port/microbit_i2c.c +++ b/src/codal_port/microbit_i2c.c @@ -103,7 +103,7 @@ STATIC mp_obj_t microbit_i2c_read(mp_uint_t n_args, const mp_obj_t *pos_args, mp } // Return bytes object with read data. - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } MP_DEFINE_CONST_FUN_OBJ_KW(microbit_i2c_read_obj, 1, microbit_i2c_read); @@ -142,11 +142,12 @@ STATIC const mp_rom_map_elem_t microbit_i2c_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_i2c_locals_dict, microbit_i2c_locals_dict_table); -STATIC const mp_obj_type_t microbit_i2c_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitI2C, - .locals_dict = (mp_obj_dict_t *)µbit_i2c_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + microbit_i2c_type, + MP_QSTR_MicroBitI2C, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_i2c_locals_dict + ); const microbit_i2c_obj_t microbit_i2c_obj = { { µbit_i2c_type }, diff --git a/src/codal_port/microbit_image.c b/src/codal_port/microbit_image.c index 6aafaa5..97f547c 100644 --- a/src/codal_port/microbit_image.c +++ b/src/codal_port/microbit_image.c @@ -509,15 +509,15 @@ STATIC mp_obj_t image_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs return microbit_image_sum(lhs, (microbit_image_obj_t *)rhs_in, op == MP_BINARY_OP_ADD); } - -const mp_obj_type_t microbit_image_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitImage, - .print = microbit_image_print, - .make_new = microbit_image_make_new, - .binary_op = image_binary_op, - .locals_dict = (mp_obj_dict_t*)µbit_image_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_image_type, + MP_QSTR_MicroBitImage, + MP_TYPE_FLAG_NONE, + make_new, microbit_image_make_new, + print, microbit_image_print, + binary_op, image_binary_op, + locals_dict, µbit_image_locals_dict + ); /////////////////////////////////////////////////////////////////////////////////// @@ -656,18 +656,19 @@ STATIC mp_obj_t microbit_scrolling_string_iter_next(mp_obj_t o_in) { return iter->img; } -const mp_obj_type_t microbit_scrolling_string_type = { - { &mp_type_type }, - .name = MP_QSTR_ScrollingString, - .getiter = get_microbit_scrolling_string_iter, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_scrolling_string_type, + MP_QSTR_ScrollingString, + MP_TYPE_FLAG_ITER_IS_GETITER, + iter, get_microbit_scrolling_string_iter + ); -const mp_obj_type_t microbit_scrolling_string_iterator_type = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = microbit_scrolling_string_iter_next, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_scrolling_string_iterator_type, + MP_QSTR_iterator, + MP_TYPE_FLAG_ITER_IS_ITERNEXT, + iter, microbit_scrolling_string_iter_next + ); /////////////////////////////////////////////////////////////////////////////////// @@ -708,13 +709,14 @@ static mp_obj_t facade_unary_op(mp_unary_op_t op, mp_obj_t self_in) { static mp_obj_t microbit_facade_iterator(mp_obj_t iterable_in, mp_obj_iter_buf_t *iter_buf); -const mp_obj_type_t string_image_facade_type = { - { &mp_type_type }, - .name = MP_QSTR_Facade, - .unary_op = facade_unary_op, - .subscr = string_image_facade_subscr, - .getiter = microbit_facade_iterator, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + string_image_facade_type, + MP_QSTR_Facade, + MP_TYPE_FLAG_ITER_IS_GETITER, + unary_op, facade_unary_op, + subscr, string_image_facade_subscr, + iter, microbit_facade_iterator + ); /////////////////////////////////////////////////////////////////////////////////// @@ -745,12 +747,12 @@ static mp_obj_t microbit_facade_iter_next(mp_obj_t iter_in) { return iter->image; } -const mp_obj_type_t microbit_facade_iterator_type = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = microbit_facade_iter_next, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_facade_iterator_type, + MP_QSTR_iterator, + MP_TYPE_FLAG_ITER_IS_ITERNEXT, + iter, microbit_facade_iter_next + ); static mp_obj_t microbit_facade_iterator(mp_obj_t iterable_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(facade_iterator_t) <= sizeof(mp_obj_iter_buf_t)); diff --git a/src/codal_port/microbit_microphone.c b/src/codal_port/microbit_microphone.c index 59a43d5..af44112 100644 --- a/src/codal_port/microbit_microphone.c +++ b/src/codal_port/microbit_microphone.c @@ -157,11 +157,12 @@ STATIC const mp_rom_map_elem_t microbit_microphone_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_microphone_locals_dict, microbit_microphone_locals_dict_table); -const mp_obj_type_t microbit_microphone_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitMicrophone, - .locals_dict = (mp_obj_dict_t *)µbit_microphone_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_microphone_type, + MP_QSTR_MicroBitMicrophone, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_microphone_locals_dict + ); const microbit_microphone_obj_t microbit_microphone_obj = { { µbit_microphone_type }, diff --git a/src/codal_port/microbit_pin.c b/src/codal_port/microbit_pin.c index e3d2d6e..4c9e79b 100644 --- a/src/codal_port/microbit_pin.c +++ b/src/codal_port/microbit_pin.c @@ -200,11 +200,12 @@ STATIC const mp_rom_map_elem_t microbit_dig_pin_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_dig_pin_locals_dict, microbit_dig_pin_locals_dict_table); -const mp_obj_type_t microbit_dig_pin_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitDigitalPin, - .locals_dict = (mp_obj_dict_t *)µbit_dig_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_dig_pin_type, + MP_QSTR_MicroBitDigitalPin, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_dig_pin_locals_dict + ); STATIC const mp_rom_map_elem_t microbit_ann_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write_digital), MP_ROM_PTR(µbit_pin_write_digital_obj) }, @@ -221,11 +222,12 @@ STATIC const mp_rom_map_elem_t microbit_ann_pin_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_ann_pin_locals_dict, microbit_ann_pin_locals_dict_table); -const mp_obj_type_t microbit_ad_pin_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitAnalogDigitalPin, - .locals_dict = (mp_obj_dict_t *)µbit_ann_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_ad_pin_type, + MP_QSTR_MicroBitAnalogDigitalPin, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_ann_pin_locals_dict + ); STATIC const mp_rom_map_elem_t microbit_touch_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write_digital), MP_ROM_PTR(µbit_pin_write_digital_obj) }, @@ -245,11 +247,12 @@ STATIC const mp_rom_map_elem_t microbit_touch_pin_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_touch_pin_locals_dict, microbit_touch_pin_locals_dict_table); -const mp_obj_type_t microbit_touch_pin_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitTouchPin, - .locals_dict = (mp_obj_dict_t *)µbit_touch_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_touch_pin_type, + MP_QSTR_MicroBitTouchPin, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_touch_pin_locals_dict + ); STATIC const mp_rom_map_elem_t microbit_touch_only_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_is_touched), MP_ROM_PTR(µbit_pin_is_touched_obj) }, @@ -258,11 +261,12 @@ STATIC const mp_rom_map_elem_t microbit_touch_only_pin_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_touch_only_pin_locals_dict, microbit_touch_only_pin_locals_dict_table); -const mp_obj_type_t microbit_touch_only_pin_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitTouchOnlyPin, - .locals_dict = (mp_obj_dict_t *)µbit_touch_only_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_touch_only_pin_type, + MP_QSTR_MicroBitTouchOnlyPin, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_touch_only_pin_locals_dict + ); const microbit_pin_obj_t *microbit_obj_get_pin(mp_const_obj_t o) { const mp_obj_type_t *type = mp_obj_get_type(o); diff --git a/src/codal_port/microbit_sound.c b/src/codal_port/microbit_sound.c index 06ef823..0b34900 100644 --- a/src/codal_port/microbit_sound.c +++ b/src/codal_port/microbit_sound.c @@ -69,9 +69,10 @@ STATIC const mp_rom_map_elem_t microbit_sound_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_sound_locals_dict, microbit_sound_locals_dict_table); -const mp_obj_type_t microbit_sound_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitSound, - .print = microbit_sound_print, - .locals_dict = (mp_obj_dict_t *)µbit_sound_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_sound_type, + MP_QSTR_MicroBitSound, + MP_TYPE_FLAG_NONE, + print, microbit_sound_print, + locals_dict, µbit_sound_locals_dict + ); diff --git a/src/codal_port/microbit_soundeffect.c b/src/codal_port/microbit_soundeffect.c index 0e00f79..836ec9a 100644 --- a/src/codal_port/microbit_soundeffect.c +++ b/src/codal_port/microbit_soundeffect.c @@ -337,11 +337,12 @@ STATIC const mp_rom_map_elem_t microbit_soundeffect_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_soundeffect_locals_dict, microbit_soundeffect_locals_dict_table); -const mp_obj_type_t microbit_soundeffect_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitSoundEffect, - .print = microbit_soundeffect_print, - .make_new = microbit_soundeffect_make_new, - .attr = microbit_soundeffect_attr, - .locals_dict = (mp_obj_dict_t *)µbit_soundeffect_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_soundeffect_type, + MP_QSTR_MicroBitSoundEffect, + MP_TYPE_FLAG_NONE, + make_new, microbit_soundeffect_make_new, + print, microbit_soundeffect_print, + attr, microbit_soundeffect_attr, + locals_dict, µbit_soundeffect_locals_dict + ); diff --git a/src/codal_port/microbit_soundevent.c b/src/codal_port/microbit_soundevent.c index 5edeec3..08ffba3 100644 --- a/src/codal_port/microbit_soundevent.c +++ b/src/codal_port/microbit_soundevent.c @@ -53,9 +53,10 @@ STATIC const mp_rom_map_elem_t microbit_soundevent_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_soundevent_locals_dict, microbit_soundevent_locals_dict_table); -const mp_obj_type_t microbit_soundevent_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitSoundEvent, - .print = microbit_soundevent_print, - .locals_dict = (mp_obj_dict_t *)µbit_soundevent_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_soundevent_type, + MP_QSTR_MicroBitSoundEvent, + MP_TYPE_FLAG_NONE, + print, microbit_soundevent_print, + locals_dict, µbit_soundevent_locals_dict + ); diff --git a/src/codal_port/microbit_speaker.c b/src/codal_port/microbit_speaker.c index 5c413d2..69d4a68 100644 --- a/src/codal_port/microbit_speaker.c +++ b/src/codal_port/microbit_speaker.c @@ -52,11 +52,12 @@ STATIC const mp_rom_map_elem_t microbit_speaker_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_speaker_locals_dict, microbit_speaker_locals_dict_table); -STATIC const mp_obj_type_t microbit_speaker_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitSpeaker, - .locals_dict = (mp_obj_dict_t *)µbit_speaker_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + microbit_speaker_type, + MP_QSTR_MicroBitSpeaker, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_speaker_locals_dict + ); const microbit_speaker_obj_t microbit_speaker_obj = { { µbit_speaker_type }, diff --git a/src/codal_port/microbit_spi.c b/src/codal_port/microbit_spi.c index b420043..5962063 100644 --- a/src/codal_port/microbit_spi.c +++ b/src/codal_port/microbit_spi.c @@ -114,7 +114,7 @@ STATIC mp_obj_t microbit_spi_read(size_t n_args, const mp_obj_t *args) { if (ret != 0) { mp_raise_OSError(ret); } - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + return mp_obj_new_bytes_from_vstr(&vstr); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_spi_read_obj, 2, 3, microbit_spi_read); @@ -140,11 +140,12 @@ STATIC const mp_rom_map_elem_t microbit_spi_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_spi_locals_dict, microbit_spi_locals_dict_table); -STATIC const mp_obj_type_t microbit_spi_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitSPI, - .locals_dict = (mp_obj_dict_t *)µbit_spi_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + microbit_spi_type, + MP_QSTR_MicroBitSPI, + MP_TYPE_FLAG_NONE, + locals_dict, µbit_spi_locals_dict + ); const microbit_spi_obj_t microbit_spi_obj = { { µbit_spi_type }, diff --git a/src/codal_port/microbit_uart.c b/src/codal_port/microbit_uart.c index 0691864..7e35b15 100644 --- a/src/codal_port/microbit_uart.c +++ b/src/codal_port/microbit_uart.c @@ -173,12 +173,13 @@ STATIC const mp_stream_p_t microbit_uart_stream_p = { .is_text = false, }; -STATIC const mp_obj_type_t microbit_uart_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitUART, - .protocol = µbit_uart_stream_p, - .locals_dict = (mp_obj_dict_t *)µbit_uart_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + microbit_uart_type, + MP_QSTR_MicroBitUART, + MP_TYPE_FLAG_NONE, + protocol, µbit_uart_stream_p, + locals_dict, µbit_uart_locals_dict + ); const microbit_uart_obj_t microbit_uart_obj = { { µbit_uart_type }, diff --git a/src/codal_port/microbitfs.c b/src/codal_port/microbitfs.c index f6b8831..a192fab 100644 --- a/src/codal_port/microbitfs.c +++ b/src/codal_port/microbitfs.c @@ -633,12 +633,13 @@ STATIC const mp_stream_p_t textio_stream_p = { .is_text = true, }; -const mp_obj_type_t uos_mbfs_textio_type = { - { &mp_type_type }, - .name = MP_QSTR_TextIO, - .protocol = &textio_stream_p, - .locals_dict = (mp_obj_dict_t*)&uos_mbfs_file_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + uos_mbfs_textio_type, + MP_QSTR_TextIO, + MP_TYPE_FLAG_NONE, + protocol, &textio_stream_p, + locals_dict, &uos_mbfs_file_locals_dict + ); STATIC const mp_stream_p_t fileio_stream_p = { @@ -646,12 +647,13 @@ STATIC const mp_stream_p_t fileio_stream_p = { .write = microbit_file_write, }; -const mp_obj_type_t uos_mbfs_fileio_type = { - { &mp_type_type }, - .name = MP_QSTR_FileIO, - .protocol = &fileio_stream_p, - .locals_dict = (mp_obj_dict_t*)&uos_mbfs_file_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + uos_mbfs_fileio_type, + MP_QSTR_FileIO, + MP_TYPE_FLAG_NONE, + protocol, &fileio_stream_p, + locals_dict, &uos_mbfs_file_locals_dict + ); // From micro:bit fileobj.c mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args) { diff --git a/src/codal_port/modantigravity.c b/src/codal_port/modantigravity.c index 5de9ee4..421355d 100644 --- a/src/codal_port/modantigravity.c +++ b/src/codal_port/modantigravity.c @@ -210,3 +210,5 @@ const mp_obj_module_t antigravity_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&antigravity_module_globals, }; + +MP_REGISTER_MODULE(MP_QSTR_antigravity, antigravity_module); diff --git a/src/codal_port/modaudio.c b/src/codal_port/modaudio.c index 6a4b6c4..5c292bc 100644 --- a/src/codal_port/modaudio.c +++ b/src/codal_port/modaudio.c @@ -256,6 +256,8 @@ const mp_obj_module_t audio_module = { .globals = (mp_obj_dict_t *)&audio_module_globals, }; +MP_REGISTER_MODULE(MP_QSTR_audio, audio_module); + /******************************************************************************/ // AudioFrame class @@ -408,16 +410,17 @@ STATIC const mp_map_elem_t microbit_audio_frame_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(microbit_audio_frame_locals_dict, microbit_audio_frame_locals_dict_table); -const mp_obj_type_t microbit_audio_frame_type = { - { &mp_type_type }, - .name = MP_QSTR_AudioFrame, - .make_new = microbit_audio_frame_new, - .unary_op = audio_frame_unary_op, - .binary_op = audio_frame_binary_op, - .subscr = audio_frame_subscr, - .buffer_p = { .get_buffer = audio_frame_get_buffer }, - .locals_dict = (mp_obj_dict_t*)µbit_audio_frame_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_audio_frame_type, + MP_QSTR_AudioFrame, + MP_TYPE_FLAG_NONE, + make_new, microbit_audio_frame_new, + unary_op, audio_frame_unary_op, + binary_op, audio_frame_binary_op, + subscr, audio_frame_subscr, + buffer, audio_frame_get_buffer, + locals_dict, µbit_audio_frame_locals_dict + ); microbit_audio_frame_obj_t *microbit_audio_frame_make_new(void) { microbit_audio_frame_obj_t *res = m_new_obj(microbit_audio_frame_obj_t); @@ -425,3 +428,5 @@ microbit_audio_frame_obj_t *microbit_audio_frame_make_new(void) { memset(res->data, 128, AUDIO_CHUNK_SIZE); return res; } + +MP_REGISTER_ROOT_POINTER(void *audio_source); diff --git a/src/codal_port/modaudio.h b/src/codal_port/modaudio.h index 3f3f477..7111715 100644 --- a/src/codal_port/modaudio.h +++ b/src/codal_port/modaudio.h @@ -40,6 +40,7 @@ typedef struct _microbit_audio_frame_obj_t { } microbit_audio_frame_obj_t; extern const mp_obj_type_t microbit_audio_frame_type; +extern const mp_obj_module_t audio_module; void microbit_audio_play_source(mp_obj_t src, mp_obj_t pin_select, bool wait, uint32_t sample_rate); void microbit_audio_stop(void); diff --git a/src/codal_port/modlog.c b/src/codal_port/modlog.c index 69daa8a..5d289e8 100644 --- a/src/codal_port/modlog.c +++ b/src/codal_port/modlog.c @@ -155,3 +155,5 @@ const mp_obj_module_t log_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&log_module_globals, }; + +MP_REGISTER_MODULE(MP_QSTR_log, log_module); diff --git a/src/codal_port/modlove.c b/src/codal_port/modlove.c index ccca73d..892d3a8 100644 --- a/src/codal_port/modlove.c +++ b/src/codal_port/modlove.c @@ -76,3 +76,5 @@ const mp_obj_module_t love_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&love_module_globals, }; + +MP_REGISTER_MODULE(MP_QSTR_love, love_module); diff --git a/src/codal_port/modmachine.c b/src/codal_port/modmachine.c index 4b34670..447cc73 100644 --- a/src/codal_port/modmachine.c +++ b/src/codal_port/modmachine.c @@ -81,4 +81,6 @@ const mp_obj_module_t machine_module = { .globals = (mp_obj_dict_t*)&machine_module_globals, }; +MP_REGISTER_MODULE(MP_QSTR_machine, machine_module); + #endif // MICROPY_PY_MACHINE diff --git a/src/codal_port/modmicrobit.c b/src/codal_port/modmicrobit.c index 07afdc9..b4abfd3 100644 --- a/src/codal_port/modmicrobit.c +++ b/src/codal_port/modmicrobit.c @@ -29,6 +29,7 @@ #include "py/mphal.h" #include "drv_softtimer.h" #include "drv_system.h" +#include "modaudio.h" #include "modmicrobit.h" STATIC mp_obj_t microbit_run_every_new(uint32_t period_ms); @@ -122,7 +123,7 @@ STATIC mp_obj_t microbit_run_every(size_t n_args, const mp_obj_t *pos_args, mp_m return run_every; } else { // Start the timer now. - return mp_obj_get_type(run_every)->call(run_every, 1, 0, &args[ARG_callback].u_obj); + return MP_OBJ_TYPE_GET_SLOT(mp_obj_get_type(run_every), call)(run_every, 1, 0, &args[ARG_callback].u_obj); } } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(microbit_run_every_obj, 0, microbit_run_every); @@ -223,6 +224,8 @@ const mp_obj_module_t microbit_module = { .globals = (mp_obj_dict_t*)µbit_module_globals, }; +MP_REGISTER_MODULE(MP_QSTR_microbit, microbit_module); + /******************************************************************************/ // run_every object @@ -272,11 +275,12 @@ STATIC mp_obj_t microbit_run_every_obj_call(mp_obj_t self_in, size_t n_args, siz return self_in; } -STATIC const mp_obj_type_t microbit_run_every_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_run_every, - .call = microbit_run_every_obj_call, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + microbit_run_every_obj_type, + MP_QSTR_run_every, + MP_TYPE_FLAG_NONE, + call, microbit_run_every_obj_call + ); STATIC mp_obj_t microbit_run_every_new(uint32_t period_ms) { microbit_run_every_obj_t *self = m_new_obj(microbit_run_every_obj_t); diff --git a/src/codal_port/modmusic.c b/src/codal_port/modmusic.c index d0bbdc8..bd9ed52 100644 --- a/src/codal_port/modmusic.c +++ b/src/codal_port/modmusic.c @@ -473,3 +473,8 @@ const mp_obj_module_t music_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)µbit_music_locals_dict, }; + +MP_REGISTER_MODULE(MP_QSTR_music, music_module); + +#undef music_data +MP_REGISTER_ROOT_POINTER(struct _music_data_t *music_data); diff --git a/src/codal_port/modos.c b/src/codal_port/modos.c index b629de2..5465a2d 100644 --- a/src/codal_port/modos.c +++ b/src/codal_port/modos.c @@ -95,3 +95,5 @@ const mp_obj_module_t os_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&os_module_globals, }; + +MP_REGISTER_MODULE(MP_QSTR_os, os_module); diff --git a/src/codal_port/modpower.c b/src/codal_port/modpower.c index a707e4a..bbfdfc8 100644 --- a/src/codal_port/modpower.c +++ b/src/codal_port/modpower.c @@ -150,3 +150,5 @@ const mp_obj_module_t power_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&power_module_globals, }; + +MP_REGISTER_MODULE(MP_QSTR_power, power_module); diff --git a/src/codal_port/modradio.c b/src/codal_port/modradio.c index 09e63e6..373bbde 100644 --- a/src/codal_port/modradio.c +++ b/src/codal_port/modradio.c @@ -290,3 +290,5 @@ const mp_obj_module_t radio_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t*)&radio_module_globals, }; + +MP_REGISTER_MODULE(MP_QSTR_radio, radio_module); diff --git a/src/codal_port/modspeech.c b/src/codal_port/modspeech.c index 4c4bcb2..172254a 100644 --- a/src/codal_port/modspeech.c +++ b/src/codal_port/modspeech.c @@ -487,3 +487,7 @@ const mp_obj_module_t speech_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t*)&_globals, }; + +MP_REGISTER_MODULE(MP_QSTR_speech, speech_module); + +MP_REGISTER_ROOT_POINTER(void *speech_data); diff --git a/src/codal_port/modthis.c b/src/codal_port/modthis.c index e57a347..8430850 100644 --- a/src/codal_port/modthis.c +++ b/src/codal_port/modthis.c @@ -71,3 +71,5 @@ const mp_obj_module_t this_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&this_module_globals, }; + +MP_REGISTER_MODULE(MP_QSTR_this, this_module); diff --git a/src/codal_port/modutime.c b/src/codal_port/modutime.c index a0b72e9..5d12a26 100644 --- a/src/codal_port/modutime.c +++ b/src/codal_port/modutime.c @@ -44,3 +44,5 @@ const mp_obj_module_t utime_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t*)&utime_module_globals, }; + +MP_REGISTER_MODULE(MP_QSTR_utime, utime_module); diff --git a/src/codal_port/mpconfigport.h b/src/codal_port/mpconfigport.h index e4333f1..2253a25 100644 --- a/src/codal_port/mpconfigport.h +++ b/src/codal_port/mpconfigport.h @@ -125,44 +125,6 @@ #define MP_STATE_PORT MP_STATE_VM -extern const struct _mp_obj_module_t antigravity_module; -extern const struct _mp_obj_module_t audio_module; -extern const struct _mp_obj_module_t log_module; -extern const struct _mp_obj_module_t love_module; -extern const struct _mp_obj_module_t machine_module; -extern const struct _mp_obj_module_t microbit_module; -extern const struct _mp_obj_module_t music_module; -extern const struct _mp_obj_module_t os_module; -extern const struct _mp_obj_module_t power_module; -extern const struct _mp_obj_module_t radio_module; -extern const struct _mp_obj_module_t speech_module; -extern const struct _mp_obj_module_t this_module; -extern const struct _mp_obj_module_t utime_module; - -#define MICROPY_PORT_BUILTIN_MODULES \ - { MP_ROM_QSTR(MP_QSTR_antigravity), MP_ROM_PTR(&antigravity_module) }, \ - { MP_ROM_QSTR(MP_QSTR_audio), MP_ROM_PTR(&audio_module) }, \ - { MP_ROM_QSTR(MP_QSTR_log), MP_ROM_PTR(&log_module) }, \ - { MP_ROM_QSTR(MP_QSTR_love), MP_ROM_PTR(&love_module) }, \ - { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \ - { MP_ROM_QSTR(MP_QSTR_microbit), MP_ROM_PTR(µbit_module) }, \ - { MP_ROM_QSTR(MP_QSTR_music), MP_ROM_PTR(&music_module) }, \ - { MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&os_module) }, \ - { MP_ROM_QSTR(MP_QSTR_power), MP_ROM_PTR(&power_module) }, \ - { MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&radio_module) }, \ - { MP_ROM_QSTR(MP_QSTR_speech), MP_ROM_PTR(&speech_module) }, \ - { MP_ROM_QSTR(MP_QSTR_this), MP_ROM_PTR(&this_module) }, \ - { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&utime_module) }, \ - -#define MICROPY_PORT_ROOT_POINTERS \ - const char *readline_hist[8]; \ - void *display_data; \ - uint8_t *radio_buf; \ - void *audio_source; \ - void *speech_data; \ - struct _music_data_t *music_data; \ - struct _microbit_soft_timer_entry_t *soft_timer_heap; \ - // These functions allow nested calls. extern void target_disable_irq(void); extern void target_enable_irq(void); From 1b618d53ad26ff6de1738ded8cdbf92c9dae14e0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 15 May 2023 18:02:50 +1000 Subject: [PATCH 12/50] CI: Update runner to use ubuntu-20.04. Signed-off-by: Damien George --- .github/workflows/build.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ebd6193..10bba8c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,20 +10,18 @@ jobs: build: strategy: matrix: - os: [ubuntu-18.04] + os: [ubuntu-20.04] fail-fast: false runs-on: ${{ matrix.os }} name: build.py ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true - name: Install toolchain (Ubuntu) if: runner.os == 'Linux' run: | - sudo add-apt-repository -y ppa:team-gcc-arm-embedded/ppa - sudo apt-get update -qq - sudo apt-get install -y gcc-arm-embedded + sudo apt-get install -y gcc-arm-none-eabi libnewlib-arm-none-eabi sudo apt-get install -y cmake - name: Check Versions run: | @@ -35,7 +33,7 @@ jobs: cd src make -j2 - name: Upload hex file - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v3 with: name: MICROBIT-MICROPYTHON-${{ github.sha }}.hex path: src/MICROBIT.hex From 665c809f0f104d35e352d5dc1d7ee3ee6fd1b0ac Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 16 May 2023 10:18:26 +1000 Subject: [PATCH 13/50] codal_app: Update codal-microbit-v2 to v0.2.51. Changes to codal-core: - streamSplitters now emit finer-grained events - introduce Pin Disconnecting flag - only wipe specified region on large ManagedBuffer::shift - reworked and updated the streams API - add rms based clap detection to level detector spl - set default DEVICE_DMESG_BUFFER_SIZE based on DMESG_ENABLE - updated DataStream to support decoupling the input fiber from the output to enable async stream data - updated StreamRecording to use the new PR/Pull metrics Changes to codal-microbit-v2: - MicroBitRadio: fix setFrequencyBand() and do not reset tx power and frequency band in enable() - simplify the BLE - Device Info - Model Number to only indicate V2 - added a small patch to confirm that all splitter channels have gone before turning the microphone off - introduce sound playback "until playback complete" option - fixed the stream wiring in MicroBitAudio - add UX feature: Triple-tap-reset to enter pairing mode - remove target.json DEVICE_DMESG_BUFFER_SIZE to use default - updated MicroBitAudio and the Mixer to correctly work with the new streams API Charges to codal-nrf52: - prevent recursive disconnet loops in NRF52Pin and accidental erasure of obj state Signed-off-by: Damien George --- src/codal_app/codal.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codal_app/codal.json b/src/codal_app/codal.json index 35d131c..fef7b27 100644 --- a/src/codal_app/codal.json +++ b/src/codal_app/codal.json @@ -2,7 +2,7 @@ "target": { "name": "codal-microbit-v2", "url": "https://github.com/lancaster-university/codal-microbit-v2", - "branch": "v0.2.48", + "branch": "v0.2.51", "type": "git", "test_ignore": true } , From eeb1db318df7d678dbc7063934efe4258eaa70ab Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 12 Jun 2023 14:39:48 +1000 Subject: [PATCH 14/50] codal_app: Update codal-microbit-v2 to v0.2.54. Changes to codal-core: - updated streams API to include connection checks by API requirement - fixed the level detectors to correctly handle initial connections to their upstream - removed duplicate documentation in cpp - adjusted CODAL_STREAM_IDLE_TIMEOUT_MS down to 75ms - added async and sync variants of play and record, for convenience - removed unusued bool and check for timeouts in getValue Changes to codal-microbit-v2: - added volume and sample rate control for MixerChannels - implemented new API requirements for Mixer2, Synth and virtual output pins - improve sound quality of virtual sound pin: - fix bug in audio mixer that could cause one inaccurate sample at the start of each DMA buffer - enable external crystal at boot to improve frequency accuracy of audio playback - add optional CONFIG block to discretize the output of virtual sound pin to nearest integer divisor of mixer - minor codepath optimization to prevent unecessary processing in audio mixer - removed old level detector Charges to codal-nrf52: - updated the ADC channels to use the new requirements for stream API classes Signed-off-by: Damien George --- src/codal_app/codal.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codal_app/codal.json b/src/codal_app/codal.json index fef7b27..cb2213e 100644 --- a/src/codal_app/codal.json +++ b/src/codal_app/codal.json @@ -2,7 +2,7 @@ "target": { "name": "codal-microbit-v2", "url": "https://github.com/lancaster-university/codal-microbit-v2", - "branch": "v0.2.51", + "branch": "v0.2.54", "type": "git", "test_ignore": true } , From f47cbe1d531a636c435083a3b15ae2edac846ebd Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 22 Aug 2023 18:22:16 +1000 Subject: [PATCH 15/50] codal_app: Update codal-microbit-v2 to v0.2.58. Changes to codal-core: - added a lock to the initial access/events for the level detector - setGain and getGain now return floats, as they use fractional values internally - StreamRecording objects now use a linked list of buffers for storage - StreamSplitter now correctly connects to its upstream - added virtual to isConnected on DataSource to prevent internal misrouting - extended DMESG with optional Fiber and Time markers - updated CodalFiber to correctly behave as a counting semaphore - corrected locking behaviour on the LevelDetectorSPL to avoid race conditions - refactored assert to remove assert_true and assert_false - set the default FiberLock count to 1 - added a "fast path" route to reduce delays on getValue calls - added a new arg to FiberLock to run in legacy MUTEX mode, or SEMAPHORE mode with corrected semantics - TouchSensor: added missing public as part of declaration - Compass::clearCalibration() resets calibration member variable - update touch code to release/reconnect on pin reuse (codal-microbit-v2#345) Changes to codal-microbit-v2: - fix BLE panic 071 (#334) - remove FXOS vestiges - removed unused include for the old LevelDetector, updated event handling for demand activation - MicroBitUtilityService - replaces PR 178 (#287) - added isMicrophoneEnabled() to MicroBitAudio to match isSpeakerEnabled - removed spurious duplicate documentation, added support for isMicrophoneEnabled - MicroBitCompassCalibrator avoid using max(int,int) (#290) - disbled the MICROBIT_BLE_UTILITY_SERVICE_PAIRING configuration by default, enabled on BETA - MicroBitBLEManager - Move MICROBIT_BLE_MAXIMUM_BONDS to MicroBitConfig (#299) Changes to codal-nrf52: - fix NeoPixel/WS2812B timing (#47) - update touch code to release/reconnect on pin reuse (codal-microbit-v2#345) Signed-off-by: Damien George --- src/codal_app/codal.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codal_app/codal.json b/src/codal_app/codal.json index cb2213e..ebefb79 100644 --- a/src/codal_app/codal.json +++ b/src/codal_app/codal.json @@ -2,7 +2,7 @@ "target": { "name": "codal-microbit-v2", "url": "https://github.com/lancaster-university/codal-microbit-v2", - "branch": "v0.2.54", + "branch": "v0.2.58", "type": "git", "test_ignore": true } , From 3534b18b59aedd38dbcf7993482c2173f92af1c3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 22 Aug 2023 18:24:57 +1000 Subject: [PATCH 16/50] lib/codal: Update codal submodule to latest. The changes made do not affect the build here, but good to keep it up-to-date. Signed-off-by: Damien George --- lib/codal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/codal b/lib/codal index 18aa65b..3864ea2 160000 --- a/lib/codal +++ b/lib/codal @@ -1 +1 @@ -Subproject commit 18aa65b99a100f1923f14f1cd7bc8fc3b38afdc6 +Subproject commit 3864ea2e452f710ac3e09598996edee4df72a5bf From d425ef21cd11969a030640244d0a0c8a018b1514 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Nov 2023 15:25:04 +1100 Subject: [PATCH 17/50] codal_app: Update codal-microbit-v2 to v0.2.63. Signed-off-by: Damien George --- src/codal_app/codal.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codal_app/codal.json b/src/codal_app/codal.json index ebefb79..c0a88d4 100644 --- a/src/codal_app/codal.json +++ b/src/codal_app/codal.json @@ -2,7 +2,7 @@ "target": { "name": "codal-microbit-v2", "url": "https://github.com/lancaster-university/codal-microbit-v2", - "branch": "v0.2.58", + "branch": "v0.2.63", "type": "git", "test_ignore": true } , From 957e810818f239fddf8115014bb9b650ccf278cb Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Nov 2023 15:25:58 +1100 Subject: [PATCH 18/50] codal_app: Add was_touched and get_touches to touch-capable pins. Pins with these new methods are: pin0, pin1, pin2, pin_logo. Fixes issue #149. Signed-off-by: Damien George --- src/codal_app/microbithal.cpp | 30 ++++++++++++++++++++++++++---- src/codal_app/microbithal.h | 2 +- src/codal_port/microbit_pin.c | 26 ++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/codal_app/microbithal.cpp b/src/codal_app/microbithal.cpp index 249606b..258e4de 100644 --- a/src/codal_app/microbithal.cpp +++ b/src/codal_app/microbithal.cpp @@ -78,6 +78,7 @@ static const PullMode pin_pull_mode_mapping[] = { }; static uint8_t pin_pull_state[32 + 6]; +static uint16_t touch_state[4]; static uint16_t button_state[2]; extern "C" { @@ -202,11 +203,32 @@ void microbit_hal_pin_write_analog_u10(int pin, int value) { pin_obj[pin]->setAnalogValue(value); } -int microbit_hal_pin_is_touched(int pin) { - if (pin == MICROBIT_HAL_PIN_LOGO) { - // For touch on the logo pin, delegate to the TouchButton instance. - return uBit.logo.buttonActive(); +int microbit_hal_pin_touch_state(int pin, int *was_touched, int *num_touches) { + if (was_touched != NULL || num_touches != NULL) { + int pin_state_index; + if (pin == MICROBIT_HAL_PIN_LOGO) { + pin_state_index = 3; + } else { + pin_state_index = pin; // pin0/1/2 + } + int t = pin_obj[pin]->wasTouched(); + uint16_t state = touch_state[pin_state_index]; + if (t) { + // Update state based on number of touches since last call. + // Low bit is "was touched at least once", upper bits are "number of touches". + state = (state + (t << 1)) | 1; + } + if (was_touched != NULL) { + *was_touched = state & 1; + state &= ~1; + } + if (num_touches != NULL) { + *num_touches = state >> 1; + state &= 1; + } + touch_state[pin_state_index] = state; } + return pin_obj[pin]->isTouched(); } diff --git a/src/codal_app/microbithal.h b/src/codal_app/microbithal.h index e8840dc..ca137f3 100644 --- a/src/codal_app/microbithal.h +++ b/src/codal_app/microbithal.h @@ -123,7 +123,7 @@ int microbit_hal_pin_read(int pin); void microbit_hal_pin_write(int pin, int value); int microbit_hal_pin_read_analog_u10(int pin); void microbit_hal_pin_write_analog_u10(int pin, int value); -int microbit_hal_pin_is_touched(int pin); +int microbit_hal_pin_touch_state(int pin, int *was_touched, int *num_touches); void microbit_hal_pin_write_ws2812(int pin, const uint8_t *buf, size_t len); int microbit_hal_i2c_init(int scl, int sda, int freq); diff --git a/src/codal_port/microbit_pin.c b/src/codal_port/microbit_pin.c index 4c9e79b..9e2712a 100644 --- a/src/codal_port/microbit_pin.c +++ b/src/codal_port/microbit_pin.c @@ -155,17 +155,35 @@ mp_obj_t microbit_pin_get_analog_period_microseconds(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(microbit_pin_get_analog_period_microseconds_obj, microbit_pin_get_analog_period_microseconds); -mp_obj_t microbit_pin_is_touched(mp_obj_t self_in) { +static int microbit_pin_get_touch_state(mp_obj_t self_in, int *was_touched, int *num_touches) { microbit_pin_obj_t *self = (microbit_pin_obj_t*)self_in; const microbit_pinmode_t *mode = microbit_pin_get_mode(self); if (mode != microbit_pin_mode_touch && mode != microbit_pin_mode_button) { microbit_obj_pin_acquire(self, microbit_pin_mode_touch); // set NO_PULL on pin } - return mp_obj_new_bool(microbit_hal_pin_is_touched(self->name)); + return microbit_hal_pin_touch_state(self->name, was_touched, num_touches); +} + +mp_obj_t microbit_pin_is_touched(mp_obj_t self_in) { + return mp_obj_new_bool(microbit_pin_get_touch_state(self_in, NULL, NULL)); } MP_DEFINE_CONST_FUN_OBJ_1(microbit_pin_is_touched_obj, microbit_pin_is_touched); +mp_obj_t microbit_pin_was_touched(mp_obj_t self_in) { + int was_touched; + microbit_pin_get_touch_state(self_in, &was_touched, NULL); + return mp_obj_new_bool(was_touched); +} +MP_DEFINE_CONST_FUN_OBJ_1(microbit_pin_was_touched_obj, microbit_pin_was_touched); + +mp_obj_t microbit_pin_get_touches(mp_obj_t self_in) { + int num_touches; + microbit_pin_get_touch_state(self_in, NULL, &num_touches); + return MP_OBJ_NEW_SMALL_INT(num_touches); +} +MP_DEFINE_CONST_FUN_OBJ_1(microbit_pin_get_touches_obj, microbit_pin_get_touches); + mp_obj_t microbit_pin_set_touch_mode(mp_obj_t self_in, mp_obj_t mode_in) { microbit_pin_obj_t *self = (microbit_pin_obj_t *)self_in; const microbit_pinmode_t *mode = microbit_pin_get_mode(self); @@ -238,6 +256,8 @@ STATIC const mp_rom_map_elem_t microbit_touch_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_set_analog_period_microseconds), MP_ROM_PTR(µbit_pin_set_analog_period_microseconds_obj) }, { MP_ROM_QSTR(MP_QSTR_get_analog_period_microseconds), MP_ROM_PTR(µbit_pin_get_analog_period_microseconds_obj) }, { MP_ROM_QSTR(MP_QSTR_is_touched), MP_ROM_PTR(µbit_pin_is_touched_obj) }, + { MP_ROM_QSTR(MP_QSTR_was_touched), MP_ROM_PTR(µbit_pin_was_touched_obj) }, + { MP_ROM_QSTR(MP_QSTR_get_touches), MP_ROM_PTR(µbit_pin_get_touches_obj) }, { MP_ROM_QSTR(MP_QSTR_get_pull), MP_ROM_PTR(µbit_pin_get_pull_obj) }, { MP_ROM_QSTR(MP_QSTR_set_pull), MP_ROM_PTR(µbit_pin_set_pull_obj) }, { MP_ROM_QSTR(MP_QSTR_get_mode), MP_ROM_PTR(µbit_pin_get_mode_obj) }, @@ -256,6 +276,8 @@ MP_DEFINE_CONST_OBJ_TYPE( STATIC const mp_rom_map_elem_t microbit_touch_only_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_is_touched), MP_ROM_PTR(µbit_pin_is_touched_obj) }, + { MP_ROM_QSTR(MP_QSTR_was_touched), MP_ROM_PTR(µbit_pin_was_touched_obj) }, + { MP_ROM_QSTR(MP_QSTR_get_touches), MP_ROM_PTR(µbit_pin_get_touches_obj) }, { MP_ROM_QSTR(MP_QSTR_set_touch_mode), MP_ROM_PTR(µbit_pin_set_touch_mode_obj) }, TOUCH_CONSTANTS, }; From a37bc963d23dc2fb39fd7998775db003b52bdf12 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Nov 2023 15:35:29 +1100 Subject: [PATCH 19/50] codal_app: Make sure volume can achieve the full CODAL range. The CODAL setVolume() method takes a value in the range 0-255. Fixes issue #159. Signed-off-by: Damien George --- src/codal_app/microbithal_audio.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/codal_app/microbithal_audio.cpp b/src/codal_app/microbithal_audio.cpp index a590274..272efef 100644 --- a/src/codal_app/microbithal_audio.cpp +++ b/src/codal_app/microbithal_audio.cpp @@ -76,11 +76,7 @@ void microbit_hal_audio_select_speaker(bool enable) { // Input value has range 0-255 inclusive. void microbit_hal_audio_set_volume(int value) { - if (value >= 255) { - uBit.audio.setVolume(128); - } else { - uBit.audio.setVolume(value / 2); - } + uBit.audio.setVolume(value); } void microbit_hal_sound_synth_callback(int event) { From 0b748ce0189a7118449db16a1f3e8cd89a5e1f28 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 15 Jan 2024 15:12:21 +1100 Subject: [PATCH 20/50] codal_app/microbithal: Mark microbit_hal_reset() as noreturn. Signed-off-by: Damien George --- src/codal_app/microbithal.cpp | 2 +- src/codal_app/microbithal.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/codal_app/microbithal.cpp b/src/codal_app/microbithal.cpp index 258e4de..e21fdba 100644 --- a/src/codal_app/microbithal.cpp +++ b/src/codal_app/microbithal.cpp @@ -95,7 +95,7 @@ void microbit_hal_idle(void) { __WFI(); } -void microbit_hal_reset(void) { +__attribute__((noreturn)) void microbit_hal_reset(void) { microbit_reset(); } diff --git a/src/codal_app/microbithal.h b/src/codal_app/microbithal.h index ca137f3..e276bea 100644 --- a/src/codal_app/microbithal.h +++ b/src/codal_app/microbithal.h @@ -104,7 +104,7 @@ extern "C" { void microbit_hal_idle(void); -void microbit_hal_reset(void); +__attribute__((noreturn)) void microbit_hal_reset(void); void microbit_hal_panic(int); int microbit_hal_temperature(void); From c648f5238ecec34b6030320a33abf87239692aad Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 15 Jan 2024 15:09:48 +1100 Subject: [PATCH 21/50] lib/micropython: Update micropython submodule to v1.22.0. Signed-off-by: Damien George --- lib/micropython | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/micropython b/lib/micropython index 294baf5..9feb068 160000 --- a/lib/micropython +++ b/lib/micropython @@ -1 +1 @@ -Subproject commit 294baf52b346e400e2255c6c1e82af5b978b18f7 +Subproject commit 9feb0689eeaca5ce88aedcc680f997a3b4d0221c From fdaf840e86ed4721123b8b1fddb4830e387532b2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 15 Jan 2024 15:13:21 +1100 Subject: [PATCH 22/50] codal_port: Update to build with latest micropython. The only user-facing change is the addition of time.ticks_cpu(). Signed-off-by: Damien George --- src/codal_port/Makefile | 7 +- src/codal_port/drv_image.c | 2 +- src/codal_port/main.c | 12 +- src/codal_port/make_microbit_version_hdr.py | 120 ++++++++++++++++++++ src/codal_port/microbitfs.c | 84 +++++++------- src/codal_port/modmachine.c | 19 ++-- src/codal_port/modos.c | 12 +- src/codal_port/modradio.c | 2 +- src/codal_port/modutime.c | 48 -------- src/codal_port/mpconfigport.h | 18 ++- src/codal_port/mphalport.h | 10 +- 11 files changed, 198 insertions(+), 136 deletions(-) create mode 100644 src/codal_port/make_microbit_version_hdr.py delete mode 100644 src/codal_port/modutime.c diff --git a/src/codal_port/Makefile b/src/codal_port/Makefile index 2d8d033..f7694e6 100644 --- a/src/codal_port/Makefile +++ b/src/codal_port/Makefile @@ -98,7 +98,6 @@ SRC_C += \ modradio.c \ modspeech.c \ modthis.c \ - modutime.c \ mphalport.c \ SRC_C += \ @@ -135,11 +134,7 @@ all: lib $(MBIT_VER_FILE) # Also rebuild MicroPython version header in correct directory to pick up git hash. $(MBIT_VER_FILE): FORCE (cd $(TOP) && $(PYTHON) py/makeversionhdr.py $(abspath $(MP_VER_FILE))) - $(PYTHON) $(TOP)/py/makeversionhdr.py $(MBIT_VER_FILE).pre - $(CAT) $(MBIT_VER_FILE).pre | $(SED) s/MICROPY_/MICROBIT_/ > $(MBIT_VER_FILE) - -# Suppress warnings bulding stackctrl.c (fixed post v1.20.0). -$(BUILD)/py/stackctrl.o: CWARN += -Wno-dangling-pointer + $(PYTHON) make_microbit_version_hdr.py $(MBIT_VER_FILE) # Suppress warnings from SAM library. $(BUILD)/$(abspath $(LOCAL_LIB_DIR))/sam/sam.o: CWARN += -Wno-array-bounds diff --git a/src/codal_port/drv_image.c b/src/codal_port/drv_image.c index 03f9e15..7e650b8 100644 --- a/src/codal_port/drv_image.c +++ b/src/codal_port/drv_image.c @@ -43,7 +43,7 @@ STATIC uint8_t monochrome_get_pixel(monochrome_5by5_t *self, mp_int_t x, mp_int_ } greyscale_t *greyscale_new(mp_int_t w, mp_int_t h) { - greyscale_t *result = m_new_obj_var(greyscale_t, uint8_t, (w*h+1)>>1); + greyscale_t *result = m_new_obj_var(greyscale_t, byte_data, uint8_t, (w*h+1)>>1); result->base.type = µbit_image_type; result->five = 0; result->width = w; diff --git a/src/codal_port/main.c b/src/codal_port/main.c index 500b9ad..8592e9b 100644 --- a/src/codal_port/main.c +++ b/src/codal_port/main.c @@ -36,7 +36,7 @@ #include "shared/readline/readline.h" #include "shared/runtime/gchelper.h" #include "shared/runtime/pyexec.h" -#include "ports/nrf/modules/uos/microbitfs.h" +#include "ports/nrf/modules/os/microbitfs.h" #include "drv_softtimer.h" #include "drv_system.h" #include "drv_display.h" @@ -136,7 +136,7 @@ void microbit_pyexec_file(const char *filename) { nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { // Parse and comple the file. - mp_lexer_t *lex = mp_lexer_new_from_file(filename); + mp_lexer_t *lex = mp_lexer_new_from_file(qstr_from_str(filename)); qstr source_name = lex->source_name; mp_parse_tree_t parse_tree = mp_parse(lex, MP_PARSE_FILE_INPUT); mp_obj_t module_fun = mp_compile(&parse_tree, source_name, false); @@ -194,16 +194,16 @@ void microbit_file_opened_for_writing(const char *name, size_t name_len) { } #if MICROPY_MBFS -mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - return uos_mbfs_new_reader(filename); +mp_lexer_t *mp_lexer_new_from_file(qstr filename) { + return os_mbfs_new_reader(qstr_str(filename)); } mp_import_stat_t mp_import_stat(const char *path) { - return uos_mbfs_import_stat(path); + return os_mbfs_import_stat(path); } mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { - return uos_mbfs_open(n_args, args); + return os_mbfs_open(n_args, args); } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); #endif diff --git a/src/codal_port/make_microbit_version_hdr.py b/src/codal_port/make_microbit_version_hdr.py new file mode 100644 index 0000000..3d532ea --- /dev/null +++ b/src/codal_port/make_microbit_version_hdr.py @@ -0,0 +1,120 @@ +""" +Generate header file with macros defining micro:bit version info. + +Adapted from MicroPython's py/makeversionhdr.py file at v1.21.0. +""" + +import argparse +import sys +import os +import datetime +import subprocess + + +def get_version_info_from_git(repo_path): + # Note: git describe doesn't work if no tag is available + try: + git_tag = subprocess.check_output( + ["git", "describe", "--tags", "--dirty", "--always", "--match", "v[1-9].*"], + cwd=repo_path, + stderr=subprocess.STDOUT, + universal_newlines=True, + ).strip() + except subprocess.CalledProcessError as er: + if er.returncode == 128: + # git exit code of 128 means no repository found + return None + git_tag = "" + except OSError: + return None + try: + git_hash = subprocess.check_output( + ["git", "rev-parse", "--short", "HEAD"], + cwd=repo_path, + stderr=subprocess.STDOUT, + universal_newlines=True, + ).strip() + except subprocess.CalledProcessError: + git_hash = "unknown" + except OSError: + return None + + try: + # Check if there are any modified files. + subprocess.check_call( + ["git", "diff", "--no-ext-diff", "--quiet", "--exit-code"], + cwd=repo_path, + stderr=subprocess.STDOUT, + ) + # Check if there are any staged files. + subprocess.check_call( + ["git", "diff-index", "--cached", "--quiet", "HEAD", "--"], + cwd=repo_path, + stderr=subprocess.STDOUT, + ) + except subprocess.CalledProcessError: + git_hash += "-dirty" + except OSError: + return None + + return git_tag, git_hash + + +def make_version_header(repo_path, filename): + info = None + if "MICROBIT_GIT_TAG" in os.environ: + info = [os.environ["MICROBIT_GIT_TAG"], os.environ["MICROBIT_GIT_HASH"]] + if info is None: + info = get_version_info_from_git(repo_path) + + git_tag, git_hash = info + + build_date = datetime.date.today() + if "SOURCE_DATE_EPOCH" in os.environ: + build_date = datetime.datetime.utcfromtimestamp( + int(os.environ["SOURCE_DATE_EPOCH"]) + ).date() + + # Generate the file with the git and version info + file_data = """\ +// This file was generated by py/makeversionhdr.py +#define MICROBIT_GIT_TAG "%s" +#define MICROBIT_GIT_HASH "%s" +#define MICROBIT_BUILD_DATE "%s" +""" % ( + git_tag, + git_hash, + build_date.strftime("%Y-%m-%d"), + ) + + # Check if the file contents changed from last time + write_file = True + if os.path.isfile(filename): + with open(filename, "r") as f: + existing_data = f.read() + if existing_data == file_data: + write_file = False + + # Only write the file if we need to + if write_file: + print("GEN %s" % filename) + with open(filename, "w") as f: + f.write(file_data) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + "-r", + "--repo-path", + default=os.path.join(os.path.dirname(sys.argv[0]), ".."), + help="path to git repo to query for version", + ) + parser.add_argument("dest", nargs=1, help="output file path") + args = parser.parse_args() + + make_version_header(args.repo_path, args.dest[0]) + + +if __name__ == "__main__": + main() diff --git a/src/codal_port/microbitfs.c b/src/codal_port/microbitfs.c index a192fab..308f208 100644 --- a/src/codal_port/microbitfs.c +++ b/src/codal_port/microbitfs.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -25,7 +25,7 @@ * THE SOFTWARE. */ -// This is a copy of the file micropython:ports/nrf/modules/uos/microbitfs.c with: +// This is a copy of the file micropython:ports/nrf/modules/os/microbitfs.c with: // - a call to `microbit_file_opened_for_writing` added in `microbit_file_open` // - a fix to `find_chunk_and_erase` to sweep the filesystem if any free chunks are found @@ -33,7 +33,7 @@ #include #include -#include "modules/uos/microbitfs.h" +#include "modules/os/microbitfs.h" #include "drivers/flash.h" #include "drivers/rng.h" #include "py/obj.h" @@ -121,13 +121,13 @@ typedef struct _persistent_config_t { uint8_t marker; // Should always be PERSISTENT_DATA_MARKER } persistent_config_t; -extern const mp_obj_type_t uos_mbfs_fileio_type; -extern const mp_obj_type_t uos_mbfs_textio_type; +extern const mp_obj_type_t os_mbfs_fileio_type; +extern const mp_obj_type_t os_mbfs_textio_type; // Page indexes count down from the end of ROM. STATIC uint8_t first_page_index; STATIC uint8_t last_page_index; -// The number of useable chunks in the file system. +// The number of usable chunks in the file system. STATIC uint8_t chunks_in_file_system; // Index of chunk to start searches. This is randomised to even out wear. STATIC uint8_t start_index; @@ -361,12 +361,7 @@ STATIC file_descriptor_obj *microbit_file_open(const char *name, size_t name_len } STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary) { - file_descriptor_obj *res = m_new_obj(file_descriptor_obj); - if (binary) { - res->base.type = &uos_mbfs_fileio_type; - } else { - res->base.type = &uos_mbfs_textio_type; - } + file_descriptor_obj *res = mp_obj_malloc(file_descriptor_obj, binary ? &os_mbfs_fileio_type : &os_mbfs_textio_type); res->start_chunk = start_chunk; res->seek_chunk = start_chunk; res->seek_offset = file_system_chunks[start_chunk].header.name_len+2; @@ -517,9 +512,9 @@ STATIC mp_uint_t file_read_byte(file_descriptor_obj *fd) { return res; } -// Now follows the code to integrate this filesystem into the uos module. +// Now follows the code to integrate this filesystem into the os module. -mp_lexer_t *uos_mbfs_new_reader(const char *filename) { +mp_lexer_t *os_mbfs_new_reader(const char *filename) { file_descriptor_obj *fd = microbit_file_open(filename, strlen(filename), false, false); if (fd == NULL) { mp_raise_OSError(MP_ENOENT); @@ -531,7 +526,7 @@ mp_lexer_t *uos_mbfs_new_reader(const char *filename) { return mp_lexer_new(qstr_from_str(filename), reader); } -mp_import_stat_t uos_mbfs_import_stat(const char *path) { +mp_import_stat_t os_mbfs_import_stat(const char *path) { uint8_t chunk = microbit_find_file(path, strlen(path)); if (chunk == FILE_NOT_FOUND) { return MP_IMPORT_STAT_NO_EXIST; @@ -540,38 +535,38 @@ mp_import_stat_t uos_mbfs_import_stat(const char *path) { } } -STATIC mp_obj_t uos_mbfs_file_name(mp_obj_t self) { +STATIC mp_obj_t os_mbfs_file_name(mp_obj_t self) { file_descriptor_obj *fd = (file_descriptor_obj*)self; return microbit_file_name(fd); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_file_name_obj, uos_mbfs_file_name); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_name_obj, os_mbfs_file_name); -STATIC mp_obj_t uos_mbfs_file_close(mp_obj_t self) { +STATIC mp_obj_t os_mbfs_file_close(mp_obj_t self) { file_descriptor_obj *fd = (file_descriptor_obj*)self; microbit_file_close(fd); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_file_close_obj, uos_mbfs_file_close); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_close_obj, os_mbfs_file_close); -STATIC mp_obj_t uos_mbfs_remove(mp_obj_t name) { +STATIC mp_obj_t os_mbfs_remove(mp_obj_t name) { return microbit_remove(name); } -MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_remove_obj, uos_mbfs_remove); +MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_remove_obj, os_mbfs_remove); -STATIC mp_obj_t uos_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t os_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; - return uos_mbfs_file_close(args[0]); + return os_mbfs_file_close(args[0]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(uos_mbfs_file___exit___obj, 4, 4, uos_mbfs_file___exit__); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_mbfs_file___exit___obj, 4, 4, os_mbfs_file___exit__); typedef struct { mp_obj_base_t base; mp_fun_1_t iternext; uint8_t index; -} uos_mbfs_ilistdir_it_t; +} os_mbfs_ilistdir_it_t; -STATIC mp_obj_t uos_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { - uos_mbfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { + os_mbfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); // Read until the next FILE_START chunk. for (; self->index <= chunks_in_file_system; self->index++) { @@ -595,28 +590,27 @@ STATIC mp_obj_t uos_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC mp_obj_t uos_mbfs_ilistdir(void) { - uos_mbfs_ilistdir_it_t *iter = m_new_obj(uos_mbfs_ilistdir_it_t); - iter->base.type = &mp_type_polymorph_iter; - iter->iternext = uos_mbfs_ilistdir_it_iternext; +STATIC mp_obj_t os_mbfs_ilistdir(void) { + os_mbfs_ilistdir_it_t *iter = mp_obj_malloc(os_mbfs_ilistdir_it_t, &mp_type_polymorph_iter); + iter->iternext = os_mbfs_ilistdir_it_iternext; iter->index = 1; return MP_OBJ_FROM_PTR(iter); } -MP_DEFINE_CONST_FUN_OBJ_0(uos_mbfs_ilistdir_obj, uos_mbfs_ilistdir); +MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_ilistdir_obj, os_mbfs_ilistdir); -MP_DEFINE_CONST_FUN_OBJ_0(uos_mbfs_listdir_obj, microbit_file_list); +MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_listdir_obj, microbit_file_list); STATIC mp_obj_t microbit_file_writable(mp_obj_t self) { return mp_obj_new_bool(((file_descriptor_obj *)self)->writable); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_file_writable_obj, microbit_file_writable); -STATIC const mp_map_elem_t uos_mbfs_file_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&uos_mbfs_file_close_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&uos_mbfs_file_name_obj }, +STATIC const mp_map_elem_t os_mbfs_file_locals_dict_table[] = { + { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&os_mbfs_file_close_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&os_mbfs_file_name_obj }, { MP_ROM_QSTR(MP_QSTR___enter__), (mp_obj_t)&mp_identity_obj }, - { MP_ROM_QSTR(MP_QSTR___exit__), (mp_obj_t)&uos_mbfs_file___exit___obj }, + { MP_ROM_QSTR(MP_QSTR___exit__), (mp_obj_t)&os_mbfs_file___exit___obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_writable), (mp_obj_t)µbit_file_writable_obj }, /* Stream methods */ { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj }, @@ -624,7 +618,7 @@ STATIC const mp_map_elem_t uos_mbfs_file_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj}, { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj}, }; -STATIC MP_DEFINE_CONST_DICT(uos_mbfs_file_locals_dict, uos_mbfs_file_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(os_mbfs_file_locals_dict, os_mbfs_file_locals_dict_table); STATIC const mp_stream_p_t textio_stream_p = { @@ -634,11 +628,11 @@ STATIC const mp_stream_p_t textio_stream_p = { }; MP_DEFINE_CONST_OBJ_TYPE( - uos_mbfs_textio_type, + os_mbfs_textio_type, MP_QSTR_TextIO, MP_TYPE_FLAG_NONE, protocol, &textio_stream_p, - locals_dict, &uos_mbfs_file_locals_dict + locals_dict, &os_mbfs_file_locals_dict ); @@ -648,15 +642,15 @@ STATIC const mp_stream_p_t fileio_stream_p = { }; MP_DEFINE_CONST_OBJ_TYPE( - uos_mbfs_fileio_type, + os_mbfs_fileio_type, MP_QSTR_FileIO, MP_TYPE_FLAG_NONE, protocol, &fileio_stream_p, - locals_dict, &uos_mbfs_file_locals_dict + locals_dict, &os_mbfs_file_locals_dict ); // From micro:bit fileobj.c -mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args) { +mp_obj_t os_mbfs_open(size_t n_args, const mp_obj_t *args) { /// -1 means default; 0 explicitly false; 1 explicitly true. int read = -1; int text = -1; @@ -690,7 +684,7 @@ mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args) { mp_raise_ValueError(MP_ERROR_TEXT("illegal mode")); } -STATIC mp_obj_t uos_mbfs_stat(mp_obj_t filename) { +STATIC mp_obj_t os_mbfs_stat(mp_obj_t filename) { mp_obj_t file_size = microbit_file_size(filename); mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL)); @@ -706,6 +700,6 @@ STATIC mp_obj_t uos_mbfs_stat(mp_obj_t filename) { t->items[9] = MP_OBJ_NEW_SMALL_INT(0); // st_ctime return MP_OBJ_FROM_PTR(t); } -MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_stat_obj, uos_mbfs_stat); +MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_stat_obj, os_mbfs_stat); #endif // MICROPY_MBFS diff --git a/src/codal_port/modmachine.c b/src/codal_port/modmachine.c index 447cc73..08094ad 100644 --- a/src/codal_port/modmachine.c +++ b/src/codal_port/modmachine.c @@ -24,12 +24,13 @@ * THE SOFTWARE. */ -#include "py/mpconfig.h" -#include "extmod/machine_mem.h" -#include "extmod/machine_pulse.h" +#include "py/runtime.h" #include "modmicrobit.h" -#if MICROPY_PY_MACHINE +#undef MICROPY_PY_MACHINE +#define MICROPY_PY_MACHINE (1) +#include "extmod/machine_mem.c" +#undef MICROPY_PY_MACHINE // Returns a string of 8 bytes (64 bits), which is the unique ID for the MCU STATIC mp_obj_t machine_unique_id(void) { @@ -37,13 +38,13 @@ STATIC mp_obj_t machine_unique_id(void) { mp_hal_unique_id(dev_id); return mp_obj_new_bytes((const void*)&dev_id, 8); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(microbit_unique_id_obj, machine_unique_id); // Get the MCU frequency STATIC mp_obj_t machine_freq(void) { return MP_OBJ_NEW_SMALL_INT(64000000); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_freq_obj, machine_freq); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(microbit_freq_obj, machine_freq); // Disable interrupt requests STATIC mp_obj_t machine_disable_irq(void) { @@ -61,9 +62,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq); STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, - { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, + { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(µbit_unique_id_obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(µbit_reset_obj) }, - { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, + { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(µbit_freq_obj) }, { MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, { MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, @@ -82,5 +83,3 @@ const mp_obj_module_t machine_module = { }; MP_REGISTER_MODULE(MP_QSTR_machine, machine_module); - -#endif // MICROPY_PY_MACHINE diff --git a/src/codal_port/modos.c b/src/codal_port/modos.c index 5465a2d..731a5ba 100644 --- a/src/codal_port/modos.c +++ b/src/codal_port/modos.c @@ -27,7 +27,7 @@ #include "py/obj.h" #include "py/objtuple.h" #include "py/objstr.h" -#include "ports/nrf/modules/uos/microbitfs.h" +#include "ports/nrf/modules/os/microbitfs.h" // Include MicroPython and micro:bit version information. #include "genhdr/mpversion.h" @@ -68,7 +68,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname); #if MICROPY_MBFS STATIC mp_obj_t os_size(mp_obj_t filename) { - mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(uos_mbfs_stat_obj.fun._1(filename)); + mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(os_mbfs_stat_obj.fun._1(filename)); return tuple->items[6]; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_size_obj, os_size); @@ -80,10 +80,10 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) }, #if MICROPY_MBFS - { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&uos_mbfs_listdir_obj) }, - { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&uos_mbfs_ilistdir_obj) }, - { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&uos_mbfs_remove_obj) }, - { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&uos_mbfs_stat_obj) }, + { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&os_mbfs_listdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&os_mbfs_ilistdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_mbfs_remove_obj) }, + { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&os_mbfs_stat_obj) }, // micro:bit v1 specific { MP_ROM_QSTR(MP_QSTR_size), MP_ROM_PTR(&os_size_obj) }, diff --git a/src/codal_port/modradio.c b/src/codal_port/modradio.c index 373bbde..5bd89f0 100644 --- a/src/codal_port/modradio.c +++ b/src/codal_port/modradio.c @@ -252,7 +252,7 @@ STATIC mp_obj_t mod_radio_receive_full(void) { mp_obj_t tuple[3] = { mp_obj_new_bytes(buf + 1, len), MP_OBJ_NEW_SMALL_INT(rssi), - MP_OBJ_NEW_SMALL_INT(timestamp_us & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)) + MP_OBJ_NEW_SMALL_INT(timestamp_us & (MICROPY_PY_TIME_TICKS_PERIOD - 1)) }; microbit_radio_pop(); return mp_obj_new_tuple(3, tuple); diff --git a/src/codal_port/modutime.c b/src/codal_port/modutime.c deleted file mode 100644 index 5d12a26..0000000 --- a/src/codal_port/modutime.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013-2017 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "extmod/utime_mphal.h" - -STATIC const mp_rom_map_elem_t utime_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(utime_module_globals, utime_module_globals_table); - -const mp_obj_module_t utime_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&utime_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, utime_module); diff --git a/src/codal_port/mpconfigport.h b/src/codal_port/mpconfigport.h index 2253a25..fcf2546 100644 --- a/src/codal_port/mpconfigport.h +++ b/src/codal_port/mpconfigport.h @@ -59,9 +59,6 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_MODULE_BUILTIN_INIT (1) -#define MICROPY_MODULE_WEAK_LINKS (1) -#define MICROPY_MODULE_FROZEN_MPY (1) -#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool #define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_ENABLE_SCHEDULER (1) @@ -81,19 +78,18 @@ #define MICROPY_PY_SYS_PLATFORM "microbit" // Extended modules -#define MICROPY_PY_UERRNO (1) -#define MICROPY_PY_UTIME_MP_HAL (1) -#define MICROPY_PY_URANDOM (1) -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (rng_generate_random_word()) -#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) -#define MICROPY_PY_MACHINE (1) +#define MICROPY_PY_ERRNO (1) +#define MICROPY_PY_RANDOM (1) +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (rng_generate_random_word()) +#define MICROPY_PY_RANDOM_EXTRA_FUNCS (1) +#define MICROPY_PY_TIME (1) #define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_HW_ENABLE_RNG (1) #define MICROPY_MBFS (1) // Custom errno list. -#define MICROPY_PY_UERRNO_LIST \ +#define MICROPY_PY_ERRNO_LIST \ X(EPERM) \ X(ENOENT) \ X(EIO) \ @@ -154,7 +150,7 @@ typedef long mp_off_t; // We need to provide a declaration/definition of alloca() #include -// Needed for MICROPY_PY_URANDOM_SEED_INIT_FUNC. +// Needed for MICROPY_PY_RANDOM_SEED_INIT_FUNC. extern uint32_t rng_generate_random_word(void); // Needed for microbitfs.c:microbit_file_open. diff --git a/src/codal_port/mphalport.h b/src/codal_port/mphalport.h index 86d965a..951a8e1 100644 --- a/src/codal_port/mphalport.h +++ b/src/codal_port/mphalport.h @@ -28,8 +28,14 @@ #include "microbithal.h" #include "nrf.h" -// Not implemented and not exposed in utime module. -#define mp_hal_ticks_cpu() (0) +static inline mp_uint_t mp_hal_ticks_cpu(void) { + if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) { + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; + DWT->CYCCNT = 0; + DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; + } + return DWT->CYCCNT; +} void mp_hal_set_interrupt_char(int c); From 9db217a10c03492e5fcb318f71bac5895b2d6419 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 27 Feb 2024 10:30:19 +1100 Subject: [PATCH 23/50] codal_app: Update codal-microbit-v2 to v0.2.66. Signed-off-by: Damien George --- src/codal_app/codal.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codal_app/codal.json b/src/codal_app/codal.json index c0a88d4..6d15e8c 100644 --- a/src/codal_app/codal.json +++ b/src/codal_app/codal.json @@ -2,7 +2,7 @@ "target": { "name": "codal-microbit-v2", "url": "https://github.com/lancaster-university/codal-microbit-v2", - "branch": "v0.2.63", + "branch": "v0.2.66", "type": "git", "test_ignore": true } , From 8dfe3958031618e7474d28d0316aaa69467891e1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 27 Feb 2024 10:30:38 +1100 Subject: [PATCH 24/50] codal_app/microbithal_audio: Set audio channel sample rate on init. Fixes the case of using `speech.say(..., mode=mode)` when the mode changes and selects a different output sample rate. Signed-off-by: Damien George --- src/codal_app/microbithal_audio.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/codal_app/microbithal_audio.cpp b/src/codal_app/microbithal_audio.cpp index 272efef..d27b429 100644 --- a/src/codal_app/microbithal_audio.cpp +++ b/src/codal_app/microbithal_audio.cpp @@ -33,6 +33,7 @@ class AudioSource : public DataSource { DataSink *sink; ManagedBuffer buf; void (*callback)(void); + MixerChannel *channel; AudioSource() : started(false) { @@ -109,7 +110,9 @@ void microbit_hal_audio_init(uint32_t sample_rate) { MicroBitAudio::requestActivation(); data_source.started = true; data_source.callback = microbit_hal_audio_ready_callback; - uBit.audio.mixer.addChannel(data_source, sample_rate, 255); + data_source.channel = uBit.audio.mixer.addChannel(data_source, sample_rate, 255); + } else { + data_source.channel->setSampleRate(sample_rate); } } @@ -126,7 +129,9 @@ void microbit_hal_audio_speech_init(uint32_t sample_rate) { MicroBitAudio::requestActivation(); speech_source.started = true; speech_source.callback = microbit_hal_audio_speech_ready_callback; - uBit.audio.mixer.addChannel(speech_source, sample_rate, 255); + speech_source.channel = uBit.audio.mixer.addChannel(speech_source, sample_rate, 255); + } else { + speech_source.channel->setSampleRate(sample_rate); } } From e86bc106a62d0dc9979b811deccc54db90f2fb18 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 1 Mar 2024 10:17:37 +1100 Subject: [PATCH 25/50] codal_port/modspeech: Make default speech mode externally configurable. By defining MICROPY_PY_SPEECH_DEFAULT_MODE in mpconfigport.h. Signed-off-by: Damien George --- src/codal_port/modspeech.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/codal_port/modspeech.c b/src/codal_port/modspeech.c index 172254a..be0f6fd 100644 --- a/src/codal_port/modspeech.c +++ b/src/codal_port/modspeech.c @@ -37,6 +37,17 @@ #include "sam/reciter.h" #include "sam/sam.h" +// The default `mode` for say/pronounce/sing can be configured externally. +// The allowed values are: +// - 0 = traditional micro:bit v1, 15625Hz (not supported with USE_DEDICATED_AUDIO_CHANNEL) +// - 1 = standard sampling fidelity, 19000Hz +// - 2 = standard sampling fidelity, 19000Hz, with sample smoothing +// - 3 = higher sampling fidelity, 38000Hz +// - 4 = higher sampling fidelity, 38000Hz, with sample smoothing +#ifndef MICROPY_PY_SPEECH_DEFAULT_MODE +#define MICROPY_PY_SPEECH_DEFAULT_MODE (1) +#endif + // If disabled, pipe speech through audio module output. // If enabled, use a dedicated audio mixer channer with a double buffer. #define USE_DEDICATED_AUDIO_CHANNEL (1) @@ -386,7 +397,7 @@ STATIC mp_obj_t articulate(mp_obj_t phonemes, mp_uint_t n_args, const mp_obj_t * { MP_QSTR_mouth, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DEFAULT_MOUTH} }, { MP_QSTR_throat, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DEFAULT_THROAT} }, { MP_QSTR_debug, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, - { MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, + { MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = MICROPY_PY_SPEECH_DEFAULT_MODE} }, { MP_QSTR_volume, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 4} }, { MP_QSTR_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(µbit_pin_default_audio_obj)} }, }; From 03d5c04730038f80155c3dfbe8128e4f8e4587b2 Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Thu, 21 Mar 2024 15:53:58 +0000 Subject: [PATCH 26/50] codal_port/modspeech: include mphal.h for the simulator MICROPY_BEGIN_ATOMIC_SECTION/MICROPY_END_ATOMIC_SECTION are only defined in modspeech because of mpconfigport.h (indirectly). Include mphal.h so that the defaults are defined if the port does not define them (as in the sim case). --- src/codal_port/modspeech.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/codal_port/modspeech.c b/src/codal_port/modspeech.c index be0f6fd..32305b5 100644 --- a/src/codal_port/modspeech.c +++ b/src/codal_port/modspeech.c @@ -28,6 +28,7 @@ #include #include +#include "py/mphal.h" #include "py/obj.h" #include "py/objtuple.h" #include "py/objstr.h" From c36fd8275307829617e2516402d58ba10114ba7a Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 25 Mar 2024 10:30:33 +1100 Subject: [PATCH 27/50] codal_port/mphalport: Move irq and atomic section defns to mphalport.h. Following how this is has changed in MicroPython v1.22.0. Signed-off-by: Damien George --- src/codal_port/mpconfigport.h | 17 ----------------- src/codal_port/mphalport.h | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/codal_port/mpconfigport.h b/src/codal_port/mpconfigport.h index fcf2546..cca2378 100644 --- a/src/codal_port/mpconfigport.h +++ b/src/codal_port/mpconfigport.h @@ -121,23 +121,6 @@ #define MP_STATE_PORT MP_STATE_VM -// These functions allow nested calls. -extern void target_disable_irq(void); -extern void target_enable_irq(void); - -static inline uint32_t disable_irq(void) { - target_disable_irq(); - return 0; -} - -static inline void enable_irq(uint32_t state) { - (void)state; - target_enable_irq(); -} - -#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq() -#define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state) - #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((uint32_t)(p) | 1)) #define MP_SSIZE_MAX (0x7fffffff) diff --git a/src/codal_port/mphalport.h b/src/codal_port/mphalport.h index 951a8e1..cf5f546 100644 --- a/src/codal_port/mphalport.h +++ b/src/codal_port/mphalport.h @@ -28,6 +28,23 @@ #include "microbithal.h" #include "nrf.h" +#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq() +#define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state) + +// These functions allow nested calls. +extern void target_disable_irq(void); +extern void target_enable_irq(void); + +static inline uint32_t disable_irq(void) { + target_disable_irq(); + return 0; +} + +static inline void enable_irq(uint32_t state) { + (void)state; + target_enable_irq(); +} + static inline mp_uint_t mp_hal_ticks_cpu(void) { if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) { CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; From fbf0652a14f912f0deccb2a67b758ba8ba1e8a03 Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Fri, 22 Mar 2024 11:51:44 +0000 Subject: [PATCH 28/50] ci: Add macOS x86_64 and arm64 build jobs & update codal submodule. Updating the codal submodule fixes issue #172, building on Apple Silicon. --- .github/workflows/build.yml | 33 +++++++++++++++++++-------------- lib/codal | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 10bba8c..1718944 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,30 +10,35 @@ jobs: build: strategy: matrix: - os: [ubuntu-20.04] + # macos-13 is x86_64, and macos-14 is arm64 + os: [ubuntu-22.04, macos-13, macos-14] fail-fast: false runs-on: ${{ matrix.os }} name: build.py ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - - name: Install toolchain (Ubuntu) - if: runner.os == 'Linux' - run: | - sudo apt-get install -y gcc-arm-none-eabi libnewlib-arm-none-eabi - sudo apt-get install -y cmake + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + - uses: carlosperate/arm-none-eabi-gcc-action@v1 + with: + release: 10.3-2021.10 + - name: Install CMake v3.22 via PyPI + run: python -m pip install cmake==3.28.3 - name: Check Versions run: | arm-none-eabi-gcc --version cmake --version - - name: Build - run: | - make -C lib/micropython/mpy-cross -j2 - cd src - make -j2 + python --version + uname -a + - name: Build mpy-cross + run: make -C lib/micropython/mpy-cross -j2 + - name: Build MicroPython + run: make -C src -j2 - name: Upload hex file - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: MICROBIT-MICROPYTHON-${{ github.sha }}.hex + name: MICROBIT-MICROPYTHON-${{ github.sha }}-${{ matrix.os }}.hex path: src/MICROBIT.hex diff --git a/lib/codal b/lib/codal index 3864ea2..871d0fc 160000 --- a/lib/codal +++ b/lib/codal @@ -1 +1 @@ -Subproject commit 3864ea2e452f710ac3e09598996edee4df72a5bf +Subproject commit 871d0fccaf385a57f7cd2c2d61c644ec04107914 From 4a4c4c421e0180e2e4fc6b746a48dc85883d1663 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 26 Mar 2024 10:18:30 +1100 Subject: [PATCH 29/50] codal_port/microbit_pinmode: Add microbit_obj_pin_acquire_and_free(). Signed-off-by: Damien George --- src/codal_port/microbit_pinmode.c | 8 ++++++++ src/codal_port/modmicrobit.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/codal_port/microbit_pinmode.c b/src/codal_port/microbit_pinmode.c index ceb5a8f..e79849e 100644 --- a/src/codal_port/microbit_pinmode.c +++ b/src/codal_port/microbit_pinmode.c @@ -73,6 +73,14 @@ bool microbit_obj_pin_acquire(const microbit_pin_obj_t *pin, const microbit_pinm } } +void microbit_obj_pin_acquire_and_free(const microbit_pin_obj_t **old_pin, const microbit_pin_obj_t *new_pin, const microbit_pinmode_t *new_mode) { + microbit_obj_pin_acquire(new_pin, new_mode); + if (*old_pin != new_pin) { + microbit_obj_pin_free(*old_pin); + *old_pin = new_pin; + } +} + static void noop(const microbit_pin_obj_t *pin) { (void)pin; } diff --git a/src/codal_port/modmicrobit.h b/src/codal_port/modmicrobit.h index 455cae6..3b753af 100644 --- a/src/codal_port/modmicrobit.h +++ b/src/codal_port/modmicrobit.h @@ -220,6 +220,9 @@ bool microbit_obj_pin_can_be_acquired(const microbit_pin_obj_t *pin); // Not safe to call in an interrupt as it may raise if pin can't be acquired. bool microbit_obj_pin_acquire(const microbit_pin_obj_t *pin, const microbit_pinmode_t *mode); +// Acquire a new pin and free a previous one, for the given mode. +void microbit_obj_pin_acquire_and_free(const microbit_pin_obj_t **old_pin, const microbit_pin_obj_t *new_pin, const microbit_pinmode_t *new_mode); + // Change the mode of a pin. This does not check the existing mode, nor release any // resources, and should only be used if pin resources are managed by the caller. void microbit_pin_set_mode(const microbit_pin_obj_t *pin, const microbit_pinmode_t *mode); From af721c760d8663195e749c7e2b4d97d4f632c258 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 26 Mar 2024 10:19:11 +1100 Subject: [PATCH 30/50] codal_port: Correctly acquire and free I2C and SPI pins. This makes sure that pins that are currently used for I2C and SPI are in the correct pin mode, and pins that were previously but no longer used for I2C/SPI are freed. Fixes issue #167. Signed-off-by: Damien George --- src/codal_port/microbit_i2c.c | 12 ++++++++++-- src/codal_port/microbit_spi.c | 18 +++++++++++------- src/codal_port/modmicrobit.h | 4 ++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/codal_port/microbit_i2c.c b/src/codal_port/microbit_i2c.c index 90b007e..b82b0a5 100644 --- a/src/codal_port/microbit_i2c.c +++ b/src/codal_port/microbit_i2c.c @@ -31,6 +31,8 @@ typedef struct _microbit_i2c_obj_t { mp_obj_base_t base; + const microbit_pin_obj_t *scl; + const microbit_pin_obj_t *sda; } microbit_i2c_obj_t; STATIC mp_obj_t microbit_i2c_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -55,8 +57,12 @@ STATIC mp_obj_t microbit_i2c_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp scl = microbit_obj_get_pin(args[ARG_scl].u_obj); } + // Acquire new pins and free the previous ones. + microbit_obj_pin_acquire_and_free(µbit_i2c_obj.scl, scl, microbit_pin_mode_i2c); + microbit_obj_pin_acquire_and_free(µbit_i2c_obj.sda, sda, microbit_pin_mode_i2c); + // Initialise the I2C bus. - int ret =microbit_hal_i2c_init(scl->name, sda->name, args[ARG_freq].u_int); + int ret = microbit_hal_i2c_init(scl->name, sda->name, args[ARG_freq].u_int); if (ret != 0) { mp_raise_OSError(ret); @@ -149,6 +155,8 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, µbit_i2c_locals_dict ); -const microbit_i2c_obj_t microbit_i2c_obj = { +microbit_i2c_obj_t microbit_i2c_obj = { { µbit_i2c_type }, + .scl = µbit_p19_obj, + .sda = µbit_p20_obj, }; diff --git a/src/codal_port/microbit_spi.c b/src/codal_port/microbit_spi.c index 5962063..bd4a923 100644 --- a/src/codal_port/microbit_spi.c +++ b/src/codal_port/microbit_spi.c @@ -32,6 +32,9 @@ typedef struct _microbit_spi_obj_t { mp_obj_base_t base; + const microbit_pin_obj_t *sclk; + const microbit_pin_obj_t *mosi; + const microbit_pin_obj_t *miso; } microbit_spi_obj_t; STATIC bool microbit_spi_initialised = false; @@ -71,12 +74,10 @@ STATIC mp_obj_t microbit_spi_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp miso = microbit_obj_get_pin(args[ARG_miso].u_obj); } - // Initialise the pins. - // Note: the pins are not freed, so init'ing the SPI a second time on - // different pins will leave the old pins still in SPI mode. - microbit_obj_pin_acquire(sclk, microbit_pin_mode_spi); - microbit_obj_pin_acquire(mosi, microbit_pin_mode_spi); - microbit_obj_pin_acquire(miso, microbit_pin_mode_spi); + // Acquire new pins and free the previous ones. + microbit_obj_pin_acquire_and_free(µbit_spi_obj.sclk, sclk, microbit_pin_mode_spi); + microbit_obj_pin_acquire_and_free(µbit_spi_obj.mosi, mosi, microbit_pin_mode_spi); + microbit_obj_pin_acquire_and_free(µbit_spi_obj.miso, miso, microbit_pin_mode_spi); // Initialise the SPI bus. int ret = microbit_hal_spi_init(sclk->name, mosi->name, miso->name, @@ -147,6 +148,9 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, µbit_spi_locals_dict ); -const microbit_spi_obj_t microbit_spi_obj = { +microbit_spi_obj_t microbit_spi_obj = { { µbit_spi_type }, + .sclk = µbit_p13_obj, + .mosi = µbit_p15_obj, + .miso = µbit_p14_obj, }; diff --git a/src/codal_port/modmicrobit.h b/src/codal_port/modmicrobit.h index 3b753af..fc0ce94 100644 --- a/src/codal_port/modmicrobit.h +++ b/src/codal_port/modmicrobit.h @@ -111,9 +111,9 @@ extern const struct _microbit_pin_obj_t microbit_p20_obj; extern const struct _microbit_pin_obj_t microbit_pin_logo_obj; extern const struct _microbit_pin_obj_t microbit_pin_speaker_obj; -extern const struct _microbit_i2c_obj_t microbit_i2c_obj; +extern struct _microbit_i2c_obj_t microbit_i2c_obj; extern const struct _microbit_uart_obj_t microbit_uart_obj; -extern const struct _microbit_spi_obj_t microbit_spi_obj; +extern struct _microbit_spi_obj_t microbit_spi_obj; extern const struct _monochrome_5by5_t microbit_const_image_heart_obj; extern const struct _monochrome_5by5_t microbit_const_image_heart_small_obj; From 3074c81e385cec0db0c493f093263f9c34e35912 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 26 Mar 2024 10:27:24 +1100 Subject: [PATCH 31/50] codal_app/main: Initialise logo pin in capacitive touch mode. Capacitive touch mode is more sensitive. The other (edge connector) pins are left in resistive touch mode by default, to match micro:bit v1. Signed-off-by: Damien George --- src/codal_app/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/codal_app/main.cpp b/src/codal_app/main.cpp index 00e91a9..09c89f7 100644 --- a/src/codal_app/main.cpp +++ b/src/codal_app/main.cpp @@ -75,6 +75,9 @@ int main() { uBit.audio.setSpeakerEnabled(true); uBit.audio.setPinEnabled(false); + // Initialise the logo pin in capacitive touch mode. + uBit.io.logo.isTouched(TouchMode::Capacitative); + mp_main(); return 0; } From 8d9067d91bcfe316cd3aea5af1a873a37ca23d13 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 26 Mar 2024 10:47:54 +1100 Subject: [PATCH 32/50] codal_port/microbit_soundeffect: Apply param and steps when changing fx. Fixes issue #155. Signed-off-by: Damien George --- src/codal_port/microbit_soundeffect.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/codal_port/microbit_soundeffect.c b/src/codal_port/microbit_soundeffect.c index 836ec9a..cdc1fc4 100644 --- a/src/codal_port/microbit_soundeffect.c +++ b/src/codal_port/microbit_soundeffect.c @@ -69,6 +69,14 @@ #define SOUND_EFFECT_FX_VIBRATO (1) #define SOUND_EFFECT_FX_WARBLE (3) +// These default fx values are the same as used by MakeCode. +#define SOUND_EFFECT_FX_VIBRATO_DEFAULT_PARAM (2) +#define SOUND_EFFECT_FX_TREMOLO_DEFAULT_PARAM (3) +#define SOUND_EFFECT_FX_WARBLE_DEFAULT_PARAM (2) +#define SOUND_EFFECT_FX_VIBRATO_DEFAULT_STEPS (512) +#define SOUND_EFFECT_FX_TREMOLO_DEFAULT_STEPS (900) +#define SOUND_EFFECT_FX_WARBLE_DEFAULT_STEPS (700) + #define SOUND_EFFECT_DEFAULT_FREQ_START (500) #define SOUND_EFFECT_DEFAULT_FREQ_END (2500) #define SOUND_EFFECT_DEFAULT_DURATION (500) @@ -116,6 +124,18 @@ STATIC const soundeffect_attr_t soundeffect_attr_table[] = { { MP_QSTR_shape, SOUND_EXPR_SHAPE_OFFSET, SOUND_EXPR_SHAPE_LENGTH }, }; +static const uint8_t fx_default_param[] = { + [SOUND_EFFECT_FX_VIBRATO] = SOUND_EFFECT_FX_VIBRATO_DEFAULT_PARAM, + [SOUND_EFFECT_FX_TREMOLO] = SOUND_EFFECT_FX_TREMOLO_DEFAULT_PARAM, + [SOUND_EFFECT_FX_WARBLE] = SOUND_EFFECT_FX_WARBLE_DEFAULT_PARAM, +}; + +static const uint16_t fx_default_steps[] = { + [SOUND_EFFECT_FX_VIBRATO] = SOUND_EFFECT_FX_VIBRATO_DEFAULT_STEPS, + [SOUND_EFFECT_FX_TREMOLO] = SOUND_EFFECT_FX_TREMOLO_DEFAULT_STEPS, + [SOUND_EFFECT_FX_WARBLE] = SOUND_EFFECT_FX_WARBLE_DEFAULT_STEPS, +}; + const char *microbit_soundeffect_get_sound_expr_data(mp_obj_t self_in) { const microbit_soundeffect_obj_t *self = MP_OBJ_TO_PTR(self_in); return &self->sound_expr[0]; @@ -273,6 +293,11 @@ STATIC void microbit_soundeffect_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des if (self->is_mutable) { unsigned int value = mp_obj_get_int(dest[1]); sound_expr_encode(self, soundeffect_attr->offset, soundeffect_attr->length, value); + if (soundeffect_attr->offset == SOUND_EXPR_FX_CHOICE_OFFSET) { + // Changing the fx choice, so also update the fx parameters for that choice. + sound_expr_encode(self, SOUND_EXPR_FX_PARAM_OFFSET, SOUND_EXPR_FX_PARAM_LENGTH, fx_default_param[value]); + sound_expr_encode(self, SOUND_EXPR_FX_STEPS_OFFSET, SOUND_EXPR_FX_STEPS_LENGTH, fx_default_steps[value]); + } dest[0] = MP_OBJ_NULL; // Indicate store succeeded. } } From 90b9b7d3dd30fd5f9e65b08f3b6315c13824e2d8 Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Tue, 16 Apr 2024 14:36:45 +0100 Subject: [PATCH 33/50] codal_port/ticks_cpu: Check CoreDebug DEMCR trace enable bit. The DAPLink controlled reset button performs a target reset via SWD, and the CoreDebug trace enable bit seems to be cleared while the DWT->CTRL cycle count enable bit is not. https://github.com/microbit-foundation/micropython-microbit-v2/issues/179#issuecomment-2059077656 --- src/codal_port/mphalport.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codal_port/mphalport.h b/src/codal_port/mphalport.h index cf5f546..a4d5405 100644 --- a/src/codal_port/mphalport.h +++ b/src/codal_port/mphalport.h @@ -46,7 +46,7 @@ static inline void enable_irq(uint32_t state) { } static inline mp_uint_t mp_hal_ticks_cpu(void) { - if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) { + if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk) || !(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk)) { CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; DWT->CYCCNT = 0; DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; From f1a4647d3bbcf2e4a2392c34da6e2243b1802c0d Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Wed, 27 Mar 2024 17:54:59 +0000 Subject: [PATCH 34/50] codal_app: Enable the Utility Service in BLE Pairing Mode. This service enables datalog access to the apps, to be able to view the logged data without a computer. This flag enables the service in pairing mode only and should have no effect when running MicroPython. --- src/codal_app/codal.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/codal_app/codal.json b/src/codal_app/codal.json index 6d15e8c..f1d9977 100644 --- a/src/codal_app/codal.json +++ b/src/codal_app/codal.json @@ -12,6 +12,7 @@ "MICROBIT_BLE_PAIRING_MODE": 1, "MICROBIT_BLE_PARTIAL_FLASHING" : 1, "MICROBIT_BLE_SECURITY_MODE": 2, + "MICROBIT_BLE_UTILITY_SERVICE_PAIRING": 1, "MICROBIT_USB_SERIAL_WAKE": 1, "LEVEL_DETECTOR_SPL_8BIT_000_POINT": 52.0 }, From c143b24acf26fdebc6eb965c625430521d4a0c21 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 30 Apr 2024 18:03:32 +1000 Subject: [PATCH 35/50] codal_port/modaudio: Make audio.stop() also stop sound expressions. Fixes issue #180. Signed-off-by: Damien George --- src/codal_port/modaudio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/codal_port/modaudio.c b/src/codal_port/modaudio.c index 5c292bc..6a4497f 100644 --- a/src/codal_port/modaudio.c +++ b/src/codal_port/modaudio.c @@ -54,6 +54,7 @@ static inline bool audio_is_running(void) { void microbit_audio_stop(void) { audio_source_iter = NULL; + microbit_hal_audio_stop_expression(); } STATIC void audio_buffer_ready(void) { From 15b467c44936b532fac529b810bdfcbba4dfb307 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 30 Apr 2024 18:12:38 +1000 Subject: [PATCH 36/50] codal_port/modaudio: Ignore return_pin argument to audio.play(). On v2 this should be ignored, as per the docs. Fixes issue #181. Signed-off-by: Damien George --- src/codal_port/modaudio.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/codal_port/modaudio.c b/src/codal_port/modaudio.c index 6a4497f..2462d62 100644 --- a/src/codal_port/modaudio.c +++ b/src/codal_port/modaudio.c @@ -212,6 +212,7 @@ STATIC mp_obj_t stop(void) { MP_DEFINE_CONST_FUN_OBJ_0(microbit_audio_stop_obj, stop); STATIC mp_obj_t play(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + // Note: the return_pin argument is for compatibility with micro:bit v1 and is ignored on v2. static const mp_arg_t allowed_args[] = { { MP_QSTR_source, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_wait, MP_ARG_BOOL, {.u_bool = true} }, @@ -222,11 +223,6 @@ STATIC mp_obj_t play(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - // The return_pin argument from micro:bit v1 is no longer supported. - if (args[3].u_obj != mp_const_none) { - mp_raise_ValueError(MP_ERROR_TEXT("return_pin not supported")); - } - mp_obj_t src = args[0].u_obj; microbit_audio_play_source(src, args[2].u_obj, args[1].u_bool, DEFAULT_SAMPLE_RATE); return mp_const_none; From ef2a57ea101647bb4b72c51aca2a0b4e6157c36d Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 20 May 2024 14:46:55 +1000 Subject: [PATCH 37/50] codal_port/microbit_spi: Raise ValueError if spi.read arg is negative. Fixes issue #208. Signed-off-by: Damien George --- src/codal_port/microbit_spi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/codal_port/microbit_spi.c b/src/codal_port/microbit_spi.c index bd4a923..9ea5a36 100644 --- a/src/codal_port/microbit_spi.c +++ b/src/codal_port/microbit_spi.c @@ -104,8 +104,12 @@ MP_DEFINE_CONST_FUN_OBJ_2(microbit_spi_write_obj, microbit_spi_write); STATIC mp_obj_t microbit_spi_read(size_t n_args, const mp_obj_t *args) { microbit_spi_check_initialised(); + mp_int_t nbytes = mp_obj_get_int(args[1]); + if (nbytes < 0) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid number of bytes")); + } vstr_t vstr; - vstr_init_len(&vstr, mp_obj_get_int(args[1])); + vstr_init_len(&vstr, nbytes); uint8_t byte_out = 0; if (n_args == 3) { byte_out = mp_obj_get_int(args[2]); From 41245c88504594d7c87d7a868065da9508085878 Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Wed, 8 May 2024 15:06:16 +0100 Subject: [PATCH 38/50] codal_port/Makefile: Keep C/C++ flags set up by MicroPython lib. --- src/codal_port/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/codal_port/Makefile b/src/codal_port/Makefile index f7694e6..c6b4643 100644 --- a/src/codal_port/Makefile +++ b/src/codal_port/Makefile @@ -45,7 +45,8 @@ INC += -I$(BUILD) CWARN = -Wall -Werror CWARN += -Wpointer-arith -Wuninitialized CFLAGS_ARCH += -DNRF52833_XXAA -CFLAGS = $(INC) $(CWARN) -std=c99 $(CFLAGS_MOD) $(CFLAGS_ARCH) $(COPT) $(CFLAGS_EXTRA) +CFLAGS += $(INC) $(CWARN) -std=c99 $(CFLAGS_MOD) $(CFLAGS_ARCH) $(COPT) $(CFLAGS_EXTRA) +CXXFLAGS += $(filter-out -std=c99,$(CFLAGS)) # Debugging/Optimization ifdef DEBUG @@ -56,7 +57,7 @@ endif CFLAGS += -g LDFLAGS_ARCH = -Wl,-map,$@.map -LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA) +LDFLAGS += $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA) SRC_C += \ drv_display.c \ From 8b8c1d3802164abe40659edde9cf3a717aabfde4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 20 May 2024 15:16:39 +1000 Subject: [PATCH 39/50] codal_port/microbit_soundevent: Add SoundEvent.CLAP object. The CODAL will emit a clap event if a "clap" is detected, and this new SoundEvent.CLAP object can be used to detect that. Signed-off-by: Damien George --- src/codal_app/microbithal.h | 1 + src/codal_port/microbit_microphone.c | 4 ++++ src/codal_port/microbit_soundevent.c | 6 ++++++ src/codal_port/modmicrobit.h | 1 + 4 files changed, 12 insertions(+) diff --git a/src/codal_app/microbithal.h b/src/codal_app/microbithal.h index e276bea..0292121 100644 --- a/src/codal_app/microbithal.h +++ b/src/codal_app/microbithal.h @@ -90,6 +90,7 @@ extern "C" { // Microphone events, passed to microbit_hal_level_detector_callback(). #define MICROBIT_HAL_MICROPHONE_EVT_THRESHOLD_LOW (1) #define MICROBIT_HAL_MICROPHONE_EVT_THRESHOLD_HIGH (2) +#define MICROBIT_HAL_MICROPHONE_EVT_CLAP (8) // Threshold kind, passed to microbit_hal_microphone_set_threshold(). #define MICROBIT_HAL_MICROPHONE_SET_THRESHOLD_LOW (0) diff --git a/src/codal_port/microbit_microphone.c b/src/codal_port/microbit_microphone.c index af44112..2d2cb21 100644 --- a/src/codal_port/microbit_microphone.c +++ b/src/codal_port/microbit_microphone.c @@ -32,6 +32,7 @@ #define SOUND_EVENT_QUIET (0) #define SOUND_EVENT_LOUD (1) +#define SOUND_EVENT_CLAP (2) typedef struct _microbit_microphone_obj_t { mp_obj_base_t base; @@ -40,6 +41,7 @@ typedef struct _microbit_microphone_obj_t { static const mp_const_obj_t sound_event_obj_map[] = { [SOUND_EVENT_QUIET] = MP_ROM_PTR(µbit_soundevent_quiet_obj), [SOUND_EVENT_LOUD] = MP_ROM_PTR(µbit_soundevent_loud_obj), + [SOUND_EVENT_CLAP] = MP_ROM_PTR(µbit_soundevent_clap_obj), }; static uint8_t sound_event_current = SOUND_EVENT_QUIET; @@ -54,6 +56,8 @@ void microbit_hal_level_detector_callback(int value) { ev = SOUND_EVENT_QUIET; } else if (value == MICROBIT_HAL_MICROPHONE_EVT_THRESHOLD_HIGH) { ev = SOUND_EVENT_LOUD; + } else if (value == MICROBIT_HAL_MICROPHONE_EVT_CLAP) { + ev = SOUND_EVENT_CLAP; } else { // Ignore unknown events. return; diff --git a/src/codal_port/microbit_soundevent.c b/src/codal_port/microbit_soundevent.c index 08ffba3..4de0494 100644 --- a/src/codal_port/microbit_soundevent.c +++ b/src/codal_port/microbit_soundevent.c @@ -42,6 +42,11 @@ const microbit_soundevent_obj_t microbit_soundevent_quiet_obj = { MP_QSTR_quiet, }; +const microbit_soundevent_obj_t microbit_soundevent_clap_obj = { + { µbit_soundevent_type }, + MP_QSTR_clap, +}; + STATIC void microbit_soundevent_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { microbit_soundevent_obj_t *self = (microbit_soundevent_obj_t *)self_in; mp_printf(print, "SoundEvent('%q')", self->name); @@ -50,6 +55,7 @@ STATIC void microbit_soundevent_print(const mp_print_t *print, mp_obj_t self_in, STATIC const mp_rom_map_elem_t microbit_soundevent_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_LOUD), MP_ROM_PTR(µbit_soundevent_loud_obj) }, { MP_ROM_QSTR(MP_QSTR_QUIET), MP_ROM_PTR(µbit_soundevent_quiet_obj) }, + { MP_ROM_QSTR(MP_QSTR_CLAP), MP_ROM_PTR(µbit_soundevent_clap_obj) }, }; STATIC MP_DEFINE_CONST_DICT(microbit_soundevent_locals_dict, microbit_soundevent_locals_dict_table); diff --git a/src/codal_port/modmicrobit.h b/src/codal_port/modmicrobit.h index fc0ce94..b4a5da4 100644 --- a/src/codal_port/modmicrobit.h +++ b/src/codal_port/modmicrobit.h @@ -184,6 +184,7 @@ extern const struct _monochrome_5by5_t microbit_const_image_scissors_obj; extern const microbit_soundevent_obj_t microbit_soundevent_loud_obj; extern const microbit_soundevent_obj_t microbit_soundevent_quiet_obj; +extern const microbit_soundevent_obj_t microbit_soundevent_clap_obj; extern struct _microbit_display_obj_t microbit_display_obj; extern const struct _microbit_accelerometer_obj_t microbit_accelerometer_obj; From 1a19abb001c3a5b2f6403d95ea472ef75f5458ba Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Aug 2024 12:49:26 +1000 Subject: [PATCH 40/50] lib/micropython: Update micropython submodule to v1.23.0. Signed-off-by: Damien George --- lib/micropython | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/micropython b/lib/micropython index 9feb068..a61c446 160000 --- a/lib/micropython +++ b/lib/micropython @@ -1 +1 @@ -Subproject commit 9feb0689eeaca5ce88aedcc680f997a3b4d0221c +Subproject commit a61c446c0b34e82aeb54b9770250d267656f2b7f From 7c304ec8e619b7fe8d2186cf0e87281aad7f1259 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Aug 2024 12:49:43 +1000 Subject: [PATCH 41/50] codal_port: Update to build with latest micropython. The only change in this commit is renaming STATIC->static. Signed-off-by: Damien George --- src/codal_port/drv_display.c | 4 +- src/codal_port/drv_image.c | 2 +- src/codal_port/drv_softtimer.c | 2 +- src/codal_port/iters.c | 2 +- src/codal_port/main.c | 2 +- src/codal_port/microbit_accelerometer.c | 58 ++++++++-------- src/codal_port/microbit_button.c | 4 +- src/codal_port/microbit_compass.c | 38 +++++----- src/codal_port/microbit_display.c | 10 +-- src/codal_port/microbit_i2c.c | 14 ++-- src/codal_port/microbit_image.c | 32 ++++----- src/codal_port/microbit_microphone.c | 32 ++++----- src/codal_port/microbit_pin.c | 16 ++--- src/codal_port/microbit_pinaudio.c | 2 +- src/codal_port/microbit_sound.c | 8 +-- src/codal_port/microbit_soundeffect.c | 30 ++++---- src/codal_port/microbit_soundevent.c | 6 +- src/codal_port/microbit_speaker.c | 14 ++-- src/codal_port/microbit_spi.c | 18 ++--- src/codal_port/microbit_uart.c | 20 +++--- src/codal_port/microbitfs.c | 92 ++++++++++++------------- src/codal_port/modantigravity.c | 14 ++-- src/codal_port/modaudio.c | 26 +++---- src/codal_port/modlog.c | 24 +++---- src/codal_port/modlove.c | 12 ++-- src/codal_port/modmachine.c | 20 +++--- src/codal_port/modmicrobit.c | 42 +++++------ src/codal_port/modmusic.c | 30 ++++---- src/codal_port/modos.c | 26 +++---- src/codal_port/modpower.c | 14 ++-- src/codal_port/modradio.c | 32 ++++----- src/codal_port/modspeech.c | 26 +++---- src/codal_port/modthis.c | 12 ++-- 33 files changed, 342 insertions(+), 342 deletions(-) diff --git a/src/codal_port/drv_display.c b/src/codal_port/drv_display.c index 03823d1..e2c5f75 100644 --- a/src/codal_port/drv_display.c +++ b/src/codal_port/drv_display.c @@ -44,7 +44,7 @@ static mp_uint_t async_delay = 1000; static mp_uint_t async_tick = 0; static bool async_clear = false; -STATIC void async_stop(void) { +static void async_stop(void) { async_iterator = NULL; async_mode = ASYNC_MODE_STOPPED; async_tick = 0; @@ -62,7 +62,7 @@ void microbit_display_stop(void) { MP_STATE_PORT(display_data) = NULL; } -STATIC void wait_for_event() { +static void wait_for_event() { while (!wakeup_event) { // allow CTRL-C to stop the animation if (MP_STATE_THREAD(mp_pending_exception) != MP_OBJ_NULL) { diff --git a/src/codal_port/drv_image.c b/src/codal_port/drv_image.c index 7e650b8..4a1877c 100644 --- a/src/codal_port/drv_image.c +++ b/src/codal_port/drv_image.c @@ -35,7 +35,7 @@ const monochrome_5by5_t microbit_blank_image = { { 0, 0, 0 } }; -STATIC uint8_t monochrome_get_pixel(monochrome_5by5_t *self, mp_int_t x, mp_int_t y) { +static uint8_t monochrome_get_pixel(monochrome_5by5_t *self, mp_int_t x, mp_int_t y) { unsigned int index = y*5+x; if (index == 24) return self->pixel44; diff --git a/src/codal_port/drv_softtimer.c b/src/codal_port/drv_softtimer.c index 6dfcafd..b780470 100644 --- a/src/codal_port/drv_softtimer.c +++ b/src/codal_port/drv_softtimer.c @@ -32,7 +32,7 @@ static bool microbit_soft_timer_paused = false; -STATIC int microbit_soft_timer_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { +static int microbit_soft_timer_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { microbit_soft_timer_entry_t *e1 = (microbit_soft_timer_entry_t *)n1; microbit_soft_timer_entry_t *e2 = (microbit_soft_timer_entry_t *)n2; return TICKS_DIFF(e1->expiry_ms, e2->expiry_ms) < 0; diff --git a/src/codal_port/iters.c b/src/codal_port/iters.c index dbfe306..b199095 100644 --- a/src/codal_port/iters.c +++ b/src/codal_port/iters.c @@ -42,7 +42,7 @@ static mp_obj_t microbit_repeat_iter_next(mp_obj_t iter_in) { return mp_obj_subscr(iter->iterable, MP_OBJ_NEW_SMALL_INT(iter->index), MP_OBJ_SENTINEL); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( microbit_repeat_iterator_type, MP_QSTR_iterator, MP_TYPE_FLAG_ITER_IS_ITERNEXT, diff --git a/src/codal_port/main.c b/src/codal_port/main.c index 8592e9b..88d5ba9 100644 --- a/src/codal_port/main.c +++ b/src/codal_port/main.c @@ -96,7 +96,7 @@ void mp_main(void) { } } -STATIC void microbit_display_exception(mp_obj_t exc_in) { +static void microbit_display_exception(mp_obj_t exc_in) { // Construct the message string ready for display. mp_uint_t n, *values; mp_obj_exception_get_traceback(exc_in, &n, &values); diff --git a/src/codal_port/microbit_accelerometer.c b/src/codal_port/microbit_accelerometer.c index dfd096b..1ef1d61 100644 --- a/src/codal_port/microbit_accelerometer.c +++ b/src/codal_port/microbit_accelerometer.c @@ -36,11 +36,11 @@ typedef struct _microbit_accelerometer_obj_t { } microbit_accelerometer_obj_t; volatile bool accelerometer_up_to_date = false; -STATIC volatile uint16_t gesture_state = 0; // 1 bit per gesture -STATIC volatile uint8_t gesture_list_cur = 0; // index into gesture_list -STATIC volatile uint8_t gesture_list[GESTURE_LIST_SIZE] = {0}; // list of pending gestures, 4-bits per element +static volatile uint16_t gesture_state = 0; // 1 bit per gesture +static volatile uint8_t gesture_list_cur = 0; // index into gesture_list +static volatile uint8_t gesture_list[GESTURE_LIST_SIZE] = {0}; // list of pending gestures, 4-bits per element -STATIC const qstr gesture_name_map[] = { +static const qstr gesture_name_map[] = { [MICROBIT_HAL_ACCELEROMETER_EVT_NONE] = MP_QSTR_, [MICROBIT_HAL_ACCELEROMETER_EVT_TILT_UP] = MP_QSTR_up, [MICROBIT_HAL_ACCELEROMETER_EVT_TILT_DOWN] = MP_QSTR_down, @@ -56,7 +56,7 @@ STATIC const qstr gesture_name_map[] = { [MICROBIT_HAL_ACCELEROMETER_EVT_SHAKE] = MP_QSTR_shake, }; -STATIC uint32_t gesture_from_obj(mp_obj_t gesture_in) { +static uint32_t gesture_from_obj(mp_obj_t gesture_in) { qstr gesture = mp_obj_str_get_qstr(gesture_in); for (uint i = 0; i < MP_ARRAY_SIZE(gesture_name_map); ++i) { if (gesture == gesture_name_map[i]) { @@ -66,7 +66,7 @@ STATIC uint32_t gesture_from_obj(mp_obj_t gesture_in) { mp_raise_ValueError(MP_ERROR_TEXT("invalid gesture")); } -STATIC void update_for_gesture(void) { +static void update_for_gesture(void) { if (!accelerometer_up_to_date) { accelerometer_up_to_date = true; int axis[3]; @@ -90,31 +90,31 @@ void microbit_hal_gesture_callback(int value) { } } -STATIC mp_obj_t microbit_accelerometer_get_x(mp_obj_t self_in) { +static mp_obj_t microbit_accelerometer_get_x(mp_obj_t self_in) { (void)self_in; int axis[3]; microbit_hal_accelerometer_get_sample(axis); return mp_obj_new_int(axis[0]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_x_obj, microbit_accelerometer_get_x); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_x_obj, microbit_accelerometer_get_x); -STATIC mp_obj_t microbit_accelerometer_get_y(mp_obj_t self_in) { +static mp_obj_t microbit_accelerometer_get_y(mp_obj_t self_in) { (void)self_in; int axis[3]; microbit_hal_accelerometer_get_sample(axis); return mp_obj_new_int(axis[1]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_y_obj, microbit_accelerometer_get_y); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_y_obj, microbit_accelerometer_get_y); -STATIC mp_obj_t microbit_accelerometer_get_z(mp_obj_t self_in) { +static mp_obj_t microbit_accelerometer_get_z(mp_obj_t self_in) { (void)self_in; int axis[3]; microbit_hal_accelerometer_get_sample(axis); return mp_obj_new_int(axis[2]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_z_obj, microbit_accelerometer_get_z); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_z_obj, microbit_accelerometer_get_z); -STATIC mp_obj_t microbit_accelerometer_get_values(mp_obj_t self_in) { +static mp_obj_t microbit_accelerometer_get_values(mp_obj_t self_in) { (void)self_in; int axis[3]; microbit_hal_accelerometer_get_sample(axis); @@ -125,33 +125,33 @@ STATIC mp_obj_t microbit_accelerometer_get_values(mp_obj_t self_in) { }; return mp_obj_new_tuple(3, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_values_obj, microbit_accelerometer_get_values); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_values_obj, microbit_accelerometer_get_values); -STATIC mp_obj_t microbit_accelerometer_get_strength(mp_obj_t self_in) { +static mp_obj_t microbit_accelerometer_get_strength(mp_obj_t self_in) { (void)self_in; int axis[3]; microbit_hal_accelerometer_get_sample(axis); int strength = sqrtf(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]); return mp_obj_new_int(strength); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_strength_obj, microbit_accelerometer_get_strength); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_strength_obj, microbit_accelerometer_get_strength); -STATIC mp_obj_t microbit_accelerometer_current_gesture(mp_obj_t self_in) { +static mp_obj_t microbit_accelerometer_current_gesture(mp_obj_t self_in) { (void)self_in; update_for_gesture(); return MP_OBJ_NEW_QSTR(gesture_name_map[microbit_hal_accelerometer_get_gesture()]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_current_gesture_obj, microbit_accelerometer_current_gesture); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_current_gesture_obj, microbit_accelerometer_current_gesture); -STATIC mp_obj_t microbit_accelerometer_is_gesture(mp_obj_t self_in, mp_obj_t gesture_in) { +static mp_obj_t microbit_accelerometer_is_gesture(mp_obj_t self_in, mp_obj_t gesture_in) { (void)self_in; uint32_t gesture = gesture_from_obj(gesture_in); update_for_gesture(); return mp_obj_new_bool(microbit_hal_accelerometer_get_gesture() == gesture); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(microbit_accelerometer_is_gesture_obj, microbit_accelerometer_is_gesture); +static MP_DEFINE_CONST_FUN_OBJ_2(microbit_accelerometer_is_gesture_obj, microbit_accelerometer_is_gesture); -STATIC mp_obj_t microbit_accelerometer_was_gesture(mp_obj_t self_in, mp_obj_t gesture_in) { +static mp_obj_t microbit_accelerometer_was_gesture(mp_obj_t self_in, mp_obj_t gesture_in) { (void)self_in; uint32_t gesture = gesture_from_obj(gesture_in); update_for_gesture(); @@ -160,9 +160,9 @@ STATIC mp_obj_t microbit_accelerometer_was_gesture(mp_obj_t self_in, mp_obj_t ge gesture_list_cur = 0; return result; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(microbit_accelerometer_was_gesture_obj, microbit_accelerometer_was_gesture); +static MP_DEFINE_CONST_FUN_OBJ_2(microbit_accelerometer_was_gesture_obj, microbit_accelerometer_was_gesture); -STATIC mp_obj_t microbit_accelerometer_get_gestures(mp_obj_t self_in) { +static mp_obj_t microbit_accelerometer_get_gestures(mp_obj_t self_in) { (void)self_in; update_for_gesture(); if (gesture_list_cur == 0) { @@ -176,16 +176,16 @@ STATIC mp_obj_t microbit_accelerometer_get_gestures(mp_obj_t self_in) { gesture_list_cur = 0; return o; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_gestures_obj, microbit_accelerometer_get_gestures); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_accelerometer_get_gestures_obj, microbit_accelerometer_get_gestures); -STATIC mp_obj_t microbit_accelerometer_set_range(mp_obj_t self_in, mp_obj_t g) { +static mp_obj_t microbit_accelerometer_set_range(mp_obj_t self_in, mp_obj_t g) { (void)self_in; microbit_hal_accelerometer_set_range(mp_obj_get_int(g)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(microbit_accelerometer_set_range_obj, microbit_accelerometer_set_range); +static MP_DEFINE_CONST_FUN_OBJ_2(microbit_accelerometer_set_range_obj, microbit_accelerometer_set_range); -STATIC const mp_rom_map_elem_t microbit_accelerometer_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_accelerometer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get_x), MP_ROM_PTR(µbit_accelerometer_get_x_obj) }, { MP_ROM_QSTR(MP_QSTR_get_y), MP_ROM_PTR(µbit_accelerometer_get_y_obj) }, { MP_ROM_QSTR(MP_QSTR_get_z), MP_ROM_PTR(µbit_accelerometer_get_z_obj) }, @@ -197,9 +197,9 @@ STATIC const mp_rom_map_elem_t microbit_accelerometer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get_gestures), MP_ROM_PTR(µbit_accelerometer_get_gestures_obj) }, { MP_ROM_QSTR(MP_QSTR_set_range), MP_ROM_PTR(µbit_accelerometer_set_range_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_accelerometer_locals_dict, microbit_accelerometer_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_accelerometer_locals_dict, microbit_accelerometer_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( microbit_accelerometer_type, MP_QSTR_MicroBitAccelerometer, MP_TYPE_FLAG_NONE, diff --git a/src/codal_port/microbit_button.c b/src/codal_port/microbit_button.c index a62d778..ce3eab3 100644 --- a/src/codal_port/microbit_button.c +++ b/src/codal_port/microbit_button.c @@ -56,13 +56,13 @@ mp_obj_t microbit_button_was_pressed(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(microbit_button_was_pressed_obj, microbit_button_was_pressed); -STATIC const mp_map_elem_t microbit_button_locals_dict_table[] = { +static const mp_map_elem_t microbit_button_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_is_pressed), (mp_obj_t)µbit_button_is_pressed_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_was_pressed), (mp_obj_t)µbit_button_was_pressed_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_get_presses), (mp_obj_t)µbit_button_get_presses_obj }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_button_locals_dict, microbit_button_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_button_locals_dict, microbit_button_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( microbit_button_type, diff --git a/src/codal_port/microbit_compass.c b/src/codal_port/microbit_compass.c index 469b963..5d5985a 100644 --- a/src/codal_port/microbit_compass.c +++ b/src/codal_port/microbit_compass.c @@ -32,63 +32,63 @@ typedef struct _microbit_compass_obj_t { mp_obj_base_t base; } microbit_compass_obj_t; -STATIC mp_obj_t microbit_compass_is_calibrated(mp_obj_t self_in) { +static mp_obj_t microbit_compass_is_calibrated(mp_obj_t self_in) { (void)self_in; return mp_obj_new_bool(microbit_hal_compass_is_calibrated()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_is_calibrated_obj, microbit_compass_is_calibrated); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_is_calibrated_obj, microbit_compass_is_calibrated); -STATIC mp_obj_t microbit_compass_calibrate(mp_obj_t self_in) { +static mp_obj_t microbit_compass_calibrate(mp_obj_t self_in) { (void)self_in; microbit_hal_compass_calibrate(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_calibrate_obj, microbit_compass_calibrate); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_calibrate_obj, microbit_compass_calibrate); -STATIC mp_obj_t microbit_compass_clear_calibration(mp_obj_t self_in) { +static mp_obj_t microbit_compass_clear_calibration(mp_obj_t self_in) { (void)self_in; microbit_hal_compass_clear_calibration(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_clear_calibration_obj, microbit_compass_clear_calibration); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_clear_calibration_obj, microbit_compass_clear_calibration); -STATIC mp_obj_t microbit_compass_heading(mp_obj_t self_in) { +static mp_obj_t microbit_compass_heading(mp_obj_t self_in) { (void)self_in; return mp_obj_new_int(microbit_hal_compass_get_heading()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_heading_obj, microbit_compass_heading); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_heading_obj, microbit_compass_heading); -STATIC mp_obj_t microbit_compass_get_x(mp_obj_t self_in) { +static mp_obj_t microbit_compass_get_x(mp_obj_t self_in) { (void)self_in; int axis[3]; microbit_hal_compass_get_sample(axis); return mp_obj_new_int(axis[0]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_get_x_obj, microbit_compass_get_x); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_get_x_obj, microbit_compass_get_x); -STATIC mp_obj_t microbit_compass_get_y(mp_obj_t self_in) { +static mp_obj_t microbit_compass_get_y(mp_obj_t self_in) { (void)self_in; int axis[3]; microbit_hal_compass_get_sample(axis); return mp_obj_new_int(axis[1]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_get_y_obj, microbit_compass_get_y); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_get_y_obj, microbit_compass_get_y); -STATIC mp_obj_t microbit_compass_get_z(mp_obj_t self_in) { +static mp_obj_t microbit_compass_get_z(mp_obj_t self_in) { (void)self_in; int axis[3]; microbit_hal_compass_get_sample(axis); return mp_obj_new_int(axis[2]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_get_z_obj, microbit_compass_get_z); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_get_z_obj, microbit_compass_get_z); -STATIC mp_obj_t microbit_compass_get_field_strength(mp_obj_t self_in) { +static mp_obj_t microbit_compass_get_field_strength(mp_obj_t self_in) { (void)self_in; return mp_obj_new_int(microbit_hal_compass_get_field_strength()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_get_field_strength_obj, microbit_compass_get_field_strength); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_compass_get_field_strength_obj, microbit_compass_get_field_strength); -STATIC const mp_rom_map_elem_t microbit_compass_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_compass_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_heading), MP_ROM_PTR(µbit_compass_heading_obj) }, { MP_ROM_QSTR(MP_QSTR_is_calibrated), MP_ROM_PTR(µbit_compass_is_calibrated_obj) }, { MP_ROM_QSTR(MP_QSTR_calibrate), MP_ROM_PTR(µbit_compass_calibrate_obj) }, @@ -98,9 +98,9 @@ STATIC const mp_rom_map_elem_t microbit_compass_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get_z), MP_ROM_PTR(µbit_compass_get_z_obj) }, { MP_ROM_QSTR(MP_QSTR_get_field_strength), MP_ROM_PTR(µbit_compass_get_field_strength_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_compass_locals_dict, microbit_compass_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_compass_locals_dict, microbit_compass_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( microbit_compass_type, MP_QSTR_MicroBitCompass, MP_TYPE_FLAG_NONE, diff --git a/src/codal_port/microbit_display.c b/src/codal_port/microbit_display.c index 27c5f8f..25f1e9d 100644 --- a/src/codal_port/microbit_display.c +++ b/src/codal_port/microbit_display.c @@ -178,7 +178,7 @@ void microbit_display_set_pixel(microbit_display_obj_t *display, mp_int_t x, mp_ microbit_hal_display_set_pixel(x, y, bright); } -STATIC mp_obj_t microbit_display_set_pixel_func(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t microbit_display_set_pixel_func(mp_uint_t n_args, const mp_obj_t *args) { (void)n_args; microbit_display_obj_t *self = (microbit_display_obj_t*)args[0]; microbit_display_set_pixel(self, mp_obj_get_int(args[1]), mp_obj_get_int(args[2]), mp_obj_get_int(args[3])); @@ -193,13 +193,13 @@ mp_int_t microbit_display_get_pixel(microbit_display_obj_t *display, mp_int_t x, return microbit_hal_display_get_pixel(x, y); } -STATIC mp_obj_t microbit_display_get_pixel_func(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) { +static mp_obj_t microbit_display_get_pixel_func(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) { microbit_display_obj_t *self = (microbit_display_obj_t*)self_in; return MP_OBJ_NEW_SMALL_INT(microbit_display_get_pixel(self, mp_obj_get_int(x_in), mp_obj_get_int(y_in))); } MP_DEFINE_CONST_FUN_OBJ_3(microbit_display_get_pixel_obj, microbit_display_get_pixel_func); -STATIC const mp_rom_map_elem_t microbit_display_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get_pixel), MP_ROM_PTR(µbit_display_get_pixel_obj) }, { MP_ROM_QSTR(MP_QSTR_set_pixel), MP_ROM_PTR(µbit_display_set_pixel_obj) }, { MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(µbit_display_show_obj) }, @@ -210,9 +210,9 @@ STATIC const mp_rom_map_elem_t microbit_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_is_on), MP_ROM_PTR(µbit_display_is_on_obj) }, { MP_ROM_QSTR(MP_QSTR_read_light_level),MP_ROM_PTR(µbit_display_read_light_level_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_display_locals_dict, microbit_display_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_display_locals_dict, microbit_display_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( microbit_display_type, MP_QSTR_MicroBitDisplay, MP_TYPE_FLAG_NONE, diff --git a/src/codal_port/microbit_i2c.c b/src/codal_port/microbit_i2c.c index b82b0a5..b8c1888 100644 --- a/src/codal_port/microbit_i2c.c +++ b/src/codal_port/microbit_i2c.c @@ -35,7 +35,7 @@ typedef struct _microbit_i2c_obj_t { const microbit_pin_obj_t *sda; } microbit_i2c_obj_t; -STATIC mp_obj_t microbit_i2c_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_i2c_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_freq, ARG_sda, ARG_scl }; static const mp_arg_t allowed_args[] = { { MP_QSTR_freq, MP_ARG_INT, {.u_int = 100000} }, @@ -72,7 +72,7 @@ STATIC mp_obj_t microbit_i2c_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp } MP_DEFINE_CONST_FUN_OBJ_KW(microbit_i2c_init_obj, 1, microbit_i2c_init); -STATIC mp_obj_t microbit_i2c_scan(mp_obj_t self_in) { +static mp_obj_t microbit_i2c_scan(mp_obj_t self_in) { mp_obj_t list = mp_obj_new_list(0, NULL); // 7-bit addresses 0b0000xxx and 0b1111xxx are reserved for (int addr = 0x08; addr < 0x78; ++addr) { @@ -85,7 +85,7 @@ STATIC mp_obj_t microbit_i2c_scan(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(microbit_i2c_scan_obj, microbit_i2c_scan); -STATIC mp_obj_t microbit_i2c_read(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_i2c_read(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_addr, ARG_n, ARG_repeat }; static const mp_arg_t allowed_args[] = { { MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, @@ -113,7 +113,7 @@ STATIC mp_obj_t microbit_i2c_read(mp_uint_t n_args, const mp_obj_t *pos_args, mp } MP_DEFINE_CONST_FUN_OBJ_KW(microbit_i2c_read_obj, 1, microbit_i2c_read); -STATIC mp_obj_t microbit_i2c_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_i2c_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_addr, ARG_buf, ARG_repeat }; static const mp_arg_t allowed_args[] = { { MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, @@ -140,15 +140,15 @@ STATIC mp_obj_t microbit_i2c_write(mp_uint_t n_args, const mp_obj_t *pos_args, m } MP_DEFINE_CONST_FUN_OBJ_KW(microbit_i2c_write_obj, 1, microbit_i2c_write); -STATIC const mp_rom_map_elem_t microbit_i2c_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_i2c_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(µbit_i2c_init_obj) }, { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(µbit_i2c_scan_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(µbit_i2c_read_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(µbit_i2c_write_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_i2c_locals_dict, microbit_i2c_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_i2c_locals_dict, microbit_i2c_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( microbit_i2c_type, MP_QSTR_MicroBitI2C, MP_TYPE_FLAG_NONE, diff --git a/src/codal_port/microbit_image.c b/src/codal_port/microbit_image.c index 97f547c..f44a5b5 100644 --- a/src/codal_port/microbit_image.c +++ b/src/codal_port/microbit_image.c @@ -29,7 +29,7 @@ #include "py/mphal.h" #include "modmicrobit.h" -STATIC void microbit_image_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void microbit_image_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { microbit_image_obj_t *self = (microbit_image_obj_t*)self_in; mp_printf(print, "Image("); if (kind == PRINT_STR) { @@ -51,7 +51,7 @@ STATIC void microbit_image_print(const mp_print_t *print, mp_obj_t self_in, mp_p mp_printf(print, ")"); } -STATIC microbit_image_obj_t *image_from_parsed_str(const char *s, mp_int_t len) { +static microbit_image_obj_t *image_from_parsed_str(const char *s, mp_int_t len) { mp_int_t w = 0; mp_int_t h = 0; mp_int_t line_len = 0; @@ -108,7 +108,7 @@ STATIC microbit_image_obj_t *image_from_parsed_str(const char *s, mp_int_t len) } -STATIC mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +static mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 3, false); @@ -177,7 +177,7 @@ greyscale_t *image_shift(microbit_image_obj_t *self, mp_int_t x, mp_int_t y) { return result; } -STATIC microbit_image_obj_t *image_crop(microbit_image_obj_t *img, mp_int_t x, mp_int_t y, mp_int_t w, mp_int_t h) { +static microbit_image_obj_t *image_crop(microbit_image_obj_t *img, mp_int_t x, mp_int_t y, mp_int_t w, mp_int_t h) { if (w < 0) { w = 0; } @@ -338,7 +338,7 @@ mp_obj_t microbit_image_invert(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(microbit_image_invert_obj, microbit_image_invert); -STATIC const mp_rom_map_elem_t microbit_image_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_image_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(µbit_image_width_obj) }, { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(µbit_image_height_obj) }, { MP_ROM_QSTR(MP_QSTR_get_pixel), MP_ROM_PTR(µbit_image_get_pixel_obj) }, @@ -420,9 +420,9 @@ STATIC const mp_rom_map_elem_t microbit_image_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_SNAKE), MP_ROM_PTR(µbit_const_image_snake_obj) }, { MP_ROM_QSTR(MP_QSTR_SCISSORS), MP_ROM_PTR(µbit_const_image_scissors_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_image_locals_dict, microbit_image_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_image_locals_dict, microbit_image_locals_dict_table); -STATIC const unsigned char *get_font_data_from_char(char c) { +static const unsigned char *get_font_data_from_char(char c) { const uint8_t *data = microbit_hal_get_font_data(c); if (data == NULL) { data = microbit_hal_get_font_data('?'); @@ -430,12 +430,12 @@ STATIC const unsigned char *get_font_data_from_char(char c) { return data; } -STATIC mp_int_t get_pixel_from_font_data(const unsigned char *data, int x, int y) { +static mp_int_t get_pixel_from_font_data(const unsigned char *data, int x, int y) { // The following logic belongs in MicroBitFont return ((data[y] >> (4 - x)) & 1); } -STATIC void microbit_image_set_from_char(greyscale_t *img, char c) { +static void microbit_image_set_from_char(greyscale_t *img, char c) { const unsigned char *data = get_font_data_from_char(c); for (int x = 0; x < MICROBIT_DISPLAY_WIDTH; ++x) { for (int y = 0; y < MICROBIT_DISPLAY_HEIGHT; ++y) { @@ -464,7 +464,7 @@ microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_float_t f return (microbit_image_obj_t *)result; } -STATIC microbit_image_obj_t *microbit_image_sum(microbit_image_obj_t *lhs, microbit_image_obj_t *rhs, bool add) { +static microbit_image_obj_t *microbit_image_sum(microbit_image_obj_t *lhs, microbit_image_obj_t *rhs, bool add) { mp_int_t h = image_height(lhs); mp_int_t w = image_width(lhs); if (image_height(rhs) != h || image_width(rhs) != w) { @@ -487,7 +487,7 @@ STATIC microbit_image_obj_t *microbit_image_sum(microbit_image_obj_t *lhs, micro return (microbit_image_obj_t *)result; } -STATIC mp_obj_t image_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t image_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (mp_obj_get_type(lhs_in) != µbit_image_type) { return MP_OBJ_NULL; // op not supported } @@ -558,7 +558,7 @@ mp_obj_t scrolling_string_image_iterable(const char* str, mp_uint_t len, mp_obj_ return result; } -STATIC int font_column_non_blank(const unsigned char *font_data, unsigned int col) { +static int font_column_non_blank(const unsigned char *font_data, unsigned int col) { for (int y = 0; y < MICROBIT_DISPLAY_HEIGHT; ++y) { if (get_pixel_from_font_data(font_data, col, y)) { return 1; @@ -568,7 +568,7 @@ STATIC int font_column_non_blank(const unsigned char *font_data, unsigned int co } /* Not strictly the rightmost non-blank column, but the rightmost in columns 2,3 or 4. */ -STATIC unsigned int rightmost_non_blank_column(const unsigned char *font_data) { +static unsigned int rightmost_non_blank_column(const unsigned char *font_data) { if (font_column_non_blank(font_data, 4)) { return 4; } @@ -594,7 +594,7 @@ static void restart(scrolling_string_iterator_t *iter) { } } -STATIC mp_obj_t get_microbit_scrolling_string_iter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t get_microbit_scrolling_string_iter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { (void)iter_buf; // not big enough to hold scrolling_string_iterator_t scrolling_string_t *str = (scrolling_string_t *)o_in; scrolling_string_iterator_t *result = m_new_obj(scrolling_string_iterator_t); @@ -609,7 +609,7 @@ STATIC mp_obj_t get_microbit_scrolling_string_iter(mp_obj_t o_in, mp_obj_iter_bu return result; } -STATIC mp_obj_t microbit_scrolling_string_iter_next(mp_obj_t o_in) { +static mp_obj_t microbit_scrolling_string_iter_next(mp_obj_t o_in) { scrolling_string_iterator_t *iter = (scrolling_string_iterator_t *)o_in; if (iter->next_char == iter->end && iter->offset == 5) { if (iter->repeat) { @@ -709,7 +709,7 @@ static mp_obj_t facade_unary_op(mp_unary_op_t op, mp_obj_t self_in) { static mp_obj_t microbit_facade_iterator(mp_obj_t iterable_in, mp_obj_iter_buf_t *iter_buf); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( string_image_facade_type, MP_QSTR_Facade, MP_TYPE_FLAG_ITER_IS_GETITER, diff --git a/src/codal_port/microbit_microphone.c b/src/codal_port/microbit_microphone.c index 2d2cb21..338f2e0 100644 --- a/src/codal_port/microbit_microphone.c +++ b/src/codal_port/microbit_microphone.c @@ -71,11 +71,11 @@ void microbit_hal_level_detector_callback(int value) { } } -STATIC void microphone_init(void) { +static void microphone_init(void) { microbit_hal_microphone_init(); } -STATIC uint8_t sound_event_from_obj(mp_obj_t sound) { +static uint8_t sound_event_from_obj(mp_obj_t sound) { for (uint8_t i = 0; i < MP_ARRAY_SIZE(sound_event_obj_map); ++i) { if (sound == sound_event_obj_map[i]) { return i; @@ -84,7 +84,7 @@ STATIC uint8_t sound_event_from_obj(mp_obj_t sound) { mp_raise_ValueError(MP_ERROR_TEXT("invalid sound")); } -STATIC mp_obj_t microbit_microphone_set_threshold(mp_obj_t self_in, mp_obj_t sound_in, mp_obj_t value_in) { +static mp_obj_t microbit_microphone_set_threshold(mp_obj_t self_in, mp_obj_t sound_in, mp_obj_t value_in) { (void)self_in; uint8_t sound = sound_event_from_obj(sound_in); int kind; @@ -100,31 +100,31 @@ STATIC mp_obj_t microbit_microphone_set_threshold(mp_obj_t self_in, mp_obj_t sou microbit_hal_microphone_set_threshold(kind, value); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(microbit_microphone_set_threshold_obj, microbit_microphone_set_threshold); +static MP_DEFINE_CONST_FUN_OBJ_3(microbit_microphone_set_threshold_obj, microbit_microphone_set_threshold); -STATIC mp_obj_t microbit_microphone_sound_level(mp_obj_t self_in) { +static mp_obj_t microbit_microphone_sound_level(mp_obj_t self_in) { (void)self_in; microphone_init(); return MP_OBJ_NEW_SMALL_INT(microbit_hal_microphone_get_level()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_sound_level_obj, microbit_microphone_sound_level); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_sound_level_obj, microbit_microphone_sound_level); -STATIC mp_obj_t microbit_microphone_current_event(mp_obj_t self_in) { +static mp_obj_t microbit_microphone_current_event(mp_obj_t self_in) { (void)self_in; microphone_init(); return (mp_obj_t)sound_event_obj_map[sound_event_current]; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_current_event_obj, microbit_microphone_current_event); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_current_event_obj, microbit_microphone_current_event); -STATIC mp_obj_t microbit_microphone_is_event(mp_obj_t self_in, mp_obj_t sound_in) { +static mp_obj_t microbit_microphone_is_event(mp_obj_t self_in, mp_obj_t sound_in) { (void)self_in; microphone_init(); uint8_t sound = sound_event_from_obj(sound_in); return mp_obj_new_bool(sound == sound_event_current); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(microbit_microphone_is_event_obj, microbit_microphone_is_event); +static MP_DEFINE_CONST_FUN_OBJ_2(microbit_microphone_is_event_obj, microbit_microphone_is_event); -STATIC mp_obj_t microbit_microphone_was_event(mp_obj_t self_in, mp_obj_t sound_in) { +static mp_obj_t microbit_microphone_was_event(mp_obj_t self_in, mp_obj_t sound_in) { (void)self_in; microphone_init(); uint8_t sound = sound_event_from_obj(sound_in); @@ -133,9 +133,9 @@ STATIC mp_obj_t microbit_microphone_was_event(mp_obj_t self_in, mp_obj_t sound_i sound_event_history_index = 0; return result; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(microbit_microphone_was_event_obj, microbit_microphone_was_event); +static MP_DEFINE_CONST_FUN_OBJ_2(microbit_microphone_was_event_obj, microbit_microphone_was_event); -STATIC mp_obj_t microbit_microphone_get_events(mp_obj_t self_in) { +static mp_obj_t microbit_microphone_get_events(mp_obj_t self_in) { (void)self_in; microphone_init(); if (sound_event_history_index == 0) { @@ -149,9 +149,9 @@ STATIC mp_obj_t microbit_microphone_get_events(mp_obj_t self_in) { sound_event_history_index = 0; return o; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_get_events_obj, microbit_microphone_get_events); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_get_events_obj, microbit_microphone_get_events); -STATIC const mp_rom_map_elem_t microbit_microphone_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_microphone_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_set_threshold), MP_ROM_PTR(µbit_microphone_set_threshold_obj) }, { MP_ROM_QSTR(MP_QSTR_sound_level), MP_ROM_PTR(µbit_microphone_sound_level_obj) }, { MP_ROM_QSTR(MP_QSTR_current_event), MP_ROM_PTR(µbit_microphone_current_event_obj) }, @@ -159,7 +159,7 @@ STATIC const mp_rom_map_elem_t microbit_microphone_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_was_event), MP_ROM_PTR(µbit_microphone_was_event_obj) }, { MP_ROM_QSTR(MP_QSTR_get_events), MP_ROM_PTR(µbit_microphone_get_events_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_microphone_locals_dict, microbit_microphone_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_microphone_locals_dict, microbit_microphone_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( microbit_microphone_type, diff --git a/src/codal_port/microbit_pin.c b/src/codal_port/microbit_pin.c index 9e2712a..6bb75cc 100644 --- a/src/codal_port/microbit_pin.c +++ b/src/codal_port/microbit_pin.c @@ -204,7 +204,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(microbit_pin_set_touch_mode_obj, microbit_pin_set_touc { MP_ROM_QSTR(MP_QSTR_RESISTIVE), MP_ROM_INT(MICROBIT_HAL_PIN_TOUCH_RESISTIVE) }, \ { MP_ROM_QSTR(MP_QSTR_CAPACITIVE), MP_ROM_INT(MICROBIT_HAL_PIN_TOUCH_CAPACITIVE) } -STATIC const mp_rom_map_elem_t microbit_dig_pin_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_dig_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write_digital), MP_ROM_PTR(µbit_pin_write_digital_obj) }, { MP_ROM_QSTR(MP_QSTR_read_digital), MP_ROM_PTR(µbit_pin_read_digital_obj) }, { MP_ROM_QSTR(MP_QSTR_write_analog), MP_ROM_PTR(µbit_pin_write_analog_obj) }, @@ -216,7 +216,7 @@ STATIC const mp_rom_map_elem_t microbit_dig_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get_mode), MP_ROM_PTR(µbit_pin_get_mode_obj) }, PULL_CONSTANTS, }; -STATIC MP_DEFINE_CONST_DICT(microbit_dig_pin_locals_dict, microbit_dig_pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_dig_pin_locals_dict, microbit_dig_pin_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( microbit_dig_pin_type, @@ -225,7 +225,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, µbit_dig_pin_locals_dict ); -STATIC const mp_rom_map_elem_t microbit_ann_pin_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_ann_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write_digital), MP_ROM_PTR(µbit_pin_write_digital_obj) }, { MP_ROM_QSTR(MP_QSTR_read_digital), MP_ROM_PTR(µbit_pin_read_digital_obj) }, { MP_ROM_QSTR(MP_QSTR_write_analog), MP_ROM_PTR(µbit_pin_write_analog_obj) }, @@ -238,7 +238,7 @@ STATIC const mp_rom_map_elem_t microbit_ann_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get_mode), MP_ROM_PTR(µbit_pin_get_mode_obj) }, PULL_CONSTANTS, }; -STATIC MP_DEFINE_CONST_DICT(microbit_ann_pin_locals_dict, microbit_ann_pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_ann_pin_locals_dict, microbit_ann_pin_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( microbit_ad_pin_type, @@ -247,7 +247,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, µbit_ann_pin_locals_dict ); -STATIC const mp_rom_map_elem_t microbit_touch_pin_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_touch_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write_digital), MP_ROM_PTR(µbit_pin_write_digital_obj) }, { MP_ROM_QSTR(MP_QSTR_read_digital), MP_ROM_PTR(µbit_pin_read_digital_obj) }, { MP_ROM_QSTR(MP_QSTR_write_analog), MP_ROM_PTR(µbit_pin_write_analog_obj) }, @@ -265,7 +265,7 @@ STATIC const mp_rom_map_elem_t microbit_touch_pin_locals_dict_table[] = { PULL_CONSTANTS, TOUCH_CONSTANTS, }; -STATIC MP_DEFINE_CONST_DICT(microbit_touch_pin_locals_dict, microbit_touch_pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_touch_pin_locals_dict, microbit_touch_pin_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( microbit_touch_pin_type, @@ -274,14 +274,14 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, µbit_touch_pin_locals_dict ); -STATIC const mp_rom_map_elem_t microbit_touch_only_pin_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_touch_only_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_is_touched), MP_ROM_PTR(µbit_pin_is_touched_obj) }, { MP_ROM_QSTR(MP_QSTR_was_touched), MP_ROM_PTR(µbit_pin_was_touched_obj) }, { MP_ROM_QSTR(MP_QSTR_get_touches), MP_ROM_PTR(µbit_pin_get_touches_obj) }, { MP_ROM_QSTR(MP_QSTR_set_touch_mode), MP_ROM_PTR(µbit_pin_set_touch_mode_obj) }, TOUCH_CONSTANTS, }; -STATIC MP_DEFINE_CONST_DICT(microbit_touch_only_pin_locals_dict, microbit_touch_only_pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_touch_only_pin_locals_dict, microbit_touch_only_pin_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( microbit_touch_only_pin_type, diff --git a/src/codal_port/microbit_pinaudio.c b/src/codal_port/microbit_pinaudio.c index 69f67d9..708ff5e 100644 --- a/src/codal_port/microbit_pinaudio.c +++ b/src/codal_port/microbit_pinaudio.c @@ -28,7 +28,7 @@ #include "modmicrobit.h" // The currently selected pin output for the audio. -STATIC const microbit_pin_obj_t *audio_routed_pin = NULL; +static const microbit_pin_obj_t *audio_routed_pin = NULL; void microbit_pin_audio_select(mp_const_obj_t select, const microbit_pinmode_t *pinmode) { // Work out which pins are requested for the audio output. diff --git a/src/codal_port/microbit_sound.c b/src/codal_port/microbit_sound.c index 0b34900..aac72a1 100644 --- a/src/codal_port/microbit_sound.c +++ b/src/codal_port/microbit_sound.c @@ -28,7 +28,7 @@ #include "modmicrobit.h" #define SOUND(name, ...) \ - STATIC const microbit_sound_obj_t microbit_sound_ ## name ## _obj = { \ + static const microbit_sound_obj_t microbit_sound_ ## name ## _obj = { \ { µbit_sound_type }, \ MP_STRINGIFY(name) \ } @@ -46,12 +46,12 @@ SOUND(yawn); #undef SOUND -STATIC void microbit_sound_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void microbit_sound_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { const microbit_sound_obj_t *self = (const microbit_sound_obj_t *)self_in; mp_printf(print, "Sound('%s')", self->name); } -STATIC const mp_rom_map_elem_t microbit_sound_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_sound_locals_dict_table[] = { #define SOUND(NAME, name) { MP_ROM_QSTR(MP_QSTR_ ## NAME), MP_ROM_PTR(µbit_sound_ ## name ## _obj) } SOUND(GIGGLE, giggle), @@ -67,7 +67,7 @@ STATIC const mp_rom_map_elem_t microbit_sound_locals_dict_table[] = { #undef SOUND }; -STATIC MP_DEFINE_CONST_DICT(microbit_sound_locals_dict, microbit_sound_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_sound_locals_dict, microbit_sound_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( microbit_sound_type, diff --git a/src/codal_port/microbit_soundeffect.c b/src/codal_port/microbit_soundeffect.c index cdc1fc4..cd51f8a 100644 --- a/src/codal_port/microbit_soundeffect.c +++ b/src/codal_port/microbit_soundeffect.c @@ -98,7 +98,7 @@ typedef struct _soundeffect_attr_t { uint8_t length; } soundeffect_attr_t; -STATIC const uint16_t waveform_to_qstr_table[5] = { +static const uint16_t waveform_to_qstr_table[5] = { [SOUND_EFFECT_WAVEFORM_SINE] = MP_QSTR_WAVEFORM_SINE, [SOUND_EFFECT_WAVEFORM_SAWTOOTH] = MP_QSTR_WAVEFORM_SAWTOOTH, [SOUND_EFFECT_WAVEFORM_TRIANGLE] = MP_QSTR_WAVEFORM_TRIANGLE, @@ -106,14 +106,14 @@ STATIC const uint16_t waveform_to_qstr_table[5] = { [SOUND_EFFECT_WAVEFORM_NOISE] = MP_QSTR_WAVEFORM_NOISE, }; -STATIC const uint16_t fx_to_qstr_table[4] = { +static const uint16_t fx_to_qstr_table[4] = { [SOUND_EFFECT_FX_NONE] = MP_QSTR_FX_NONE, [SOUND_EFFECT_FX_TREMOLO] = MP_QSTR_FX_TREMOLO, [SOUND_EFFECT_FX_VIBRATO] = MP_QSTR_FX_VIBRATO, [SOUND_EFFECT_FX_WARBLE] = MP_QSTR_FX_WARBLE, }; -STATIC const soundeffect_attr_t soundeffect_attr_table[] = { +static const soundeffect_attr_t soundeffect_attr_table[] = { { MP_QSTR_freq_start, SOUND_EXPR_FREQUENCY_START_OFFSET, SOUND_EXPR_FREQUENCY_START_LENGTH }, { MP_QSTR_freq_end, SOUND_EXPR_FREQUENCY_END_OFFSET, SOUND_EXPR_FREQUENCY_END_LENGTH }, { MP_QSTR_duration, SOUND_EXPR_DURATION_OFFSET, SOUND_EXPR_DURATION_LENGTH }, @@ -141,7 +141,7 @@ const char *microbit_soundeffect_get_sound_expr_data(mp_obj_t self_in) { return &self->sound_expr[0]; } -STATIC void sound_expr_encode(microbit_soundeffect_obj_t *self, size_t offset, size_t length, unsigned int value) { +static void sound_expr_encode(microbit_soundeffect_obj_t *self, size_t offset, size_t length, unsigned int value) { if (offset == SOUND_EXPR_VOLUME_START_OFFSET || offset == SOUND_EXPR_VOLUME_END_OFFSET) { if (value > 255) { mp_raise_ValueError(MP_ERROR_TEXT("maximum value is 255")); @@ -163,7 +163,7 @@ STATIC void sound_expr_encode(microbit_soundeffect_obj_t *self, size_t offset, s } } -STATIC unsigned int sound_expr_decode(const microbit_soundeffect_obj_t *self, size_t offset, size_t length) { +static unsigned int sound_expr_decode(const microbit_soundeffect_obj_t *self, size_t offset, size_t length) { unsigned int value = 0; for (size_t i = 0; i < length; ++i) { value = value * 10 + self->sound_expr[offset + i] - '0'; @@ -174,7 +174,7 @@ STATIC unsigned int sound_expr_decode(const microbit_soundeffect_obj_t *self, si return value; } -STATIC void microbit_soundeffect_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void microbit_soundeffect_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { const microbit_soundeffect_obj_t *self = MP_OBJ_TO_PTR(self_in); unsigned int freq_start = sound_expr_decode(self, SOUND_EXPR_FREQUENCY_START_OFFSET, SOUND_EXPR_FREQUENCY_START_LENGTH); @@ -228,7 +228,7 @@ STATIC void microbit_soundeffect_print(const mp_print_t *print, mp_obj_t self_in // Constructor: // SoundEffect(freq_start, freq_end, duration, vol_start, vol_end, waveform, fx, shape) -STATIC mp_obj_t microbit_soundeffect_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { +static mp_obj_t microbit_soundeffect_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { enum { ARG_freq_start, ARG_freq_end, ARG_duration, ARG_vol_start, ARG_vol_end, ARG_waveform, ARG_fx, ARG_shape }; static const mp_arg_t allowed_args[] = { { MP_QSTR_freq_start, MP_ARG_INT, {.u_int = SOUND_EFFECT_DEFAULT_FREQ_START} }, @@ -270,7 +270,7 @@ STATIC mp_obj_t microbit_soundeffect_make_new(const mp_obj_type_t *type, size_t return MP_OBJ_FROM_PTR(self); } -STATIC void microbit_soundeffect_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void microbit_soundeffect_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { microbit_soundeffect_obj_t *self = MP_OBJ_TO_PTR(self_in); const soundeffect_attr_t *soundeffect_attr = NULL; for (size_t i = 0; i < MP_ARRAY_SIZE(soundeffect_attr_table); ++i) { @@ -303,7 +303,7 @@ STATIC void microbit_soundeffect_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des } } -STATIC mp_obj_t microbit_soundeffect_from_string(mp_obj_t str_in) { +static mp_obj_t microbit_soundeffect_from_string(mp_obj_t str_in) { microbit_soundeffect_obj_t *self = m_new_obj(microbit_soundeffect_obj_t); self->base.type = µbit_soundeffect_type; self->is_mutable = true; @@ -319,10 +319,10 @@ STATIC mp_obj_t microbit_soundeffect_from_string(mp_obj_t str_in) { return MP_OBJ_FROM_PTR(self); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_soundeffect_from_string_obj, microbit_soundeffect_from_string); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(microbit_soundeffect_from_string_staticmethod_obj, MP_ROM_PTR(µbit_soundeffect_from_string_obj)); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_soundeffect_from_string_obj, microbit_soundeffect_from_string); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(microbit_soundeffect_from_string_staticmethod_obj, MP_ROM_PTR(µbit_soundeffect_from_string_obj)); -STATIC mp_obj_t microbit_soundeffect_copy(mp_obj_t self_in) { +static mp_obj_t microbit_soundeffect_copy(mp_obj_t self_in) { microbit_soundeffect_obj_t *self = MP_OBJ_TO_PTR(self_in); microbit_soundeffect_obj_t *copy = m_new_obj(microbit_soundeffect_obj_t); copy->base.type = self->base.type; @@ -331,9 +331,9 @@ STATIC mp_obj_t microbit_soundeffect_copy(mp_obj_t self_in) { return MP_OBJ_FROM_PTR(copy); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_soundeffect_copy_obj, microbit_soundeffect_copy); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_soundeffect_copy_obj, microbit_soundeffect_copy); -STATIC const mp_rom_map_elem_t microbit_soundeffect_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_soundeffect_locals_dict_table[] = { // Static methods. { MP_ROM_QSTR(MP_QSTR__from_string), MP_ROM_PTR(µbit_soundeffect_from_string_staticmethod_obj) }, @@ -360,7 +360,7 @@ STATIC const mp_rom_map_elem_t microbit_soundeffect_locals_dict_table[] = { #undef C }; -STATIC MP_DEFINE_CONST_DICT(microbit_soundeffect_locals_dict, microbit_soundeffect_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_soundeffect_locals_dict, microbit_soundeffect_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( microbit_soundeffect_type, diff --git a/src/codal_port/microbit_soundevent.c b/src/codal_port/microbit_soundevent.c index 4de0494..71b7b20 100644 --- a/src/codal_port/microbit_soundevent.c +++ b/src/codal_port/microbit_soundevent.c @@ -47,17 +47,17 @@ const microbit_soundevent_obj_t microbit_soundevent_clap_obj = { MP_QSTR_clap, }; -STATIC void microbit_soundevent_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void microbit_soundevent_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { microbit_soundevent_obj_t *self = (microbit_soundevent_obj_t *)self_in; mp_printf(print, "SoundEvent('%q')", self->name); } -STATIC const mp_rom_map_elem_t microbit_soundevent_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_soundevent_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_LOUD), MP_ROM_PTR(µbit_soundevent_loud_obj) }, { MP_ROM_QSTR(MP_QSTR_QUIET), MP_ROM_PTR(µbit_soundevent_quiet_obj) }, { MP_ROM_QSTR(MP_QSTR_CLAP), MP_ROM_PTR(µbit_soundevent_clap_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_soundevent_locals_dict, microbit_soundevent_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_soundevent_locals_dict, microbit_soundevent_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( microbit_soundevent_type, diff --git a/src/codal_port/microbit_speaker.c b/src/codal_port/microbit_speaker.c index 69d4a68..936cea3 100644 --- a/src/codal_port/microbit_speaker.c +++ b/src/codal_port/microbit_speaker.c @@ -32,27 +32,27 @@ typedef struct _microbit_speaker_obj_t { mp_obj_base_t base; } microbit_speaker_obj_t; -STATIC mp_obj_t microbit_speaker_off(mp_obj_t self_in) { +static mp_obj_t microbit_speaker_off(mp_obj_t self_in) { (void)self_in; microbit_hal_audio_select_speaker(false); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_speaker_off_obj, microbit_speaker_off); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_speaker_off_obj, microbit_speaker_off); -STATIC mp_obj_t microbit_speaker_on(mp_obj_t self_in) { +static mp_obj_t microbit_speaker_on(mp_obj_t self_in) { (void)self_in; microbit_hal_audio_select_speaker(true); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_speaker_on_obj, microbit_speaker_on); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_speaker_on_obj, microbit_speaker_on); -STATIC const mp_rom_map_elem_t microbit_speaker_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_speaker_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(µbit_speaker_off_obj) }, { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(µbit_speaker_on_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_speaker_locals_dict, microbit_speaker_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_speaker_locals_dict, microbit_speaker_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( microbit_speaker_type, MP_QSTR_MicroBitSpeaker, MP_TYPE_FLAG_NONE, diff --git a/src/codal_port/microbit_spi.c b/src/codal_port/microbit_spi.c index 9ea5a36..3685f4e 100644 --- a/src/codal_port/microbit_spi.c +++ b/src/codal_port/microbit_spi.c @@ -37,15 +37,15 @@ typedef struct _microbit_spi_obj_t { const microbit_pin_obj_t *miso; } microbit_spi_obj_t; -STATIC bool microbit_spi_initialised = false; +static bool microbit_spi_initialised = false; -STATIC void microbit_spi_check_initialised(void) { +static void microbit_spi_check_initialised(void) { if (!microbit_spi_initialised) { mp_raise_ValueError(MP_ERROR_TEXT("SPI not initialised")); } } -STATIC mp_obj_t microbit_spi_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_spi_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_bits, ARG_mode, ARG_sclk, ARG_mosi, ARG_miso }; static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 1000000} }, @@ -93,7 +93,7 @@ STATIC mp_obj_t microbit_spi_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp } MP_DEFINE_CONST_FUN_OBJ_KW(microbit_spi_init_obj, 1, microbit_spi_init); -STATIC mp_obj_t microbit_spi_write(mp_obj_t self_in, mp_obj_t buf_in) { +static mp_obj_t microbit_spi_write(mp_obj_t self_in, mp_obj_t buf_in) { microbit_spi_check_initialised(); mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); @@ -102,7 +102,7 @@ STATIC mp_obj_t microbit_spi_write(mp_obj_t self_in, mp_obj_t buf_in) { } MP_DEFINE_CONST_FUN_OBJ_2(microbit_spi_write_obj, microbit_spi_write); -STATIC mp_obj_t microbit_spi_read(size_t n_args, const mp_obj_t *args) { +static mp_obj_t microbit_spi_read(size_t n_args, const mp_obj_t *args) { microbit_spi_check_initialised(); mp_int_t nbytes = mp_obj_get_int(args[1]); if (nbytes < 0) { @@ -123,7 +123,7 @@ STATIC mp_obj_t microbit_spi_read(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_spi_read_obj, 2, 3, microbit_spi_read); -STATIC mp_obj_t microbit_spi_write_readinto(mp_obj_t self_in, mp_obj_t write_buf, mp_obj_t read_buf) { +static mp_obj_t microbit_spi_write_readinto(mp_obj_t self_in, mp_obj_t write_buf, mp_obj_t read_buf) { microbit_spi_check_initialised(); mp_buffer_info_t write_bufinfo; mp_get_buffer_raise(write_buf, &write_bufinfo, MP_BUFFER_READ); @@ -137,15 +137,15 @@ STATIC mp_obj_t microbit_spi_write_readinto(mp_obj_t self_in, mp_obj_t write_buf } MP_DEFINE_CONST_FUN_OBJ_3(microbit_spi_write_readinto_obj, microbit_spi_write_readinto); -STATIC const mp_rom_map_elem_t microbit_spi_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_spi_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(µbit_spi_init_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(µbit_spi_write_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(µbit_spi_read_obj) }, { MP_ROM_QSTR(MP_QSTR_write_readinto), MP_ROM_PTR(µbit_spi_write_readinto_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_spi_locals_dict, microbit_spi_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_spi_locals_dict, microbit_spi_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( microbit_spi_type, MP_QSTR_MicroBitSPI, MP_TYPE_FLAG_NONE, diff --git a/src/codal_port/microbit_uart.c b/src/codal_port/microbit_uart.c index 7e35b15..80cc403 100644 --- a/src/codal_port/microbit_uart.c +++ b/src/codal_port/microbit_uart.c @@ -39,9 +39,9 @@ typedef struct _microbit_uart_obj_t { } microbit_uart_obj_t; // timeout (in ms) to wait between characters when reading -STATIC uint16_t microbit_uart_timeout_char = 0; +static uint16_t microbit_uart_timeout_char = 0; -STATIC mp_obj_t microbit_uart_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_uart_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_bits, ARG_parity, ARG_stop, ARG_pins, ARG_tx, ARG_rx }; static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 9600} }, @@ -93,7 +93,7 @@ STATIC mp_obj_t microbit_uart_init(mp_uint_t n_args, const mp_obj_t *pos_args, m } MP_DEFINE_CONST_FUN_OBJ_KW(microbit_uart_init_obj, 1, microbit_uart_init); -STATIC mp_obj_t microbit_uart_any(mp_obj_t self_in) { +static mp_obj_t microbit_uart_any(mp_obj_t self_in) { (void)self_in; if (mp_hal_stdio_poll(MP_STREAM_POLL_RD)) { return mp_const_true; @@ -103,7 +103,7 @@ STATIC mp_obj_t microbit_uart_any(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(microbit_uart_any_obj, microbit_uart_any); -STATIC const mp_rom_map_elem_t microbit_uart_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_uart_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(µbit_uart_init_obj) }, { MP_ROM_QSTR(MP_QSTR_any), MP_ROM_PTR(µbit_uart_any_obj) }, @@ -115,11 +115,11 @@ STATIC const mp_rom_map_elem_t microbit_uart_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ODD), MP_ROM_INT(1) }, { MP_ROM_QSTR(MP_QSTR_EVEN), MP_ROM_INT(0) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_uart_locals_dict, microbit_uart_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_uart_locals_dict, microbit_uart_locals_dict_table); // Waits at most timeout_ms for at least 1 char to become ready for reading. // Returns true if something available, false if not. -STATIC bool microbit_uart_rx_wait(uint32_t timeout_ms) { +static bool microbit_uart_rx_wait(uint32_t timeout_ms) { uint32_t start = mp_hal_ticks_ms(); for (;;) { if (mp_hal_stdio_poll(MP_STREAM_POLL_RD)) { @@ -132,7 +132,7 @@ STATIC bool microbit_uart_rx_wait(uint32_t timeout_ms) { } } -STATIC mp_uint_t microbit_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t microbit_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { (void)self_in; byte *buf = (byte*)buf_in; (void)errcode; @@ -159,7 +159,7 @@ STATIC mp_uint_t microbit_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t si } } -STATIC mp_uint_t microbit_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t microbit_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { (void)self_in; const char *buf = (const char*)buf_in; (void)errcode; @@ -167,13 +167,13 @@ STATIC mp_uint_t microbit_uart_write(mp_obj_t self_in, const void *buf_in, mp_ui return size; } -STATIC const mp_stream_p_t microbit_uart_stream_p = { +static const mp_stream_p_t microbit_uart_stream_p = { .read = microbit_uart_read, .write = microbit_uart_write, .is_text = false, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( microbit_uart_type, MP_QSTR_MicroBitUART, MP_TYPE_FLAG_NONE, diff --git a/src/codal_port/microbitfs.c b/src/codal_port/microbitfs.c index 308f208..0ddff1c 100644 --- a/src/codal_port/microbitfs.c +++ b/src/codal_port/microbitfs.c @@ -125,13 +125,13 @@ extern const mp_obj_type_t os_mbfs_fileio_type; extern const mp_obj_type_t os_mbfs_textio_type; // Page indexes count down from the end of ROM. -STATIC uint8_t first_page_index; -STATIC uint8_t last_page_index; +static uint8_t first_page_index; +static uint8_t last_page_index; // The number of usable chunks in the file system. -STATIC uint8_t chunks_in_file_system; +static uint8_t chunks_in_file_system; // Index of chunk to start searches. This is randomised to even out wear. -STATIC uint8_t start_index; -STATIC file_chunk *file_system_chunks; +static uint8_t start_index; +static file_chunk *file_system_chunks; // Defined by the linker extern byte _fs_start[]; @@ -140,25 +140,25 @@ extern byte _fs_end[]; STATIC_ASSERT((sizeof(file_chunk) == CHUNK_SIZE)); // From micro:bit memory.h -STATIC inline byte *rounddown(byte *addr, uint32_t align) { +static inline byte *rounddown(byte *addr, uint32_t align) { return (byte*)(((uint32_t)addr)&(-align)); } // From micro:bit memory.h -STATIC inline byte *roundup(byte *addr, uint32_t align) { +static inline byte *roundup(byte *addr, uint32_t align) { return (byte*)((((uint32_t)addr)+align-1)&(-align)); } -STATIC inline void *first_page(void) { +static inline void *first_page(void) { return _fs_end - FLASH_PAGESIZE * first_page_index; } -STATIC inline void *last_page(void) { +static inline void *last_page(void) { return _fs_end - FLASH_PAGESIZE * last_page_index; } -STATIC void init_limits(void) { +static void init_limits(void) { // First determine where to end byte *end = _fs_end; end = rounddown(end, FLASH_PAGESIZE)-FLASH_PAGESIZE; @@ -173,7 +173,7 @@ STATIC void init_limits(void) { chunks_in_file_system = (end-start)>>MBFS_LOG_CHUNK_SIZE; } -STATIC void randomise_start_index(void) { +static void randomise_start_index(void) { start_index = rng_generate_random_word() % chunks_in_file_system + 1; } @@ -191,7 +191,7 @@ void microbit_filesystem_init(void) { } } -STATIC void copy_page(void *dest, void *src) { +static void copy_page(void *dest, void *src) { DEBUG(("FILE DEBUG: Copying page from %lx to %lx.\r\n", (uint32_t)src, (uint32_t)dest)); flash_page_erase((uint32_t)dest); file_chunk *src_chunk = src; @@ -214,7 +214,7 @@ STATIC void copy_page(void *dest, void *src) { // Then all the pages are copied, one by one, into the adjacent newly unused page. // Finally, the persistent data is saved back to the opposite end of the filesystem from whence it came. // -STATIC void filesystem_sweep(void) { +static void filesystem_sweep(void) { persistent_config_t config; uint8_t *page; uint8_t *end_page; @@ -244,11 +244,11 @@ STATIC void filesystem_sweep(void) { } -STATIC inline byte *seek_address(file_descriptor_obj *self) { +static inline byte *seek_address(file_descriptor_obj *self) { return (byte*)&(file_system_chunks[self->seek_chunk].data[self->seek_offset]); } -STATIC uint8_t microbit_find_file(const char *name, int name_len) { +static uint8_t microbit_find_file(const char *name, int name_len) { for (uint8_t index = 1; index <= chunks_in_file_system; index++) { const file_chunk *p = &file_system_chunks[index]; if (p->marker != FILE_START) @@ -272,7 +272,7 @@ STATIC uint8_t microbit_find_file(const char *name, int name_len) { // 3a. Sweep the filesystem and restart. // 3b. Otherwise, fail and return FILE_NOT_FOUND. // -STATIC uint8_t find_chunk_and_erase(void) { +static uint8_t find_chunk_and_erase(void) { // Start search at a random chunk to spread the wear more evenly. // Search for unused chunk uint8_t index = start_index; @@ -320,13 +320,13 @@ STATIC uint8_t find_chunk_and_erase(void) { return find_chunk_and_erase(); } -STATIC mp_obj_t microbit_file_name(file_descriptor_obj *fd) { +static mp_obj_t microbit_file_name(file_descriptor_obj *fd) { return mp_obj_new_str(&(file_system_chunks[fd->start_chunk].header.filename[0]), file_system_chunks[fd->start_chunk].header.name_len); } -STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary); +static file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary); -STATIC void clear_file(uint8_t chunk) { +static void clear_file(uint8_t chunk) { do { flash_write_byte((uint32_t)&(file_system_chunks[chunk].marker), FREED_CHUNK); DEBUG(("FILE DEBUG: Freeing chunk %d.\n", chunk)); @@ -334,7 +334,7 @@ STATIC void clear_file(uint8_t chunk) { } while (chunk <= chunks_in_file_system); } -STATIC file_descriptor_obj *microbit_file_open(const char *name, size_t name_len, bool write, bool binary) { +static file_descriptor_obj *microbit_file_open(const char *name, size_t name_len, bool write, bool binary) { if (name_len > MAX_FILENAME_LENGTH) { return NULL; } @@ -360,7 +360,7 @@ STATIC file_descriptor_obj *microbit_file_open(const char *name, size_t name_len return microbit_file_descriptor_new(index, write, binary); } -STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary) { +static file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary) { file_descriptor_obj *res = mp_obj_malloc(file_descriptor_obj, binary ? &os_mbfs_fileio_type : &os_mbfs_textio_type); res->start_chunk = start_chunk; res->seek_chunk = start_chunk; @@ -371,7 +371,7 @@ STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bo return res; } -STATIC mp_obj_t microbit_remove(mp_obj_t filename) { +static mp_obj_t microbit_remove(mp_obj_t filename) { size_t name_len; const char *name = mp_obj_str_get_data(filename, &name_len); mp_uint_t index = microbit_find_file(name, name_len); @@ -382,13 +382,13 @@ STATIC mp_obj_t microbit_remove(mp_obj_t filename) { return mp_const_none; } -STATIC void check_file_open(file_descriptor_obj *self) { +static void check_file_open(file_descriptor_obj *self) { if (!self->open) { mp_raise_ValueError(MP_ERROR_TEXT("I/O operation on closed file")); } } -STATIC int advance(file_descriptor_obj *self, uint32_t n, bool write) { +static int advance(file_descriptor_obj *self, uint32_t n, bool write) { DEBUG(("FILE DEBUG: Advancing from chunk %d, offset %d.\r\n", self->seek_chunk, self->seek_offset)); self->seek_offset += n; if (self->seek_offset == DATA_PER_CHUNK) { @@ -410,7 +410,7 @@ STATIC int advance(file_descriptor_obj *self, uint32_t n, bool write) { return 0; } -STATIC mp_uint_t microbit_file_read(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t microbit_file_read(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) { file_descriptor_obj *self = (file_descriptor_obj *)obj; check_file_open(self); if (self->writable || file_system_chunks[self->start_chunk].marker == FREED_CHUNK) { @@ -440,7 +440,7 @@ STATIC mp_uint_t microbit_file_read(mp_obj_t obj, void *buf, mp_uint_t size, int return bytes_read; } -STATIC mp_uint_t microbit_file_write(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t microbit_file_write(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode) { file_descriptor_obj *self = (file_descriptor_obj *)obj; check_file_open(self); if (!self->writable || file_system_chunks[self->start_chunk].marker == FREED_CHUNK) { @@ -463,14 +463,14 @@ STATIC mp_uint_t microbit_file_write(mp_obj_t obj, const void *buf, mp_uint_t si return size; } -STATIC void microbit_file_close(file_descriptor_obj *fd) { +static void microbit_file_close(file_descriptor_obj *fd) { if (fd->writable) { flash_write_byte((uint32_t)&(file_system_chunks[fd->start_chunk].header.end_offset), fd->seek_offset); } fd->open = false; } -STATIC mp_obj_t microbit_file_list(void) { +static mp_obj_t microbit_file_list(void) { mp_obj_t res = mp_obj_new_list(0, NULL); for (uint8_t index = 1; index <= chunks_in_file_system; index++) { if (file_system_chunks[index].marker == FILE_START) { @@ -481,7 +481,7 @@ STATIC mp_obj_t microbit_file_list(void) { return res; } -STATIC mp_obj_t microbit_file_size(mp_obj_t filename) { +static mp_obj_t microbit_file_size(mp_obj_t filename) { size_t name_len; const char *name = mp_obj_str_get_data(filename, &name_len); uint8_t chunk = microbit_find_file(name, name_len); @@ -500,7 +500,7 @@ STATIC mp_obj_t microbit_file_size(mp_obj_t filename) { return mp_obj_new_int(len); } -STATIC mp_uint_t file_read_byte(file_descriptor_obj *fd) { +static mp_uint_t file_read_byte(file_descriptor_obj *fd) { if (file_system_chunks[fd->seek_chunk].next_chunk == UNUSED_CHUNK) { uint8_t end_offset = file_system_chunks[fd->start_chunk].header.end_offset; if (end_offset == UNUSED_CHUNK || fd->seek_offset == end_offset) { @@ -535,29 +535,29 @@ mp_import_stat_t os_mbfs_import_stat(const char *path) { } } -STATIC mp_obj_t os_mbfs_file_name(mp_obj_t self) { +static mp_obj_t os_mbfs_file_name(mp_obj_t self) { file_descriptor_obj *fd = (file_descriptor_obj*)self; return microbit_file_name(fd); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_name_obj, os_mbfs_file_name); +static MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_name_obj, os_mbfs_file_name); -STATIC mp_obj_t os_mbfs_file_close(mp_obj_t self) { +static mp_obj_t os_mbfs_file_close(mp_obj_t self) { file_descriptor_obj *fd = (file_descriptor_obj*)self; microbit_file_close(fd); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_close_obj, os_mbfs_file_close); +static MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_close_obj, os_mbfs_file_close); -STATIC mp_obj_t os_mbfs_remove(mp_obj_t name) { +static mp_obj_t os_mbfs_remove(mp_obj_t name) { return microbit_remove(name); } MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_remove_obj, os_mbfs_remove); -STATIC mp_obj_t os_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t os_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; return os_mbfs_file_close(args[0]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_mbfs_file___exit___obj, 4, 4, os_mbfs_file___exit__); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_mbfs_file___exit___obj, 4, 4, os_mbfs_file___exit__); typedef struct { mp_obj_base_t base; @@ -565,7 +565,7 @@ typedef struct { uint8_t index; } os_mbfs_ilistdir_it_t; -STATIC mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { +static mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { os_mbfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); // Read until the next FILE_START chunk. @@ -590,7 +590,7 @@ STATIC mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC mp_obj_t os_mbfs_ilistdir(void) { +static mp_obj_t os_mbfs_ilistdir(void) { os_mbfs_ilistdir_it_t *iter = mp_obj_malloc(os_mbfs_ilistdir_it_t, &mp_type_polymorph_iter); iter->iternext = os_mbfs_ilistdir_it_iternext; iter->index = 1; @@ -601,12 +601,12 @@ MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_ilistdir_obj, os_mbfs_ilistdir); MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_listdir_obj, microbit_file_list); -STATIC mp_obj_t microbit_file_writable(mp_obj_t self) { +static mp_obj_t microbit_file_writable(mp_obj_t self) { return mp_obj_new_bool(((file_descriptor_obj *)self)->writable); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_file_writable_obj, microbit_file_writable); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_file_writable_obj, microbit_file_writable); -STATIC const mp_map_elem_t os_mbfs_file_locals_dict_table[] = { +static const mp_map_elem_t os_mbfs_file_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&os_mbfs_file_close_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&os_mbfs_file_name_obj }, { MP_ROM_QSTR(MP_QSTR___enter__), (mp_obj_t)&mp_identity_obj }, @@ -618,10 +618,10 @@ STATIC const mp_map_elem_t os_mbfs_file_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj}, { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj}, }; -STATIC MP_DEFINE_CONST_DICT(os_mbfs_file_locals_dict, os_mbfs_file_locals_dict_table); +static MP_DEFINE_CONST_DICT(os_mbfs_file_locals_dict, os_mbfs_file_locals_dict_table); -STATIC const mp_stream_p_t textio_stream_p = { +static const mp_stream_p_t textio_stream_p = { .read = microbit_file_read, .write = microbit_file_write, .is_text = true, @@ -636,7 +636,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); -STATIC const mp_stream_p_t fileio_stream_p = { +static const mp_stream_p_t fileio_stream_p = { .read = microbit_file_read, .write = microbit_file_write, }; @@ -684,7 +684,7 @@ mp_obj_t os_mbfs_open(size_t n_args, const mp_obj_t *args) { mp_raise_ValueError(MP_ERROR_TEXT("illegal mode")); } -STATIC mp_obj_t os_mbfs_stat(mp_obj_t filename) { +static mp_obj_t os_mbfs_stat(mp_obj_t filename) { mp_obj_t file_size = microbit_file_size(filename); mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL)); diff --git a/src/codal_port/modantigravity.c b/src/codal_port/modantigravity.c index 421355d..842c2c4 100644 --- a/src/codal_port/modantigravity.c +++ b/src/codal_port/modantigravity.c @@ -31,12 +31,12 @@ #define GET_PIXEL(x, y) microbit_hal_display_get_pixel(x, y) #define SET_PIXEL(x, y, v) microbit_hal_display_set_pixel(x, y, v) -STATIC void antigravity_output_char(char c) { +static void antigravity_output_char(char c) { MP_PLAT_PRINT_STRN((char *)&c, 1); } // NOTE: string has to be plain ASCII -STATIC void antigravity_print_rle(const char *s) { +static void antigravity_print_rle(const char *s) { /* RLE encoding format (2 characters, [0] (first) and [1] (second)): * [0] the amount of times to output the specified character (max 127), * bitwise or'ed with 0x80 (to set the last bit, ie: bit 7) @@ -67,7 +67,7 @@ STATIC void antigravity_print_rle(const char *s) { */ //#define ANTIGRAVITY_COMIC_LARGE -STATIC void antigravity(uint8_t interval_ms) { +static void antigravity(uint8_t interval_ms) { /* move all of the LEDs upwards (we can move them in other directions in the * future). * first, output the traditional XKCD comic (either in full or micro:size :) @@ -194,17 +194,17 @@ STATIC void antigravity(uint8_t interval_ms) { } } -STATIC mp_obj_t antigravity__init__(void) { +static mp_obj_t antigravity__init__(void) { antigravity(200); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(antigravity___init___obj, antigravity__init__); +static MP_DEFINE_CONST_FUN_OBJ_0(antigravity___init___obj, antigravity__init__); -STATIC const mp_rom_map_elem_t antigravity_module_globals_table[] = { +static const mp_rom_map_elem_t antigravity_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_antigravity) }, { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&antigravity___init___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(antigravity_module_globals, antigravity_module_globals_table); +static MP_DEFINE_CONST_DICT(antigravity_module_globals, antigravity_module_globals_table); const mp_obj_module_t antigravity_module = { .base = { &mp_type_module }, diff --git a/src/codal_port/modaudio.c b/src/codal_port/modaudio.c index 2462d62..5962c22 100644 --- a/src/codal_port/modaudio.c +++ b/src/codal_port/modaudio.c @@ -57,7 +57,7 @@ void microbit_audio_stop(void) { microbit_hal_audio_stop_expression(); } -STATIC void audio_buffer_ready(void) { +static void audio_buffer_ready(void) { uint32_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION(); audio_output_state_t old_state = audio_output_state; audio_output_state = AUDIO_OUTPUT_STATE_DATA_READY; @@ -67,7 +67,7 @@ STATIC void audio_buffer_ready(void) { } } -STATIC void audio_data_fetcher(void) { +static void audio_data_fetcher(void) { audio_fetcher_scheduled = false; if (audio_source_iter == NULL) { return; @@ -109,11 +109,11 @@ STATIC void audio_data_fetcher(void) { } } -STATIC mp_obj_t audio_data_fetcher_wrapper(mp_obj_t arg) { +static mp_obj_t audio_data_fetcher_wrapper(mp_obj_t arg) { audio_data_fetcher(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(audio_data_fetcher_wrapper_obj, audio_data_fetcher_wrapper); +static MP_DEFINE_CONST_FUN_OBJ_1(audio_data_fetcher_wrapper_obj, audio_data_fetcher_wrapper); void microbit_hal_audio_ready_callback(void) { if (audio_output_state == AUDIO_OUTPUT_STATE_DATA_READY) { @@ -205,13 +205,13 @@ void microbit_audio_play_source(mp_obj_t src, mp_obj_t pin_select, bool wait, ui } } -STATIC mp_obj_t stop(void) { +static mp_obj_t stop(void) { microbit_audio_stop(); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(microbit_audio_stop_obj, stop); -STATIC mp_obj_t play(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t play(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // Note: the return_pin argument is for compatibility with micro:bit v1 and is ignored on v2. static const mp_arg_t allowed_args[] = { { MP_QSTR_source, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -238,7 +238,7 @@ mp_obj_t is_playing(void) { } MP_DEFINE_CONST_FUN_OBJ_0(microbit_audio_is_playing_obj, is_playing); -STATIC const mp_rom_map_elem_t audio_globals_table[] = { +static const mp_rom_map_elem_t audio_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audio) }, { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(µbit_audio_stop_obj) }, { MP_ROM_QSTR(MP_QSTR_play), MP_ROM_PTR(µbit_audio_play_obj) }, @@ -246,7 +246,7 @@ STATIC const mp_rom_map_elem_t audio_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_AudioFrame), MP_ROM_PTR(µbit_audio_frame_type) }, { MP_ROM_QSTR(MP_QSTR_SoundEffect), MP_ROM_PTR(µbit_soundeffect_type) }, }; -STATIC MP_DEFINE_CONST_DICT(audio_module_globals, audio_globals_table); +static MP_DEFINE_CONST_DICT(audio_module_globals, audio_globals_table); const mp_obj_module_t audio_module = { .base = { &mp_type_module }, @@ -258,14 +258,14 @@ MP_REGISTER_MODULE(MP_QSTR_audio, audio_module); /******************************************************************************/ // AudioFrame class -STATIC mp_obj_t microbit_audio_frame_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +static mp_obj_t microbit_audio_frame_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { (void)type_in; (void)args; mp_arg_check_num(n_args, n_kw, 0, 0, false); return microbit_audio_frame_make_new(); } -STATIC mp_obj_t audio_frame_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value_in) { +static mp_obj_t audio_frame_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value_in) { microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in; mp_int_t index = mp_obj_get_int(index_in); if (index < 0 || index >= AUDIO_CHUNK_SIZE) { @@ -376,7 +376,7 @@ static void mult(microbit_audio_frame_obj_t *self, float f) { } } -STATIC mp_obj_t audio_frame_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t audio_frame_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (mp_obj_get_type(lhs_in) != µbit_audio_frame_type) { return MP_OBJ_NULL; // op not supported } @@ -402,10 +402,10 @@ STATIC mp_obj_t audio_frame_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj } } -STATIC const mp_map_elem_t microbit_audio_frame_locals_dict_table[] = { +static const mp_map_elem_t microbit_audio_frame_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_copyfrom), (mp_obj_t)©from_obj }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_audio_frame_locals_dict, microbit_audio_frame_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_audio_frame_locals_dict, microbit_audio_frame_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( microbit_audio_frame_type, diff --git a/src/codal_port/modlog.c b/src/codal_port/modlog.c index 5d289e8..548c9c2 100644 --- a/src/codal_port/modlog.c +++ b/src/codal_port/modlog.c @@ -31,7 +31,7 @@ #define TIMESTAMP_DEFAULT_FORMAT (MICROBIT_HAL_LOG_TIMESTAMP_SECONDS) -STATIC void log_check_error(int result) { +static void log_check_error(int result) { if (result == MICROBIT_HAL_DEVICE_NO_RESOURCES) { mp_raise_OSError(MP_ENOSPC); } else if (result != MICROBIT_HAL_DEVICE_OK) { @@ -39,13 +39,13 @@ STATIC void log_check_error(int result) { } } -STATIC mp_obj_t log___init__(void) { +static mp_obj_t log___init__(void) { microbit_hal_log_set_timestamp(TIMESTAMP_DEFAULT_FORMAT); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(log___init___obj, log___init__); -STATIC mp_obj_t log_set_labels(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t log_set_labels(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_timestamp }; static const mp_arg_t allowed_args[] = { { MP_QSTR_timestamp, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_INT(TIMESTAMP_DEFAULT_FORMAT)} }, @@ -73,15 +73,15 @@ STATIC mp_obj_t log_set_labels(size_t n_args, const mp_obj_t *pos_args, mp_map_t return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(log_set_labels_obj, 0, log_set_labels); +static MP_DEFINE_CONST_FUN_OBJ_KW(log_set_labels_obj, 0, log_set_labels); -STATIC mp_obj_t log_set_mirroring(mp_obj_t serial) { +static mp_obj_t log_set_mirroring(mp_obj_t serial) { microbit_hal_log_set_mirroring(mp_obj_is_true(serial)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(log_set_mirroring_obj, log_set_mirroring); +static MP_DEFINE_CONST_FUN_OBJ_1(log_set_mirroring_obj, log_set_mirroring); -STATIC mp_obj_t log_delete(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t log_delete(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_full }; static const mp_arg_t allowed_args[] = { { MP_QSTR_full, MP_ARG_BOOL, {.u_bool = false} }, @@ -94,9 +94,9 @@ STATIC mp_obj_t log_delete(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(log_delete_obj, 0, log_delete); +static MP_DEFINE_CONST_FUN_OBJ_KW(log_delete_obj, 0, log_delete); -STATIC mp_obj_t log_add(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t log_add(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // Get the dict to add as a row. mp_map_t *map; if (n_args == 0) { @@ -132,9 +132,9 @@ STATIC mp_obj_t log_add(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(log_add_obj, 0, log_add); +static MP_DEFINE_CONST_FUN_OBJ_KW(log_add_obj, 0, log_add); -STATIC const mp_rom_map_elem_t log_module_globals_table[] = { +static const mp_rom_map_elem_t log_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_log) }, { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&log___init___obj) }, @@ -149,7 +149,7 @@ STATIC const mp_rom_map_elem_t log_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_HOURS), MP_ROM_INT(MICROBIT_HAL_LOG_TIMESTAMP_HOURS) }, { MP_ROM_QSTR(MP_QSTR_DAYS), MP_ROM_INT(MICROBIT_HAL_LOG_TIMESTAMP_DAYS) }, }; -STATIC MP_DEFINE_CONST_DICT(log_module_globals, log_module_globals_table); +static MP_DEFINE_CONST_DICT(log_module_globals, log_module_globals_table); const mp_obj_module_t log_module = { .base = { &mp_type_module }, diff --git a/src/codal_port/modlove.c b/src/codal_port/modlove.c index 892d3a8..541decf 100644 --- a/src/codal_port/modlove.c +++ b/src/codal_port/modlove.c @@ -28,11 +28,11 @@ #include "py/mphal.h" #include "modmicrobit.h" -STATIC const mp_float_t bright_levels[7] = { +static const mp_float_t bright_levels[7] = { 0.0, 1.0 / 9, 2.0 / 9, 4.0 / 9, 6.0 / 9, 7.0 / 9, 1.0, }; -STATIC void love(int interval_ms) { +static void love(int interval_ms) { microbit_image_obj_t *hearts[MP_ARRAY_SIZE(bright_levels)]; for (uint i = 0; i < MP_ARRAY_SIZE(bright_levels); i++) { hearts[i] = microbit_image_dim(HEART_IMAGE, bright_levels[i]); @@ -57,20 +57,20 @@ STATIC void love(int interval_ms) { microbit_display_clear(); } -STATIC mp_obj_t love_badaboom(void) { +static mp_obj_t love_badaboom(void) { // make love(25); // ! war return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(love_badaboom_obj, love_badaboom); +static MP_DEFINE_CONST_FUN_OBJ_0(love_badaboom_obj, love_badaboom); -STATIC const mp_map_elem_t love_module_globals_table[] = { +static const mp_map_elem_t love_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_love) }, { MP_OBJ_NEW_QSTR(MP_QSTR___init__), (mp_obj_t)&love_badaboom_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_badaboom), (mp_obj_t)&love_badaboom_obj }, }; -STATIC MP_DEFINE_CONST_DICT(love_module_globals, love_module_globals_table); +static MP_DEFINE_CONST_DICT(love_module_globals, love_module_globals_table); const mp_obj_module_t love_module = { .base = { &mp_type_module }, diff --git a/src/codal_port/modmachine.c b/src/codal_port/modmachine.c index 08094ad..3b786e3 100644 --- a/src/codal_port/modmachine.c +++ b/src/codal_port/modmachine.c @@ -33,34 +33,34 @@ #undef MICROPY_PY_MACHINE // Returns a string of 8 bytes (64 bits), which is the unique ID for the MCU -STATIC mp_obj_t machine_unique_id(void) { +static mp_obj_t machine_unique_id(void) { uint32_t dev_id[2]; mp_hal_unique_id(dev_id); return mp_obj_new_bytes((const void*)&dev_id, 8); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(microbit_unique_id_obj, machine_unique_id); +static MP_DEFINE_CONST_FUN_OBJ_0(microbit_unique_id_obj, machine_unique_id); // Get the MCU frequency -STATIC mp_obj_t machine_freq(void) { +static mp_obj_t machine_freq(void) { return MP_OBJ_NEW_SMALL_INT(64000000); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(microbit_freq_obj, machine_freq); +static MP_DEFINE_CONST_FUN_OBJ_0(microbit_freq_obj, machine_freq); // Disable interrupt requests -STATIC mp_obj_t machine_disable_irq(void) { +static mp_obj_t machine_disable_irq(void) { return mp_obj_new_int(mp_hal_disable_irq()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq); +static MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq); // Enable interrupt requests -STATIC mp_obj_t machine_enable_irq(mp_obj_t state_in) { +static mp_obj_t machine_enable_irq(mp_obj_t state_in) { uint32_t state = mp_obj_get_int(state_in); mp_hal_enable_irq(state); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq); -STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { +static const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(µbit_unique_id_obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(µbit_reset_obj) }, @@ -75,7 +75,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_time_pulse_us), MP_ROM_PTR(&machine_time_pulse_us_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table); +static MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table); const mp_obj_module_t machine_module = { .base = { &mp_type_module }, diff --git a/src/codal_port/modmicrobit.c b/src/codal_port/modmicrobit.c index b4abfd3..98d1086 100644 --- a/src/codal_port/modmicrobit.c +++ b/src/codal_port/modmicrobit.c @@ -32,15 +32,15 @@ #include "modaudio.h" #include "modmicrobit.h" -STATIC mp_obj_t microbit_run_every_new(uint32_t period_ms); +static mp_obj_t microbit_run_every_new(uint32_t period_ms); -STATIC mp_obj_t microbit_reset_(void) { +static mp_obj_t microbit_reset_(void) { microbit_hal_reset(); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(microbit_reset_obj, microbit_reset_); -STATIC mp_obj_t microbit_sleep(mp_obj_t ms_in) { +static mp_obj_t microbit_sleep(mp_obj_t ms_in) { mp_int_t ms; if (mp_obj_is_integer(ms_in)) { ms = mp_obj_get_int(ms_in); @@ -54,12 +54,12 @@ STATIC mp_obj_t microbit_sleep(mp_obj_t ms_in) { } MP_DEFINE_CONST_FUN_OBJ_1(microbit_sleep_obj, microbit_sleep); -STATIC mp_obj_t microbit_running_time(void) { +static mp_obj_t microbit_running_time(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms()); } MP_DEFINE_CONST_FUN_OBJ_0(microbit_running_time_obj, microbit_running_time); -STATIC mp_obj_t microbit_panic(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t microbit_panic(mp_uint_t n_args, const mp_obj_t *args) { if (n_args == 0) { // TODO the docs don't mention this, so maybe remove it? microbit_hal_panic(999); @@ -70,12 +70,12 @@ STATIC mp_obj_t microbit_panic(mp_uint_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_panic_obj, 0, 1, microbit_panic); -STATIC mp_obj_t microbit_temperature(void) { +static mp_obj_t microbit_temperature(void) { return mp_obj_new_int(microbit_hal_temperature()); } MP_DEFINE_CONST_FUN_OBJ_0(microbit_temperature_obj, microbit_temperature); -STATIC mp_obj_t microbit_set_volume(mp_obj_t volume_in) { +static mp_obj_t microbit_set_volume(mp_obj_t volume_in) { mp_int_t volume = mp_obj_get_int(volume_in); if (volume < 0) { volume = 0; @@ -85,18 +85,18 @@ STATIC mp_obj_t microbit_set_volume(mp_obj_t volume_in) { microbit_hal_audio_set_volume(volume); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_set_volume_obj, microbit_set_volume); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_set_volume_obj, microbit_set_volume); -STATIC mp_obj_t microbit_ws2812_write(mp_obj_t pin_in, mp_obj_t buf_in) { +static mp_obj_t microbit_ws2812_write(mp_obj_t pin_in, mp_obj_t buf_in) { uint8_t pin = microbit_obj_get_pin(pin_in)->name; mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); microbit_hal_pin_write_ws2812(pin, bufinfo.buf, bufinfo.len); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(microbit_ws2812_write_obj, microbit_ws2812_write); +static MP_DEFINE_CONST_FUN_OBJ_2(microbit_ws2812_write_obj, microbit_ws2812_write); -STATIC mp_obj_t microbit_run_every(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_run_every(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_callback, ARG_days, ARG_h, ARG_min, ARG_s, ARG_ms }; static const mp_arg_t allowed_args[] = { { MP_QSTR_callback, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -126,9 +126,9 @@ STATIC mp_obj_t microbit_run_every(size_t n_args, const mp_obj_t *pos_args, mp_m return MP_OBJ_TYPE_GET_SLOT(mp_obj_get_type(run_every), call)(run_every, 1, 0, &args[ARG_callback].u_obj); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(microbit_run_every_obj, 0, microbit_run_every); +static MP_DEFINE_CONST_FUN_OBJ_KW(microbit_run_every_obj, 0, microbit_run_every); -STATIC mp_obj_t microbit_scale(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_scale(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_value, ARG_from_, ARG_to }; static const mp_arg_t allowed_args[] = { { MP_QSTR_value, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -161,9 +161,9 @@ STATIC mp_obj_t microbit_scale(size_t n_args, const mp_obj_t *pos_args, mp_map_t return mp_obj_new_int(MICROPY_FLOAT_C_FUN(nearbyint)(to_value)); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(microbit_scale_obj, 0, microbit_scale); +static MP_DEFINE_CONST_FUN_OBJ_KW(microbit_scale_obj, 0, microbit_scale); -STATIC const mp_rom_map_elem_t microbit_module_globals_table[] = { +static const mp_rom_map_elem_t microbit_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_microbit) }, { MP_ROM_QSTR(MP_QSTR_Image), (mp_obj_t)µbit_image_type }, @@ -217,7 +217,7 @@ STATIC const mp_rom_map_elem_t microbit_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_pin_speaker), MP_ROM_PTR(µbit_pin_speaker_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_module_globals, microbit_module_globals_table); +static MP_DEFINE_CONST_DICT(microbit_module_globals, microbit_module_globals_table); const mp_obj_module_t microbit_module = { .base = { &mp_type_module }, @@ -234,7 +234,7 @@ typedef struct _microbit_run_every_obj_t { mp_obj_t user_callback; } microbit_run_every_obj_t; -STATIC mp_obj_t microbit_run_every_callback(mp_obj_t self_in) { +static mp_obj_t microbit_run_every_callback(mp_obj_t self_in) { microbit_run_every_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->user_callback == MP_OBJ_NULL) { @@ -264,9 +264,9 @@ STATIC mp_obj_t microbit_run_every_callback(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_run_every_callback_obj, microbit_run_every_callback); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_run_every_callback_obj, microbit_run_every_callback); -STATIC mp_obj_t microbit_run_every_obj_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t microbit_run_every_obj_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { microbit_run_every_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_arg_check_num(n_args, n_kw, 1, 1, false); self->timer.py_callback = MP_OBJ_FROM_PTR(µbit_run_every_callback_obj); @@ -275,14 +275,14 @@ STATIC mp_obj_t microbit_run_every_obj_call(mp_obj_t self_in, size_t n_args, siz return self_in; } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( microbit_run_every_obj_type, MP_QSTR_run_every, MP_TYPE_FLAG_NONE, call, microbit_run_every_obj_call ); -STATIC mp_obj_t microbit_run_every_new(uint32_t period_ms) { +static mp_obj_t microbit_run_every_new(uint32_t period_ms) { microbit_run_every_obj_t *self = m_new_obj(microbit_run_every_obj_t); self->timer.pairheap.base.type = µbit_run_every_obj_type; self->timer.flags = MICROBIT_SOFT_TIMER_FLAG_PY_CALLBACK | MICROBIT_SOFT_TIMER_FLAG_GC_ALLOCATED; diff --git a/src/codal_port/modmusic.c b/src/codal_port/modmusic.c index bd9ed52..13603a5 100644 --- a/src/codal_port/modmusic.c +++ b/src/codal_port/modmusic.c @@ -66,13 +66,13 @@ typedef struct _music_data_t { mp_obj_t async_note; } music_data_t; -STATIC uint32_t start_note(const char *note_str, size_t note_len); +static uint32_t start_note(const char *note_str, size_t note_len); -STATIC void music_output_amplitude(uint32_t amplitude) { +static void music_output_amplitude(uint32_t amplitude) { microbit_hal_pin_write_analog_u10(MICROBIT_HAL_PIN_MIXER, amplitude); } -STATIC int music_output_period_us(uint32_t period) { +static int music_output_period_us(uint32_t period) { return microbit_hal_pin_set_analog_period_us(MICROBIT_HAL_PIN_MIXER, period); } @@ -132,7 +132,7 @@ void microbit_music_tick(void) { } } -STATIC void wait_async_music_idle(void) { +static void wait_async_music_idle(void) { nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { // Wait for the async music state to become idle. @@ -149,7 +149,7 @@ STATIC void wait_async_music_idle(void) { } } -STATIC uint32_t start_note(const char *note_str, size_t note_len) { +static uint32_t start_note(const char *note_str, size_t note_len) { music_output_amplitude(MUSIC_OUTPUT_AMPLITUDE_ON); // [NOTE](#|b)(octave)(:length) @@ -158,9 +158,9 @@ STATIC uint32_t start_note(const char *note_str, size_t note_len) { // array of us periods // these are the periods of note4 (the octave ascending from middle c) from A->B then C->G - STATIC uint16_t periods_us[] = {2273, 2025, 3822, 3405, 3034, 2863, 2551}; + static uint16_t periods_us[] = {2273, 2025, 3822, 3405, 3034, 2863, 2551}; // A#, -, C#, D#, -, F#, G# - STATIC uint16_t periods_sharps_us[] = {2145, 0, 3608, 3214, 0, 2703, 2408}; + static uint16_t periods_sharps_us[] = {2145, 0, 3608, 3214, 0, 2703, 2408}; // we'll represent the note as an integer (A=0, G=6) // TODO: validate the note @@ -259,7 +259,7 @@ STATIC uint32_t start_note(const char *note_str, size_t note_len) { return gap_ms; } -STATIC mp_obj_t microbit_music_reset(void) { +static mp_obj_t microbit_music_reset(void) { music_data->bpm = DEFAULT_BPM; music_data->ticks = DEFAULT_TICKS; music_data->last_octave = DEFAULT_OCTAVE; @@ -268,7 +268,7 @@ STATIC mp_obj_t microbit_music_reset(void) { } MP_DEFINE_CONST_FUN_OBJ_0(microbit_music_reset_obj, microbit_music_reset); -STATIC mp_obj_t microbit_music_get_tempo(void) { +static mp_obj_t microbit_music_get_tempo(void) { mp_obj_t tempo_tuple[2]; tempo_tuple[0] = mp_obj_new_int(music_data->bpm); tempo_tuple[1] = mp_obj_new_int(music_data->ticks); @@ -276,7 +276,7 @@ STATIC mp_obj_t microbit_music_get_tempo(void) { } MP_DEFINE_CONST_FUN_OBJ_0(microbit_music_get_tempo_obj, microbit_music_get_tempo); -STATIC mp_obj_t microbit_music_stop(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t microbit_music_stop(mp_uint_t n_args, const mp_obj_t *args) { mp_const_obj_t pin; if (n_args == 0) { pin = MUSIC_OUTPUT_DEFAULT_PIN; @@ -296,7 +296,7 @@ STATIC mp_obj_t microbit_music_stop(mp_uint_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_music_stop_obj, 0, 1, microbit_music_stop); -STATIC mp_obj_t microbit_music_play(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_music_play(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_music, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_pin, MP_ARG_OBJ, {.u_obj = (mp_obj_t)MUSIC_OUTPUT_DEFAULT_PIN} }, @@ -352,7 +352,7 @@ STATIC mp_obj_t microbit_music_play(mp_uint_t n_args, const mp_obj_t *pos_args, } MP_DEFINE_CONST_FUN_OBJ_KW(microbit_music_play_obj, 0, microbit_music_play); -STATIC mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_frequency, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_duration, MP_ARG_INT, {.u_int = -1} }, @@ -400,7 +400,7 @@ STATIC mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args, } MP_DEFINE_CONST_FUN_OBJ_KW(microbit_music_pitch_obj, 0, microbit_music_pitch); -STATIC mp_obj_t microbit_music_set_tempo(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_music_set_tempo(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_ticks, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_bpm, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, @@ -434,7 +434,7 @@ static mp_obj_t music_init(void) { } MP_DEFINE_CONST_FUN_OBJ_0(music___init___obj, music_init); -STATIC const mp_rom_map_elem_t microbit_music_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_music_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_music) }, { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&music___init___obj) }, @@ -467,7 +467,7 @@ STATIC const mp_rom_map_elem_t microbit_music_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_POWER_UP), MP_ROM_PTR(µbit_music_tune_power_up_obj) }, { MP_ROM_QSTR(MP_QSTR_POWER_DOWN), MP_ROM_PTR(µbit_music_tune_power_down_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_music_locals_dict, microbit_music_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_music_locals_dict, microbit_music_locals_dict_table); const mp_obj_module_t music_module = { .base = { &mp_type_module }, diff --git a/src/codal_port/modos.c b/src/codal_port/modos.c index 731a5ba..d70fb36 100644 --- a/src/codal_port/modos.c +++ b/src/codal_port/modos.c @@ -40,17 +40,17 @@ const char microbit_release_string[] = MICROBIT_RELEASE; const char microbit_version_string[] = MICROBIT_VERSION; -STATIC const qstr os_uname_info_fields[] = { +static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -STATIC const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_PY_SYS_PLATFORM); -STATIC const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_PY_SYS_PLATFORM); -STATIC const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, microbit_release_string); -STATIC const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, microbit_version_string); -STATIC const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROBIT_BOARD_NAME " with " MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_PY_SYS_PLATFORM); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_PY_SYS_PLATFORM); +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, microbit_release_string); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, microbit_version_string); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROBIT_BOARD_NAME " with " MICROPY_HW_MCU_NAME); -STATIC MP_DEFINE_ATTRTUPLE( +static MP_DEFINE_ATTRTUPLE( os_uname_info_obj, os_uname_info_fields, 5, @@ -61,20 +61,20 @@ STATIC MP_DEFINE_ATTRTUPLE( MP_ROM_PTR(&os_uname_info_machine_obj) ); -STATIC mp_obj_t os_uname(void) { +static mp_obj_t os_uname(void) { return MP_OBJ_FROM_PTR(&os_uname_info_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname); +static MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname); #if MICROPY_MBFS -STATIC mp_obj_t os_size(mp_obj_t filename) { +static mp_obj_t os_size(mp_obj_t filename) { mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(os_mbfs_stat_obj.fun._1(filename)); return tuple->items[6]; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_size_obj, os_size); +static MP_DEFINE_CONST_FUN_OBJ_1(os_size_obj, os_size); #endif -STATIC const mp_rom_map_elem_t os_module_globals_table[] = { +static const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) }, @@ -89,7 +89,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_size), MP_ROM_PTR(&os_size_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); +static MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); const mp_obj_module_t os_module = { .base = { &mp_type_module }, diff --git a/src/codal_port/modpower.c b/src/codal_port/modpower.c index bbfdfc8..2cec449 100644 --- a/src/codal_port/modpower.c +++ b/src/codal_port/modpower.c @@ -28,7 +28,7 @@ #include "py/mphal.h" #include "drv_softtimer.h" -STATIC size_t get_array(mp_obj_t *src, mp_obj_t **items) { +static size_t get_array(mp_obj_t *src, mp_obj_t **items) { if (*src == mp_const_none) { // None, so an array of length 0. *items = NULL; @@ -45,13 +45,13 @@ STATIC size_t get_array(mp_obj_t *src, mp_obj_t **items) { } } -STATIC mp_obj_t power_off(void) { +static mp_obj_t power_off(void) { microbit_hal_power_off(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(power_off_obj, power_off); +static MP_DEFINE_CONST_FUN_OBJ_0(power_off_obj, power_off); -STATIC mp_obj_t power_deep_sleep(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t power_deep_sleep(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_ms, ARG_wake_on, ARG_run_every }; static const mp_arg_t allowed_args[] = { { MP_QSTR_ms, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -136,15 +136,15 @@ STATIC mp_obj_t power_deep_sleep(size_t n_args, const mp_obj_t *pos_args, mp_map return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(power_deep_sleep_obj, 0, power_deep_sleep); +static MP_DEFINE_CONST_FUN_OBJ_KW(power_deep_sleep_obj, 0, power_deep_sleep); -STATIC const mp_rom_map_elem_t power_module_globals_table[] = { +static const mp_rom_map_elem_t power_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_power) }, { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&power_off_obj) }, { MP_ROM_QSTR(MP_QSTR_deep_sleep), MP_ROM_PTR(&power_deep_sleep_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(power_module_globals, power_module_globals_table); +static MP_DEFINE_CONST_DICT(power_module_globals, power_module_globals_table); const mp_obj_module_t power_module = { .base = { &mp_type_module }, diff --git a/src/codal_port/modradio.c b/src/codal_port/modradio.c index 5bd89f0..d49e256 100644 --- a/src/codal_port/modradio.c +++ b/src/codal_port/modradio.c @@ -32,24 +32,24 @@ #include "py/smallint.h" #include "drv_radio.h" -STATIC microbit_radio_config_t radio_config; +static microbit_radio_config_t radio_config; -STATIC mp_obj_t mod_radio_reset(void); +static mp_obj_t mod_radio_reset(void); -STATIC void ensure_enabled(void) { +static void ensure_enabled(void) { if (MP_STATE_PORT(radio_buf) == NULL) { mp_raise_ValueError(MP_ERROR_TEXT("radio is not enabled")); } } -STATIC mp_obj_t mod_radio___init__(void) { +static mp_obj_t mod_radio___init__(void) { mod_radio_reset(); microbit_radio_enable(&radio_config); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(mod_radio___init___obj, mod_radio___init__); -STATIC mp_obj_t mod_radio_reset(void) { +static mp_obj_t mod_radio_reset(void) { radio_config.max_payload = MICROBIT_RADIO_DEFAULT_MAX_PAYLOAD; radio_config.queue_len = MICROBIT_RADIO_DEFAULT_QUEUE_LEN; radio_config.channel = MICROBIT_RADIO_DEFAULT_CHANNEL; @@ -61,7 +61,7 @@ STATIC mp_obj_t mod_radio_reset(void) { } MP_DEFINE_CONST_FUN_OBJ_0(mod_radio_reset_obj, mod_radio_reset); -STATIC mp_obj_t mod_radio_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mod_radio_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { (void)pos_args; // unused if (n_args != 0) { @@ -160,19 +160,19 @@ STATIC mp_obj_t mod_radio_config(size_t n_args, const mp_obj_t *pos_args, mp_map } MP_DEFINE_CONST_FUN_OBJ_KW(mod_radio_config_obj, 0, mod_radio_config); -STATIC mp_obj_t mod_radio_on(void) { +static mp_obj_t mod_radio_on(void) { microbit_radio_enable(&radio_config); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(mod_radio_on_obj, mod_radio_on); -STATIC mp_obj_t mod_radio_off(void) { +static mp_obj_t mod_radio_off(void) { microbit_radio_disable(); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(mod_radio_off_obj, mod_radio_off); -STATIC mp_obj_t mod_radio_send_bytes(mp_obj_t buf_in) { +static mp_obj_t mod_radio_send_bytes(mp_obj_t buf_in) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); ensure_enabled(); @@ -181,7 +181,7 @@ STATIC mp_obj_t mod_radio_send_bytes(mp_obj_t buf_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mod_radio_send_bytes_obj, mod_radio_send_bytes); -STATIC mp_obj_t mod_radio_receive_bytes(void) { +static mp_obj_t mod_radio_receive_bytes(void) { ensure_enabled(); const uint8_t *buf = microbit_radio_peek(); if (buf == NULL) { @@ -194,7 +194,7 @@ STATIC mp_obj_t mod_radio_receive_bytes(void) { } MP_DEFINE_CONST_FUN_OBJ_0(mod_radio_receive_bytes_obj, mod_radio_receive_bytes); -STATIC mp_obj_t mod_radio_send(mp_obj_t buf_in) { +static mp_obj_t mod_radio_send(mp_obj_t buf_in) { mp_uint_t len; const char *data = mp_obj_str_get_data(buf_in, &len); ensure_enabled(); @@ -203,7 +203,7 @@ STATIC mp_obj_t mod_radio_send(mp_obj_t buf_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mod_radio_send_obj, mod_radio_send); -STATIC mp_obj_t mod_radio_receive(void) { +static mp_obj_t mod_radio_receive(void) { ensure_enabled(); const uint8_t *buf = microbit_radio_peek(); if (buf == NULL) { @@ -221,7 +221,7 @@ STATIC mp_obj_t mod_radio_receive(void) { } MP_DEFINE_CONST_FUN_OBJ_0(mod_radio_receive_obj, mod_radio_receive); -STATIC mp_obj_t mod_radio_receive_bytes_into(mp_obj_t buf_in) { +static mp_obj_t mod_radio_receive_bytes_into(mp_obj_t buf_in) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE); ensure_enabled(); @@ -237,7 +237,7 @@ STATIC mp_obj_t mod_radio_receive_bytes_into(mp_obj_t buf_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mod_radio_receive_bytes_into_obj, mod_radio_receive_bytes_into); -STATIC mp_obj_t mod_radio_receive_full(void) { +static mp_obj_t mod_radio_receive_full(void) { ensure_enabled(); const uint8_t *buf = microbit_radio_peek(); if (buf == NULL) { @@ -260,7 +260,7 @@ STATIC mp_obj_t mod_radio_receive_full(void) { } MP_DEFINE_CONST_FUN_OBJ_0(mod_radio_receive_full_obj, mod_radio_receive_full); -STATIC const mp_map_elem_t radio_module_globals_table[] = { +static const mp_map_elem_t radio_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_radio) }, { MP_OBJ_NEW_QSTR(MP_QSTR___init__), (mp_obj_t)&mod_radio___init___obj }, @@ -284,7 +284,7 @@ STATIC const mp_map_elem_t radio_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_RATE_2MBIT), MP_OBJ_NEW_SMALL_INT(RADIO_MODE_MODE_Nrf_2Mbit) }, }; -STATIC MP_DEFINE_CONST_DICT(radio_module_globals, radio_module_globals_table); +static MP_DEFINE_CONST_DICT(radio_module_globals, radio_module_globals_table); const mp_obj_module_t radio_module = { .base = { &mp_type_module }, diff --git a/src/codal_port/modspeech.c b/src/codal_port/modspeech.c index 32305b5..ed587c0 100644 --- a/src/codal_port/modspeech.c +++ b/src/codal_port/modspeech.c @@ -104,7 +104,7 @@ void microbit_hal_audio_speech_ready_callback(void) { #endif } -STATIC void sam_output_reset(microbit_audio_frame_obj_t *src_frame) { +static void sam_output_reset(microbit_audio_frame_obj_t *src_frame) { sam_output_frame = src_frame; buf_start_pos = 0; last_pos = 0; @@ -123,7 +123,7 @@ STATIC void sam_output_reset(microbit_audio_frame_obj_t *src_frame) { #endif } -STATIC void speech_wait_output_drained(void) { +static void speech_wait_output_drained(void) { #if USE_DEDICATED_AUDIO_CHANNEL while (speech_output_read >= 0) { mp_handle_pending(true); @@ -147,7 +147,7 @@ STATIC void speech_wait_output_drained(void) { } #if USE_DEDICATED_AUDIO_CHANNEL -STATIC void speech_output_sample(uint8_t b) { +static void speech_output_sample(uint8_t b) { speech_output_buffer[OUT_CHUNK_SIZE * speech_output_write + speech_output_buffer_idx++] = b; if (speech_output_buffer_idx >= OUT_CHUNK_SIZE) { speech_wait_output_drained(); @@ -327,7 +327,7 @@ void SamOutputByte(unsigned int pos, unsigned char b) { // This iterator assumes that the speech renderer can generate samples // at least as fast as we can consume them. -STATIC mp_obj_t next(mp_obj_t iter) { +static mp_obj_t next(mp_obj_t iter) { if (exhausted) { return MP_OBJ_STOP_ITERATION; } @@ -344,14 +344,14 @@ STATIC mp_obj_t next(mp_obj_t iter) { } } -STATIC const mp_obj_type_t speech_iterator_type = { +static const mp_obj_type_t speech_iterator_type = { { &mp_type_type }, .name = MP_QSTR_iterator, .getiter = mp_identity_getiter, .iternext = next, }; -STATIC mp_obj_t make_speech_iter(void) { +static mp_obj_t make_speech_iter(void) { speech_iterator_t *result = m_new_obj(speech_iterator_t); result->base.type = &speech_iterator_type; result->empty = microbit_audio_frame_make_new(); @@ -361,7 +361,7 @@ STATIC mp_obj_t make_speech_iter(void) { #endif -STATIC mp_obj_t translate(mp_obj_t words) { +static mp_obj_t translate(mp_obj_t words) { mp_uint_t len, outlen; const char *txt = mp_obj_str_get_data(words, &len); // Reciter truncates *output* at about 120 characters. @@ -391,7 +391,7 @@ STATIC mp_obj_t translate(mp_obj_t words) { } MP_DEFINE_CONST_FUN_OBJ_1(translate_obj, translate); -STATIC mp_obj_t articulate(mp_obj_t phonemes, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, bool sing) { +static mp_obj_t articulate(mp_obj_t phonemes, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, bool sing) { static const mp_arg_t allowed_args[] = { { MP_QSTR_pitch, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DEFAULT_PITCH} }, { MP_QSTR_speed, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DEFAULT_SPEED} }, @@ -470,30 +470,30 @@ STATIC mp_obj_t articulate(mp_obj_t phonemes, mp_uint_t n_args, const mp_obj_t * return mp_const_none; } -STATIC mp_obj_t say(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t say(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_obj_t phonemes = translate(pos_args[0]); return articulate(phonemes, n_args-1, pos_args+1, kw_args, false); } MP_DEFINE_CONST_FUN_OBJ_KW(say_obj, 1, say); -STATIC mp_obj_t pronounce(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pronounce(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return articulate(pos_args[0], n_args-1, pos_args+1, kw_args, false); } MP_DEFINE_CONST_FUN_OBJ_KW(pronounce_obj, 1, pronounce); -STATIC mp_obj_t sing(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t sing(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return articulate(pos_args[0], n_args-1, pos_args+1, kw_args, true); } MP_DEFINE_CONST_FUN_OBJ_KW(sing_obj, 1, sing); -STATIC const mp_map_elem_t _globals_table[] = { +static const mp_map_elem_t _globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_speech) }, { MP_OBJ_NEW_QSTR(MP_QSTR_say), (mp_obj_t)&say_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_sing), (mp_obj_t)&sing_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_pronounce), (mp_obj_t)&pronounce_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_translate), (mp_obj_t)&translate_obj }, }; -STATIC MP_DEFINE_CONST_DICT(_globals, _globals_table); +static MP_DEFINE_CONST_DICT(_globals, _globals_table); const mp_obj_module_t speech_module = { .base = { &mp_type_module }, diff --git a/src/codal_port/modthis.c b/src/codal_port/modthis.c index 8430850..105b6dd 100644 --- a/src/codal_port/modthis.c +++ b/src/codal_port/modthis.c @@ -26,7 +26,7 @@ #include "py/runtime.h" -STATIC const char *this_text = +static const char *this_text = "The Zen of MicroPython, by Nicholas H. Tollervey\n" "\n" "Code,\n" @@ -41,31 +41,31 @@ STATIC const char *this_text = "Happy hacking! :-)\n"; // If you contribute code to this project, add your name here. -STATIC const char *authors_text = +static const char *authors_text = "MicroPython on the micro:bit is brought to you by:\n" "Damien P. George, Mark Shannon, Radomir Dopieralski, Matthew Else,\n" "Carol Willing, Tom Viner, Alan Jackson, Nick Coghlan, Joseph Haig,\n" "Alex Chan, Andrea Grandi, Paul Egan, Piotr Kasprzyk, Andrew Mulholland,\n" "Matt Wheeler, Joe Glancy, Abbie Brooks and Nicholas H. Tollervey.\n"; -STATIC mp_obj_t this__init__(void) { +static mp_obj_t this__init__(void) { mp_printf(&mp_plat_print, "%s", this_text); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(this___init___obj, this__init__); -STATIC mp_obj_t this_authors(void) { +static mp_obj_t this_authors(void) { mp_printf(&mp_plat_print, "%s", authors_text); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(this_authors_obj, this_authors); -STATIC const mp_rom_map_elem_t this_module_globals_table[] = { +static const mp_rom_map_elem_t this_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_this) }, { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&this___init___obj) }, { MP_ROM_QSTR(MP_QSTR_authors), MP_ROM_PTR(&this_authors_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(this_module_globals, this_module_globals_table); +static MP_DEFINE_CONST_DICT(this_module_globals, this_module_globals_table); const mp_obj_module_t this_module = { .base = { &mp_type_module }, From 94868138f327c6b329ec894ad65e7b03e4cf28f8 Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Tue, 6 Aug 2024 16:45:32 +0100 Subject: [PATCH 42/50] codal_app: Update codal-microbit-v2 to v0.2.67. Removed workaround needed before CODAL set the uBit.io.logo touch mode to capacitive by default. Discussion: https://github.com/microbit-foundation/micropython-microbit-v2/issues/168 CODAL changelog: https://github.com/lancaster-university/codal-microbit-v2/blob/master/Changelog.md#v0267 --- src/codal_app/codal.json | 2 +- src/codal_app/main.cpp | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/codal_app/codal.json b/src/codal_app/codal.json index f1d9977..9444ac5 100644 --- a/src/codal_app/codal.json +++ b/src/codal_app/codal.json @@ -2,7 +2,7 @@ "target": { "name": "codal-microbit-v2", "url": "https://github.com/lancaster-university/codal-microbit-v2", - "branch": "v0.2.66", + "branch": "v0.2.67", "type": "git", "test_ignore": true } , diff --git a/src/codal_app/main.cpp b/src/codal_app/main.cpp index 09c89f7..00e91a9 100644 --- a/src/codal_app/main.cpp +++ b/src/codal_app/main.cpp @@ -75,9 +75,6 @@ int main() { uBit.audio.setSpeakerEnabled(true); uBit.audio.setPinEnabled(false); - // Initialise the logo pin in capacitive touch mode. - uBit.io.logo.isTouched(TouchMode::Capacitative); - mp_main(); return 0; } From d7f0a294d3e8e299db3a40d7a3537638e4f0c37b Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 22 Aug 2024 11:08:39 +1000 Subject: [PATCH 43/50] codal_app/microbithal: Add sound effect default constants. Signed-off-by: Damien George --- src/codal_app/microbithal.cpp | 14 ++++++++++++-- src/codal_app/microbithal.h | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/codal_app/microbithal.cpp b/src/codal_app/microbithal.cpp index e21fdba..67ec283 100644 --- a/src/codal_app/microbithal.cpp +++ b/src/codal_app/microbithal.cpp @@ -25,11 +25,23 @@ */ #include "main.h" +#include "microbithal.h" #include "MicroBitDevice.h" #include "neopixel.h" #define HAL_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +// It's not possible to include the CODAL header file that defines the SFX_DEFAULT_xxx +// constants in C code, because that CODAL header file is C++. Instead we define our +// own MICROBIT_HAL_SFX_DEFAULT_xxx versions of the constants in a C-compatible header +// file, and assert here that they have the same value as the CODAL constants. +static_assert(MICROBIT_HAL_SFX_DEFAULT_VIBRATO_PARAM == SFX_DEFAULT_VIBRATO_PARAM, ""); +static_assert(MICROBIT_HAL_SFX_DEFAULT_VIBRATO_STEPS == SFX_DEFAULT_VIBRATO_STEPS, ""); +static_assert(MICROBIT_HAL_SFX_DEFAULT_TREMOLO_PARAM == SFX_DEFAULT_TREMOLO_PARAM, ""); +static_assert(MICROBIT_HAL_SFX_DEFAULT_TREMOLO_STEPS == SFX_DEFAULT_TREMOLO_STEPS, ""); +static_assert(MICROBIT_HAL_SFX_DEFAULT_WARBLE_PARAM == SFX_DEFAULT_WARBLE_PARAM, ""); +static_assert(MICROBIT_HAL_SFX_DEFAULT_WARBLE_STEPS == SFX_DEFAULT_WARBLE_STEPS, ""); + NRF52Pin *const pin_obj[] = { &uBit.io.P0, &uBit.io.P1, @@ -83,8 +95,6 @@ static uint16_t button_state[2]; extern "C" { -#include "microbithal.h" - void microbit_hal_background_processing(void) { // This call takes about 200us. Event(DEVICE_ID_SCHEDULER, DEVICE_SCHEDULER_EVT_IDLE); diff --git a/src/codal_app/microbithal.h b/src/codal_app/microbithal.h index 0292121..2ebeaf0 100644 --- a/src/codal_app/microbithal.h +++ b/src/codal_app/microbithal.h @@ -103,6 +103,14 @@ extern "C" { #define MICROBIT_HAL_LOG_TIMESTAMP_HOURS (36000) #define MICROBIT_HAL_LOG_TIMESTAMP_DAYS (864000) +// These default fx values are the same as defined by CODAL, but here in a C-compatible header. +#define MICROBIT_HAL_SFX_DEFAULT_VIBRATO_PARAM (2) +#define MICROBIT_HAL_SFX_DEFAULT_VIBRATO_STEPS (512) +#define MICROBIT_HAL_SFX_DEFAULT_TREMOLO_PARAM (3) +#define MICROBIT_HAL_SFX_DEFAULT_TREMOLO_STEPS (900) +#define MICROBIT_HAL_SFX_DEFAULT_WARBLE_PARAM (2) +#define MICROBIT_HAL_SFX_DEFAULT_WARBLE_STEPS (700) + void microbit_hal_idle(void); __attribute__((noreturn)) void microbit_hal_reset(void); From 251bd63c243c0d03c291e0cf29d489b2f653c165 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 21 Aug 2024 11:54:58 +1000 Subject: [PATCH 44/50] codal_port/microbit_soundeffect: Add comments for CODAL fx constants. It's not possible to include the CODAL header file that defines these constants because that header file is C++. Signed-off-by: Damien George --- src/codal_port/microbit_soundeffect.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/codal_port/microbit_soundeffect.c b/src/codal_port/microbit_soundeffect.c index cd51f8a..70bc969 100644 --- a/src/codal_port/microbit_soundeffect.c +++ b/src/codal_port/microbit_soundeffect.c @@ -25,6 +25,7 @@ */ #include "py/runtime.h" +#include "microbithal.h" #include "modmicrobit.h" #include "modaudio.h" @@ -69,14 +70,6 @@ #define SOUND_EFFECT_FX_VIBRATO (1) #define SOUND_EFFECT_FX_WARBLE (3) -// These default fx values are the same as used by MakeCode. -#define SOUND_EFFECT_FX_VIBRATO_DEFAULT_PARAM (2) -#define SOUND_EFFECT_FX_TREMOLO_DEFAULT_PARAM (3) -#define SOUND_EFFECT_FX_WARBLE_DEFAULT_PARAM (2) -#define SOUND_EFFECT_FX_VIBRATO_DEFAULT_STEPS (512) -#define SOUND_EFFECT_FX_TREMOLO_DEFAULT_STEPS (900) -#define SOUND_EFFECT_FX_WARBLE_DEFAULT_STEPS (700) - #define SOUND_EFFECT_DEFAULT_FREQ_START (500) #define SOUND_EFFECT_DEFAULT_FREQ_END (2500) #define SOUND_EFFECT_DEFAULT_DURATION (500) @@ -125,15 +118,15 @@ static const soundeffect_attr_t soundeffect_attr_table[] = { }; static const uint8_t fx_default_param[] = { - [SOUND_EFFECT_FX_VIBRATO] = SOUND_EFFECT_FX_VIBRATO_DEFAULT_PARAM, - [SOUND_EFFECT_FX_TREMOLO] = SOUND_EFFECT_FX_TREMOLO_DEFAULT_PARAM, - [SOUND_EFFECT_FX_WARBLE] = SOUND_EFFECT_FX_WARBLE_DEFAULT_PARAM, + [SOUND_EFFECT_FX_VIBRATO] = MICROBIT_HAL_SFX_DEFAULT_VIBRATO_PARAM, + [SOUND_EFFECT_FX_TREMOLO] = MICROBIT_HAL_SFX_DEFAULT_TREMOLO_PARAM, + [SOUND_EFFECT_FX_WARBLE] = MICROBIT_HAL_SFX_DEFAULT_WARBLE_PARAM, }; static const uint16_t fx_default_steps[] = { - [SOUND_EFFECT_FX_VIBRATO] = SOUND_EFFECT_FX_VIBRATO_DEFAULT_STEPS, - [SOUND_EFFECT_FX_TREMOLO] = SOUND_EFFECT_FX_TREMOLO_DEFAULT_STEPS, - [SOUND_EFFECT_FX_WARBLE] = SOUND_EFFECT_FX_WARBLE_DEFAULT_STEPS, + [SOUND_EFFECT_FX_VIBRATO] = MICROBIT_HAL_SFX_DEFAULT_VIBRATO_STEPS, + [SOUND_EFFECT_FX_TREMOLO] = MICROBIT_HAL_SFX_DEFAULT_TREMOLO_STEPS, + [SOUND_EFFECT_FX_WARBLE] = MICROBIT_HAL_SFX_DEFAULT_WARBLE_STEPS, }; const char *microbit_soundeffect_get_sound_expr_data(mp_obj_t self_in) { From 0df07b1945aa0bba44f6ca08ca28e8d177d56204 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 9 Sep 2024 11:42:15 +1000 Subject: [PATCH 45/50] codal_app/microbithal: Add microbit_hal_display_rotate() function. Signed-off-by: Damien George --- src/codal_app/microbithal.cpp | 10 ++++++++++ src/codal_app/microbithal.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/codal_app/microbithal.cpp b/src/codal_app/microbithal.cpp index 67ec283..5e31e49 100644 --- a/src/codal_app/microbithal.cpp +++ b/src/codal_app/microbithal.cpp @@ -375,6 +375,16 @@ int microbit_hal_display_read_light_level(void) { return uBit.display.readLightLevel(); } +void microbit_hal_display_rotate(unsigned int rotation) { + static DisplayRotation angle_map[4] = { + MATRIX_DISPLAY_ROTATION_0, + MATRIX_DISPLAY_ROTATION_90, + MATRIX_DISPLAY_ROTATION_180, + MATRIX_DISPLAY_ROTATION_270, + }; + uBit.display.rotateTo(angle_map[rotation & 3]); +} + void microbit_hal_accelerometer_get_sample(int axis[3]) { Sample3D sample = uBit.accelerometer.getSample(); axis[0] = sample.x; diff --git a/src/codal_app/microbithal.h b/src/codal_app/microbithal.h index 2ebeaf0..09ecb52 100644 --- a/src/codal_app/microbithal.h +++ b/src/codal_app/microbithal.h @@ -150,6 +150,7 @@ void microbit_hal_display_enable(int value); int microbit_hal_display_get_pixel(int x, int y); void microbit_hal_display_set_pixel(int x, int y, int bright); int microbit_hal_display_read_light_level(void); +void microbit_hal_display_rotate(unsigned int rotation); void microbit_hal_accelerometer_get_sample(int axis[3]); int microbit_hal_accelerometer_get_gesture(void); From ff39fbf5d7635035b5a84e625b9d248dbb380b4b Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 9 Sep 2024 11:42:36 +1000 Subject: [PATCH 46/50] codal_port/microbit_display: Add display.rotate(angle) method. This takes an angle in degrees and rounds it towards the nearest multiple of 90. Signed-off-by: Damien George --- src/codal_port/microbit_display.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/codal_port/microbit_display.c b/src/codal_port/microbit_display.c index 25f1e9d..e9e3f04 100644 --- a/src/codal_port/microbit_display.c +++ b/src/codal_port/microbit_display.c @@ -24,6 +24,7 @@ * THE SOFTWARE. */ +#include #include "py/runtime.h" #include "py/objstr.h" #include "py/mphal.h" @@ -199,6 +200,24 @@ static mp_obj_t microbit_display_get_pixel_func(mp_obj_t self_in, mp_obj_t x_in, } MP_DEFINE_CONST_FUN_OBJ_3(microbit_display_get_pixel_obj, microbit_display_get_pixel_func); +static mp_obj_t microbit_display_rotate(mp_obj_t self_in, mp_obj_t angle_in) { + (void)self_in; + mp_float_t angle_degrees = mp_obj_get_float(angle_in); + + // Round angle towards nearest multiple of 90 degrees, within 0..359. + angle_degrees = MICROPY_FLOAT_C_FUN(fmod)(angle_degrees, 360); + if (angle_degrees < 0) { + angle_degrees += 360; + } + unsigned int rotation = (unsigned int)((angle_degrees + 45) / 90); + + // Set the display rotation. + microbit_hal_display_rotate(rotation); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(microbit_display_rotate_obj, microbit_display_rotate); + static const mp_rom_map_elem_t microbit_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get_pixel), MP_ROM_PTR(µbit_display_get_pixel_obj) }, { MP_ROM_QSTR(MP_QSTR_set_pixel), MP_ROM_PTR(µbit_display_set_pixel_obj) }, @@ -209,6 +228,7 @@ static const mp_rom_map_elem_t microbit_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(µbit_display_off_obj) }, { MP_ROM_QSTR(MP_QSTR_is_on), MP_ROM_PTR(µbit_display_is_on_obj) }, { MP_ROM_QSTR(MP_QSTR_read_light_level),MP_ROM_PTR(µbit_display_read_light_level_obj) }, + { MP_ROM_QSTR(MP_QSTR_rotate),MP_ROM_PTR(µbit_display_rotate_obj) }, }; static MP_DEFINE_CONST_DICT(microbit_display_locals_dict, microbit_display_locals_dict_table); From 8dad9e62b1b021d131436277e09c7add7e8c1992 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 9 Sep 2024 12:07:22 +1000 Subject: [PATCH 47/50] codal_app/microbithal_microphone: Add hal_microphone_get_level_db(). Signed-off-by: Damien George --- src/codal_app/microbithal.h | 1 + src/codal_app/microbithal_microphone.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/codal_app/microbithal.h b/src/codal_app/microbithal.h index 09ecb52..ac60201 100644 --- a/src/codal_app/microbithal.h +++ b/src/codal_app/microbithal.h @@ -166,6 +166,7 @@ int microbit_hal_compass_get_heading(void); void microbit_hal_microphone_init(void); void microbit_hal_microphone_set_threshold(int kind, int value); int microbit_hal_microphone_get_level(void); +float microbit_hal_microphone_get_level_db(void); const uint8_t *microbit_hal_get_font_data(char c); diff --git a/src/codal_app/microbithal_microphone.cpp b/src/codal_app/microbithal_microphone.cpp index 0cceb16..e530432 100644 --- a/src/codal_app/microbithal_microphone.cpp +++ b/src/codal_app/microbithal_microphone.cpp @@ -59,4 +59,11 @@ int microbit_hal_microphone_get_level(void) { return value; } +float microbit_hal_microphone_get_level_db(void) { + uBit.audio.levelSPL->setUnit(LEVEL_DETECTOR_SPL_DB); + float value = uBit.audio.levelSPL->getValue(); + uBit.audio.levelSPL->setUnit(LEVEL_DETECTOR_SPL_8BIT); + return value; +} + } From e876dcac96d597fb35f7541f752c2ea34dcae854 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 9 Sep 2024 12:07:45 +1000 Subject: [PATCH 48/50] codal_port/microbit_microphone: Add microphone.sound_level_db() method. This returns a floating-point number in dB. Signed-off-by: Damien George --- src/codal_port/microbit_microphone.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/codal_port/microbit_microphone.c b/src/codal_port/microbit_microphone.c index 338f2e0..cf37069 100644 --- a/src/codal_port/microbit_microphone.c +++ b/src/codal_port/microbit_microphone.c @@ -109,6 +109,13 @@ static mp_obj_t microbit_microphone_sound_level(mp_obj_t self_in) { } static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_sound_level_obj, microbit_microphone_sound_level); +static mp_obj_t microbit_microphone_sound_level_db(mp_obj_t self_in) { + (void)self_in; + microphone_init(); + return mp_obj_new_float_from_f(microbit_hal_microphone_get_level_db()); +} +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_sound_level_db_obj, microbit_microphone_sound_level_db); + static mp_obj_t microbit_microphone_current_event(mp_obj_t self_in) { (void)self_in; microphone_init(); @@ -154,6 +161,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_get_events_obj, microbit_mi static const mp_rom_map_elem_t microbit_microphone_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_set_threshold), MP_ROM_PTR(µbit_microphone_set_threshold_obj) }, { MP_ROM_QSTR(MP_QSTR_sound_level), MP_ROM_PTR(µbit_microphone_sound_level_obj) }, + { MP_ROM_QSTR(MP_QSTR_sound_level_db), MP_ROM_PTR(µbit_microphone_sound_level_db_obj) }, { MP_ROM_QSTR(MP_QSTR_current_event), MP_ROM_PTR(µbit_microphone_current_event_obj) }, { MP_ROM_QSTR(MP_QSTR_is_event), MP_ROM_PTR(µbit_microphone_is_event_obj) }, { MP_ROM_QSTR(MP_QSTR_was_event), MP_ROM_PTR(µbit_microphone_was_event_obj) }, From 24e75fffb1c659dd24a0b09f0777d5189d107a88 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 9 Sep 2024 12:28:01 +1000 Subject: [PATCH 49/50] codal_app/microbithal: Add microbit_hal_pin_touch_calibrate() function. Signed-off-by: Damien George --- src/codal_app/microbithal.cpp | 4 ++++ src/codal_app/microbithal.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/codal_app/microbithal.cpp b/src/codal_app/microbithal.cpp index 5e31e49..23c4231 100644 --- a/src/codal_app/microbithal.cpp +++ b/src/codal_app/microbithal.cpp @@ -213,6 +213,10 @@ void microbit_hal_pin_write_analog_u10(int pin, int value) { pin_obj[pin]->setAnalogValue(value); } +void microbit_hal_pin_touch_calibrate(int pin) { + pin_obj[pin]->touchCalibrate(); +} + int microbit_hal_pin_touch_state(int pin, int *was_touched, int *num_touches) { if (was_touched != NULL || num_touches != NULL) { int pin_state_index; diff --git a/src/codal_app/microbithal.h b/src/codal_app/microbithal.h index ac60201..78d455f 100644 --- a/src/codal_app/microbithal.h +++ b/src/codal_app/microbithal.h @@ -132,6 +132,7 @@ int microbit_hal_pin_read(int pin); void microbit_hal_pin_write(int pin, int value); int microbit_hal_pin_read_analog_u10(int pin); void microbit_hal_pin_write_analog_u10(int pin, int value); +void microbit_hal_pin_touch_calibrate(int pin); int microbit_hal_pin_touch_state(int pin, int *was_touched, int *num_touches); void microbit_hal_pin_write_ws2812(int pin, const uint8_t *buf, size_t len); From 3f22f306bcbc3461b0c3c60702b74bbce6689013 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 9 Sep 2024 12:28:19 +1000 Subject: [PATCH 50/50] codal_port/microbit_pin: Add pin.touch_calibrate() method. Added to pins that have touch capabilities. Signed-off-by: Damien George --- src/codal_port/microbit_pin.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/codal_port/microbit_pin.c b/src/codal_port/microbit_pin.c index 6bb75cc..c330341 100644 --- a/src/codal_port/microbit_pin.c +++ b/src/codal_port/microbit_pin.c @@ -51,6 +51,13 @@ const microbit_pin_obj_t microbit_p20_obj = {{µbit_dig_pin_type}, 20, MICR const microbit_pin_obj_t microbit_pin_logo_obj = {{µbit_touch_only_pin_type}, 30, MICROBIT_HAL_PIN_LOGO, MODE_UNUSED}; const microbit_pin_obj_t microbit_pin_speaker_obj = {{µbit_dig_pin_type}, 31, MICROBIT_HAL_PIN_SPEAKER, MODE_UNUSED}; +static mp_obj_t microbit_pin_touch_calibrate(mp_obj_t self_in) { + microbit_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); + microbit_hal_pin_touch_calibrate(self->name); + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_pin_touch_calibrate_obj, microbit_pin_touch_calibrate); + static mp_obj_t microbit_pin_get_mode_func(mp_obj_t self_in) { microbit_pin_obj_t *self = (microbit_pin_obj_t*)self_in; return MP_OBJ_NEW_QSTR(microbit_pin_get_mode(self)->name); @@ -248,6 +255,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); static const mp_rom_map_elem_t microbit_touch_pin_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_touch_calibrate), MP_ROM_PTR(µbit_pin_touch_calibrate_obj) }, { MP_ROM_QSTR(MP_QSTR_write_digital), MP_ROM_PTR(µbit_pin_write_digital_obj) }, { MP_ROM_QSTR(MP_QSTR_read_digital), MP_ROM_PTR(µbit_pin_read_digital_obj) }, { MP_ROM_QSTR(MP_QSTR_write_analog), MP_ROM_PTR(µbit_pin_write_analog_obj) }, @@ -275,6 +283,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); static const mp_rom_map_elem_t microbit_touch_only_pin_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_touch_calibrate), MP_ROM_PTR(µbit_pin_touch_calibrate_obj) }, { MP_ROM_QSTR(MP_QSTR_is_touched), MP_ROM_PTR(µbit_pin_is_touched_obj) }, { MP_ROM_QSTR(MP_QSTR_was_touched), MP_ROM_PTR(µbit_pin_was_touched_obj) }, { MP_ROM_QSTR(MP_QSTR_get_touches), MP_ROM_PTR(µbit_pin_get_touches_obj) }, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy