8000 RP2: Add Audio support for Arduino Nano RP2040. · micropython/micropython@fdeb249 · GitHub
[go: up one dir, main page]

Skip to content

Commit fdeb249

Browse files
committed
RP2: Add Audio support for Arduino Nano RP2040.
1 parent 37f07f2 commit fdeb249

File tree

8 files changed

+1501
-0
lines changed

8 files changed

+1501
-0
lines changed

ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/audio/modaudio.c

Lines changed: 484 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; This file is part of the MicroPython project, http://micropython.org/
2+
;
3+
; The MIT License (MIT)
4+
;
5+
; Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io>
6+
;
7+
; Permission is hereby granted, free of charge, to any person obtaining a copy
8+
; of this software and associated documentation files (the "Software"), to deal
9+
; in the Software without restriction, including without limitation the rights
10+
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
; copies of the Software, and to permit persons to whom the Software is
12+
; furnished to do so, subject to the following conditions:
13+
;
14+
; The above copyright notice and this permission notice shall be included in
15+
; all copies or substantial portions of the Software.
16+
;
17+
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
; THE SOFTWARE.
24+
25+
.program pdm_pio
26+
.side_set 1
27+
.wrap_target
28+
push iffull noblock side 1
29+
in pins, 1 side 0
30+
.wrap
31+
32+
% c-sdk {
33+
#include "hardware/gpio.h"
34+
35+
static inline void pdm_pio_program_init(PIO pio, uint sm, uint offset, uint clk, uint din, float div) {
36+
pio_sm_config c = pdm_pio_program_get_default_config(offset);
37+
38+
sm_config_set_sideset(&c, 1, false, false);
39+
sm_config_set_in_shift(&c, false, false, 8);
40+
41+
sm_config_set_in_pins(&c, din);
42+
sm_config_set_sideset_pins(&c, clk);
43+
sm_config_set_clkdiv(&c, div);
44+
45+
pio_sm_set_consecutive_pindirs(pio, sm, din, 1, false);
46+
pio_sm_set_consecutive_pindirs(pio, sm, clk, 1, true);
47+
pio_sm_set_pins_with_mask(pio, sm, 0, (1u << clk) );
48+
pio_gpio_init(pio, clk);
49+
50+
pio_sm_init(pio, sm, offset, &c);
51+
pio_sm_set_enabled(pio, sm, true);
52+
}
53+
54+
%}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Create an INTERFACE library for our C module.
2+
add_library(nano_modules INTERFACE)
3+
4+
target_compile_definitions(nano_modules INTERFACE
5+
MICROPY_PY_AUDIO=1
6+
USE_LUT
7+
)
8+
9+
# Add the current directory as an include directory.
10+
target_include_directories(nano_modules INTERFACE
11+
${CMAKE_CURRENT_LIST_DIR}/openpdm
12+
)
13+
14+
# Add our source files to the lib
15+
target_sources(nano_modules INTERFACE
16+
${CMAKE_CURRENT_LIST_DIR}/audio/modaudio.c
17+
${CMAKE_CURRENT_LIST_DIR}/openpdm/OpenPDMFilter.c
18+
)
19+
20+
# PDM PIO program
21+
pico_generate_pio_header(nano_modules
22+
${CMAKE_CURRENT_LIST_DIR}/audio/pdm.pio
23+
)
24+
25+
# Link our INTERFACE library to the usermod target.
26+
target_link_libraries(usermod INTERFACE nano_modules)

ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ set(MICROPY_PY_BLUETOOTH 1)
33
set(MICROPY_BLUETOOTH_NIMBLE 1)
44
set(MICROPY_PY_NETWORK_NINAW10 1)
55
set(MICROPY_HW_ENABLE_DOUBLE_TAP 1)
6+
set(USER_C_MODULES ${MICROPY_BOARD_DIR}/micropython.cmake)
67
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)

ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,14 @@
3737
#define MICROPY_HW_NINA_GPIO0 (2)
3838
#define MICROPY_HW_NINA_GPIO1 (9)
3939
#define MICROPY_HW_NINA_ACK (10)
40+
41+
// AUDIO config.
42+
#define MICROPY_HW_PDM_PIO (pio1)
43+
#define MICROPY_HW_PDM_SM (0)
44+
#define MICROPY_HW_PDM_DMA (1)
45+
#define MICROPY_HW_PDM_DMA_IRQ (DMA_IRQ_1)
46+
47+
#define MICROPY_HW_PDM_CLK_PIN (23)
48+
#define MICROPY_HW_PDM_DIN_PIN (22)
49+
50+
#define MICROPY_BOARD_ROOT_POINTERS struct _audio_data_t *audio_data;

0 commit comments

Comments
 (0)
0