]> www.fi.muni.cz Git - bike-lights.git/commitdiff
gpio.c: gpio leds and other tools
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 28 Aug 2012 14:04:35 +0000 (16:04 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 28 Aug 2012 14:58:23 +0000 (16:58 +0200)
Makefile
gpio.c [new file with mode: 0644]
lights.h
main.c

index 989bffbd60e46e740416fc9e7a0292828ecf0f43..c2e1d6a89a54d2d9351acdc662f475af9f760130 100644 (file)
--- 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 (file)
index 0000000..e0f58b9
--- /dev/null
+++ b/gpio.c
@@ -0,0 +1,25 @@
+#include <avr/io.h>
+
+#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;
+       }
+}
+
index d6e0cbd71c8a9a63c513e7c86784fb2dd482022d..6619be73b66ff4181116473d155e1bf40bcae8d6 100644 (file)
--- 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 324b8849bb10666f0a7d1993770c388e5a83b361..fe906e51424643cefd6bf108ce804a334370557d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -15,6 +15,7 @@ int main(void)
        init_tmr();
 
        pwmled_init();
+       gpio_init();
 
        log_set_state(3);