Skip to content

nRF52: Add support for sound output over I2S #2623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@ ifeq ($(USE_JIT),1)
SOURCES += src/jsjit.c src/jsjitc.c
endif

ifeq ($(USE_I2S),1)
DEFINES += -DUSE_I2S
WRAPPERSOURCES += src/jswrap_i2s.c
endif


endif # BOOTLOADER ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DON'T USE STUFF ABOVE IN BOOTLOADER

Expand Down
3 changes: 2 additions & 1 deletion boards/JOLTJS.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
'GRAPHICS',
# 'NFC',
'NEOPIXEL',
'JIT' # JIT compiler enabled
'JIT', # JIT compiler enabled
'I2S'
],
'makefile' : [
'DEFINES+=-DESPR_OFFICIAL_BOARD', # Don't display the donations nag screen
Expand Down
1 change: 1 addition & 0 deletions boards/XIAOBLE.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
# "TENSORFLOW",
"NEOPIXEL",
"JIT",
"I2S",
],
"makefile": [
"DEFINES += -DESPR_LSE_ENABLE", # Ensure low speed external osc enabled
Expand Down
4 changes: 4 additions & 0 deletions make/common/NRF5X.make
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ else # no BOOTLOADER
# Neopixel support (only NRF52)
SOURCES += targets/nrf5x/i2s_ws2812b_drive.c
endif
ifeq ($(USE_I2S),1)
# I2S support
SOURCES += targets/nrf5x/jsi2s.c
endif
endif

# Careful here.. All these includes and sources assume a SoftDevice. Not efficient/clean if softdevice (ble) is not enabled...
Expand Down
37 changes: 37 additions & 0 deletions src/jsi2s.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
*
* Copyright (C) 2025 Simon Sievert <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* ----------------------------------------------------------------------------
* I2S support
* ----------------------------------------------------------------------------
*/

#ifndef JSI2S_H
#define JSI2S_H

#include "jspin.h"

typedef void (*jsi2s_data_cb_t)(void);

typedef void (*jsi2s_buffer_release_cb_t)(uint32_t *buf_ptr);

bool jsi2s_init(Pin bclk, Pin lrck, Pin dout, int sample_width_bytes);

void jsi2s_uninit();

bool jsi2s_start(uint32_t *buf_ptr, uint32_t buffer_size_bytes, jsi2s_data_cb_t data_callback,
jsi2s_buffer_release_cb_t buffer_released_callback);

void jsi2s_stop();

bool jsi2s_set_next_buffer(uint32_t *buf_ptr, uint32_t buffer_size_bytes);

bool jsi2s_idle();

#endif // JSI2S_H
Loading
Loading