ReSpeaker Switch V02

Dependencies:   mbed MbedJSONValue

Revision:
5:cca17ebe4a1f
Parent:
4:7c08791dcac1
Child:
6:696bf69e99d2
--- a/main.cpp	Mon Feb 19 10:23:59 2018 +0000
+++ b/main.cpp	Sun Apr 08 14:03:17 2018 +0000
@@ -16,6 +16,12 @@
 
 */
 
+/* 
+    Bugs:
+    PA_14 and PA_13 are share with stlink - not available as interrupt pins
+    Used in polling mode instead
+
+*/
 /*
    Board : Nucleo STM32F446RE
    Power Source : USB || Jumper 5V source from STM32 DSP board
@@ -26,6 +32,10 @@
     to use PH_0(MUX_S2) as IO modify boards as followed:
     SB54 and SB55 ON
     SB16 and SB50 (MCO) OFF
+
+    For use GPIO PC15 , PC14
+    SB48 and SB49 ON
+    R34 and R36 removed
     http://www.st.com/content/ccc/resource/technical/document/user_manual/98/2e/fa/4b/e0/82/43/b7/DM00105823.pdf/files/DM00105823.pdf/jcr:content/translations/en.DM00105823.pdf
 */
 
@@ -97,6 +107,7 @@
 //#define DEBUG_MOD2   // json parse
 //#define DEBUG_MOD3   // switch handler
 #define DEBUG_MOD4   // serial with dsp module
+#define DEBUG_MOD5   // Microphone interrupt debug
 #define DEBUG_MOD10   // responsivity msges to gui
 
 #define MSG_BUFFER_SIZE 512
@@ -136,11 +147,11 @@
 DigitalOut en_spk_5(PB_13);
 
 // MIC interrupts
-DigitalOut inter_1(PC_15);
-DigitalOut inter_2(PC_14);
-DigitalOut inter_3(PA_15);
-DigitalOut inter_4(PA_14);
-DigitalOut inter_5(PA_13);
+DigitalIn inter_1(PC_15 , PullDown);
+DigitalIn inter_2(PC_14 , PullDown);
+DigitalIn inter_3(PA_15 , PullDown);
+DigitalIn inter_4(PA_14 , PullDown);
+DigitalIn inter_5(PA_13 , PullDown);
 
 // analog input
 AnalogIn a_data_1(PA_0);
@@ -155,6 +166,9 @@
 // analog input from microphone
 uint16_t micAData[5]= {0};
 
+// mic interrupt flag
+int micInterrupt = 0;
+
 // json buffer
 char json[MSG_BUFFER_SIZE];
 
@@ -176,6 +190,27 @@
 // Functions //
 ///////////////
 
+// mic interrupt functions
+void micInt_1()
+{
+    micInterrupt = 1;
+}
+void micInt_2()
+{
+    micInterrupt = 2;
+}
+void micInt_3()
+{
+    micInterrupt = 3;
+}
+void micInt_4()
+{
+    micInterrupt = 4;
+}
+void micInt_5()
+{
+    micInterrupt = 5;
+}
 // Serial Event function
 void rxCallback(void);
 
@@ -205,10 +240,10 @@
     dsp.baud(57600);
     // attach serial event interrupt
     pc.attach(&rxCallback, Serial::RxIrq);
-    
+
     // attach serial event interrupt
     dsp.attach(&rxDspCallback, Serial::RxIrq);
-    
+
     // initialize switch
     initSwitch();
 #ifdef DEBUG_MOD1
@@ -217,8 +252,8 @@
     ///////////////////////
     //  Main Code Loop : //
     ///////////////////////
-    while(0) { // does nothing. everything is currently in the callbacks
-        if(1) {
+    while(1) { // does nothing. everything is currently in the callbacks
+        if(0) { // no analog data to read (not implemented yet
             micAData[0] = a_data_1.read_u16();
             micAData[1] = a_data_2.read_u16();
             micAData[2] = a_data_3.read_u16();
@@ -227,6 +262,22 @@
             pc.printf("Data:%d,%d,%d,%d,%d\r\n",micAData[0],micAData[1],micAData[2],micAData[3],micAData[4]);
             wait(1);
         }
+        // change to interrupt - Problematic as PA_14 and PA_13 are share with stlink
+        if (1) { // polling on digital input from micrphones for automatic mic selection
+            if (inter_1.read()) micInterrupt=1;
+            if (inter_2.read()) micInterrupt=2;
+            if (inter_3.read()) micInterrupt=3;
+            if (inter_4.read()) micInterrupt=4;
+            if (inter_5.read()) micInterrupt=5;
+        }
+        // mic interrupts
+        if (micInterrupt > 0 ) {
+            pc.printf("IntMic: %d \r\n",micInterrupt);
+            // led blink
+            led = !led;
+            wait(0.1);
+            micInterrupt=0;
+        }
 
     }// end main loop
 }// end main
@@ -239,6 +290,13 @@
 {
     // attach serial event interrupt
     pc.attach(&rxCallback, Serial::RxIrq);
+
+    // attach mic interrupts
+    //inter_1.rise(&micInt_1);
+    //inter_2.rise(&micInt_2);
+    //inter_3.rise(&micInt_3);
+    //inter_4.rise(&micInt_4);
+    //inter_5.rise(&micInt_5);
     // reset output / input
     mux_s0.write(0);
     mux_s1.write(0);