for dissembly

Dependencies:   X_NUCLEO_CCA02M1 ST_Events-old mbed

Fork of HelloWorld_CCA02M1 by ST

Committer:
Davidroid
Date:
Thu May 04 10:40:50 2017 +0000
Revision:
11:e4e1ce8b3a26
Parent:
8:0dcb2485700e
Child:
12:203c08553f4d
Enabled default configuration at 44.1 KHz (CD audio quality).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davide.aliprandi@st.com 0:7d07f4df31e1 1 /**
davide.aliprandi@st.com 0:7d07f4df31e1 2 ******************************************************************************
davide.aliprandi@st.com 0:7d07f4df31e1 3 * @file main.cpp
davide.aliprandi@st.com 0:7d07f4df31e1 4 * @author Davide Aliprandi, STMicroelectronics
davide.aliprandi@st.com 0:7d07f4df31e1 5 * @version V1.0.0
davide.aliprandi@st.com 0:7d07f4df31e1 6 * @date October 28th, 2016
davide.aliprandi@st.com 0:7d07f4df31e1 7 * @brief mbed test application for the STMicroelectronics X-NUCLEO-CCA02M1
davide.aliprandi@st.com 0:7d07f4df31e1 8 * MEMS Microphones Expansion Board.
davide.aliprandi@st.com 0:7d07f4df31e1 9 ******************************************************************************
davide.aliprandi@st.com 0:7d07f4df31e1 10 * @attention
davide.aliprandi@st.com 0:7d07f4df31e1 11 *
davide.aliprandi@st.com 0:7d07f4df31e1 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
davide.aliprandi@st.com 0:7d07f4df31e1 13 *
davide.aliprandi@st.com 0:7d07f4df31e1 14 * Redistribution and use in source and binary forms, with or without modification,
davide.aliprandi@st.com 0:7d07f4df31e1 15 * are permitted provided that the following conditions are met:
davide.aliprandi@st.com 0:7d07f4df31e1 16 * 1. Redistributions of source code must retain the above copyright notice,
davide.aliprandi@st.com 0:7d07f4df31e1 17 * this list of conditions and the following disclaimer.
davide.aliprandi@st.com 0:7d07f4df31e1 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
davide.aliprandi@st.com 0:7d07f4df31e1 19 * this list of conditions and the following disclaimer in the documentation
davide.aliprandi@st.com 0:7d07f4df31e1 20 * and/or other materials provided with the distribution.
davide.aliprandi@st.com 0:7d07f4df31e1 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
davide.aliprandi@st.com 0:7d07f4df31e1 22 * may be used to endorse or promote products derived from this software
davide.aliprandi@st.com 0:7d07f4df31e1 23 * without specific prior written permission.
davide.aliprandi@st.com 0:7d07f4df31e1 24 *
davide.aliprandi@st.com 0:7d07f4df31e1 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
davide.aliprandi@st.com 0:7d07f4df31e1 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
davide.aliprandi@st.com 0:7d07f4df31e1 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
davide.aliprandi@st.com 0:7d07f4df31e1 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
davide.aliprandi@st.com 0:7d07f4df31e1 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
davide.aliprandi@st.com 0:7d07f4df31e1 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
davide.aliprandi@st.com 0:7d07f4df31e1 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
davide.aliprandi@st.com 0:7d07f4df31e1 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
davide.aliprandi@st.com 0:7d07f4df31e1 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
davide.aliprandi@st.com 0:7d07f4df31e1 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
davide.aliprandi@st.com 0:7d07f4df31e1 35 *
davide.aliprandi@st.com 0:7d07f4df31e1 36 ******************************************************************************
davide.aliprandi@st.com 0:7d07f4df31e1 37 */
davide.aliprandi@st.com 0:7d07f4df31e1 38
davide.aliprandi@st.com 0:7d07f4df31e1 39
davide.aliprandi@st.com 0:7d07f4df31e1 40 /* Includes ------------------------------------------------------------------*/
davide.aliprandi@st.com 0:7d07f4df31e1 41
davide.aliprandi@st.com 0:7d07f4df31e1 42 /* mbed specific header files. */
davide.aliprandi@st.com 0:7d07f4df31e1 43 #include "mbed.h"
davide.aliprandi@st.com 0:7d07f4df31e1 44 #include "rtos.h"
davide.aliprandi@st.com 0:7d07f4df31e1 45
davide.aliprandi@st.com 0:7d07f4df31e1 46
davide.aliprandi@st.com 0:7d07f4df31e1 47 #if DEVICE_I2S
davide.aliprandi@st.com 0:7d07f4df31e1 48
davide.aliprandi@st.com 0:7d07f4df31e1 49 /* Expansion Board specific header files. */
davide.aliprandi@st.com 0:7d07f4df31e1 50 #include "XNucleoCCA02M1.h"
davide.aliprandi@st.com 0:7d07f4df31e1 51
davide.aliprandi@st.com 0:7d07f4df31e1 52
davide.aliprandi@st.com 0:7d07f4df31e1 53 /* Variables -----------------------------------------------------------------*/
davide.aliprandi@st.com 0:7d07f4df31e1 54
Davidroid 7:760d8e527b67 55 /*
Davidroid 7:760d8e527b67 56 * Initialization parameters.
Davidroid 7:760d8e527b67 57 * Note: put a jumper to connect PB_5 and PB_13 on the MORPHO connector when
Davidroid 7:760d8e527b67 58 * running a mono configuration.
Davidroid 7:760d8e527b67 59 */
davide.aliprandi@st.com 0:7d07f4df31e1 60 XNucleoCCA02M1_init_t init =
davide.aliprandi@st.com 0:7d07f4df31e1 61 {
Davidroid 11:e4e1ce8b3a26 62 44100, /* Default Sampling Frequency [Hz]. */
davide.aliprandi@st.com 0:7d07f4df31e1 63 2 /* Default number of channels. */
davide.aliprandi@st.com 0:7d07f4df31e1 64 };
davide.aliprandi@st.com 0:7d07f4df31e1 65
davide.aliprandi@st.com 0:7d07f4df31e1 66 /* Thread to manage I2S peripherals. */
davide.aliprandi@st.com 0:7d07f4df31e1 67 static rtos::Thread i2s_bh_daemon;
davide.aliprandi@st.com 0:7d07f4df31e1 68
davide.aliprandi@st.com 0:7d07f4df31e1 69
davide.aliprandi@st.com 0:7d07f4df31e1 70 /* Functions -----------------------------------------------------------------*/
davide.aliprandi@st.com 0:7d07f4df31e1 71
davide.aliprandi@st.com 0:7d07f4df31e1 72 /**
davide.aliprandi@st.com 0:7d07f4df31e1 73 * @brief Entry point function of mbedOS.
davide.aliprandi@st.com 0:7d07f4df31e1 74 * @param None
davide.aliprandi@st.com 0:7d07f4df31e1 75 * @retval None
davide.aliprandi@st.com 0:7d07f4df31e1 76 */
davide.aliprandi@st.com 0:7d07f4df31e1 77 int main(void)
davide.aliprandi@st.com 0:7d07f4df31e1 78 {
davide.aliprandi@st.com 0:7d07f4df31e1 79 /*----- Initialization. -----*/
davide.aliprandi@st.com 0:7d07f4df31e1 80
davide.aliprandi@st.com 0:7d07f4df31e1 81 /* Initializing MEMS Microphones Expansion Board on the I2S1 interface. */
davide.aliprandi@st.com 0:7d07f4df31e1 82 XNucleoCCA02M1 *microphones = new XNucleoCCA02M1(PB_15, PB_13);
davide.aliprandi@st.com 0:7d07f4df31e1 83 if (microphones->init(&init) != COMPONENT_OK)
davide.aliprandi@st.com 0:7d07f4df31e1 84 {
davide.aliprandi@st.com 0:7d07f4df31e1 85 error("Initialization of the MEMS Microphones Expansion Board failed.\r\n");
davide.aliprandi@st.com 0:7d07f4df31e1 86 exit(EXIT_FAILURE);
davide.aliprandi@st.com 0:7d07f4df31e1 87 }
davide.aliprandi@st.com 0:7d07f4df31e1 88
davide.aliprandi@st.com 0:7d07f4df31e1 89 /* Starting a thread to manage I2S peripherals. */
davide.aliprandi@st.com 0:7d07f4df31e1 90 Callback<void()> i2s_bh_task(&I2S::i2s_bh_queue, &events::EventQueue::dispatch_forever);
davide.aliprandi@st.com 0:7d07f4df31e1 91 i2s_bh_daemon.start(i2s_bh_task);
davide.aliprandi@st.com 0:7d07f4df31e1 92
davide.aliprandi@st.com 0:7d07f4df31e1 93 /* Enabling transmission via USB. */
davide.aliprandi@st.com 0:7d07f4df31e1 94 microphones->enable_usb();
davide.aliprandi@st.com 0:7d07f4df31e1 95
davide.aliprandi@st.com 0:7d07f4df31e1 96 /* Printing to the console. */
davide.aliprandi@st.com 0:7d07f4df31e1 97 printf("MEMS Microphones Application Example\r\n\n");
davide.aliprandi@st.com 0:7d07f4df31e1 98
davide.aliprandi@st.com 0:7d07f4df31e1 99
davide.aliprandi@st.com 0:7d07f4df31e1 100 /*----- Recording. -----*/
davide.aliprandi@st.com 0:7d07f4df31e1 101
davide.aliprandi@st.com 0:7d07f4df31e1 102 /* Printing to the console. */
davide.aliprandi@st.com 0:7d07f4df31e1 103 printf("--> Recording...\r\n");
davide.aliprandi@st.com 0:7d07f4df31e1 104 microphones->record();
davide.aliprandi@st.com 0:7d07f4df31e1 105 }
davide.aliprandi@st.com 0:7d07f4df31e1 106
davide.aliprandi@st.com 0:7d07f4df31e1 107 #else // DEVICE_I2S
davide.aliprandi@st.com 0:7d07f4df31e1 108
davide.aliprandi@st.com 0:7d07f4df31e1 109 int main(void)
davide.aliprandi@st.com 0:7d07f4df31e1 110 {
davide.aliprandi@st.com 0:7d07f4df31e1 111 printf("The target does not support I2S API.\r\n");
davide.aliprandi@st.com 0:7d07f4df31e1 112 }
davide.aliprandi@st.com 0:7d07f4df31e1 113
davide.aliprandi@st.com 0:7d07f4df31e1 114 #endif // DEVICE_I2S