Fork to see if I can get working

Dependencies:   BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated

Fork of xDotBridge_update_test20180823 by Matt Briggs

Revision:
44:ece6330e9b57
Parent:
41:9ef4c4d77711
Child:
47:a68747642a7a
--- a/xDotBridge/src/main.cpp	Tue Jan 31 21:02:56 2017 +0000
+++ b/xDotBridge/src/main.cpp	Wed Feb 01 15:20:45 2017 -0700
@@ -3,7 +3,8 @@
 #include "xdot_flash.h"
 #include "dot_util.h"
 #include "RadioEvent.h"
-//#include <OneWire.h>
+#include "W25X40BV.h"
+#include "BaseboardIO.h"
 //#include <xdot_low_power.h>
 
 #include "CommProtocolPeerBrute.h"
@@ -12,15 +13,15 @@
 // I/O Configuration //
 ///////////////////////
 DigitalOut led1(GPIO0);
-AnalogIn an1(GPIO1);
+//AnalogIn an1(GPIO1);
 //AnalogIn an2(GPIO2);
 
 // Inputs
+InterruptIn intTest(GPIO1);  // Works.  Be careful of which pins are interrupts.
 //DigitalIn gpio3(GPIO3);
 //DigitalIn wake_DOUT(WAKE);
 //DigitalIn i2cOut1(I2C1_SCL);
 //DigitalIn i2cOut2(I2C1_SDA);
-//InterruptIn intTest(GPIO2);
 //DigitalIn uartOut1(UART1_CTS);
 //DigitalIn uartOut2(UART1_RTS);
 //DigitalIn jtag_gpio1(SWDIO);
@@ -39,15 +40,17 @@
 
 Serial pc(USBTX, USBRX);
 
-//unsigned int callbackCnt = 0;
-//
-//static void testCallback () {
-////    callbackCnt = us_ticker_read();
-//    callbackCnt++;
-//}
+unsigned int callbackCnt = 0;
+static void testCallback () {
+//    callbackCnt = us_ticker_read();
+    callbackCnt++;
+}
 
 int main() {
+    BaseboardIO bbio;
     RadioEvent events;  // Custom event handler for automatically displaying RX data
+    W25X40BV flash(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_NSS);
+//    flash.frequency(48e6); // TODO try overridding for faster freq (Default 1MHz)
 
     pc.baud(115200);
 
@@ -65,7 +68,7 @@
     dot->setLogLevel(mts::MTSLog::INFO_LEVEL);
 
     // attach the custom events handler
-//    dot->setEvents(&events);
+    dot->setEvents(&events);  // Little bonus event debug information
 
     // Setup programmable voltage detector
     // PVD_LEVEL0 Falling 1.85
@@ -86,10 +89,11 @@
 
     // TODO setup IO here
 
+    CommProtocolPeerBrute protocol; // TX
 #if BRIDGE_TX_BRUTE
-    CommProtocolPeerBrute protocol(true); // TX
+    protocol.setTx(true);
 #else
-    CommProtocolPeerBrute protocol(false); // RX
+    protocol.setTx(false);
 #endif
     protocol.init();
 
@@ -107,9 +111,9 @@
     uint16_t seqNum=0;
 
     // mbed-os Interrupt setup
-//    intTest.mode(PullUp);
-//    intTest.fall(&testCallback);
-//    intTest.enable_irq(); // TODO check if this is useful
+    intTest.mode(PullUp);
+    intTest.fall(&testCallback);
+    intTest.enable_irq(); // TODO check if this is useful
 
 //    dot->setWakePin(GPIO2); // This works but disables the wake button
 
@@ -151,55 +155,55 @@
         std::vector<uint8_t> data;
         led1=0;
 
-		if (protocol.isTx()) {
-#if LED_FEEDBACK
-            led1=1;
-#endif
-            // TODO check for CC_IN
-
-            data.push_back((seqNum >> 8) & 0xFF);
-            data.push_back(seqNum & 0xFF);
-            protocol.send(data);
-            seqNum++;
-
-#if LED_FEEDBACK
-            led1=0;
-#endif
-            sleep_save_io();
-            sleep_configure_io();
-            dot->sleep(0, mDot::INTERRUPT, false);  // Go to sleep until wake button
-            sleep_restore_io();
-		}
-
-		if (protocol.isRx()) {
-		    bool msgPending;
-		    protocol.listen(msgPending);
-		    if (msgPending) {
-		        protocol.recv(data);
-                std::string dataStr(data.begin(), data.end());
-                logInfo("Got msg num: %d, payload: %s", seqNum, dataStr.c_str());
-                // TODO add CC_OUT code here
-                seqNum++;
-#if LED_FEEDBACK
-                led1 = 1;
-                wait(0.5);
-#endif
-		    }
-            led1=0;
-            logInfo("Sleeping.  Time %d", us_ticker_read());
-            sleep_save_io();
-            sleep_configure_io();
-            // TODO maybe add if statement here to prevent double hits by sleeping for a longer time
-            dot->sleep(2, mDot::RTC_ALARM_OR_INTERRUPT, false);  // Go to sleep until wake button
-            sleep_restore_io();
-		}
+//		if (protocol.isTx()) {
+//#if LED_FEEDBACK
+//            led1=1;
+//#endif
+//            // TODO check for CC_IN
+//
+//            data.push_back((seqNum >> 8) & 0xFF);
+//            data.push_back(seqNum & 0xFF);
+//            protocol.send(data);
+//            seqNum++;
+//
+//#if LED_FEEDBACK
+//            led1=0;
+//#endif
+//            sleep_save_io();
+//            sleep_configure_io();
+//            dot->sleep(0, mDot::INTERRUPT, false);  // Go to sleep until wake button
+//            sleep_restore_io();
+//		}
+//
+//		if (protocol.isRx()) {
+//		    bool msgPending;
+//		    protocol.listen(msgPending);
+//		    if (msgPending) {
+//		        protocol.recv(data);
+//                std::string dataStr(data.begin(), data.end());
+//                logInfo("Got msg num: %d, payload: %s", seqNum, dataStr.c_str());
+//                // TODO add CC_OUT code here
+//                seqNum++;
+//#if LED_FEEDBACK
+//                led1 = 1;
+//                wait(0.5);
+//#endif
+//		    }
+//            led1=0;
+//            logInfo("Sleeping.  Time %d", us_ticker_read());
+//            sleep_save_io();
+//            sleep_configure_io();
+//            // TODO maybe add if statement here to prevent double hits by sleeping for a longer time
+//            dot->sleep(2, mDot::RTC_ALARM_OR_INTERRUPT, false);  // Go to sleep until wake button
+//            sleep_restore_io();
+//		}
 
         //////////////
         // I/O Play //
         //////////////
 
-//        // Check interrupt
-//        logInfo("Callback last called @ %d", callbackCnt);
+        // Check interrupt
+        logInfo("Callback last called @ %d", callbackCnt);
 
 //        // Check Analog
 //        logInfo("Read AN1/GPIO1: %f", an1.read());
@@ -233,8 +237,8 @@
 //		uartOut1 = !uartOut1;
 //		uartOut2 = !uartOut2;
 
-//        logInfo("================================");
-//        wait(1.0);
+        logInfo("================================");
+        wait(1.0);
 //		sleep_save_io();
 //		sleep_configure_io();
 //        __GPIOA_CLK_ENABLE();
@@ -242,8 +246,7 @@
 //        __GPIOC_CLK_ENABLE();
 //        __GPIOH_CLK_ENABLE();
 
-//        xdot_enter_stop_mode();
-//        dot->sleep(2, mDot::INTERRUPT, false);  // Go to sleep until wake button
+        dot->sleep(2, mDot::INTERRUPT, false);  // Go to sleep until wake button
         //////////////////
         // OneWire Play //
         //////////////////