ReSpeaker Test Code

Dependencies:   MbedJSONValue mbed

Files at this revision

API Documentation at this revision

Comitter:
Arkadi
Date:
Mon Feb 19 10:23:59 2018 +0000
Parent:
3:9c3169e549f0
Child:
5:cca17ebe4a1f
Commit message:
Added uart forwarding to dsp module

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Feb 04 16:14:03 2018 +0000
+++ b/main.cpp	Mon Feb 19 10:23:59 2018 +0000
@@ -96,6 +96,7 @@
 //#define DEBUG_MOD1  // json packet recognise
 //#define DEBUG_MOD2   // json parse
 //#define DEBUG_MOD3   // switch handler
+#define DEBUG_MOD4   // serial with dsp module
 #define DEBUG_MOD10   // responsivity msges to gui
 
 #define MSG_BUFFER_SIZE 512
@@ -111,6 +112,9 @@
 // uart
 Serial pc(USBTX, USBRX);
 
+// uart switch_dsp
+Serial dsp(PC_10, PC_11);
+
 // digital input
 DigitalIn user_button(PC_13);
 
@@ -175,6 +179,9 @@
 // Serial Event function
 void rxCallback(void);
 
+// serial event from DSP
+void rxDspCallback(void);
+
 // initialize packet struct
 void initPacket(void);
 
@@ -195,9 +202,13 @@
     initPacket();
     // init uart
     pc.baud(57600);
+    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
@@ -206,7 +217,7 @@
     ///////////////////////
     //  Main Code Loop : //
     ///////////////////////
-    while(0) {
+    while(0) { // does nothing. everything is currently in the callbacks
         if(1) {
             micAData[0] = a_data_1.read_u16();
             micAData[1] = a_data_2.read_u16();
@@ -240,6 +251,16 @@
     en_spk_5.write(0);
 }// end init switch
 
+// serial event from DSP
+void rxDspCallback(void)
+{
+    while (dsp.readable()) {
+        uint8_t in_byte = dsp.getc();
+#ifdef DEBUG_MOD4
+        pc.putc(in_byte);
+#endif
+    }
+} // end rxDspCallback
 
 // Serial Event function
 void rxCallback(void)
@@ -375,7 +396,10 @@
         switchPacket();
     } else if (targetName == "dsp") {
         // send msg to dsp
+        dsp.printf("json:%s", json);
+#ifdef DEBUG_MOD2
         pc.printf("json:%s", json);
+#endif
     } else {
 #ifdef DEBUG_MOD2
         // unrecognised target
@@ -398,10 +422,10 @@
     for (int ii=0 ; ii < 5 ; ii++) {
         spkChannle[ii] = guiCmd["spk"][ii].get<bool>();
     }
-#ifdef DEBUG_MOD10    
+#ifdef DEBUG_MOD10
     // send parsed values
     pc.printf("mic: %d , spk: [%d,%d,%d,%d,%d]\r\n", micChannle,spkChannle[0],spkChannle[1],spkChannle[2],spkChannle[3],spkChannle[4]);
-#endif    
+#endif
     // update hardware
     // update mic select mux
     uint8_t micByte = (uint8_t) micChannle;