Skip to content

Added API for nRF52 core #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions examples/PrimoDeepSleep/PrimoDeepSleep.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
a wakeup source.
The board will be reset when it wakes up from power off.
You can use wakeUpCause() function to find out what signals woke up
the board if you use more than one wakeUpBy.. function.
the board if you use enableWakeUpFrom() function more than once..

This example code is in the public domain.
*/
Expand All @@ -31,13 +31,16 @@ const int digitalPin = 10;
const int analogPin = A0;


void StmEspPM(bool sleep){
void StmWifiPM(bool sleep){
// enable USER1_BUTTON to turn STM32 off and on when pressed.
// note that when STM32 is off you cannot load any new sketch.
pinMode(USER1_BUTTON, STM32_IT);
LowPower.enableStm32Sleep();

// turn ESP8266 off or on
digitalWrite(GPIO_ESP_PW, sleep ? LOW: HIGH);
// turn WiFi off or on
if(sleep)
LowPower.powerOffWifi();
else
LowPower.powerOnWifi();
}

void setup() {
Expand All @@ -62,8 +65,8 @@ void setup() {

Serial.println("Hi all, I return to sleep");

LowPower.companionLowPowerCallback(StmEspPM);
// Send sleep command to ESP and enable USER1_BUTTON to turn STM off
LowPower.companionLowPowerCallback(StmWifiPM);
// Send sleep command to WiFi and enable USER1_BUTTON to turn STM off
LowPower.companionSleep();

//set digital pin 10 to wake up the board when LOW level is detected
Expand Down
4 changes: 4 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ companionLowPowerCallback KEYWORD2
companionSleep KEYWORD2
companionWakeup KEYWORD2
wakeupReason KEYWORD2
powerOnWifi KEYWORD2
powerOffWifi KEYWORD2
enableStm32Sleep KEYWORD2
disableStm32Standby KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down
4 changes: 4 additions & 0 deletions src/ArduinoLowPower.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class ArduinoLowPowerClass {
#ifdef ARDUINO_ARCH_NRF52
void enableWakeupFrom(wakeup_reason peripheral, uint32_t pin = 0xFF, uint32_t event = 0xFF, uint32_t option = 0xFF);
wakeup_reason wakeupReason();
void powerOnWifi(void);
void powerOffWifi(void);
void enableStm32Sleep(void);
void disableStm32Standby(void);
#endif

private:
Expand Down
20 changes: 20 additions & 0 deletions src/nrf52/ArduinoLowPower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ wakeup_reason ArduinoLowPowerClass::wakeupReason(){
return OTHER_WAKEUP;
}

void ArduinoLowPowerClass::powerOnWifi(){
//turn the WiFi on
digitalWrite(GPIO_ESP_PW, HIGH);
}

void ArduinoLowPowerClass::powerOffWifi(){
//turn the WiFi off
digitalWrite(GPIO_ESP_PW, LOW);
}

void ArduinoLowPowerClass::enableStm32Sleep(){
//setup USER1_BUTTON as an interrupt to trigger STM32 enter to sleep mode or wake up from sleep mode
pinMode(USER1_BUTTON, STM32_IT);
}

void ArduinoLowPowerClass::disableStm32Standby(){
//disable STM32 enter to standby mode
pinMode(BAT_VOL, INPUT);
}


ArduinoLowPowerClass LowPower;

Expand Down