Il y avait des problèmes dans la libraire...

Dependencies:   ST_FREQUENCY_DIVIDER ST_I2S USBDEVICE

Fork of X_NUCLEO_CCA02M1 by ST

Committer:
davide.aliprandi@st.com
Date:
Fri Apr 21 10:33:08 2017 +0200
Revision:
2:9f389fd8fb2e
Child:
16:4ab2eac7be21
Aligned to ARM mbed codinmg style; OpenPDM2PCM middleware added.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davide.aliprandi@st.com 2:9f389fd8fb2e 1 /**
davide.aliprandi@st.com 2:9f389fd8fb2e 2 ******************************************************************************
davide.aliprandi@st.com 2:9f389fd8fb2e 3 * @file XNucleoCCA02M1.h
davide.aliprandi@st.com 2:9f389fd8fb2e 4 * @author AST / Software Platforms and Cloud
davide.aliprandi@st.com 2:9f389fd8fb2e 5 * @version V1.0
davide.aliprandi@st.com 2:9f389fd8fb2e 6 * @date October 17th, 2016
davide.aliprandi@st.com 2:9f389fd8fb2e 7 * @brief Class header file for the X_NUCLEO_CCA02M1 expansion board.
davide.aliprandi@st.com 2:9f389fd8fb2e 8 ******************************************************************************
davide.aliprandi@st.com 2:9f389fd8fb2e 9 * @attention
davide.aliprandi@st.com 2:9f389fd8fb2e 10 *
davide.aliprandi@st.com 2:9f389fd8fb2e 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
davide.aliprandi@st.com 2:9f389fd8fb2e 12 *
davide.aliprandi@st.com 2:9f389fd8fb2e 13 * Redistribution and use in source and binary forms, with or without modification,
davide.aliprandi@st.com 2:9f389fd8fb2e 14 * are permitted provided that the following conditions are met:
davide.aliprandi@st.com 2:9f389fd8fb2e 15 * 1. Redistributions of source code must retain the above copyright notice,
davide.aliprandi@st.com 2:9f389fd8fb2e 16 * this list of conditions and the following disclaimer.
davide.aliprandi@st.com 2:9f389fd8fb2e 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
davide.aliprandi@st.com 2:9f389fd8fb2e 18 * this list of conditions and the following disclaimer in the documentation
davide.aliprandi@st.com 2:9f389fd8fb2e 19 * and/or other materials provided with the distribution.
davide.aliprandi@st.com 2:9f389fd8fb2e 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
davide.aliprandi@st.com 2:9f389fd8fb2e 21 * may be used to endorse or promote products derived from this software
davide.aliprandi@st.com 2:9f389fd8fb2e 22 * without specific prior written permission.
davide.aliprandi@st.com 2:9f389fd8fb2e 23 *
davide.aliprandi@st.com 2:9f389fd8fb2e 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
davide.aliprandi@st.com 2:9f389fd8fb2e 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
davide.aliprandi@st.com 2:9f389fd8fb2e 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
davide.aliprandi@st.com 2:9f389fd8fb2e 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
davide.aliprandi@st.com 2:9f389fd8fb2e 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
davide.aliprandi@st.com 2:9f389fd8fb2e 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
davide.aliprandi@st.com 2:9f389fd8fb2e 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
davide.aliprandi@st.com 2:9f389fd8fb2e 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
davide.aliprandi@st.com 2:9f389fd8fb2e 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
davide.aliprandi@st.com 2:9f389fd8fb2e 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
davide.aliprandi@st.com 2:9f389fd8fb2e 34 *
davide.aliprandi@st.com 2:9f389fd8fb2e 35 ******************************************************************************
davide.aliprandi@st.com 2:9f389fd8fb2e 36 */
davide.aliprandi@st.com 2:9f389fd8fb2e 37
davide.aliprandi@st.com 2:9f389fd8fb2e 38
davide.aliprandi@st.com 2:9f389fd8fb2e 39 /* Generated with STM32CubeTOO -----------------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 40
davide.aliprandi@st.com 2:9f389fd8fb2e 41
davide.aliprandi@st.com 2:9f389fd8fb2e 42 /* Define to prevent recursive inclusion -------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 43
davide.aliprandi@st.com 2:9f389fd8fb2e 44 #ifndef __X_NUCLEO_CCA02M1_CLASS_H
davide.aliprandi@st.com 2:9f389fd8fb2e 45 #define __X_NUCLEO_CCA02M1_CLASS_H
davide.aliprandi@st.com 2:9f389fd8fb2e 46
davide.aliprandi@st.com 2:9f389fd8fb2e 47
davide.aliprandi@st.com 2:9f389fd8fb2e 48 /* Includes ------------------------------------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 49
davide.aliprandi@st.com 2:9f389fd8fb2e 50 /* ACTION 1 ------------------------------------------------------------------*
davide.aliprandi@st.com 2:9f389fd8fb2e 51 * Include here platform specific header files. *
davide.aliprandi@st.com 2:9f389fd8fb2e 52 *----------------------------------------------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 53 #include "mbed.h"
davide.aliprandi@st.com 2:9f389fd8fb2e 54 #include "I2S.h"
davide.aliprandi@st.com 2:9f389fd8fb2e 55 #include "FrequencyDivider.h"
davide.aliprandi@st.com 2:9f389fd8fb2e 56 #include "USBAudio.h"
davide.aliprandi@st.com 2:9f389fd8fb2e 57 /* ACTION 2 ------------------------------------------------------------------*
davide.aliprandi@st.com 2:9f389fd8fb2e 58 * Include here expansion board configuration's header files. *
davide.aliprandi@st.com 2:9f389fd8fb2e 59 *----------------------------------------------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 60 /* ACTION 3 ------------------------------------------------------------------*
davide.aliprandi@st.com 2:9f389fd8fb2e 61 * Include here expansion board's components' header files. *
davide.aliprandi@st.com 2:9f389fd8fb2e 62 * *
davide.aliprandi@st.com 2:9f389fd8fb2e 63 * Example: *
davide.aliprandi@st.com 2:9f389fd8fb2e 64 * #include "COMPONENT_1.h" *
davide.aliprandi@st.com 2:9f389fd8fb2e 65 * #include "COMPONENT_2.h" *
davide.aliprandi@st.com 2:9f389fd8fb2e 66 *----------------------------------------------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 67 #include "component_def.h"
davide.aliprandi@st.com 2:9f389fd8fb2e 68 #include "PDM2PCMAudio.h"
davide.aliprandi@st.com 2:9f389fd8fb2e 69
davide.aliprandi@st.com 2:9f389fd8fb2e 70
davide.aliprandi@st.com 2:9f389fd8fb2e 71 /* Definitions ---------------------------------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 72
davide.aliprandi@st.com 2:9f389fd8fb2e 73 /* Maximum number of mounted "X-NUCLEO-CCA02M1" Expansion Boards. */
davide.aliprandi@st.com 2:9f389fd8fb2e 74 #define EXPBRD_MOUNTED_NR_MAX 1
davide.aliprandi@st.com 2:9f389fd8fb2e 75
davide.aliprandi@st.com 2:9f389fd8fb2e 76 /* Bytes per sample. */
davide.aliprandi@st.com 2:9f389fd8fb2e 77 #define BYTES_PER_SAMPLE 2
davide.aliprandi@st.com 2:9f389fd8fb2e 78
davide.aliprandi@st.com 2:9f389fd8fb2e 79 /* Default paramters. */
davide.aliprandi@st.com 2:9f389fd8fb2e 80 #define DEFAULT_FREQUENCY 32000
davide.aliprandi@st.com 2:9f389fd8fb2e 81 #define DEFAULT_CHANNELS 2
davide.aliprandi@st.com 2:9f389fd8fb2e 82
davide.aliprandi@st.com 2:9f389fd8fb2e 83 /* PCM buffer size and thresholds in ms. */
davide.aliprandi@st.com 2:9f389fd8fb2e 84 #define PCM_BUFFER_TH_LOW_ms 1
davide.aliprandi@st.com 2:9f389fd8fb2e 85 #define PCM_BUFFER_TH_MED_ms 4
davide.aliprandi@st.com 2:9f389fd8fb2e 86 #define PCM_BUFFER_TH_HIG_ms 7
davide.aliprandi@st.com 2:9f389fd8fb2e 87 #define PCM_BUFFER_SIZE_ms 9
davide.aliprandi@st.com 2:9f389fd8fb2e 88
davide.aliprandi@st.com 2:9f389fd8fb2e 89
davide.aliprandi@st.com 2:9f389fd8fb2e 90 /* Types ---------------------------------------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 91
davide.aliprandi@st.com 2:9f389fd8fb2e 92 /* Audio processor initialization structure. */
davide.aliprandi@st.com 2:9f389fd8fb2e 93 typedef struct
davide.aliprandi@st.com 2:9f389fd8fb2e 94 {
davide.aliprandi@st.com 2:9f389fd8fb2e 95 uint32_t frequency;
davide.aliprandi@st.com 2:9f389fd8fb2e 96 uint8_t channels;
davide.aliprandi@st.com 2:9f389fd8fb2e 97 } XNucleoCCA02M1_init_t;
davide.aliprandi@st.com 2:9f389fd8fb2e 98
davide.aliprandi@st.com 2:9f389fd8fb2e 99
davide.aliprandi@st.com 2:9f389fd8fb2e 100 /* Classes -------------------------------------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 101
davide.aliprandi@st.com 2:9f389fd8fb2e 102 /** Class representing a X_NUCLEO_CCA02M1 board.
davide.aliprandi@st.com 2:9f389fd8fb2e 103 */
davide.aliprandi@st.com 2:9f389fd8fb2e 104 class XNucleoCCA02M1
davide.aliprandi@st.com 2:9f389fd8fb2e 105 {
davide.aliprandi@st.com 2:9f389fd8fb2e 106 public:
davide.aliprandi@st.com 2:9f389fd8fb2e 107
davide.aliprandi@st.com 2:9f389fd8fb2e 108 /*** Constructor, Destructor, and Initialization Methods ***/
davide.aliprandi@st.com 2:9f389fd8fb2e 109
davide.aliprandi@st.com 2:9f389fd8fb2e 110 /**
davide.aliprandi@st.com 2:9f389fd8fb2e 111 * @brief Constructor.
davide.aliprandi@st.com 2:9f389fd8fb2e 112 * @param dpin pin name of the data input/output pin of the I2S device.
davide.aliprandi@st.com 2:9f389fd8fb2e 113 * @param clk pin name of the clock pin of the I2S device.
davide.aliprandi@st.com 2:9f389fd8fb2e 114 * @param wsel pin name of the word select output pin of the I2S device (might be NC for PDM sources).
davide.aliprandi@st.com 2:9f389fd8fb2e 115 * @param fdpin pin name of the data input pin of the I2S device (for full-duplex operations, default = NC).
davide.aliprandi@st.com 2:9f389fd8fb2e 116 * @param mck pin name of the master clock output pin of the I2S device (additional pin when needed for some external audio devices, default = NC)
davide.aliprandi@st.com 2:9f389fd8fb2e 117 */
davide.aliprandi@st.com 2:9f389fd8fb2e 118 XNucleoCCA02M1(PinName dpin, PinName clk, PinName wsel = NC, PinName fdpin = NC, PinName mck = NC) :
davide.aliprandi@st.com 2:9f389fd8fb2e 119 dev_i2s(dpin, clk, wsel, fdpin, mck),
davide.aliprandi@st.com 2:9f389fd8fb2e 120 _usb_enabled(false),
davide.aliprandi@st.com 2:9f389fd8fb2e 121 _volume(PDM2PCM_NOGAIN_VOLUME),
davide.aliprandi@st.com 2:9f389fd8fb2e 122 _decimation_factor(PDM2PCM_DECIMATION_FACTOR),
davide.aliprandi@st.com 2:9f389fd8fb2e 123 _frequency(DEFAULT_FREQUENCY),
davide.aliprandi@st.com 2:9f389fd8fb2e 124 _channels(DEFAULT_CHANNELS),
davide.aliprandi@st.com 2:9f389fd8fb2e 125 _callback_attached(false)
davide.aliprandi@st.com 2:9f389fd8fb2e 126 #ifdef X_NUCLEO_CCA02M1_DEBUG
davide.aliprandi@st.com 2:9f389fd8fb2e 127 , _i2s_signal(D13),
davide.aliprandi@st.com 2:9f389fd8fb2e 128 _usb_signal(D12),
davide.aliprandi@st.com 2:9f389fd8fb2e 129 _buffer_overrun(D11),
davide.aliprandi@st.com 2:9f389fd8fb2e 130 _buffer_underrun(D10)
davide.aliprandi@st.com 2:9f389fd8fb2e 131 #endif
davide.aliprandi@st.com 2:9f389fd8fb2e 132 {
davide.aliprandi@st.com 2:9f389fd8fb2e 133 /* Checking stackability. */
davide.aliprandi@st.com 2:9f389fd8fb2e 134 if (!(_number_of_boards < EXPBRD_MOUNTED_NR_MAX))
davide.aliprandi@st.com 2:9f389fd8fb2e 135 error("Instantiation of the X_NUCLEO_CCA02M1 expansion board failed: it can be stacked up to %d times.\r\n", EXPBRD_MOUNTED_NR_MAX);
davide.aliprandi@st.com 2:9f389fd8fb2e 136 _XNucleoCCA02M1_Id = _number_of_boards++;
davide.aliprandi@st.com 2:9f389fd8fb2e 137 }
davide.aliprandi@st.com 2:9f389fd8fb2e 138
davide.aliprandi@st.com 2:9f389fd8fb2e 139 /**
davide.aliprandi@st.com 2:9f389fd8fb2e 140 * @brief Destructor.
davide.aliprandi@st.com 2:9f389fd8fb2e 141 */
davide.aliprandi@st.com 2:9f389fd8fb2e 142 virtual ~XNucleoCCA02M1(void) {}
davide.aliprandi@st.com 2:9f389fd8fb2e 143
davide.aliprandi@st.com 2:9f389fd8fb2e 144
davide.aliprandi@st.com 2:9f389fd8fb2e 145 /*** Public Component Related Methods ***/
davide.aliprandi@st.com 2:9f389fd8fb2e 146
davide.aliprandi@st.com 2:9f389fd8fb2e 147 /**
davide.aliprandi@st.com 2:9f389fd8fb2e 148 * @brief Initializing the X_NUCLEO_CCA02M1 board.
davide.aliprandi@st.com 2:9f389fd8fb2e 149 * @param init Pointer to device specific initalization structure.
davide.aliprandi@st.com 2:9f389fd8fb2e 150 * @retval "0" in case of success, an error code otherwise.
davide.aliprandi@st.com 2:9f389fd8fb2e 151 */
davide.aliprandi@st.com 2:9f389fd8fb2e 152 virtual status_t init(void *init = NULL);
davide.aliprandi@st.com 2:9f389fd8fb2e 153
davide.aliprandi@st.com 2:9f389fd8fb2e 154 /**
davide.aliprandi@st.com 2:9f389fd8fb2e 155 * @brief Enabling transmission via USB.
davide.aliprandi@st.com 2:9f389fd8fb2e 156 * @param None.
davide.aliprandi@st.com 2:9f389fd8fb2e 157 * @retval "0" in case of success, an error code otherwise.
davide.aliprandi@st.com 2:9f389fd8fb2e 158 */
davide.aliprandi@st.com 2:9f389fd8fb2e 159 virtual status_t enable_usb(void);
davide.aliprandi@st.com 2:9f389fd8fb2e 160
davide.aliprandi@st.com 2:9f389fd8fb2e 161 /**
davide.aliprandi@st.com 2:9f389fd8fb2e 162 * @brief Disabling transmission via USB.
davide.aliprandi@st.com 2:9f389fd8fb2e 163 * @param None.
davide.aliprandi@st.com 2:9f389fd8fb2e 164 * @retval "0" in case of success, an error code otherwise.
davide.aliprandi@st.com 2:9f389fd8fb2e 165 */
davide.aliprandi@st.com 2:9f389fd8fb2e 166 virtual status_t disable_usb(void);
davide.aliprandi@st.com 2:9f389fd8fb2e 167
davide.aliprandi@st.com 2:9f389fd8fb2e 168 /**
davide.aliprandi@st.com 2:9f389fd8fb2e 169 * @brief Start recording audio.
davide.aliprandi@st.com 2:9f389fd8fb2e 170 * @param None.
davide.aliprandi@st.com 2:9f389fd8fb2e 171 * @retval "0" in case of success, an error code otherwise.
davide.aliprandi@st.com 2:9f389fd8fb2e 172 */
davide.aliprandi@st.com 2:9f389fd8fb2e 173 virtual status_t record(void);
davide.aliprandi@st.com 2:9f389fd8fb2e 174
davide.aliprandi@st.com 2:9f389fd8fb2e 175 /**
davide.aliprandi@st.com 2:9f389fd8fb2e 176 * @brief Attach a user-defined callback that will be executed whenever PCM
davide.aliprandi@st.com 2:9f389fd8fb2e 177 * data are ready, i.e. once each millisecond.
davide.aliprandi@st.com 2:9f389fd8fb2e 178 * The provided PCM buffer will be filled by the microphones.
davide.aliprandi@st.com 2:9f389fd8fb2e 179 * @param fptr Callback to attach.
davide.aliprandi@st.com 2:9f389fd8fb2e 180 * @retval None.
davide.aliprandi@st.com 2:9f389fd8fb2e 181 */
davide.aliprandi@st.com 2:9f389fd8fb2e 182 void attach(void (*fptr) (int16_t *PCM_buffer, uint16_t PCM_buffer_bytes));
davide.aliprandi@st.com 2:9f389fd8fb2e 183
davide.aliprandi@st.com 2:9f389fd8fb2e 184 /**
davide.aliprandi@st.com 2:9f389fd8fb2e 185 * @brief Attach a user-defined non-static callback that will be executed
davide.aliprandi@st.com 2:9f389fd8fb2e 186 * whenever PCM data are ready, i.e. once each millisecond.
davide.aliprandi@st.com 2:9f389fd8fb2e 187 * The provided PCM buffer will be filled by the microphones.
davide.aliprandi@st.com 2:9f389fd8fb2e 188 * @param tptr Pointer to an object.
davide.aliprandi@st.com 2:9f389fd8fb2e 189 * @param mptr Pointer to an object's callback.
davide.aliprandi@st.com 2:9f389fd8fb2e 190 * @retval None.
davide.aliprandi@st.com 2:9f389fd8fb2e 191 */
davide.aliprandi@st.com 2:9f389fd8fb2e 192 template<typename T>
davide.aliprandi@st.com 2:9f389fd8fb2e 193 void attach(T *tptr, void (T::*mptr) (int16_t *PCM_buffer, uint16_t PCM_buffer_bytes));
davide.aliprandi@st.com 2:9f389fd8fb2e 194
davide.aliprandi@st.com 2:9f389fd8fb2e 195
davide.aliprandi@st.com 2:9f389fd8fb2e 196 /*** Other Public Expansion Board Related Methods ***/
davide.aliprandi@st.com 2:9f389fd8fb2e 197
davide.aliprandi@st.com 2:9f389fd8fb2e 198 /*** Public Expansion Board Related Attributes ***/
davide.aliprandi@st.com 2:9f389fd8fb2e 199
davide.aliprandi@st.com 2:9f389fd8fb2e 200 /* ACTION 4 --------------------------------------------------------------*
davide.aliprandi@st.com 2:9f389fd8fb2e 201 * Declare here a public attribute for each expansion board's component. *
davide.aliprandi@st.com 2:9f389fd8fb2e 202 * You will have to call these attributes' public methods within your *
davide.aliprandi@st.com 2:9f389fd8fb2e 203 * main program. *
davide.aliprandi@st.com 2:9f389fd8fb2e 204 * *
davide.aliprandi@st.com 2:9f389fd8fb2e 205 * Example: *
davide.aliprandi@st.com 2:9f389fd8fb2e 206 * COMPONENT_1 *component_1; *
davide.aliprandi@st.com 2:9f389fd8fb2e 207 * COMPONENT_2 *component_2; *
davide.aliprandi@st.com 2:9f389fd8fb2e 208 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 209
davide.aliprandi@st.com 2:9f389fd8fb2e 210
davide.aliprandi@st.com 2:9f389fd8fb2e 211 protected:
davide.aliprandi@st.com 2:9f389fd8fb2e 212
davide.aliprandi@st.com 2:9f389fd8fb2e 213 /*** Protected Expansion Board Related Related Methods ***/
davide.aliprandi@st.com 2:9f389fd8fb2e 214
davide.aliprandi@st.com 2:9f389fd8fb2e 215 /* ACTION 5 --------------------------------------------------------------*
davide.aliprandi@st.com 2:9f389fd8fb2e 216 * Declare here a protected initialization method for each expansion *
davide.aliprandi@st.com 2:9f389fd8fb2e 217 * board's component. *
davide.aliprandi@st.com 2:9f389fd8fb2e 218 * *
davide.aliprandi@st.com 2:9f389fd8fb2e 219 * Example: *
davide.aliprandi@st.com 2:9f389fd8fb2e 220 * bool init_COMPONENT_1(void); *
davide.aliprandi@st.com 2:9f389fd8fb2e 221 * bool init_COMPONENT_2(void); *
davide.aliprandi@st.com 2:9f389fd8fb2e 222 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 223 /**
davide.aliprandi@st.com 2:9f389fd8fb2e 224 * @brief I2S callback which is executed whenever PCM data are ready, i.e. once
davide.aliprandi@st.com 2:9f389fd8fb2e 225 * each millisecond.
davide.aliprandi@st.com 2:9f389fd8fb2e 226 * @param narg Narg flag.
davide.aliprandi@st.com 2:9f389fd8fb2e 227 * @retval None.
davide.aliprandi@st.com 2:9f389fd8fb2e 228 */
davide.aliprandi@st.com 2:9f389fd8fb2e 229 void i2s_callback(int narg);
davide.aliprandi@st.com 2:9f389fd8fb2e 230
davide.aliprandi@st.com 2:9f389fd8fb2e 231 /**
davide.aliprandi@st.com 2:9f389fd8fb2e 232 * @brief Sending PCM data via USB.
davide.aliprandi@st.com 2:9f389fd8fb2e 233 * @param None.
davide.aliprandi@st.com 2:9f389fd8fb2e 234 * @retval None.
davide.aliprandi@st.com 2:9f389fd8fb2e 235 */
davide.aliprandi@st.com 2:9f389fd8fb2e 236 void usb_handler(void);
davide.aliprandi@st.com 2:9f389fd8fb2e 237
davide.aliprandi@st.com 2:9f389fd8fb2e 238
davide.aliprandi@st.com 2:9f389fd8fb2e 239 /*** Expansion Board's Instance Variables ***/
davide.aliprandi@st.com 2:9f389fd8fb2e 240
davide.aliprandi@st.com 2:9f389fd8fb2e 241 /* ACTION 6 --------------------------------------------------------------*
davide.aliprandi@st.com 2:9f389fd8fb2e 242 * Declare here the component's static and non-static data, one variable *
davide.aliprandi@st.com 2:9f389fd8fb2e 243 * per line. *
davide.aliprandi@st.com 2:9f389fd8fb2e 244 * *
davide.aliprandi@st.com 2:9f389fd8fb2e 245 * Example: *
davide.aliprandi@st.com 2:9f389fd8fb2e 246 * int instance_id; *
davide.aliprandi@st.com 2:9f389fd8fb2e 247 * static int number_of_instances; *
davide.aliprandi@st.com 2:9f389fd8fb2e 248 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 2:9f389fd8fb2e 249 public:
davide.aliprandi@st.com 2:9f389fd8fb2e 250
davide.aliprandi@st.com 2:9f389fd8fb2e 251 /* I2S Audio Device (exclusive). */
davide.aliprandi@st.com 2:9f389fd8fb2e 252 I2S dev_i2s;
davide.aliprandi@st.com 2:9f389fd8fb2e 253
davide.aliprandi@st.com 2:9f389fd8fb2e 254
davide.aliprandi@st.com 2:9f389fd8fb2e 255 protected:
davide.aliprandi@st.com 2:9f389fd8fb2e 256
davide.aliprandi@st.com 2:9f389fd8fb2e 257 /* USB Audio Device. */
davide.aliprandi@st.com 2:9f389fd8fb2e 258 USBAudio *_usb_audio;
davide.aliprandi@st.com 2:9f389fd8fb2e 259 bool _usb_enabled;
davide.aliprandi@st.com 2:9f389fd8fb2e 260
davide.aliprandi@st.com 2:9f389fd8fb2e 261 /* PDM to PCM conversion library. */
davide.aliprandi@st.com 2:9f389fd8fb2e 262 PDM2PCMAudio *_pdm2pcm;
davide.aliprandi@st.com 2:9f389fd8fb2e 263
davide.aliprandi@st.com 2:9f389fd8fb2e 264 /* PDM to PCM conversion parameters. */
davide.aliprandi@st.com 2:9f389fd8fb2e 265 uint32_t _volume;
davide.aliprandi@st.com 2:9f389fd8fb2e 266 uint32_t _decimation_factor;
davide.aliprandi@st.com 2:9f389fd8fb2e 267
davide.aliprandi@st.com 2:9f389fd8fb2e 268 /* Microphone parameters. */
davide.aliprandi@st.com 2:9f389fd8fb2e 269 uint32_t _frequency;
davide.aliprandi@st.com 2:9f389fd8fb2e 270 uint32_t _channels;
davide.aliprandi@st.com 2:9f389fd8fb2e 271
davide.aliprandi@st.com 2:9f389fd8fb2e 272 /* Size of the buffers to store audio data. */
davide.aliprandi@st.com 2:9f389fd8fb2e 273 uint32_t _PDM_samples_one_ms;
davide.aliprandi@st.com 2:9f389fd8fb2e 274 uint32_t _PDM_samples_two_ms;
davide.aliprandi@st.com 2:9f389fd8fb2e 275 uint32_t _PCM_samples_one_ms;
davide.aliprandi@st.com 2:9f389fd8fb2e 276
davide.aliprandi@st.com 2:9f389fd8fb2e 277 /* Input and output audio buffers. */
davide.aliprandi@st.com 2:9f389fd8fb2e 278 uint16_t *_PDM_buffer_two_ms; /* Input double-buffered PDM audio data, from microphones. */
davide.aliprandi@st.com 2:9f389fd8fb2e 279 int16_t *_PCM_buffer_n_ms; /* Output n-ms-buffered PCM audio data, to USB. */
davide.aliprandi@st.com 2:9f389fd8fb2e 280
davide.aliprandi@st.com 2:9f389fd8fb2e 281 /* Support audio buffers for processing data. */
davide.aliprandi@st.com 2:9f389fd8fb2e 282 uint16_t *_PDM_buffer_one_ms;
davide.aliprandi@st.com 2:9f389fd8fb2e 283 int16_t *_USB_PCM_buffer_one_ms;
davide.aliprandi@st.com 2:9f389fd8fb2e 284 int16_t *_USER_PCM_buffer_one_ms;
davide.aliprandi@st.com 2:9f389fd8fb2e 285
davide.aliprandi@st.com 2:9f389fd8fb2e 286 /* Indexes of the output PCM buffer. */
davide.aliprandi@st.com 2:9f389fd8fb2e 287 static uint32_t _PCM_buffer_read_index;
davide.aliprandi@st.com 2:9f389fd8fb2e 288 static uint32_t _PCM_buffer_write_index;
davide.aliprandi@st.com 2:9f389fd8fb2e 289
davide.aliprandi@st.com 2:9f389fd8fb2e 290 /* User-defined PCM-data-ready callback. */
davide.aliprandi@st.com 2:9f389fd8fb2e 291 Callback<void(int16_t *PCM_buffer, uint16_t PCM_buffer_bytes)> _callback;
davide.aliprandi@st.com 2:9f389fd8fb2e 292 bool _callback_attached;
davide.aliprandi@st.com 2:9f389fd8fb2e 293
davide.aliprandi@st.com 2:9f389fd8fb2e 294 /* Accessing shared areas: the PCM buffer. */
davide.aliprandi@st.com 2:9f389fd8fb2e 295 static SingletonPtr<PlatformMutex> _mutex;
davide.aliprandi@st.com 2:9f389fd8fb2e 296
davide.aliprandi@st.com 2:9f389fd8fb2e 297 /* Expansion board identifier. */
davide.aliprandi@st.com 2:9f389fd8fb2e 298 uint8_t _XNucleoCCA02M1_Id;
davide.aliprandi@st.com 2:9f389fd8fb2e 299
davide.aliprandi@st.com 2:9f389fd8fb2e 300 /* Number of expansion boards. */
davide.aliprandi@st.com 2:9f389fd8fb2e 301 static uint8_t _number_of_boards;
davide.aliprandi@st.com 2:9f389fd8fb2e 302
davide.aliprandi@st.com 2:9f389fd8fb2e 303 #ifdef X_NUCLEO_CCA02M1_DEBUG
davide.aliprandi@st.com 2:9f389fd8fb2e 304 /* Signals for debugging purposes. */
davide.aliprandi@st.com 2:9f389fd8fb2e 305 DigitalOut _i2s_signal;
davide.aliprandi@st.com 2:9f389fd8fb2e 306 DigitalOut _usb_signal;
davide.aliprandi@st.com 2:9f389fd8fb2e 307 DigitalOut _buffer_overrun;
davide.aliprandi@st.com 2:9f389fd8fb2e 308 DigitalOut _buffer_underrun;
davide.aliprandi@st.com 2:9f389fd8fb2e 309 #endif
davide.aliprandi@st.com 2:9f389fd8fb2e 310 };
davide.aliprandi@st.com 2:9f389fd8fb2e 311
davide.aliprandi@st.com 2:9f389fd8fb2e 312 #endif /* __X_NUCLEO_CCA02M1_CLASS_H */
davide.aliprandi@st.com 2:9f389fd8fb2e 313
davide.aliprandi@st.com 2:9f389fd8fb2e 314 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/