Simple test application for the STMicroelectronics X-NUCLEO-CCA02M1 MEMS Microphones Expansion Board, built against mbed OS.

Dependencies:   X_NUCLEO_CCA02M1

Fork of HelloWorld_CCA02M1 by ST Expansion SW Team

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    October 28th, 2016
00007  * @brief   mbed test application for the STMicroelectronics X-NUCLEO-CCA02M1
00008  *          MEMS Microphones 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 #include "rtos.h"
00045 
00046 
00047 #if DEVICE_I2S
00048 
00049 /* Expansion Board specific header files. */
00050 #include "XNucleoCCA02M1.h"
00051 
00052 
00053 /* Variables -----------------------------------------------------------------*/
00054 
00055 /*
00056  * Initialization parameters.
00057  * Note: put a jumper to connect PB_5 and PB_13 on the MORPHO connector when
00058  *       running a mono configuration.
00059  */
00060 XNucleoCCA02M1_init_t init =
00061 {
00062     44100,  /* Default Sampling Frequency [Hz]. */
00063     2       /* Default number of channels. */
00064 };
00065 
00066 /* Thread to manage I2S peripherals. */
00067 static rtos::Thread i2s_bh_daemon;
00068 
00069 
00070 /* Functions -----------------------------------------------------------------*/
00071 
00072 /**
00073  * @brief  Entry point function of mbedOS.
00074  * @param  None
00075  * @retval None
00076  */
00077 int main(void)
00078 {
00079     /*----- Initialization. -----*/
00080 
00081     /* Initializing MEMS Microphones Expansion Board on the I2S1 interface. */
00082     XNucleoCCA02M1 *microphones = new XNucleoCCA02M1(PB_15, PB_13);
00083     if (microphones->init(&init) != COMPONENT_OK)
00084     {
00085         error("Initialization of the MEMS Microphones Expansion Board failed.\r\n");
00086         exit(EXIT_FAILURE);
00087     }
00088 
00089     /* Starting a thread to manage I2S peripherals. */
00090     Callback<void()> i2s_bh_task(&I2S::i2s_bh_queue, &events::EventQueue::dispatch_forever);
00091     i2s_bh_daemon.start(i2s_bh_task);
00092 
00093     /* Enabling transmission via USB. */
00094     microphones->enable_usb();
00095 
00096     /* Printing to the console. */
00097     printf("MEMS Microphones Application Example\r\n\n");
00098 
00099 
00100     /*----- Recording. -----*/
00101 
00102     /* Printing to the console. */
00103     printf("--> Recording...\r\n");
00104     microphones->record();
00105 }
00106 
00107 #else // DEVICE_I2S
00108 
00109 int main(void)
00110 {
00111     printf("The target does not support I2S API.\r\n");
00112 }
00113 
00114 #endif // DEVICE_I2S