fork of StateScript

Dependencies:   mbed SOMO_II

Fork of stateScript_v2 by Mattias Karlsson

Revision:
10:f65649c13b5b
Parent:
9:f783bce314cd
--- a/mbedInterface/mbedInterface.cpp	Wed Apr 26 16:40:36 2017 +0000
+++ b/mbedInterface/mbedInterface.cpp	Fri Apr 28 14:47:55 2017 +0000
@@ -1,8 +1,6 @@
 #include "mbedInterface.h"
 #include "mbed.h"
 
-
-
 //--------------------------------------------------------------
 //--------------------------------------------------------------
 //This section is required for all custom harware interfaces
@@ -49,9 +47,16 @@
 bool RFSyncReadable = false;
 bool RFSyncWritable = true;
 
+#ifdef LPC1768
 //Recieve clock signal from RF system
 InterruptIn RFClock(p28);
 DigitalIn RFData(p27);
+#endif
+
+#ifdef K64
+InterruptIn RFClock(PTA1);
+DigitalIn RFData(PTB9);
+#endif
 
 
 void callback_RFClock(void) {
@@ -134,61 +139,58 @@
 //---------------------------------------------------------------------
 
 //translate pin numbers to hardware pins
-//PinName dOutPins[NUMDIGOUTPORTS] = {p11,p13,p15,p18,p21,p23,p25,p29,p20,p6}; //Old board output pins
 
-//PinName dOutPins[NUMDIGOUTPORTS] = {p18,p15,p13,p11,p29,p25,p23,p21,p20}; //New board output pins
-//PinName dInPins[NUMDIGINPORTS] = {p12,p14,p16,p17,p22,p24,p26,p30,p7};
-//PinName aInPins[NUMANINPORTS] = {};
-//PinName aOutPins[NUMANOUTPORTS] = {};
-
+#ifdef LPC1768
+PinName dInPins[NUMDIGINPORTS] = {p5,p14,p16,p17,p22,p24,p26,p30};
 PinName dOutPins[NUMDIGOUTPORTS] = {p7,p15,p13,p11,p29,p25,p23,p21}; //With analog pins
-PinName dInPins[NUMDIGINPORTS] = {p12,p14,p16,p17,p22,p24,p26,p30};
 PinName aInPins[NUMANINPORTS] = {p20};
 PinName aOutPins[NUMANOUTPORTS] = {p18};
+// SOMO II sound module  http://www.4dsystems.com.au/product/SOMO_II/
+// Datasheet http://www.4dsystems.com.au/productpages/SOMO-II/downloads/SOMO-II_datasheet_R_1_2.pdf
+SOMO audio(p9,p10);        //(TX,RX)
+#endif
+
+#ifdef K64
+PinName dInPins[NUMDIGINPORTS]  =  {PTB2, PTB9, PTC10, PTA1, PTD1};
+PinName dOutPins[NUMDIGOUTPORTS] = {PTB11, PTC14, PTC11, PTC15,  PTE24, PTD4, PTC9, PTB18, PTD0};
+PinName aInPins[NUMANINPORTS] = {};
+PinName aOutPins[NUMANOUTPORTS] = {};
+
+SOMO audio(PTC17,PTC16);        //(TX,RX,Reset)
+#endif
 
 
-//The sound output uses a SmartWav device and their simple serial library
-SMARTWAV sWav(p9,p10,p19);   //(TX,RX,Reset);
-
+#ifdef LPC1768
 //This is the callback for the MBED timer
 extern "C" void TIMER0_IRQHandler (void) {
-
-    /*if (clockSlave) {
-
-        //The function is called every 100 us
-        if((LPC_TIM0->IR & 0x01) == 0x01) {  // if MR0 interrupt, proceed
-
-            LPC_TIM0->IR |= 1 << 0;         // Clear MR0 interrupt flag
-            uSec_SinceLastClockInc = uSec_SinceLastClockInc+100;
-            uSec_SinceLastReset = uSec_SinceLastReset+100;
-
-        }
-
+    //The function is called every 1 ms
+    if((LPC_TIM0->IR & 0x01) == 0x01) {  // if MR0 interrupt, proceed
+        LPC_TIM0->IR |= 1 << 0;         // Clear MR0 interrupt flag
+        timeKeeper++;
 
-    } else {*/
-        //The function is called every 1 ms
-        if((LPC_TIM0->IR & 0x01) == 0x01) {  // if MR0 interrupt, proceed
-
-            LPC_TIM0->IR |= 1 << 0;         // Clear MR0 interrupt flag
-            timeKeeper++;
-
-            if (resetTimer) {
-                timeKeeper = 0;
-                resetTimer = false;
-            }
+        if (resetTimer) {
+            timeKeeper = 0;
+            resetTimer = false;
         }
-    //}
-
+    }
 }
 //-----------------------------------------------------------------------
-
+#endif
 
 
 MBEDSystem::MBEDSystem():
+    #ifdef LPC1768
     clockResetInt(p5),
     clockExternalIncrement(p8) {
+    clockResetInt.rise(this, &MBEDSystem::externalClockReset);
 
-    clockResetInt.rise(this, &MBEDSystem::externalClockReset);
+    #endif
+    #ifdef K64
+    clockResetInt(PTD4),
+    clockExternalIncrement(PTD6) {
+    clockResetInt.rise(callback(this, &MBEDSystem::externalClockReset));
+    #endif
+
     clockResetInt.fall(&externalResetDown);
     clockResetInt.mode(PullDown);
 
@@ -218,11 +220,12 @@
 
 
 
-    sWav.reset();
+    audio.reset();
 
 }
 
 void MBEDSystem::timerinit() {
+    #ifdef LPC1768
     //intiatiation of timer (specific to the LPC17xx chip). This is used in
     //standalone mode to increment the clock every ms.
     //----------------------------------------------------
@@ -230,7 +233,7 @@
     //LPC_SC->PCLKSEL1 |= (1 << 12); //sets it to 1*SystemCoreClock - table 42 (page 57 in user manual)
     //LPC_SC->PCLKSEL0 &= (3 << 3); //mask
     //LPC_SC->PCLKSEL0 |= (1 << 3); //sets it to 1*SystemCoreClock - table 42 (page 57 in user manual)
-    LPC_SC->PCONP |=1<1;            //timer0 power on   
+    LPC_SC->PCONP |=1<1;            //timer0 power on
 
 
     LPC_TIM0->MR0 = 23980;        //1 msec
@@ -245,6 +248,7 @@
     NVIC_EnableIRQ(TIMER0_IRQn);    //enable timer0 interrupt
     LPC_TIM0->TCR = 1;              //enable Timer0
     //--------------------------------------------------------------
+    #endif
 }
 
 void MBEDSystem::pauseInterrupts() {
@@ -324,7 +328,9 @@
 
 
     if (clockSlave) {
+    #ifdef LPC1768
         LPC_TIM0->TCR = 0x02;    // reset timer
+    #endif
         externalIncrementCounter = 0;
 
         immediateClockReset();
@@ -334,7 +340,9 @@
 
 void MBEDSystem::setStandAloneClock() {
     clockSlave = false;
+#ifdef LPC1768
     NVIC_DisableIRQ(TIMER0_IRQn); // Disable the interrupt
+#endif
     timerinit(); //set up and enable interrupt
     clockExternalIncrement.rise(NULL); //remove the callback to the external interrupt
     //clockExternalIncrement.fall(NULL);
@@ -344,10 +352,14 @@
 
 void MBEDSystem::setSlaveClock() {
     clockSlave = true;
+#ifdef LPC1768
     NVIC_DisableIRQ(TIMER0_IRQn); // Disable the interrupt
-    //timerinit(); //set up and enable interrupt
     clockExternalIncrement.rise(this, &MBEDSystem::incrementClock);
-    //clockExternalIncrement.fall(&externalClockIncDown);
+#endif
+#ifdef K64
+    clockExternalIncrement.rise(callback(this, &MBEDSystem::incrementClock));
+#endif
+
     clockSlave = true;
     changeToSlave = false;
     changeToStandAlone = false;
@@ -387,20 +399,20 @@
 
 void MBEDSound::execute() {
     if (reset) {
-        sWav.reset();
+        audio.reset();
     } else if (!play) {
-        sWav.stopTrack();
+        audio.stopTrack();
     } else {
         if (volume > -1) {
-            sWav.volume(volume);
+            audio.volume(volume);
         } else if (volumePtr != NULL) {
-            sWav.volume(*volumePtr);
+            audio.volume(*volumePtr);
         }
 
         if (fileNameExists) {
-            //sWav.playTracks();
-            sWav.stopTrack();
-            sWav.playTrackName(fileName);
+            //audio.playTracks();
+            audio.stopTrack();
+            audio.playTrackName(fileName);
         }
     }
 }
@@ -501,8 +513,14 @@
         inpin_interrupt = new InterruptIn(dInPins[pin]);
         inpin->mode(PullDown);
         //Set up callbacks for the port interrupts
+    #ifdef LPC1768
         inpin_interrupt->rise(this, &MBEDDigitalIn::interrupt_up_callback);
         inpin_interrupt->fall(this, &MBEDDigitalIn::interrupt_down_callback);
+    #endif
+    #ifdef K64
+        inpin_interrupt->rise(callback(this, &MBEDDigitalIn::interrupt_up_callback));
+        inpin_interrupt->fall(callback(this, &MBEDDigitalIn::interrupt_down_callback));
+    #endif
         pinExists = true;
     }
 }