]> www.fi.muni.cz Git - bike-lights.git/blob - firmware/gpio.c
2ee32109d754360434afc6ec0ed3d5c3a8269592
[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(PB2) | _BV(PB4);
8         PORTB &=~ (_BV(PB2) | _BV(PB4));
9
10         gpio_set(GPIO_LED2, 1);
11 }
12
13 void gpio_set(unsigned char n, unsigned char on)
14 {
15         unsigned char bits = 0;
16         switch(n) {
17         case GPIO_LED1: bits = _BV(PB4); break;
18         case GPIO_LED2: bits = _BV(PB2); break;
19         }
20
21         if (on) {
22                 PORTB |= bits;
23         } else {
24                 PORTB &= ~bits;
25         }
26 }
27