summaryrefslogtreecommitdiff
path: root/examples/device
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2023-10-10 19:08:25 +0200
committerHiFiPhile <[email protected]>2023-10-10 20:00:50 +0200
commitc8430f5f85d587a996bc0301a47be12cc70cedb7 (patch)
treea5805f14e1078f2ed5c9e575acb053bad6fa6ac1 /examples/device
parente2852da668ae5f8e2398ac0a4c2a93d5f50f2618 (diff)
Refactor to get rid of CMSIS DSP lib.
Diffstat (limited to 'examples/device')
-rw-r--r--examples/device/audio_4_channel_mic/CMakeLists.txt12
-rw-r--r--examples/device/audio_4_channel_mic/Makefile6
-rw-r--r--examples/device/audio_4_channel_mic/skip.txt1
-rw-r--r--examples/device/audio_4_channel_mic/src/main.c55
4 files changed, 38 insertions, 36 deletions
diff --git a/examples/device/audio_4_channel_mic/CMakeLists.txt b/examples/device/audio_4_channel_mic/CMakeLists.txt
index ae6bf0142..0f5d36193 100644
--- a/examples/device/audio_4_channel_mic/CMakeLists.txt
+++ b/examples/device/audio_4_channel_mic/CMakeLists.txt
@@ -23,18 +23,16 @@ target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
)
-# CMSIS sources
-target_sources(${PROJECT} PUBLIC
- ${TOP}/lib/CMSIS_5/CMSIS/DSP/Source/CommonTables/arm_common_tables.c
- ${TOP}/lib/CMSIS_5/CMSIS/DSP/Source/FastMathFunctions/arm_sin_q15.c
- )
-
# Example include
target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
- ${TOP}/lib/CMSIS_5/CMSIS/DSP/Include
)
+# Add libm for GCC
+if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ target_link_libraries(${PROJECT} PUBLIC m)
+endif()
+
# Configure compilation flags and libraries for the example without RTOS.
# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
family_configure_device_example(${PROJECT} noos)
diff --git a/examples/device/audio_4_channel_mic/Makefile b/examples/device/audio_4_channel_mic/Makefile
index 97e4118c0..8ee6a01ec 100644
--- a/examples/device/audio_4_channel_mic/Makefile
+++ b/examples/device/audio_4_channel_mic/Makefile
@@ -3,18 +3,12 @@ include ../../make.mk
INC += \
src \
$(TOP)/hw \
- $(TOP)/lib/CMSIS_5/CMSIS/DSP/Include \
# Example source
EXAMPLE_SOURCE += \
src/main.c \
src/usb_descriptors.c \
-# CMSIS sources
-SRC_C += \
- lib/CMSIS_5/CMSIS/DSP/Source/CommonTables/arm_common_tables.c \
- lib/CMSIS_5/CMSIS/DSP/Source/FastMathFunctions/arm_sin_q15.c \
-
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
include ../../rules.mk
diff --git a/examples/device/audio_4_channel_mic/skip.txt b/examples/device/audio_4_channel_mic/skip.txt
index 1ee86a485..3c42a96d9 100644
--- a/examples/device/audio_4_channel_mic/skip.txt
+++ b/examples/device/audio_4_channel_mic/skip.txt
@@ -1,3 +1,4 @@
mcu:SAMD11
mcu:SAME5X
mcu:SAMG
+family:broadcom_64bit
diff --git a/examples/device/audio_4_channel_mic/src/main.c b/examples/device/audio_4_channel_mic/src/main.c
index 3b21b4ac6..4bcbdb692 100644
--- a/examples/device/audio_4_channel_mic/src/main.c
+++ b/examples/device/audio_4_channel_mic/src/main.c
@@ -34,7 +34,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include "arm_math.h"
+#include <math.h>
#include "bsp/board_api.h"
#include "tusb.h"
@@ -96,6 +96,27 @@ int main(void)
sampleFreqRng.subrange[0].bMax = AUDIO_SAMPLE_RATE;
sampleFreqRng.subrange[0].bRes = 0;
+ // Generate dummy data
+ uint16_t * p_buff = i2s_dummy_buffer[0];
+ uint16_t dataVal = 1;
+ for (uint16_t cnt = 0; cnt < AUDIO_SAMPLE_RATE/1000; cnt++)
+ {
+ // CH0 saw wave
+ *p_buff++ = dataVal;
+ // CH1 inverted saw wave
+ *p_buff++ = 60 + AUDIO_SAMPLE_RATE/1000 - dataVal;
+ dataVal++;
+ }
+ p_buff = i2s_dummy_buffer[1];
+ for (uint16_t cnt = 0; cnt < AUDIO_SAMPLE_RATE/1000; cnt++)
+ {
+ // CH3 square wave
+ *p_buff++ = cnt < (AUDIO_SAMPLE_RATE/1000/2) ? 120:170;
+ // CH4 sinus wave
+ float t = 2*3.1415f * cnt / (AUDIO_SAMPLE_RATE/1000);
+ *p_buff++ = (uint16_t)(sinf(t) * 25) + 200;
+ }
+
while (1)
{
tud_task(); // tinyusb device task
@@ -399,7 +420,16 @@ bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t itf, uint8_t ep_in, u
(void) ep_in;
(void) cur_alt_setting;
- // Write buffer[0] (CH0-1) and buffer[1] (CH1-2) into FIFO
+
+ // In read world application data flow is driven by I2S clock,
+ // both tud_audio_tx_done_pre_load_cb() & tud_audio_tx_done_post_load_cb() are hardly used.
+ // For example in your I2S receive callback:
+ // void I2S_Rx_Callback(int channel, const void* data, uint16_t samples)
+ // {
+ // tud_audio_write_support_ff(channel, data, samples * N_BYTES_PER_SAMPLE * N_CHANNEL_PER_FIFO);
+ // }
+
+ // Write I2S buffer into FIFO
for (uint8_t cnt=0; cnt < 2; cnt++)
{
tud_audio_write_support_ff(cnt, i2s_dummy_buffer[cnt], AUDIO_SAMPLE_RATE/1000 * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX);
@@ -416,27 +446,6 @@ bool tud_audio_tx_done_post_load_cb(uint8_t rhport, uint16_t n_bytes_copied, uin
(void) ep_in;
(void) cur_alt_setting;
- // Generate dummy data
- uint16_t * p_buff = i2s_dummy_buffer[0];
- uint16_t dataVal = 1;
- for (uint16_t cnt = 0; cnt < AUDIO_SAMPLE_RATE/1000; cnt++)
- {
- // CH0 saw wave
- *p_buff++ = dataVal;
- // CH1 inverted saw wave
- *p_buff++ = 60 + AUDIO_SAMPLE_RATE/1000 - dataVal;
- dataVal++;
- }
- p_buff = i2s_dummy_buffer[1];
- for (uint16_t cnt = 0; cnt < AUDIO_SAMPLE_RATE/1000; cnt++)
- {
- // CH3 square wave
- *p_buff++ = cnt < (AUDIO_SAMPLE_RATE/1000/2) ? 120:170;
- // CH4 sinus wave
- q15_t t = 0x7FFF * cnt / (AUDIO_SAMPLE_RATE/1000);
- *p_buff++ = arm_sin_q15(t) / 1300 + 200;
- }
-
return true;
}