BayEOSArduino Library
BayEOS-Arduino
libraries
Sleep
Sleep.h
1
/*
2
Sleep.h - Arduino Sleep library
3
Copyright (c) arms22<arms22 at gmail.com>. All right reserved.
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
*/
12
13
#ifndef Sleep_h
14
#define Sleep_h
15
16
#include <avr/sleep.h>
17
#include <avr/power.h>
18
#include <avr/interrupt.h>
19
20
21
#ifndef cbi
22
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
23
#endif
24
#ifndef sbi
25
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
26
#endif
27
28
#include <inttypes.h>
29
#include <avr/wdt.h>
30
31
#define TIMER0_ON 1
32
#define TIMER1_ON 2
33
#define TIMER2_ON 4
34
#define TWI_ON 8
35
#define SPI_ON 16
36
#define USART0_ON 32
37
38
class
SleepClass
39
{
40
public
:
41
/*
42
* 0-9:
43
SLEEP_15Ms,
44
SLEEP_30MS,
45
SLEEP_60MS,
46
SLEEP_120MS,
47
SLEEP_250MS,
48
SLEEP_500MS,
49
SLEEP_1S,
50
SLEEP_2S,
51
SLEEP_4S,
52
SLEEP_8S,
53
*/
54
static
void
setupWatchdog(
int
ii=6);
55
56
/*
57
* NEED a RTC crystal!
58
*
59
* CS22 CS21 CS20 DESCRIPTION
60
* 0 0 0 Timer/Counter2 Disabled
61
* 0 0 1 No Prescaling 1 -> 0,0078125sec
62
* 0 1 0 Clock / 8 2 > 0,0625sec
63
* 0 1 1 Clock / 32 3 -> 0,25sec
64
* 1 0 0 Clock / 64 4 -> 0,5sec
65
* 1 0 1 Clock / 128 5 -> 1sec
66
* 1 1 0 Clock / 256 6 -> 2sec
67
* 1 1 1 Clock / 1024 7 ->8sec
68
*/
69
static
void
setupTimer2(
int
ii=5);
70
71
72
static
void
sleep(uint8_t modules=0,uint8_t sm=SLEEP_MODE_PWR_DOWN);
73
};
74
75
extern
SleepClass
Sleep;
76
77
78
#endif
SleepClass
Definition:
Sleep.h:39
Generated by
1.9.1