ReSpeaker DSP V02

Dependencies:   mbed MbedJSONValue

Revision:
8:8a3e6241c104
Parent:
7:25c81cb23e42
Child:
9:7e20c1e5a354
--- a/main.cpp	Mon Aug 06 12:30:23 2018 +0000
+++ b/main.cpp	Wed Aug 22 12:57:13 2018 +0000
@@ -82,9 +82,9 @@
 
 // digital
 DigitalIn user_button(PC_13);
-DigitalIn sw_trigger(PA_10);
-DigitalOut led(PA_5);
-DigitalOut mytoggle(PA_6);
+DigitalIn sw_trigger(PA_10);// D2
+DigitalOut led(PA_5);       // D13
+DigitalOut mytoggle(PA_6);  // D12
 
 // analog / define to init at mbed initialization. work directly with registers
 AnalogOut dsp_output(PA_4);
@@ -120,7 +120,7 @@
 __IO uint32_t Dac_Reg = 0;
 
 // analog input
-uint16_t adc_in=0;
+//uint16_t adc_in=0;
 
 // toogle pin state
 bool toggelState=0;
@@ -139,11 +139,18 @@
 
 
 // Trigger mode variables
-float trigTresh = 0.75; // threshold for trigger mode
-uint32_t trigDelaySet = 3000; // counter for pulse pass
+float signalGain = 1.0; // Signal Gain
+float trigTresh = 0.5; // threshold for trigger mode
+uint32_t trigDelaySet = 5000; // counter for pulse pass
 uint32_t trigDelay = trigDelaySet; // counter for pulse pass
-uint32_t trigPause = 5000; // pause after trigger in microseconds
+uint32_t trigPause = 10; // pause after trigger in microseconds
 
+// Buffer mode variables
+uint32_t bufferSizeSet = 5000;
+uint32_t bufferSize = bufferSizeSet;
+uint32_t preBufferSizeSet = 1000;
+uint32_t bufferCountDown = bufferSizeSet - preBufferSizeSet;
+float bufferADC[5000] = {0};
 ///////////////
 // Functions //
 ///////////////
@@ -170,6 +177,9 @@
 // DSP Packet Handler
 void dspPacket(void);
 
+// DSP Param Packet Handler
+void dspParamPacket(void);
+
 // initialize DSP
 void initDSP(void);
 
@@ -387,6 +397,8 @@
     // select handler based on target mcu
     if (targetName == "dsp") {
         dspPacket();
+    } else if (targetName == "dspParam") {
+        dspParamPacket();
     } else {
 #ifdef DEBUG_MOD2
         // unrecognised target
@@ -407,7 +419,7 @@
 #ifdef DEBUG_MOD10
     // send parsed values
     pc.printf("mode: %s\r\n", modeType.c_str());
-    switch_dsp.printf("mode: %s\r\n", modeType.c_str());
+    //switch_dsp.printf("mode: %s\r\n", modeType.c_str());
 #endif
     // selected operation mode
     if ( modeType == "off" ) {
@@ -416,13 +428,13 @@
     } else if( modeType == "passthrough" ) {
         FilterFunction = passthrough;
         operationMode = 1 ;
-    }else if( modeType == "highpass" ) {
+    } else if( modeType == "highpass" ) {
         FilterFunction = highpass;
         operationMode = 2 ;
-    }else if( modeType == "hpf_trig" ) {
+    } else if( modeType == "hpf_trig" ) {
         FilterFunction = highpassTrig;
         operationMode = 3 ;
-    }else if( modeType == "gain_trig" ) {
+    } else if( modeType == "gain_trig" ) {
         FilterFunction = GainsTrig;
         operationMode = 4 ;
     } else {
@@ -431,4 +443,20 @@
         operationMode = 0 ;
     }
 
-}// end dspPacket
\ No newline at end of file
+}// end dspPacket
+// DSP Param Packet Handler
+void dspParamPacket(void)
+{ 
+    // get values.
+    signalGain      = ((float)guiCmd["gain"].get<int>())/1000; // issue in parsing doubles when the number is round
+    trigTresh       = ((float)guiCmd["trigTresh"].get<int>()) / 100.0f;
+    trigDelaySet    = (uint32_t)guiCmd["trigPass"].get<int>();
+    trigPause       = (uint32_t)guiCmd["trigPause"].get<int>();
+
+    trigDelay = trigDelaySet;
+#ifdef DEBUG_MOD10
+    // send parsed values
+    pc.printf("SignalGain: %f , trigTresh: %f , trigDelaySet %d , trigPause: %d\r\n", signalGain , trigTresh , trigDelaySet , trigPause);
+#endif
+
+} // end dspParamPacket
\ No newline at end of file