Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RP2: Add Audio support for Arduino Nano RP2040.
- Loading branch information
1 parent
9facc18
commit 8c1c590
Showing
8 changed files
with
1,501 additions
and
0 deletions.
There are no files selected for viewing
484 changes: 484 additions & 0 deletions
484
ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/audio/modaudio.c
Large diffs are not rendered by default.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/audio/pdm.pio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
; This file is part of the MicroPython project, http://micropython.org/ | ||
; | ||
; The MIT License (MIT) | ||
; | ||
; Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io> | ||
; | ||
; 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. | ||
|
||
.program pdm_pio | ||
.side_set 1 | ||
.wrap_target | ||
push iffull noblock side 1 | ||
in pins, 1 side 0 | ||
.wrap | ||
|
||
% c-sdk { | ||
#include "hardware/gpio.h" | ||
|
||
static inline void pdm_pio_program_init(PIO pio, uint sm, uint offset, uint clk, uint din, float div) { | ||
pio_sm_config c = pdm_pio_program_get_default_config(offset); | ||
|
||
sm_config_set_sideset(&c, 1, false, false); | ||
sm_config_set_in_shift(&c, false, false, 8); | ||
|
||
sm_config_set_in_pins(&c, din); | ||
sm_config_set_sideset_pins(&c, clk); | ||
sm_config_set_clkdiv(&c, div); | ||
|
||
pio_sm_set_consecutive_pindirs(pio, sm, din, 1, false); | ||
pio_sm_set_consecutive_pindirs(pio, sm, clk, 1, true); | ||
pio_sm_set_pins_with_mask(pio, sm, 0, (1u << clk) ); | ||
pio_gpio_init(pio, clk); | ||
|
||
pio_sm_init(pio, sm, offset, &c); | ||
pio_sm_set_enabled(pio, sm, true); | ||
} | ||
|
||
%} |
26 changes: 26 additions & 0 deletions
26
ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/micropython.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Create an INTERFACE library for our C module. | ||
add_library(nano_modules INTERFACE) | ||
|
||
target_compile_definitions(nano_modules INTERFACE | ||
MICROPY_PY_AUDIO=1 | ||
USE_LUT | ||
) | ||
|
||
# Add the current directory as an include directory. | ||
target_include_directories(nano_modules INTERFACE | ||
${CMAKE_CURRENT_LIST_DIR}/openpdm | ||
) | ||
|
||
# Add our source files to the lib | ||
target_sources(nano_modules INTERFACE | ||
${CMAKE_CURRENT_LIST_DIR}/audio/modaudio.c | ||
${CMAKE_CURRENT_LIST_DIR}/openpdm/OpenPDMFilter.c | ||
) | ||
|
||
# PDM PIO program | ||
pico_generate_pio_header(nano_modules | ||
${CMAKE_CURRENT_LIST_DIR}/audio/pdm.pio | ||
) | ||
|
||
# Link our INTERFACE library to the usermod target. | ||
target_link_libraries(usermod INTERFACE nano_modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.