COSA
An Object-Oriented Platform for Arduino Programming
Power.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_POWER_HH
22 #define COSA_POWER_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/Bits.h"
26 #include <avr/power.h>
27 
31 class Power {
32 public:
40  static uint8_t set(uint8_t mode)
41  __attribute__((always_inline))
42  {
43  uint8_t res = s_mode;
44  s_mode = mode;
45  return (res);
46  }
47 
53  static void sleep(uint8_t mode = POWER_SLEEP_MODE);
54 
55  static void adc_enable()
56  __attribute__((always_inline))
57  {
58  power_adc_enable();
59  bit_set(ADCSRA, ADEN);
60  }
61 
62  static void adc_disable()
63  __attribute__((always_inline))
64  {
65  bit_clear(ADCSRA, ADEN);
66  power_adc_disable();
67  }
68 
69  static void timer0_enable()
70  __attribute__((always_inline))
71  {
72  power_timer0_enable();
73  }
74 
75  static void timer0_disable()
76  __attribute__((always_inline))
77  {
78  power_timer0_disable();
79  }
80 
81  static void timer1_enable()
82  __attribute__((always_inline))
83  {
84  power_timer1_enable();
85  }
86 
87  static void timer1_disable()
88  __attribute__((always_inline))
89  {
90  power_timer1_disable();
91  }
92 
93 #if defined(power_timer2_enable)
94  static void timer2_enable()
95  __attribute__((always_inline))
96  {
97  power_timer2_enable();
98  }
99 
100  static void timer2_disable()
101  __attribute__((always_inline))
102  {
103  power_timer2_disable();
104  }
105 #endif
106 
107 #if defined(power_timer3_enable)
108  static void timer3_enable()
109  __attribute__((always_inline))
110  {
111  power_timer3_enable();
112  }
113 
114  static void timer3_disable()
115  __attribute__((always_inline))
116  {
117  power_timer3_disable();
118  }
119 #endif
120 
121 #if defined(power_timer4_enable)
122  static void timer4_enable()
123  __attribute__((always_inline))
124  {
125  power_timer4_enable();
126  }
127 
128  static void timer4_disable()
129  __attribute__((always_inline))
130  {
131  power_timer4_disable();
132  }
133 #endif
134 
135 #if defined(power_timer5_enable)
136  __attribute__((always_inline))
137  static void timer5_enable()
138  {
139  power_timer5_enable();
140  }
141 
142  static void timer5_disable()
143  __attribute__((always_inline))
144  {
145  power_timer5_disable();
146  }
147 #endif
148 
149 #if defined(power_usart0_enable)
150  static void usart0_enable()
151  __attribute__((always_inline))
152  {
153  power_usart0_enable();
154  }
155 
156  static void usart0_disable()
157  __attribute__((always_inline))
158  {
159  power_usart0_disable();
160  }
161 #endif
162 
163 #if defined(power_usart1_enable)
164  static void usart1_enable()
165  __attribute__((always_inline))
166  {
167  power_usart1_enable();
168  }
169 
170  static void usart1_disable()
171  __attribute__((always_inline))
172  {
173  power_usart1_disable();
174  }
175 #endif
176 
177 #if defined(power_usart2_enable)
178  static void usart2_enable()
179  __attribute__((always_inline))
180  {
181  power_usart2_enable();
182  }
183 
184  static void usart2_disable()
185  __attribute__((always_inline))
186  {
187  power_usart2_disable();
188  }
189 #endif
190 
191 #if defined(power_usart3_enable)
192  static void usart3_enable()
193  __attribute__((always_inline))
194  {
195  power_usart3_enable();
196  }
197 
198  static void usart3_disable()
199  __attribute__((always_inline))
200  {
201  power_usart3_disable();
202  }
203 #endif
204 
205 #if defined(power_usb_enable)
206  static void usb_enable()
207  __attribute__((always_inline))
208  {
209  power_usb_enable();
210  }
211 
212  static void usb_disable()
213  __attribute__((always_inline))
214  {
215  power_usb_disable();
216  }
217 #endif
218 
219 #if defined(power_usi_enable)
220  static void usi_enable()
221  __attribute__((always_inline))
222  {
223  power_usi_enable();
224  }
225 
226  static void usi_disable()
227  __attribute__((always_inline))
228  {
229  power_usi_disable();
230  }
231 #endif
232 
233 #if defined(power_spi_enable)
234  static void spi_enable()
235  __attribute__((always_inline))
236  {
237  power_spi_enable();
238  }
239 
240  static void spi_disable()
241  __attribute__((always_inline))
242  {
243  power_spi_disable();
244  }
245 #endif
246 
247 #if defined(power_twi_enable)
248  static void twi_enable()
249  __attribute__((always_inline))
250  {
251  power_twi_enable();
252  }
253 
254  static void twi_disable()
255  __attribute__((always_inline))
256  {
257  power_twi_disable();
258  }
259 #endif
260 
261  static void all_enable()
262  __attribute__((always_inline))
263  {
264  power_all_enable();
265  bit_set(ADCSRA, ADEN);
266  }
267 
268  static void all_disable()
269  __attribute__((always_inline))
270  {
271  bit_clear(ADCSRA, ADEN);
272  power_all_disable();
273  }
274 
275 private:
279  Power() {}
280 
282  static const uint8_t POWER_SLEEP_MODE = 0xff;
283 
285  static uint8_t s_mode;
286 };
287 
288 #endif
static void timer1_disable()
Definition: Power.hh:87
#define bit_set(p, b)
Definition: Bits.h:35
Definition: Power.hh:31
#define bit_clear(p, b)
Definition: Bits.h:36
static void all_disable()
Definition: Power.hh:268
static void sleep(uint8_t mode=POWER_SLEEP_MODE)
Definition: Power.cpp:30
static void timer0_disable()
Definition: Power.hh:75
static void adc_disable()
Definition: Power.hh:62
static void all_enable()
Definition: Power.hh:261
static void adc_enable()
Definition: Power.hh:55
static void timer1_enable()
Definition: Power.hh:81
static void timer0_enable()
Definition: Power.hh:69