From: Jan "Yenya" Kasprzak Date: Tue, 28 Aug 2012 14:04:35 +0000 (+0200) Subject: gpio.c: gpio leds and other tools X-Git-Tag: gedasymbols-20120913~53 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=355758d26d0bd1cfffd97b115673522e63b42820;p=bike-lights.git gpio.c: gpio leds and other tools --- diff --git a/Makefile b/Makefile index 989bffb..c2e1d6a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PROGRAM=lights -SRC=main.c logging.c adc.c pwm.c tmr.c pwmled.c +SRC=main.c logging.c adc.c pwm.c tmr.c pwmled.c gpio.c OBJ=$(SRC:.c=.o) diff --git a/gpio.c b/gpio.c new file mode 100644 index 0000000..e0f58b9 --- /dev/null +++ b/gpio.c @@ -0,0 +1,25 @@ +#include + +#include "lights.h" + +void gpio_init() +{ + DDRB |= _BV(PB2) | _BV(PB4); + PORTB &=~ (_BV(PB2) | _BV(PB4)); +} + +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; + } +} + diff --git a/lights.h b/lights.h index d6e0cbd..6619be7 100644 --- a/lights.h +++ b/lights.h @@ -40,6 +40,12 @@ void pwmled_adc(unsigned char n, uint16_t adcval); void pwmled_set_mode(unsigned char n, unsigned char mode); unsigned char pwmled_is_on(unsigned char n); +/* gpio.c */ +#define GPIO_LED1 0 +#define GPIO_LED2 1 + +void gpio_init(); +void gpio_set(unsigned char n, unsigned char on); #endif /* !LIGHTS_H__ */ diff --git a/main.c b/main.c index 324b884..fe906e5 100644 --- a/main.c +++ b/main.c @@ -15,6 +15,7 @@ int main(void) init_tmr(); pwmled_init(); + gpio_init(); log_set_state(3);