X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=firmware%2Fgpio.c;h=d2a240b4e31fd4a3690ba4b69ace130b5dd83538;hb=a06ea914a745c95ca286ea41337ff5bbf3d02cbd;hp=2ee32109d754360434afc6ec0ed3d5c3a8269592;hpb=f956c1fa7f47b0e8b8afe323c2eff1b6c2607c2a;p=bike-lights.git diff --git a/firmware/gpio.c b/firmware/gpio.c index 2ee3210..d2a240b 100644 --- a/firmware/gpio.c +++ b/firmware/gpio.c @@ -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; + } } }