Il y avait des problèmes dans la libraire...
Dependencies: ST_FREQUENCY_DIVIDER ST_I2S USBDEVICE
Fork of X_NUCLEO_CCA02M1 by
BSP/XNucleoCCA02M1.h@20:9952bef19da1, 2017-05-05 (annotated)
- Committer:
- Davidroid
- Date:
- Fri May 05 11:34:10 2017 +0000
- Revision:
- 20:9952bef19da1
- Parent:
- 18:bc6113bdde85
Simplifying code.
Who changed what in which revision?
User | Revision | Line number | New 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>© 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 | |
Davidroid | 17:a758b376b018 | 48 | /* Configuration -------------------------------------------------------------*/ |
Davidroid | 17:a758b376b018 | 49 | |
Davidroid | 17:a758b376b018 | 50 | /** |
Davidroid | 17:a758b376b018 | 51 | * Enable to debug the duration of functions related to the I2S and USB usage |
Davidroid | 18:bc6113bdde85 | 52 | * through an oscilloscope. |
Davidroid | 18:bc6113bdde85 | 53 | */ |
Davidroid | 17:a758b376b018 | 54 | //#define X_NUCLEO_CCA02M1_DEBUG |
Davidroid | 17:a758b376b018 | 55 | |
Davidroid | 17:a758b376b018 | 56 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 57 | /* Includes ------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 58 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 59 | /* ACTION 1 ------------------------------------------------------------------* |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 60 | * Include here platform specific header files. * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 61 | *----------------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 62 | #include "mbed.h" |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 63 | #include "I2S.h" |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 64 | #include "FrequencyDivider.h" |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 65 | #include "USBAudio.h" |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 66 | /* ACTION 2 ------------------------------------------------------------------* |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 67 | * Include here expansion board configuration's header files. * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 68 | *----------------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 69 | /* ACTION 3 ------------------------------------------------------------------* |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 70 | * Include here expansion board's components' header files. * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 71 | * * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 72 | * Example: * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 73 | * #include "COMPONENT_1.h" * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 74 | * #include "COMPONENT_2.h" * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 75 | *----------------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 76 | #include "component_def.h" |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 77 | #include "PDM2PCMAudio.h" |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 78 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 79 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 80 | /* Definitions ---------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 81 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 82 | /* Maximum number of mounted "X-NUCLEO-CCA02M1" Expansion Boards. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 83 | #define EXPBRD_MOUNTED_NR_MAX 1 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 84 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 85 | /* Bytes per sample. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 86 | #define BYTES_PER_SAMPLE 2 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 87 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 88 | /* Default paramters. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 89 | #define DEFAULT_FREQUENCY 32000 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 90 | #define DEFAULT_CHANNELS 2 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 91 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 92 | /* PCM buffer size and thresholds in ms. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 93 | #define PCM_BUFFER_TH_LOW_ms 1 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 94 | #define PCM_BUFFER_TH_MED_ms 4 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 95 | #define PCM_BUFFER_TH_HIG_ms 7 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 96 | #define PCM_BUFFER_SIZE_ms 9 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 97 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 98 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 99 | /* Types ---------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 100 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 101 | /* Audio processor initialization structure. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 102 | typedef struct |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 103 | { |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 104 | uint32_t frequency; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 105 | uint8_t channels; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 106 | } XNucleoCCA02M1_init_t; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 107 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 108 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 109 | /* Classes -------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 110 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 111 | /** Class representing a X_NUCLEO_CCA02M1 board. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 112 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 113 | class XNucleoCCA02M1 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 114 | { |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 115 | public: |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 116 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 117 | /*** Constructor, Destructor, and Initialization Methods ***/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 118 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 119 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 120 | * @brief Constructor. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 121 | * @param dpin pin name of the data input/output pin of the I2S device. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 122 | * @param clk pin name of the clock pin of the I2S device. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 123 | * @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 | 124 | * @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 | 125 | * @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 | 126 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 127 | XNucleoCCA02M1(PinName dpin, PinName clk, PinName wsel = NC, PinName fdpin = NC, PinName mck = NC) : |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 128 | dev_i2s(dpin, clk, wsel, fdpin, mck), |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 129 | _usb_enabled(false), |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 130 | _volume(PDM2PCM_NOGAIN_VOLUME), |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 131 | _frequency(DEFAULT_FREQUENCY), |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 132 | _channels(DEFAULT_CHANNELS), |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 133 | _callback_attached(false) |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 134 | #ifdef X_NUCLEO_CCA02M1_DEBUG |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 135 | , _i2s_signal(D13), |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 136 | _usb_signal(D12), |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 137 | _buffer_overrun(D11), |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 138 | _buffer_underrun(D10) |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 139 | #endif |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 140 | { |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 141 | /* Checking stackability. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 142 | if (!(_number_of_boards < EXPBRD_MOUNTED_NR_MAX)) |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 143 | 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 | 144 | _XNucleoCCA02M1_Id = _number_of_boards++; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 145 | } |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 146 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 147 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 148 | * @brief Destructor. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 149 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 150 | virtual ~XNucleoCCA02M1(void) {} |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 151 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 152 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 153 | /*** Public Component Related Methods ***/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 154 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 155 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 156 | * @brief Initializing the X_NUCLEO_CCA02M1 board. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 157 | * @param init Pointer to device specific initalization structure. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 158 | * @retval "0" in case of success, an error code otherwise. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 159 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 160 | virtual status_t init(void *init = NULL); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 161 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 162 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 163 | * @brief Enabling transmission via USB. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 164 | * @param None. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 165 | * @retval "0" in case of success, an error code otherwise. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 166 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 167 | virtual status_t enable_usb(void); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 168 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 169 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 170 | * @brief Disabling transmission via USB. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 171 | * @param None. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 172 | * @retval "0" in case of success, an error code otherwise. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 173 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 174 | virtual status_t disable_usb(void); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 175 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 176 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 177 | * @brief Start recording audio. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 178 | * @param None. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 179 | * @retval "0" in case of success, an error code otherwise. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 180 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 181 | virtual status_t record(void); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 182 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 183 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 184 | * @brief Attach a user-defined callback that will be executed whenever PCM |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 185 | * data are ready, i.e. once each millisecond. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 186 | * The provided PCM buffer will be filled by the microphones. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 187 | * @param fptr Callback to attach. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 188 | * @retval None. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 189 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 190 | void attach(void (*fptr) (int16_t *PCM_buffer, uint16_t PCM_buffer_bytes)); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 191 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 192 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 193 | * @brief Attach a user-defined non-static callback that will be executed |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 194 | * whenever PCM data are ready, i.e. once each millisecond. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 195 | * The provided PCM buffer will be filled by the microphones. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 196 | * @param tptr Pointer to an object. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 197 | * @param mptr Pointer to an object's callback. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 198 | * @retval None. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 199 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 200 | template<typename T> |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 201 | void attach(T *tptr, void (T::*mptr) (int16_t *PCM_buffer, uint16_t PCM_buffer_bytes)); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 202 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 203 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 204 | /*** Other Public Expansion Board Related Methods ***/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 205 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 206 | /*** Public Expansion Board Related Attributes ***/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 207 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 208 | /* ACTION 4 --------------------------------------------------------------* |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 209 | * Declare here a public attribute for each expansion board's component. * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 210 | * You will have to call these attributes' public methods within your * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 211 | * main program. * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 212 | * * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 213 | * Example: * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 214 | * COMPONENT_1 *component_1; * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 215 | * COMPONENT_2 *component_2; * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 216 | *------------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 217 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 218 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 219 | protected: |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 220 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 221 | /*** Protected Expansion Board Related Related Methods ***/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 222 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 223 | /* ACTION 5 --------------------------------------------------------------* |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 224 | * Declare here a protected initialization method for each expansion * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 225 | * board's component. * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 226 | * * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 227 | * Example: * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 228 | * bool init_COMPONENT_1(void); * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 229 | * bool init_COMPONENT_2(void); * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 230 | *------------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 231 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 232 | * @brief I2S callback which is executed whenever PCM data are ready, i.e. once |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 233 | * each millisecond. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 234 | * @param narg Narg flag. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 235 | * @retval None. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 236 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 237 | void i2s_callback(int narg); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 238 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 239 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 240 | * @brief Sending PCM data via USB. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 241 | * @param None. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 242 | * @retval None. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 243 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 244 | void usb_handler(void); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 245 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 246 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 247 | /*** Expansion Board's Instance Variables ***/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 248 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 249 | /* ACTION 6 --------------------------------------------------------------* |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 250 | * Declare here the component's static and non-static data, one variable * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 251 | * per line. * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 252 | * * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 253 | * Example: * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 254 | * int instance_id; * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 255 | * static int number_of_instances; * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 256 | *------------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 257 | public: |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 258 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 259 | /* I2S Audio Device (exclusive). */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 260 | I2S dev_i2s; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 261 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 262 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 263 | protected: |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 264 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 265 | /* USB Audio Device. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 266 | USBAudio *_usb_audio; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 267 | bool _usb_enabled; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 268 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 269 | /* PDM to PCM conversion library. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 270 | PDM2PCMAudio *_pdm2pcm; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 271 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 272 | /* PDM to PCM conversion parameters. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 273 | uint32_t _volume; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 274 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 275 | /* Microphone parameters. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 276 | uint32_t _frequency; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 277 | uint32_t _channels; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 278 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 279 | /* Size of the buffers to store audio data. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 280 | uint32_t _PDM_samples_one_ms; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 281 | uint32_t _PDM_samples_two_ms; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 282 | uint32_t _PCM_samples_one_ms; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 283 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 284 | /* Input and output audio buffers. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 285 | uint16_t *_PDM_buffer_two_ms; /* Input double-buffered PDM audio data, from microphones. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 286 | int16_t *_PCM_buffer_n_ms; /* Output n-ms-buffered PCM audio data, to USB. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 287 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 288 | /* Support audio buffers for processing data. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 289 | uint16_t *_PDM_buffer_one_ms; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 290 | int16_t *_USB_PCM_buffer_one_ms; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 291 | int16_t *_USER_PCM_buffer_one_ms; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 292 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 293 | /* Indexes of the output PCM buffer. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 294 | static uint32_t _PCM_buffer_read_index; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 295 | static uint32_t _PCM_buffer_write_index; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 296 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 297 | /* User-defined PCM-data-ready callback. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 298 | Callback<void(int16_t *PCM_buffer, uint16_t PCM_buffer_bytes)> _callback; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 299 | bool _callback_attached; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 300 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 301 | /* Accessing shared areas: the PCM buffer. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 302 | static SingletonPtr<PlatformMutex> _mutex; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 303 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 304 | /* Expansion board identifier. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 305 | uint8_t _XNucleoCCA02M1_Id; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 306 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 307 | /* Number of expansion boards. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 308 | static uint8_t _number_of_boards; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 309 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 310 | #ifdef X_NUCLEO_CCA02M1_DEBUG |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 311 | /* Signals for debugging purposes. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 312 | DigitalOut _i2s_signal; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 313 | DigitalOut _usb_signal; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 314 | DigitalOut _buffer_overrun; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 315 | DigitalOut _buffer_underrun; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 316 | #endif |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 317 | }; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 318 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 319 | #endif /* __X_NUCLEO_CCA02M1_CLASS_H */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 320 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 321 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |