Skip to content

Commit d7f0a29

Browse files
committed
codal_app/microbithal: Add sound effect default constants.
Signed-off-by: Damien George <[email protected]>
1 parent 9486813 commit d7f0a29

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/codal_app/microbithal.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,23 @@
2525
*/
2626

2727
#include "main.h"
28+
#include "microbithal.h"
2829
#include "MicroBitDevice.h"
2930
#include "neopixel.h"
3031

3132
#define HAL_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
3233

34+
// It's not possible to include the CODAL header file that defines the SFX_DEFAULT_xxx
35+
// constants in C code, because that CODAL header file is C++. Instead we define our
36+
// own MICROBIT_HAL_SFX_DEFAULT_xxx versions of the constants in a C-compatible header
37+
// file, and assert here that they have the same value as the CODAL constants.
38+
static_assert(MICROBIT_HAL_SFX_DEFAULT_VIBRATO_PARAM == SFX_DEFAULT_VIBRATO_PARAM, "");
39+
static_assert(MICROBIT_HAL_SFX_DEFAULT_VIBRATO_STEPS == SFX_DEFAULT_VIBRATO_STEPS, "");
40+
static_assert(MICROBIT_HAL_SFX_DEFAULT_TREMOLO_PARAM == SFX_DEFAULT_TREMOLO_PARAM, "");
41+
static_assert(MICROBIT_HAL_SFX_DEFAULT_TREMOLO_STEPS == SFX_DEFAULT_TREMOLO_STEPS, "");
42+
static_assert(MICROBIT_HAL_SFX_DEFAULT_WARBLE_PARAM == SFX_DEFAULT_WARBLE_PARAM, "");
43+
static_assert(MICROBIT_HAL_SFX_DEFAULT_WARBLE_STEPS == SFX_DEFAULT_WARBLE_STEPS, "");
44+
3345
NRF52Pin *const pin_obj[] = {
3446
&uBit.io.P0,
3547
&uBit.io.P1,
@@ -83,8 +95,6 @@ static uint16_t button_state[2];
8395

8496
extern "C" {
8597

86-
#include "microbithal.h"
87-
8898
void microbit_hal_background_processing(void) {
8999
// This call takes about 200us.
90100
Event(DEVICE_ID_SCHEDULER, DEVICE_SCHEDULER_EVT_IDLE);

src/codal_app/microbithal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ extern "C" {
103103
#define MICROBIT_HAL_LOG_TIMESTAMP_HOURS (36000)
104104
#define MICROBIT_HAL_LOG_TIMESTAMP_DAYS (864000)
105105

106+
// These default fx values are the same as defined by CODAL, but here in a C-compatible header.
107+
#define MICROBIT_HAL_SFX_DEFAULT_VIBRATO_PARAM (2)
108+
#define MICROBIT_HAL_SFX_DEFAULT_VIBRATO_STEPS (512)
109+
#define MICROBIT_HAL_SFX_DEFAULT_TREMOLO_PARAM (3)
110+
#define MICROBIT_HAL_SFX_DEFAULT_TREMOLO_STEPS (900)
111+
#define MICROBIT_HAL_SFX_DEFAULT_WARBLE_PARAM (2)
112+
#define MICROBIT_HAL_SFX_DEFAULT_WARBLE_STEPS (700)
113+
106114
void microbit_hal_idle(void);
107115

108116
__attribute__((noreturn)) void microbit_hal_reset(void);

0 commit comments

Comments
 (0)