Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. /**
  2. ******************************************************************************
  3. * @file main.cpp
  4. * @author Davide Aliprandi, STMicroelectronics
  5. * @version V1.0.0
  6. * @date March 25th, 2016
  7. * @brief mbed test application for the STMicroelectronics X-NUCLEO-CCA01M1
  8. * Sound Terminal Expansion Board.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  13. *
  14. * Redistribution and use in source and binary forms, with or without modification,
  15. * are permitted provided that the following conditions are met:
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. ******************************************************************************
  37. */
  38.  
  39.  
  40. /* Includes ------------------------------------------------------------------*/
  41.  
  42. /* mbed specific header files. */
  43. #include "mbed.h"
  44. #include "rtos.h"
  45. #include "USBHostMSD.h"
  46. #include "SDFileSystem.h"
  47. #if DEVICE_I2S
  48.  
  49. /* Helper header files. */
  50. #include "DevI2C.h"
  51.  
  52. /* Component specific header files. */
  53. #include "STA350BW.h"
  54.  
  55. /* My song header file. */
  56. #include "my_song.h"
  57.  
  58.  
  59. /* Definitions ---------------------------------------------------------------*/
  60.  
  61. /* Events. */
  62. #define PLAY_STOP_EVENT (0x1)
  63.  
  64. /* Variables -----------------------------------------------------------------*/
  65. Serial pc(USBTX,USBRX);
  66. #define buffer_size 100
  67. int16_t valori1[buffer_size]= {0}; //2 perchè ci sono due canali
  68. //int16_t valori2[buffer_size]= {0};
  69. DigitalOut myledMIO(LED1);
  70. //int16_t valori[buffer_size]={0};
  71. int c=0;
  72. int b=0;
  73. bool fine1=false;
  74. bool fine2=false;
  75. /* Initialization parameters. */
  76. STA350BW_init_t init = {
  77. 44100, /* Default Sampling Frequency [Hz]. */
  78. 100 /* Default Volume. */
  79. };
  80.  
  81. /* Sound Terminal Component. */
  82. STA350BW *sound_terminal;
  83.  
  84. /* Thread to manage I2S peripherals. */
  85. static rtos::Thread i2s_bh_daemon;
  86.  
  87. /* Threads. */
  88. Thread *play_stop_thread;
  89.  
  90. /* User button handling. */
  91. InterruptIn event(USER_BUTTON);
  92.  
  93.  
  94. /* Functions -----------------------------------------------------------------*/
  95.  
  96. /**
  97. * @brief User button handler function.
  98. * @param None.
  99. * @retval None.
  100. */
  101. void pressed(void)
  102. {
  103. /* Signal to play/stop handler thread. */
  104. play_stop_thread->signal_set(PLAY_STOP_EVENT);
  105. }
  106.  
  107. /**
  108. * @brief Play/stop handler function.
  109. * @param None.
  110. * @retval None.
  111. */
  112. /*void play_stop_handler(void)
  113. {
  114. while (true)
  115. {
  116. static bool stop = true;
  117.  
  118. // Waiting for play/stop events.
  119. play_stop_thread->signal_wait(PLAY_STOP_EVENT);
  120.  
  121. if (stop)
  122. sound_terminal->stop();
  123. else
  124. sound_terminal->play((int16_t *) valori, (uint16_t) sizeof(valori), true);
  125. printf("--> %s\r\n", stop ? "Stop." : "Playing...");
  126.  
  127. stop = !stop;
  128. }
  129. }*/
  130.  
  131.  
  132.  
  133. /**
  134. * @brief Entry point function of mbedOS.
  135. * @param None
  136. * @retval None
  137. */
  138. int main(void)
  139. {
  140.  
  141. SDFileSystem sd(D11, D12, D13, D10, "sd");
  142. sd.mount();
  143.  
  144. /*----- Initialization. -----*/
  145. printf("TP1\r\n");
  146. //if (!msd.connect()) {
  147. // error("USB Flash drive not found.\n");
  148. // }
  149. printf("TP2\r\n");
  150.  
  151. /*----- Initialization. -----*/
  152.  
  153. /* Initializing I2C bus. */
  154. DevI2C *dev_i2c = new DevI2C(PB_9, PB_8);
  155.  
  156. /* Initializing Sound Terminal Component. */
  157. #ifndef USE_I2S2
  158. sound_terminal = new STA350BW(PA_10, STA350BW_ADDRESS_1, *dev_i2c, PB_15, PB_13, PB_12, NC, PC_6);
  159. #else
  160. sound_terminal = new STA350BW(PA_10, STA350BW_ADDRESS_2, *dev_i2c, PC_12, PC_10, PA_4, NC, PC_7);
  161. #endif
  162. if (sound_terminal->init(&init) != COMPONENT_OK) {
  163. error("Initialization of the Sound Terminal Expansion Board failed.\r\n");
  164. exit(EXIT_FAILURE);
  165. }
  166.  
  167. /* Starting a thread to manage I2S peripherals. */
  168. Callback<void()> i2s_bh_task(&I2S::i2s_bh_queue, &events::EventQueue::dispatch_forever);
  169. i2s_bh_daemon.start(i2s_bh_task);
  170.  
  171. /* Scheduling the play/stop function. */
  172. // play_stop_thread = new Thread();
  173. // osStatus status = play_stop_thread->start(play_stop_handler);
  174. //if (status != osOK)
  175. // printf("Could not start the play/stop handler thread.\r\n");
  176. //event.fall(&pressed);
  177.  
  178. /* Setting Sound Terminal Component's parameters. */
  179. sound_terminal->set_frequency(44100);
  180. sound_terminal->set_volume(STA350BW_CHANNEL_MASTER, MAX_VOLUME);
  181.  
  182. /* Printing to the console. */
  183. printf("Sound Terminal Application Example\r\n\n");
  184.  
  185.  
  186. FILE *fp = fopen("/sd/sdtest.txt", "r");
  187.  
  188. while(1)
  189. {
  190. //wait(0.5);
  191. //c=(c+2);
  192. //b=(b+4);
  193.  
  194.  
  195. // pc.printf("Val=%i\n\r",fp);
  196.  
  197.  
  198. //for(int k=0; k<c; k++)
  199. //{
  200. for(int i=0; i<(buffer_size); i++)
  201. {
  202. fread(&valori1[i],1,1,fp);
  203. // valori1[i+1]=valori1[i];
  204. }
  205. /* for(int i=0; i<(buffer_size); i++)
  206. {
  207. valori2[i] = valori1[i];
  208. }
  209. */
  210. //printf("v1%d\r\n",valori1);
  211. //}
  212.  
  213. /* fine1=true;
  214. printf("b%d\r\n",b);
  215. for (int x=0; x<b; x++) {
  216. for(int f=0; f<buffer_size; f++)
  217. {
  218. fread(&valori2[2*f],2,1,fp);
  219. valori2[2*f+1]=valori2[2*f];
  220. }
  221. printf("v2%d\r\n",valori2);
  222. }
  223. fine2=true;*/
  224.  
  225.  
  226.  
  227. /*----- Playing. -----*/
  228.  
  229. /* Printing to the console. */
  230. // printf("--> Playing...\r\n");
  231.  
  232. //wait(0.10);
  233. // if(fine1==true) {
  234. //sound_terminal->play((int16_t *) valori1, (uint16_t) sizeof(valori1), true);
  235. for(int i=0; i<(buffer_size); i++)
  236. {
  237. pc.printf("Val= %d\n\r",valori1[i]);
  238. wait(0.125);
  239. }
  240. // wait(0.10);
  241. //fine1=false;
  242. //}
  243. /*if(fine2==true) {
  244. sound_terminal->play((int16_t *) valori2, (uint16_t) sizeof(valori2), true);
  245. fine2=false;
  246. }*/
  247. }
  248. fclose(fp);
  249. //sd.unmount();
  250. }
  251. #else // DEVICE_I2S
  252.  
  253. int main(void)
  254. {
  255. printf("The target does not support I2S API.\r\n");
  256. }
  257.  
  258. #endif // DEVICE_I2S
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement