From d7f0a294d3e8e299db3a40d7a3537638e4f0c37b Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 22 Aug 2024 11:08:39 +1000 Subject: [PATCH 1/2] 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 2/2] 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) {