Simple test application for the STMicroelectronics X-NUCLEO-CCA01M1 Sound Terminal Expansion Board, built against mbed classic.
Dependencies: X_NUCLEO_CCA01M1 ST_Events-old mbed
Fork of HelloWorld_CCA01M1_mbedOS by
Playing audio with the X-NUCLEO-CCA01M1 Expansion Board
This application provides a simple example of usage of the X-NUCLEO-CCA01M1 Sound Terminal Expansion Board, built against mbed classic.
It shows how to play a 2-channel stereo signal stored in an array of PCM samples directly on the speakers connected to the expansion board.
It also allows to stop/play the audio by pressing the user button on the Nucleo board.
Platform compatibility
- This board can be currently used with a Nucleo-F401RE board only and has been tested with the default configuration provided by this example.
- Please note that the main application makes use of the "events" library, which is not included into the "mbed" library.
- The application built against mbed OS 5.x can be found here.
Revision 9:34ebb3f5a2ad, committed 2017-05-15
- Comitter:
- Davidroid
- Date:
- Mon May 15 15:51:10 2017 +0000
- Parent:
- 8:ff75f4f451d2
- Commit message:
- Simple test application for the STMicroelectronics X-NUCLEO-CCA01M1 MEMS Microphones Expansion Board, built against mbed classic.
Changed in this revision
diff -r ff75f4f451d2 -r 34ebb3f5a2ad events.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/events.lib Mon May 15 15:51:10 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/ST/code/ST_Events/#dba7bd0f39f3
diff -r ff75f4f451d2 -r 34ebb3f5a2ad main.cpp --- a/main.cpp Wed May 03 16:32:32 2017 +0000 +++ b/main.cpp Mon May 15 15:51:10 2017 +0000 @@ -41,7 +41,6 @@ /* mbed specific header files. */ #include "mbed.h" -#include "rtos.h" #if DEVICE_I2S @@ -74,54 +73,10 @@ /* Sound Terminal Component. */ STA350BW *sound_terminal; -/* Thread to manage I2S peripherals. */ -static rtos::Thread i2s_bh_daemon; - -/* Threads. */ -Thread *play_stop_thread; - -/* User button handling. */ -InterruptIn event(USER_BUTTON); - /* Functions -----------------------------------------------------------------*/ /** - * @brief User button handler function. - * @param None. - * @retval None. - */ -void pressed(void) -{ - /* Signal to play/stop handler thread. */ - play_stop_thread->signal_set(PLAY_STOP_EVENT); -} - -/** - * @brief Play/stop handler function. - * @param None. - * @retval None. - */ -void play_stop_handler(void) -{ - while (true) - { - static bool stop = true; - - /* Waiting for play/stop events. */ - play_stop_thread->signal_wait(PLAY_STOP_EVENT); - - if (stop) - sound_terminal->stop(); - else - sound_terminal->play((int16_t *) my_song, (uint16_t) sizeof(my_song), true); - printf("--> %s\r\n", stop ? "Stop." : "Playing..."); - - stop = !stop; - } -} - -/** * @brief Entry point function of mbedOS. * @param None * @retval None @@ -145,17 +100,6 @@ exit(EXIT_FAILURE); } - /* Starting a thread to manage I2S peripherals. */ - Callback<void()> i2s_bh_task(&I2S::i2s_bh_queue, &events::EventQueue::dispatch_forever); - i2s_bh_daemon.start(i2s_bh_task); - - /* Scheduling the play/stop function. */ - play_stop_thread = new Thread(); - osStatus status = play_stop_thread->start(play_stop_handler); - if (status != osOK) - printf("Could not start the play/stop handler thread.\r\n"); - event.fall(&pressed); - /* Setting Sound Terminal Component's parameters. */ sound_terminal->set_frequency(MY_SONG_AUDIO_FREQUENCY); sound_terminal->set_volume(STA350BW_CHANNEL_MASTER, 60); @@ -169,6 +113,9 @@ /* Printing to the console. */ printf("--> Playing...\r\n"); sound_terminal->play((int16_t *) my_song, (uint16_t) sizeof(my_song), true); + + /* Dispatching forever the I2S queue. */ + I2S::i2s_bh_queue.dispatch_forever(); } #else // DEVICE_I2S
diff -r ff75f4f451d2 -r 34ebb3f5a2ad mbed-os.lib --- a/mbed-os.lib Wed May 03 16:32:32 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://github.com/ARMmbed/mbed-os/#42be5c01a7f91292d5e27124ad9584236025f6ab
diff -r ff75f4f451d2 -r 34ebb3f5a2ad mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon May 15 15:51:10 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/4eea097334d6 \ No newline at end of file