ST / Mbed 2 deprecated HelloWorld_CCA01M1

Dependencies:   X_NUCLEO_CCA01M1 ST_Events-old mbed

Fork of HelloWorld_CCA01M1_mbedOS by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    main.cpp
00004  * @author  Davide Aliprandi, STMicroelectronics
00005  * @version V1.0.0
00006  * @date    March 25th, 2016
00007  * @brief   mbed test application for the STMicroelectronics X-NUCLEO-CCA01M1
00008  *          Sound Terminal Expansion Board.
00009  ******************************************************************************
00010  * @attention
00011  *
00012  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00013  *
00014  * Redistribution and use in source and binary forms, with or without modification,
00015  * are permitted provided that the following conditions are met:
00016  *   1. Redistributions of source code must retain the above copyright notice,
00017  *      this list of conditions and the following disclaimer.
00018  *   2. Redistributions in binary form must reproduce the above copyright notice,
00019  *      this list of conditions and the following disclaimer in the documentation
00020  *      and/or other materials provided with the distribution.
00021  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00022  *      may be used to endorse or promote products derived from this software
00023  *      without specific prior written permission.
00024  *
00025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00029  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  ******************************************************************************
00037  */
00038 
00039 
00040 /* Includes ------------------------------------------------------------------*/
00041 
00042 /* mbed specific header files. */
00043 #include "mbed.h"
00044 
00045 
00046 #if DEVICE_I2S
00047 
00048 /* Helper header files. */
00049 #include "DevI2C.h"
00050 
00051 /* Component specific header files. */
00052 #include "STA350BW.h"
00053 
00054 /* My song header file. */
00055 #include "my_song.h"
00056 
00057 
00058 /* Definitions ---------------------------------------------------------------*/
00059 
00060 /* Events. */
00061 #define PLAY_STOP_EVENT      (0x1)
00062 
00063 
00064 /* Variables -----------------------------------------------------------------*/
00065 
00066 /* Initialization parameters. */
00067 STA350BW_init_t init =
00068 {
00069     32000,   /* Default Sampling Frequency [Hz]. */
00070     100      /* Default Volume. */
00071 };
00072 
00073 /* Sound Terminal Component. */
00074 STA350BW *sound_terminal;
00075 
00076 
00077 /* Functions -----------------------------------------------------------------*/
00078 
00079 /**
00080  * @brief  Entry point function of mbedOS.
00081  * @param  None
00082  * @retval None
00083  */
00084 int main(void)
00085 {
00086     /*----- Initialization. -----*/
00087 
00088     /* Initializing I2C bus. */
00089     DevI2C *dev_i2c = new DevI2C(PB_9, PB_8);
00090 
00091     /* Initializing Sound Terminal Component. */
00092 #ifndef USE_I2S2
00093     sound_terminal = new STA350BW(PA_10, STA350BW_ADDRESS_1, *dev_i2c, PB_15, PB_13, PB_12, NC, PC_6);
00094 #else
00095     sound_terminal = new STA350BW(PA_10, STA350BW_ADDRESS_2, *dev_i2c, PC_12, PC_10, PA_4, NC, PC_7);
00096 #endif
00097     if (sound_terminal->init(&init) != COMPONENT_OK)
00098     {
00099         error("Initialization of the Sound Terminal Expansion Board failed.\r\n");
00100         exit(EXIT_FAILURE);
00101     }
00102 
00103     /* Setting Sound Terminal Component's parameters. */
00104     sound_terminal->set_frequency(MY_SONG_AUDIO_FREQUENCY);
00105     sound_terminal->set_volume(STA350BW_CHANNEL_MASTER, 60);
00106 
00107     /* Printing to the console. */
00108     printf("Sound Terminal Application Example\r\n\n");
00109 
00110 
00111     /*----- Playing. -----*/
00112 
00113     /* Printing to the console. */
00114     printf("--> Playing...\r\n");
00115     sound_terminal->play((int16_t *) my_song, (uint16_t) sizeof(my_song), true);
00116 
00117     /* Dispatching forever the I2S queue. */
00118     I2S::i2s_bh_queue.dispatch_forever();
00119 }
00120 
00121 #else // DEVICE_I2S
00122 
00123 int main(void)
00124 {
00125     printf("The target does not support I2S API.\r\n");
00126 }
00127 
00128 #endif // DEVICE_I2S