X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=firmware%2Fgpio.c;fp=firmware%2Fgpio.c;h=2ee32109d754360434afc6ec0ed3d5c3a8269592;hb=f956c1fa7f47b0e8b8afe323c2eff1b6c2607c2a;hp=0000000000000000000000000000000000000000;hpb=f7cba12a75f10da7267c2e4d4488bb5ccddbb9d9;p=bike-lights.git diff --git a/firmware/gpio.c b/firmware/gpio.c new file mode 100644 index 0000000..2ee3210 --- /dev/null +++ b/firmware/gpio.c @@ -0,0 +1,27 @@ +#include + +#include "lights.h" + +void gpio_init() +{ + DDRB |= _BV(PB2) | _BV(PB4); + PORTB &=~ (_BV(PB2) | _BV(PB4)); + + gpio_set(GPIO_LED2, 1); +} + +void gpio_set(unsigned char n, unsigned char on) +{ + unsigned char bits = 0; + switch(n) { + case GPIO_LED1: bits = _BV(PB4); break; + case GPIO_LED2: bits = _BV(PB2); break; + } + + if (on) { + PORTB |= bits; + } else { + PORTB &= ~bits; + } +} +