Skip to content

Allow sleepings fractions of a second #23

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ Arduino library to support STM32 Low Power.

## Requirement
* [Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32) version >= 1.3.0
* [STM32RTC](https://github.com/stm32duino/STM32RTC)
* [STM32RTC](https://github.com/stm32duino/STM32RTC) version >= 1.0.4

## API

* **`void begin()`**: configure the Low Power

* **`void idle(uint32_t millis)`**: enter in idle mode
**param** millis (optional): number of milliseconds before to exit the mode. At least 1000 ms. The RTC is used in alarm mode to wakeup the chip in millis milliseconds.
**param** millis (optional): number of milliseconds before to exit the mode. The RTC is used in alarm mode to wakeup the chip in millis milliseconds.

* **`void sleep(uint32_t millis)`**: enter in sleep mode
**param** millis (optional): number of milliseconds before to exit the mode. At least 1000 ms. The RTC is used in alarm mode to wakeup the chip in millis milliseconds.
**param** millis (optional): number of milliseconds before to exit the mode. he RTC is used in alarm mode to wakeup the chip in millis milliseconds.

* **`void deepSleep(uint32_t millis)`**: enter in deepSleep mode
**param** millis (optional): number of milliseconds before to exit the mode. At least 1000 ms. The RTC is used in alarm mode to wakeup the chip in millis milliseconds.
**param** millis (optional): number of milliseconds before to exit the mode. The RTC is used in alarm mode to wakeup the chip in millis milliseconds.

* **`void shutdown(uint32_t millis)`**: enter in shutdown mode
**param** millis (optional): number of milliseconds before to exit the mode. At least 1000 ms. The RTC is used in alarm mode to wakeup the board in millis milliseconds.
**param** millis (optional): number of milliseconds before to exit the mode. The RTC is used in alarm mode to wakeup the board in millis milliseconds.

* **`void attachInterruptWakeup(uint32_t pin, voidFuncPtrVoid callback, uint32_t mode)`**: Enable GPIO pin in interrupt mode. If the pin is a wakeup pin, it is configured as wakeup source (see board documentation).
**param** pin: pin number
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=STM32duino Low Power
version=1.0.3
version=1.0.4
author=Wi6Labs
maintainer=stm32duino
sentence=Power save primitives features for STM32 boards
Expand Down
18 changes: 12 additions & 6 deletions src/STM32LowPower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,14 @@ void STM32LowPower::enableWakeupFrom(STM32RTC *rtc, voidFuncPtr callback, void *

/**
* @brief Configure the RTC alarm
* @param millis: time of the alarm in milliseconds. At least 1000ms.
* @param millis: time of the alarm in milliseconds.
* @param lp_mode: low power mode targeted.
* @retval None
*/
void STM32LowPower::programRtcWakeUp(uint32_t millis, LP_Mode lp_mode)
{
int epoc;
uint32_t epoc_ms;
uint32_t sec;
STM32RTC &rtc = STM32RTC::getInstance();
STM32RTC::Source_Clock clkSrc = rtc.getClockSource();
Expand Down Expand Up @@ -204,12 +205,17 @@ void STM32LowPower::programRtcWakeUp(uint32_t millis, LP_Mode lp_mode)
if (millis > 0) {
// Convert millisecond to second
sec = millis / 1000;
// Minimum is 1 second
if (sec == 0) {
sec = 1;
millis = millis % 1000;

epoc = rtc.getEpoch(&epoc_ms);

//Update epoch_ms - might need to add a second to epoch
epoc_ms += millis;
if (epoc_ms >= 1000) {
sec ++;
epoc_ms -= 1000;
}

epoc = rtc.getEpoch();
rtc.setAlarmEpoch(epoc + sec);
rtc.setAlarmEpoch(epoc + sec, STM32RTC::MATCH_DHHMMSS, epoc_ms);
}
}