]> www.fi.muni.cz Git - bike-lights.git/blob - firmware/gpio.c
mudflap for dual rearlights
[bike-lights.git] / firmware / gpio.c
1 #include <avr/io.h>
2
3 #include "lights.h"
4
5 void gpio_init()
6 {
7         DDRB |=    _BV(PB0) | _BV(PB2);     // LED4, LED5
8         PORTB &=~ (_BV(PB0) | _BV(PB2));
9
10         DDRA |=    _BV(PA3) | _BV(PA4);     // LED6, LED7
11         PORTA &=~ (_BV(PA3) | _BV(PA4));
12
13         gpio_set(1, 1);
14 }
15
16 void susp_gpio()
17 {
18         DDRB &=  ~(_BV(PB0) | _BV(PB2));     // LED4, LED5
19         PORTB &=~ (_BV(PB0) | _BV(PB2));
20
21         DDRA &=  ~(_BV(PA3) | _BV(PA4));     // LED6, LED7
22         PORTA &=~ (_BV(PA3) | _BV(PA4));
23 }
24
25 void gpio_before_poweroff()
26 {
27         DDRA |= _BV(PA4);
28         PORTA |= _BV(PA4);
29 }
30
31 void gpio_set(unsigned char n, unsigned char on)
32 {
33         if (on) {
34                 switch(n) {
35                 case 0: PORTB |= _BV(PB0); break;
36                 case 1: PORTB |= _BV(PB2); break;
37                 case 2: PORTA |= _BV(PA3); break;
38                 case 3: PORTA |= _BV(PA4); break;
39                 }
40         } else {
41                 switch(n) {
42                 case 0: PORTB &= ~_BV(PB0); break;
43                 case 1: PORTB &= ~_BV(PB2); break;
44                 case 2: PORTA &= ~_BV(PA3); break;
45                 case 3: PORTA &= ~_BV(PA4); break;
46                 }
47         }
48 }
49