Skip to content

Commit 65efd29

Browse files
committed
Change buffers to int32_t to accomodate signed data from I2S
1 parent f52db6d commit 65efd29

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
.idea
3+
cmake-*
4+
build/

CMakeLists.txt

+21-9
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,40 @@ cmake_minimum_required(VERSION 3.13)
2222
set(CMAKE_C_STANDARD 11)
2323
set(CMAKE_CXX_STANDARD 17)
2424

25-
# Initialise pico_sdk from installed location
26-
# (note this can come from environment, CMake cache etc)
27-
set(PICO_SDK_PATH "/Users/studiodc/Development/raspi/pico/sdk")
25+
26+
# Set standard CMake build type options
27+
## Default C compiler flags
28+
set(CMAKE_C_FLAGS_DEBUG_INIT "-g3 -Og -Wall -Wextra -DDEBUG")
29+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING "" FORCE)
30+
set(CMAKE_C_FLAGS_RELEASE_INIT "-O3 -Wall")
31+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT}" CACHE STRING "" FORCE)
32+
set(CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os -Wall")
33+
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL_INIT}" CACHE STRING "" FORCE)
34+
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -Wall")
35+
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING "" FORCE)
36+
## Default C++ compiler flags
37+
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g3 -Og -Wall -Wextra -DDEBUG")
38+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING "" FORCE)
39+
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -Wall")
40+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT}" CACHE STRING "" FORCE)
41+
set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Os -Wall")
42+
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL_INIT}" CACHE STRING "" FORCE)
43+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -Wall")
44+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING "" FORCE)
2845

2946
# Pull in Raspberry Pi Pico SDK (must be before project)
3047
include(pico_sdk_import.cmake)
31-
3248
project(i2s_example C CXX ASM)
33-
34-
# Initialise the Raspberry Pi Pico SDK
3549
pico_sdk_init()
3650

37-
# Add executable. Default name is the project name, version 0.1
38-
3951
add_executable(i2s_example i2s.c)
4052

4153
pico_generate_pio_header(i2s_example ${CMAKE_CURRENT_LIST_DIR}/i2s.pio)
4254

4355
target_sources(i2s_example PRIVATE i2s_example.c)
4456

4557
pico_set_program_name(i2s_example "i2s_test")
46-
pico_set_program_version(i2s_example "0.1")
58+
pico_set_program_version(i2s_example "1.0.1")
4759

4860
# no_flash means the target is to run from RAM
4961
# pico_set_binary_type(i2s_test no_flash)

i2s.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ typedef struct pio_i2s {
6363
uint dma_ch_in_data;
6464
uint dma_ch_out_ctrl;
6565
uint dma_ch_out_data;
66-
uint32_t* in_ctrl_blocks[2]; // Control blocks MUST have 8-byte alignment.
67-
uint32_t* out_ctrl_blocks[2];
68-
uint32_t input_buffer[STEREO_BUFFER_SIZE * 2];
69-
uint32_t output_buffer[STEREO_BUFFER_SIZE * 2];
66+
int32_t* in_ctrl_blocks[2]; // Control blocks MUST have 8-byte alignment.
67+
int32_t* out_ctrl_blocks[2];
68+
int32_t input_buffer[STEREO_BUFFER_SIZE * 2];
69+
int32_t output_buffer[STEREO_BUFFER_SIZE * 2];
7070
i2s_config config;
7171
} pio_i2s;
7272

i2s_example.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const uint LED_PIN = PICO_DEFAULT_LED_PIN;
4747

4848
static __attribute__((aligned(8))) pio_i2s i2s;
4949

50-
static void process_audio(const uint32_t* input, uint32_t* output, size_t num_frames) {
50+
static void process_audio(const int32_t* input, int32_t* output, size_t num_frames) {
5151
// Just copy the input to the output
5252
for (size_t i = 0; i < num_frames * 2; i++) {
5353
output[i] = input[i];
@@ -59,7 +59,7 @@ static void dma_i2s_in_handler(void) {
5959
* DMA is currently reading from, we can identify which buffer it has just
6060
* finished reading (the completion of which has triggered this interrupt).
6161
*/
62-
if (*(uint32_t**)dma_hw->ch[i2s.dma_ch_in_ctrl].read_addr == i2s.input_buffer) {
62+
if (*(int32_t**)dma_hw->ch[i2s.dma_ch_in_ctrl].read_addr == i2s.input_buffer) {
6363
// It is inputting to the second buffer so we can overwrite the first
6464
process_audio(i2s.input_buffer, i2s.output_buffer, AUDIO_BUFFER_FRAMES);
6565
} else {

0 commit comments

Comments
 (0)