]> www.fi.muni.cz Git - bike-lights.git/blobdiff - firmware/gpio.c
gpio: suspend function, status poweroff led
[bike-lights.git] / firmware / gpio.c
index 2ee32109d754360434afc6ec0ed3d5c3a8269592..d2a240b4e31fd4a3690ba4b69ace130b5dd83538 100644 (file)
@@ -4,24 +4,46 @@
 
 void gpio_init()
 {
-       DDRB |= _BV(PB2) | _BV(PB4);
-       PORTB &=~ (_BV(PB2) | _BV(PB4));
+       DDRB |=    _BV(PB0) | _BV(PB2);     // LED4, LED5
+       PORTB &=~ (_BV(PB0) | _BV(PB2));
 
-       gpio_set(GPIO_LED2, 1);
+       DDRA |=    _BV(PA3) | _BV(PA4);     // LED6, LED7
+       PORTA &=~ (_BV(PA3) | _BV(PA4));
+
+       gpio_set(1, 1);
 }
 
-void gpio_set(unsigned char n, unsigned char on)
+void susp_gpio()
 {
-       unsigned char bits = 0;
-       switch(n) {
-       case GPIO_LED1: bits = _BV(PB4); break;
-       case GPIO_LED2: bits = _BV(PB2); break;
-       }
+       DDRB &=  ~(_BV(PB0) | _BV(PB2));     // LED4, LED5
+       PORTB &=~ (_BV(PB0) | _BV(PB2));
+
+       DDRA &=  ~(_BV(PA3) | _BV(PA4));     // LED6, LED7
+       PORTA &=~ (_BV(PA3) | _BV(PA4));
+}
 
+void gpio_before_poweroff()
+{
+       DDRA |= _BV(PA4);
+       PORTA |= _BV(PA4);
+}
+
+void gpio_set(unsigned char n, unsigned char on)
+{
        if (on) {
-               PORTB |= bits;
+               switch(n) {
+               case 0: PORTB |= _BV(PB0); break;
+               case 1: PORTB |= _BV(PB2); break;
+               case 2: PORTA |= _BV(PA3); break;
+               case 3: PORTA |= _BV(PA4); break;
+               }
        } else {
-               PORTB &= ~bits;
+               switch(n) {
+               case 0: PORTB &= ~_BV(PB0); break;
+               case 1: PORTB &= ~_BV(PB2); break;
+               case 2: PORTA &= ~_BV(PA3); break;
+               case 3: PORTA &= ~_BV(PA4); break;
+               }
        }
 }