From: Jan "Yenya" Kasprzak <kas@fi.muni.cz>
Date: Sun, 11 Nov 2012 18:17:27 +0000 (+0100)
Subject: firmware: move buttons and GPIO LEDs
X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=5ea15612762e0ed843fd31734b4937c15892b546;p=bike-lights.git

firmware: move buttons and GPIO LEDs

Move buttons to PA3, PA4, and GPIO LEDs to PB0,2,4,6 (as in schematics).
---

diff --git a/firmware/buttons.c b/firmware/buttons.c
index 9a4c7e1..d0cbd51 100644
--- a/firmware/buttons.c
+++ b/firmware/buttons.c
@@ -13,8 +13,8 @@ void init_buttons()
 {
 	unsigned char i;
 
-	DDRB &= ~(_BV(PB4) | _BV(PB6));
-	PORTB |=  _BV(PB4) | _BV(PB6);
+	DDRA &= ~(_BV(PA3) | _BV(PA4));
+	PORTA |=  _BV(PA3) | _BV(PA4);
 
 	for (i=0; i < N_BUTTONS; i++) {
 		button_start[i] = 0;
@@ -23,7 +23,7 @@ void init_buttons()
 
 	just_waked_up = 1;
 
-	// log_byte(PORTB);
+	// log_byte(PORTA);
 }
 
 static void do_sleep()
@@ -34,7 +34,7 @@ static void do_sleep()
 	hw_suspend();
 	gpio_before_poweroff(); // Set the status LED on again
 
-	while((PINB & _BV(PB6)) == 0)
+	while((PINA & _BV(PA3)) == 0)
 		; // wait for button release
 
 	_delay_ms(100);
@@ -58,11 +58,11 @@ static void inline short_press(unsigned char n)
 
 void timer_check_buttons()
 {
-	unsigned char pinb = PINB;
+	unsigned char pin = PINA;
 	unsigned char i;
 	unsigned char port_states[N_BUTTONS] = {
-		pinb & _BV(PB6),
-		pinb & _BV(PB4),
+		pin & _BV(PA3),
+		pin & _BV(PA4),
 	};
 
 	for (i = 0; i < N_BUTTONS; i++) {
diff --git a/firmware/gpio.c b/firmware/gpio.c
index d2a240b..8e39bd2 100644
--- a/firmware/gpio.c
+++ b/firmware/gpio.c
@@ -4,28 +4,22 @@
 
 void gpio_init()
 {
-	DDRB |=    _BV(PB0) | _BV(PB2);     // LED4, LED5
-	PORTB &=~ (_BV(PB0) | _BV(PB2));
-
-	DDRA |=    _BV(PA3) | _BV(PA4);     // LED6, LED7
-	PORTA &=~ (_BV(PA3) | _BV(PA4));
+	DDRB |=    _BV(PB0) | _BV(PB2) | _BV(PB4) | _BV(PB6);
+	PORTB &=~ (_BV(PB0) | _BV(PB2) | _BV(PB4) | _BV(PB6));
 
 	gpio_set(1, 1);
 }
 
 void susp_gpio()
 {
-	DDRB &=  ~(_BV(PB0) | _BV(PB2));     // LED4, LED5
-	PORTB &=~ (_BV(PB0) | _BV(PB2));
-
-	DDRA &=  ~(_BV(PA3) | _BV(PA4));     // LED6, LED7
-	PORTA &=~ (_BV(PA3) | _BV(PA4));
+	DDRB  &= ~(_BV(PB0) | _BV(PB2) | _BV(PB4) | _BV(PB6));
+	PORTB &= ~(_BV(PB0) | _BV(PB2) | _BV(PB4) | _BV(PB6));
 }
 
 void gpio_before_poweroff()
 {
-	DDRA |= _BV(PA4);
-	PORTA |= _BV(PA4);
+	DDRB |= _BV(PB2);
+	PORTB |= _BV(PB2);
 }
 
 void gpio_set(unsigned char n, unsigned char on)
@@ -34,15 +28,15 @@ void gpio_set(unsigned char n, unsigned char on)
 		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;
+		case 2: PORTB |= _BV(PB4); break;
+		case 3: PORTB |= _BV(PB6); break;
 		}
 	} else {
 		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;
+		case 2: PORTB &= ~_BV(PB4); break;
+		case 3: PORTB &= ~_BV(PB6); break;
 		}
 	}
 }