-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathled.c
More file actions
42 lines (31 loc) · 650 Bytes
/
led.c
File metadata and controls
42 lines (31 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <avr/interrupt.h>
#include "led.h"
#include "config.h"
#ifdef HAS_LED
ISR(TIMER1_COMPA_vect) {
led_toggle();
}
inline void led_init() {
LED_DDR |= (1 << LED_PIN);
led_on();
// One second time to blink LED
OCR1A = (F_CPU / 1024) - 1;
TCCR1B |= (1 << WGM12) | (1 << CS10) | (1 << CS12);
TIMSK1 = (1 << OCIE1A);
}
inline void led_on() {
LED_PORT |= (1 << LED_PIN);
}
inline void led_off() {
LED_PORT &= ~(1 << LED_PIN);
}
inline void led_toggle() {
LED_PORT ^= (1 << LED_PIN);
}
#else
// no LED support
inline void led_init() {}
inline void led_on() {}
inline void led_off() {}
inline void led_toggle() {}
#endif