Rev 1199 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1199 | Rev 1437 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2011 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2011-2012 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/ * |
5 | * * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License. * |
8 | * the Free Software Foundation; either version 2 of the License. * |
9 | * * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
14 | * * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ****************************************************************************/ |
19 | ****************************************************************************/ |
20 | 20 | ||
21 | #include "buttons.h" |
21 | #include "buttons.h" |
22 | 22 | ||
23 | volatile uint8_t BUTTONS; |
23 | volatile uint8_t BUTTONS; |
24 | 24 | ||
25 | void buttons_init() { |
25 | void buttons_init() { |
26 | DDRD &= ~((1 << PD4) | (1 << PD5)); // switches are input |
26 | DDRD &= ~((1 << PD4) | (1 << PD5)); // switches are input |
27 | PORTD |= ((1 << PD4) | (1 << PD5)); // pullups for switches |
27 | PORTD |= ((1 << PD4) | (1 << PD5)); // pullups for switches |
28 | 28 | ||
29 | // unmask pin change interrupts 28 and 29 |
29 | // unmask pin change interrupts 28 and 29 |
30 | PCMSK3 |= ((1 << PCINT28) | (1 << PCINT29)); |
30 | PCMSK3 |= ((1 << PCINT28) | (1 << PCINT29)); |
31 | 31 | ||
32 | // enable PCINT31..24 |
32 | // enable PCINT31..24 |
33 | PCICR |= (1 << PCIE3); |
33 | PCICR |= (1 << PCIE3); |
34 | } |
34 | } |
35 | 35 | ||
36 | ISR(PCINT3_vect) { |
36 | ISR(PCINT3_vect) { |
37 | uint8_t raw = PIND; // for different buttons |
37 | uint8_t raw = PIND; // for different buttons |
38 | // mode |
38 | // mode |
39 | if (!(raw & (1 << MODE))) { |
39 | if (!(raw & (1 << MODE))) { |
40 | BUTTONS |= (1 << MODE); |
40 | BUTTONS |= (1 << MODE); |
41 | } |
41 | } |
42 | // set |
42 | // set |
43 | if (!(raw & (1 << SET))) { |
43 | if (!(raw & (1 << SET))) { |
44 | BUTTONS |= (1 << SET); |
44 | BUTTONS |= (1 << SET); |
45 | } |
45 | } |
46 | } |
46 | } |
47 | 47 | ||
48 | uint8_t mode_pressed() { |
48 | uint8_t mode_pressed() { |
49 | if (BUTTONS & (1 << MODE)) { |
49 | if (BUTTONS & (1 << MODE)) { |
50 | BUTTONS &= ~(1 << MODE); |
50 | BUTTONS &= ~(1 << MODE); |
51 | CEPILEPSYFLAGS |= CEPI_DIRTYEEPROM; |
51 | CEPILEPSYFLAGS |= CEPI_DIRTYEEPROM; |
52 | return 1; |
52 | return 1; |
53 | } |
53 | } |
54 | return 0; |
54 | return 0; |
55 | } |
55 | } |
56 | 56 | ||
57 | uint8_t set_pressed() { |
57 | uint8_t set_pressed() { |
58 | if (BUTTONS & (1 << SET)) { |
58 | if (BUTTONS & (1 << SET)) { |
59 | BUTTONS &= ~(1 << SET); |
59 | BUTTONS &= ~(1 << SET); |
60 | CEPILEPSYFLAGS |= CEPI_DIRTYEEPROM; |
60 | CEPILEPSYFLAGS |= CEPI_DIRTYEEPROM; |
61 | return 1; |
61 | return 1; |
62 | } |
62 | } |
63 | return 0; |
63 | return 0; |
64 | } |
64 | } |
65 | 65 |