ReSpeaker DSP V02

Dependencies:   mbed MbedJSONValue

Revision:
13:c0a13a99905e
Parent:
12:9d30df1529be
--- a/main.cpp	Tue Aug 28 08:20:15 2018 +0000
+++ b/main.cpp	Sat Jun 08 11:02:34 2019 +0000
@@ -1,6 +1,6 @@
 ////////////////////////////////////////
-//      Tau_ReSpeaker_DSP V01         //
-//  Arkadiraf@gmail.com - 26/08/2018  //
+//      Tau_ReSpeaker_DSP V02         //
+//  Arkadiraf@gmail.com - 08/06/2019  //
 ////////////////////////////////////////
 /*
  Json Format: json:{"name":"dsp","mode":"off"}\r\n
@@ -10,7 +10,7 @@
 
 /*
    Board : Nucleo STM32F446RE
-   Power Source : USB
+   Power Source : DC-DC 5V Regulator E5V Jumper
 */
 
 /*
@@ -23,10 +23,6 @@
     PC_10 (Tx) --> SW_Rx
     PC_11 (Rx) --> SW_Tx
 
-    I2C_Bus
-    PB_8 --> SCL
-    PB_9 --> SDA
-
     Digital output
     PA_5 --> led (DigitalOut)
     PA_10 --> DSP_Trigger
@@ -49,7 +45,7 @@
 ///////////////
 #include "mbed.h"
 #include "MbedJSONValue.h"
-
+#include "chirp.h"
 ///////////////
 // #defines  //
 ///////////////
@@ -176,6 +172,9 @@
 // DSP Filter Packet Handler
 void dspFilterPacket(void);
 
+// DSP Play Packet Handler
+void dspPlayPacket(void);
+
 // initialize DSP
 void initDSP(void);
 
@@ -219,9 +218,8 @@
         } else if (operationMode == 3) {
             highpassTrig();
         } else if (operationMode == 4) {
-            GainsTrig();
+            GainsTrig();    
         }
-        //highpass_filter();
         // more elegant but much slower option:
         //FilterFunction();
 #ifdef TOGGLE_IO_MODE
@@ -258,7 +256,7 @@
     Dac_Reg += __HAL_DHR12R1_ALIGNEMENT(DAC_ALIGN_12B_R);
 
     // intialize filter function pointer
-    FilterFunction = passthrough;//highpass_filter;
+    FilterFunction = offMode;//highpass_filter;
     operationMode = 0 ;
 }
 
@@ -404,6 +402,8 @@
         dspParamPacket();
     } else if (targetName == "dspFilter") {
         dspFilterPacket();
+    } else if (targetName == "dspPlay") {
+        dspPlayPacket();
     } else {
 #ifdef DEBUG_MOD2
         // unrecognised target
@@ -414,6 +414,7 @@
     led = !led;
 }// end parse
 
+            
 // DSP Packet Handler
 void dspPacket(void)
 {
@@ -491,4 +492,47 @@
 #endif
     // succesfull parse
     switch_dsp.printf("{\"Ack\":\"dspFilter\",\"FilterSections\":%d,\"Gscale\":%.3f}\r\n", FilterSections , Gscale);
-} // end dspFilterPacket
\ No newline at end of file
+} // end dspFilterPacket
+
+// DSP Play Packet Handler
+void dspPlayPacket(void)
+{
+    // get values.
+    float playGain      = ((float)guiCmd["gain"].get<int>())/1000; // issue in parsing doubles when the number is round
+    uint32_t playFile       = (uint32_t)guiCmd["file"].get<int>(); // file to play
+
+    // succesfull parse
+    switch_dsp.printf("{\"Ack\":\"dspPlay\",\"file\":%d,\"gain\":%.3f}\r\n", playFile, playGain);
+            //////////////////////////////////////////////////////////////////
+            // Temp mode - need to update file selection ,  gain settings   //
+            //////////////////////////////////////////////////////////////////
+            __disable_irq();    // Disable Interrupts
+            // generate chirp out
+            for (int ii=0; ii<NUM_SAMPLES; ii++) {
+                // toogle io for loop frequency
+                toggelState=!toggelState;
+                mytoggle.write(toggelState);
+                // generate delay for 1MHz Sample rate
+                for (int jj=0; jj<31; jj++) {
+                    NOP();
+                }
+                // micro nops :)
+                NOP();
+                NOP();
+                NOP();
+                NOP();
+                NOP();
+                NOP();
+                NOP();
+                // Output value using DAC
+                // HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, ADCValueOut);
+                *(__IO uint32_t *) Dac_Reg = chirpData[ii];
+            }
+            // Output value using DAC
+            // HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, ADCValueOut);
+            *(__IO uint32_t *) Dac_Reg = (uint16_t)(4095/2);
+            __enable_irq();     // Enable Interrupts
+            
+            // Option to reset play mode after file has been played
+            //operationMode = 0;
+} // end dspPlayPacket