Maxim Integrated / LP_Receiver_Wakeup

Dependencies:   MAX30208 mbed-dev max32630fthr USBDevice

Revision:
0:41ed595f83f5
Child:
1:8834bc22c2e7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jan 09 19:10:44 2018 +0000
@@ -0,0 +1,102 @@
+#include "mbed.h"
+#include "max32630fthr.h"
+#include "USBSerial.h"
+#include "mxc_config.h"
+#include "lp.h"
+#include "gpio.h"
+
+MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
+
+DigitalOut rLED(LED1);
+DigitalOut gLED(LED2);
+DigitalOut bLED(LED3);
+
+DigitalIn sw1(SW1);
+
+gpio_cfg_t gpioLP0;
+
+#define LP0_WAKE_GPIO_PORT  2
+#define LP0_WAKE_GPIO_PIN   PIN_3
+
+// *****************************************************************************
+void Wakeup_blinks()
+{
+    int numBlinks = 3;
+
+    bLED = LED_OFF;
+    gLED = LED_OFF;
+    
+    while(numBlinks) {
+        rLED = LED_ON;
+        wait_ms(167);
+        rLED = LED_OFF;
+        wait_ms(167);
+
+        numBlinks--;
+    }
+    
+}
+
+// *****************************************************************************
+void Powerdown_blinks()
+{
+    gLED = LED_OFF;
+    
+    int numBlinks = 3;
+
+    while(numBlinks) {
+        bLED = LED_ON;
+        wait_ms(167);
+        bLED = LED_OFF;
+        wait_ms(167);
+
+        numBlinks--;
+    }
+    
+}
+
+/******************************************************************************/
+int main(void)
+{
+    //check if starting at main because of LP0 wake-up
+    if(LP_IsLP0WakeUp())
+        Wakeup_blinks();        //blinks red LED 3 times
+    else {
+        //We did not wake up from sleep and this is first power-on
+
+    }
+
+    //initialize LEDs
+    gLED = LED_ON;
+    bLED = LED_OFF;
+    rLED = LED_OFF;
+    
+    //use the gpio_cfg_t type to control GPIO operation with built-in Maxim library functions
+    gpioLP0.port = LP0_WAKE_GPIO_PORT;
+    gpioLP0.mask = LP0_WAKE_GPIO_PIN;
+    gpioLP0.func = GPIO_FUNC_GPIO;
+    gpioLP0.pad = GPIO_PAD_INPUT_PULLUP;
+    GPIO_Config(&gpioLP0);
+
+    while(1) {
+        //Wait for user to push sw1 to enter LP0
+        if(sw1 == 0)
+        {
+            Powerdown_blinks();     //blinks blue LED 3 times
+
+            //Clear existing wake-up config
+            LP_ClearWakeUpConfig();
+
+            //Clear any event flags
+            LP_ClearWakeUpFlags();
+
+            //configure wake-up on GPIO
+            LP_ConfigGPIOWakeUpDetect(&gpioLP0, 0, LP_WEAK_PULL_UP);
+
+            //interrupts are disabled in LP_EnterLP0
+            LP_EnterLP0();
+
+            //firmware will reset with no prior knowledge on wake-up
+        }
+    }
+}