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:
58:15aa7a785b9f
Parent:
57:bdac7dd17af2
Child:
59:485545afc4dc
--- a/xDotBridge/src/BaseboardIO.cpp	Tue Feb 28 09:26:27 2017 -0700
+++ b/xDotBridge/src/BaseboardIO.cpp	Wed Mar 01 17:28:32 2017 -0700
@@ -8,6 +8,7 @@
 #include "BaseboardIO.h"
 #include "MTSLog.h"
 #include "dot_util.h" // FIXME just need the reference to dot somehow
+#include "xdot_low_power.h"
 
 const float COIL_ON_TIME = 0.030; // 30 ms
 
@@ -39,13 +40,12 @@
  */
 
 BaseboardIO::BaseboardIO()
-    : mOWMaster(I2C_SDA),
-      mCCIn(WAKE), // Interrupt pin PA_0
-      mTamper(GPIO1), // Interrupt pin PA_5
-      mPairBtn(UART_CTS), // Interrupt pin PA_11
-//      mLed(SWDIO),
-      mLed(GPIO0),
-      mSwitchedIOCtrl(I2C_SCL, 0)
+    : mOWMaster(OneWireMasterPinName),
+      mCCIn(CCInPinName),
+      mTamper(TamperPinName),
+      mPairBtn(PairBtnPinName),
+      mLed(LedPinName),
+      mSwitchedIOCtrl(SwitchedIOCtrlPinName, 0)
 {
     mPortExpanderVal0 = 0x00;
     mPortExpanderVal1 = 0x00;
@@ -159,7 +159,7 @@
 void BaseboardIO::regPairBtnInt(Callback<void()> func)
 {
     // Pulled low, switched high
-    mPairBtn.mode(PullDown);
+    mPairBtn.mode(PullNone);
     mPairBtn.rise(func);
     mPairBtn.enable_irq();
 }
@@ -509,6 +509,100 @@
     return cmdSuccess;
 }
 
+CmdResult BaseboardIO::prepareSleep()
+{
+	// Save current GPUIO state
+    xdot_save_gpio_state();
+
+    // Configure all IO expect for pins for interrupt in lowest mode possible
+    // GPIO Ports Clock Enable
+    __GPIOA_CLK_ENABLE();
+    __GPIOB_CLK_ENABLE();
+    __GPIOC_CLK_ENABLE();
+    __GPIOH_CLK_ENABLE();
+
+    GPIO_InitTypeDef GPIO_InitStruct;
+
+    // UART1_TX, UART1_RTS & UART1_CTS to analog nopull - RX could be a wakeup source
+    // UART1_TX, UART1_RTS & UART1_CTS to analog nopull - RX could be a wakeup source
+//    GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_11 | GPIO_PIN_12;
+    GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_12;
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+    // I2C_SDA & I2C_SCL to analog nopull
+    GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9;
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+    // SPI_MOSI, SPI_MISO, SPI_SCK, & SPI_NSS to analog nopull
+    GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+    // iterate through potential wake pins - leave the configured wake pin alone if one is needed
+    if ((CCInPinName != WAKE && TamperPinName != WAKE && PairBtnPinName != WAKE)
+            || dot->getWakeMode() == mDot::RTC_ALARM) {
+        GPIO_InitStruct.Pin = GPIO_PIN_0;
+        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+        GPIO_InitStruct.Pull = GPIO_NOPULL;
+        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+    }
+    if ((CCInPinName != GPIO0 && TamperPinName != GPIO0 && PairBtnPinName != GPIO0)
+            || dot->getWakeMode() == mDot::RTC_ALARM) {
+        GPIO_InitStruct.Pin = GPIO_PIN_4;
+        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+        GPIO_InitStruct.Pull = GPIO_NOPULL;
+        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+    }
+    if ((CCInPinName != GPIO1 && TamperPinName != GPIO1 && PairBtnPinName != GPIO1)
+            || dot->getWakeMode() == mDot::RTC_ALARM) {
+        GPIO_InitStruct.Pin = GPIO_PIN_5;
+        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+        GPIO_InitStruct.Pull = GPIO_NOPULL;
+        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+    }
+    if ((CCInPinName != GPIO2 && TamperPinName != GPIO2 && PairBtnPinName != GPIO2)
+            || dot->getWakeMode() == mDot::RTC_ALARM) {
+        GPIO_InitStruct.Pin = GPIO_PIN_0;
+        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+        GPIO_InitStruct.Pull = GPIO_NOPULL;
+        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+    }
+    if ((CCInPinName != GPIO3 && TamperPinName != GPIO3 && PairBtnPinName != GPIO3)
+            || dot->getWakeMode() == mDot::RTC_ALARM) {
+        GPIO_InitStruct.Pin = GPIO_PIN_2;
+        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+        GPIO_InitStruct.Pull = GPIO_NOPULL;
+        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+    }
+    if ((CCInPinName != UART1_RX && TamperPinName != UART1_RX && PairBtnPinName != UART1_RX)
+            || dot->getWakeMode() == mDot::RTC_ALARM) {
+        GPIO_InitStruct.Pin = GPIO_PIN_10;
+        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+        GPIO_InitStruct.Pull = GPIO_NOPULL;
+        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+    }
+    if ((CCInPinName != UART_CTS && TamperPinName != UART_CTS && PairBtnPinName != UART_CTS)
+            || dot->getWakeMode() == mDot::RTC_ALARM) {
+        GPIO_InitStruct.Pin = GPIO_PIN_11;
+        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+        GPIO_InitStruct.Pull = GPIO_NOPULL;
+        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+    }
+
+    return cmdSuccess;
+}
+
+CmdResult BaseboardIO::exitSleep()
+{
+    xdot_restore_gpio_state();
+    return cmdSuccess;
+}
+
 // NvmBBIOObj
 NvmBBIOObj::NvmBBIOObj()
 {