Rev 2039 | Rev 2598 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2039 | Rev 2099 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009-2014 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2009-2015 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
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 "main.h" |
21 | #include "main.h" |
22 | #include <avr/io.h> |
22 | #include <avr/io.h> |
23 | #include <avr/interrupt.h> |
23 | #include <avr/interrupt.h> |
24 | #include "ppm.h" |
24 | #include "ppm.h" |
25 | #include "max7456_software_spi.h" // clearing |
25 | #include "max7456_software_spi.h" // clearing |
26 | 26 | ||
27 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
27 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
28 | 28 | ||
29 | volatile uint16_t old_timer1 = 0, ppm = 0; |
29 | volatile uint16_t old_timer1 = 0, ppm = 0; |
30 | 30 | ||
31 | /** |
31 | /** |
32 | * init ppm, including timer1 for measurement |
32 | * init ppm, including timer1 for measurement |
33 | */ |
33 | */ |
34 | void ppm_init() { |
34 | void ppm_init() { |
35 | PORTE |= (1 << PORTE0); // enable pullup on INT0 pin |
35 | PORTE |= (1 << PORTE0); // enable pullup on INT0 pin |
36 | GICR |= (1 << INT2); // External Interrupt Request 2 Enable |
36 | GICR |= (1 << INT2); // External Interrupt Request 2 Enable |
37 | EMCUCR |= (1 << ISC2); // a rising edge on INT2 activates the interrupt |
37 | EMCUCR |= (1 << ISC2); // a rising edge on INT2 activates the interrupt |
38 | TCCR1B |= (0 << CS12) | (1 << CS10) | (1 << CS11); // timer1 up with prescaler 64 |
38 | TCCR1B |= (0 << CS12) | (1 << CS10) | (1 << CS11); // timer1 up with prescaler 64 |
39 | } |
39 | } |
40 | 40 | ||
41 | /** |
41 | /** |
42 | * Handle INT2 interrupts that occur on changing edges of ppm signal |
42 | * Handle INT2 interrupts that occur on changing edges of ppm signal |
43 | */ |
43 | */ |
44 | ISR(INT2_vect) { |
44 | ISR(INT2_vect) { |
45 | // since the pin might get bogus reads we wait for 123 signals |
45 | // since the pin might get bogus reads we wait for 123 signals |
46 | static uint8_t valid_ppm_to_go = 123; |
46 | static uint8_t valid_ppm_to_go = 123; |
47 | if (EMCUCR & (1 << ISC2)) { // rising |
47 | if (EMCUCR & (1 << ISC2)) { // rising |
48 | old_timer1 = TCNT1; |
48 | old_timer1 = TCNT1; |
49 | EMCUCR &= ~(1 << ISC2); // next one is falling |
49 | EMCUCR &= ~(1 << ISC2); // next one is falling |
50 | } else { |
50 | } else { |
51 | if (valid_ppm_to_go) { |
51 | if (valid_ppm_to_go) { |
52 | valid_ppm_to_go--; |
52 | valid_ppm_to_go--; |
53 | } else { |
53 | } else { |
54 | if (TCNT1 > old_timer1 + 256) { |
54 | if (TCNT1 > old_timer1 + 256) { |
55 | ppm = TCNT1 - old_timer1; |
55 | ppm = TCNT1 - old_timer1; |
56 | ppm -= 256; |
56 | ppm -= 256; |
57 | } else { |
57 | } else { |
58 | ppm = 0; |
58 | ppm = 0; |
59 | } |
59 | } |
60 | if (ppm < 128) { // we want HUD |
60 | if (ppm < 128) { // we want HUD |
61 | if (!(COSD_FLAGS_MODES & COSD_FLAG_HUD)) { |
61 | if (!(COSD_FLAGS_MODES & COSD_FLAG_HUD)) { |
62 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
62 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
63 | } |
63 | } |
64 | COSD_FLAGS_MODES |= COSD_FLAG_HUD; |
64 | COSD_FLAGS_MODES |= COSD_FLAG_HUD; |
65 | } else { // we do not want hud |
65 | } else { // we do not want hud |
66 | COSD_FLAGS_MODES &= ~COSD_FLAG_HUD; |
66 | COSD_FLAGS_MODES &= ~COSD_FLAG_HUD; |
67 | } |
67 | } |
68 | } |
68 | } |
69 | EMCUCR |= (1 << ISC2); // next one is rising |
69 | EMCUCR |= (1 << ISC2); // next one is rising |
70 | } |
70 | } |
71 | //write_ndigit_number_u(2, 6, valid_ppm_to_go, 100, 0); // debug |
71 | //write_ndigit_number_u(2, 6, valid_ppm_to_go, 100, 0); // debug |
72 | //write_ndigit_number_u(2, 7, COSD_FLAGS_CONFIG, 100, 0); // debug |
72 | //write_ndigit_number_u(2, 7, COSD_FLAGS_CONFIG, 100, 0); // debug |
73 | //PORTC ^= (1 << PC3); // LED4_TOGGLE // debug |
73 | //PORTC ^= (1 << PC3); // LED4_TOGGLE // debug |
74 | //uptime = ppm; |
74 | //uptime = ppm; |
75 | } |
75 | } |
76 | 76 | ||
77 | #endif |
77 | #endif |
78 | 78 |