]> www.fi.muni.cz Git - bike-lights.git/blob - firmware/gpio.c
gpio leds according to new pins.txt
[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         PORTB &=~ (_BV(PA3) | _BV(PA4));
12
13         gpio_set(1, 1);
14 }
15
16 void gpio_set(unsigned char n, unsigned char on)
17 {
18         if (on) {
19                 switch(n) {
20                 case 0: PORTB |= _BV(PB0); break;
21                 case 1: PORTB |= _BV(PB2); break;
22                 case 2: PORTA |= _BV(PA3); break;
23                 case 3: PORTA |= _BV(PA4); break;
24                 }
25         } else {
26                 switch(n) {
27                 case 0: PORTB &= ~_BV(PB0); break;
28                 case 1: PORTB &= ~_BV(PB2); break;
29                 case 2: PORTA &= ~_BV(PA3); break;
30                 case 3: PORTA &= ~_BV(PA4); break;
31                 }
32         }
33 }
34