generated from macoy/gamelib-project-template
6 changed files with 115 additions and 2 deletions
@ -0,0 +1,22 @@ |
|||
# http://releases.llvm.org/6.0.0/tools/clang/docs/ClangFormatStyleOptions.html |
|||
BasedOnStyle: Google |
|||
AccessModifierOffset: -4 |
|||
AllowShortBlocksOnASingleLine: false |
|||
AllowShortFunctionsOnASingleLine: None |
|||
AllowShortIfStatementsOnASingleLine: false |
|||
AllowShortLoopsOnASingleLine: false |
|||
BreakBeforeBraces: Allman |
|||
BraceWrapping: |
|||
AfterNamespace: false |
|||
BreakBeforeTernaryOperators: false |
|||
ColumnLimit: 100 |
|||
ConstructorInitializerIndentWidth: 4 |
|||
ContinuationIndentWidth: 4 |
|||
IndentWidth: 4 |
|||
Standard: Cpp11 |
|||
TabWidth: 4 |
|||
UseTab: ForIndentation |
|||
DerivePointerAlignment: false |
|||
PointerAlignment: Left |
|||
NamespaceIndentation: None |
|||
IndentCaseLabels: true |
@ -0,0 +1,58 @@ |
|||
// Partially copied from https://github.com/rocketscream/Low-Power
|
|||
#include "LowPower.h" |
|||
|
|||
#include <avr/interrupt.h> |
|||
#include <avr/power.h> |
|||
#include <avr/sleep.h> |
|||
#include <avr/wdt.h> |
|||
|
|||
// Only Pico Power devices can change BOD settings through software
|
|||
#define sleep_bod_disable() \ |
|||
do \ |
|||
{ \ |
|||
unsigned char tempreg; \ |
|||
__asm__ __volatile__( \ |
|||
"in %[tempreg], %[mcucr]" \ |
|||
"\n\t" \ |
|||
"ori %[tempreg], %[bods_bodse]" \ |
|||
"\n\t" \ |
|||
"out %[mcucr], %[tempreg]" \ |
|||
"\n\t" \ |
|||
"andi %[tempreg], %[not_bodse]" \ |
|||
"\n\t" \ |
|||
"out %[mcucr], %[tempreg]" \ |
|||
: [ tempreg ] "=&d"(tempreg) \ |
|||
: [ mcucr ] "I" _SFR_IO_ADDR(MCUCR), [ bods_bodse ] "i"(_BV(BODS) | _BV(BODSE)), \ |
|||
[ not_bodse ] "i"(~_BV(BODSE))); \ |
|||
} while (0) |
|||
|
|||
// Only Pico Power devices can change BOD settings through software
|
|||
#define lowPowerBodOff(mode) \ |
|||
do \ |
|||
{ \ |
|||
set_sleep_mode(mode); \ |
|||
cli(); \ |
|||
sleep_enable(); \ |
|||
sleep_bod_disable(); \ |
|||
sei(); \ |
|||
sleep_cpu(); \ |
|||
sleep_disable(); \ |
|||
sei(); \ |
|||
} while (0); |
|||
|
|||
ISR(WDT_vect) |
|||
{ |
|||
// WDIE & WDIF is cleared in hardware upon entering this ISR
|
|||
wdt_disable(); |
|||
} |
|||
|
|||
// the loop function runs over and over again forever
|
|||
void startLowPowerSleep(period_t period) |
|||
{ |
|||
// These are disabled from here on out!
|
|||
ADCSRA &= ~(1 << ADEN); |
|||
wdt_enable(period); |
|||
WDTCSR |= (1 << WDIE); |
|||
lowPowerBodOff(SLEEP_MODE_PWR_DOWN); |
|||
// end low sleep here
|
|||
} |
@ -0,0 +1,17 @@ |
|||
#ifndef LOWPOWER_H |
|||
#define LOWPOWER_H |
|||
typedef enum period_t { |
|||
SLEEP_15MS, |
|||
SLEEP_30MS, |
|||
SLEEP_60MS, |
|||
SLEEP_120MS, |
|||
SLEEP_250MS, |
|||
SLEEP_500MS, |
|||
SLEEP_1S, |
|||
SLEEP_2S, |
|||
SLEEP_4S, |
|||
SLEEP_8S, |
|||
SLEEP_FOREVER |
|||
} period_t; |
|||
void startLowPowerSleep(period_t period); |
|||
#endif |
Loading…
Reference in new issue