Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- ******************************************************************************
- * @file main.cpp
- * @author Davide Aliprandi, STMicroelectronics
- * @version V1.0.0
- * @date March 25th, 2016
- * @brief mbed test application for the STMicroelectronics X-NUCLEO-CCA01M1
- * Sound Terminal Expansion Board.
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- /* mbed specific header files. */
- #include "mbed.h"
- #include "rtos.h"
- #include "USBHostMSD.h"
- #if DEVICE_I2S
- /* Helper header files. */
- #include "DevI2C.h"
- /* Component specific header files. */
- #include "STA350BW.h"
- /* My song header file. */
- #include "my_song.h"
- /* Definitions ---------------------------------------------------------------*/
- /* Events. */
- #define PLAY_STOP_EVENT (0x1)
- /* Variables -----------------------------------------------------------------*/
- Serial pc(USBTX,USBRX);
- #define buffer_size 32767
- int16_t valori1[buffer_size]= {0}; //2 perchè ci sono due canali
- //int16_t valori2[2*buffer_size]= {0};
- DigitalOut myledMIO(LED1);
- //int16_t valori[buffer_size]={0};
- int c=0;
- int b=0;
- bool fine1=false;
- bool fine2=false;
- /* Initialization parameters. */
- STA350BW_init_t init = {
- 32000, /* Default Sampling Frequency [Hz]. */
- 100 /* Default Volume. */
- };
- /* Sound Terminal Component. */
- STA350BW *sound_terminal;
- /* Thread to manage I2S peripherals. */
- static rtos::Thread i2s_bh_daemon;
- /* Threads. */
- Thread *play_stop_thread;
- /* User button handling. */
- InterruptIn event(USER_BUTTON);
- /* Functions -----------------------------------------------------------------*/
- /**
- * @brief User button handler function.
- * @param None.
- * @retval None.
- */
- void pressed(void)
- {
- /* Signal to play/stop handler thread. */
- play_stop_thread->signal_set(PLAY_STOP_EVENT);
- }
- /**
- * @brief Play/stop handler function.
- * @param None.
- * @retval None.
- */
- /*void play_stop_handler(void)
- {
- while (true)
- {
- static bool stop = true;
- // Waiting for play/stop events.
- play_stop_thread->signal_wait(PLAY_STOP_EVENT);
- if (stop)
- sound_terminal->stop();
- else
- sound_terminal->play((int16_t *) valori, (uint16_t) sizeof(valori), true);
- printf("--> %s\r\n", stop ? "Stop." : "Playing...");
- stop = !stop;
- }
- }*/
- /**
- * @brief Entry point function of mbedOS.
- * @param None
- * @retval None
- */
- int main(void)
- {
- USBHostMSD msd("usb");
- /*----- Initialization. -----*/
- printf("TP1\r\n");
- if (!msd.connect()) {
- error("USB Flash drive not found.\n");
- }
- printf("TP2\r\n");
- /*----- Initialization. -----*/
- /* Initializing I2C bus. */
- DevI2C *dev_i2c = new DevI2C(PB_9, PB_8);
- /* Initializing Sound Terminal Component. */
- #ifndef USE_I2S2
- sound_terminal = new STA350BW(PA_10, STA350BW_ADDRESS_1, *dev_i2c, PB_15, PB_13, PB_12, NC, PC_6);
- #else
- sound_terminal = new STA350BW(PA_10, STA350BW_ADDRESS_2, *dev_i2c, PC_12, PC_10, PA_4, NC, PC_7);
- #endif
- if (sound_terminal->init(&init) != COMPONENT_OK) {
- error("Initialization of the Sound Terminal Expansion Board failed.\r\n");
- exit(EXIT_FAILURE);
- }
- /* Starting a thread to manage I2S peripherals. */
- Callback<void()> i2s_bh_task(&I2S::i2s_bh_queue, &events::EventQueue::dispatch_forever);
- i2s_bh_daemon.start(i2s_bh_task);
- /* Scheduling the play/stop function. */
- // play_stop_thread = new Thread();
- // osStatus status = play_stop_thread->start(play_stop_handler);
- //if (status != osOK)
- // printf("Could not start the play/stop handler thread.\r\n");
- //event.fall(&pressed);
- /* Setting Sound Terminal Component's parameters. */
- sound_terminal->set_frequency(44100);
- sound_terminal->set_volume(STA350BW_CHANNEL_MASTER, 100);
- /* Printing to the console. */
- printf("Sound Terminal Application Example\r\n\n");
- FILE *fp = fopen("/usb/coez.wav", "r");
- while(c!=EOF)
- {
- c=(c+2);
- //b=(b+4);
- // pc.printf("Val=%i\n\r",fp);
- for(int k=0; k<c; k++) {
- for(int i=0; i<(buffer_size); i++)
- {
- valori1[i+1]=valori1[i];
- fread(&valori1[i],2,1,fp);
- }
- //printf("v1%d\r\n",valori1);
- }
- /* fine1=true;
- printf("b%d\r\n",b);
- for (int x=0; x<b; x++) {
- for(int f=0; f<buffer_size; f++)
- {
- fread(&valori2[2*f],2,1,fp);
- valori2[2*f+1]=valori2[2*f];
- }
- printf("v2%d\r\n",valori2);
- }
- fine2=true;*/
- /*----- Playing. -----*/
- /* Printing to the console. */
- // printf("--> Playing...\r\n");
- // if(fine1==true) {
- sound_terminal->play((int16_t *) valori1, (uint16_t) sizeof(valori1), true);
- //wait(0.2);
- //fine1=false;
- //}
- /*if(fine2==true) {
- sound_terminal->play((int16_t *) valori2, (uint16_t) sizeof(valori2), true);
- fine2=false;
- }*/
- }
- fclose(fp);
- }
- #else // DEVICE_I2S
- int main(void)
- {
- printf("The target does not support I2S API.\r\n");
- }
- #endif // DEVICE_I2S
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement