f303k8 wav player

Dependencies:   SDFileSystem mbed

Revision:
0:1561c4efda0e
Child:
1:7a3f34b2d18b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jul 31 12:13:36 2016 +0000
@@ -0,0 +1,81 @@
+#include "mbed.h"
+#include <stdio.h>
+#include "SDFileSystem.h"
+#include "stm32f3xx_hal_rcc.h"
+#include "cmsis_nvic.h"
+#include "wavPlayer.h"
+
+static void MX_TIM6_Init(void);
+static void MX_NVIC_Init(void);
+void TIM6_IRQHandler(void);
+TIM_HandleTypeDef htim6;
+Ticker flipper;
+FATFS FatFs;
+wavPlayerOnDAC wavPlayer(PA_4);
+//AnalogOut DACout(PA_4);
+
+SDFileSystem sd(PB_5, PB_4, PB_3, PA_11, "sd"); // the pinout on the mbed Cool Components workshop board
+DigitalOut pin(PA_12);
+DigitalOut pin2(PB_0);
+DigitalIn button(PA_0,PullDown);
+BusIn DipSW(PA_10,PA_9,PA_12,PB_0);
+
+
+void TIM6_IRQHandler() {
+    __HAL_TIM_CLEAR_IT(&htim6 , TIM_FLAG_UPDATE);
+    wavPlayer.DACOutProc();
+}
+
+
+static void MX_NVIC_Init(void)
+{
+    /* TIM6_DAC1_IRQn interrupt configuration */
+    HAL_NVIC_SetPriority(TIM6_DAC1_IRQn, 0, 0);
+    HAL_NVIC_EnableIRQ(TIM6_DAC1_IRQn);
+}
+/* TIM6 init function */
+static void MX_TIM6_Init(void)
+{
+    __TIM6_CLK_ENABLE();
+    htim6.Instance = TIM6;
+    htim6.Init.Prescaler = 1;
+    htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
+    htim6.Init.Period = 1451;
+    if (HAL_TIM_Base_Init(&htim6) != HAL_OK) {
+        while(1) {
+        }
+    }
+    HAL_TIM_Base_Start_IT(&htim6);
+}
+
+
+int main(void)
+{
+    FRESULT wavFileResult;
+    FIL     fil;
+    int     i,j;
+    
+    MX_TIM6_Init();
+    NVIC_SetVector(TIM6_DAC1_IRQn, (uint32_t)&TIM6_IRQHandler);
+    MX_NVIC_Init();
+    
+    DipSW.mode(PullDown);
+    
+    f_mount(&FatFs,"",0);
+    wavFileResult = f_open(&fil, "LondonCalling.wav", FA_READ);
+    printf("error:%d\r\n",(int)wavFileResult);
+    wavPlayer.setFile(&fil);
+    printf("buff ok\r\n");
+    while(button == 1)
+    {
+    }
+    printf("start\r\n");
+    while(1) {
+
+        if(wavPlayer.readProc() == 1)
+        {
+            printf("END\r\n");
+            wavPlayer.rewind();
+        }
+    }
+}
\ No newline at end of file