Subversion Repositories Projects

Rev

Rev 2099 | Rev 2598 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
477 cascade 1
/****************************************************************************
2225 - 2
 *   Copyright (C) 2009-2016 by Claas Anders "CaScAdE" Rathje               *
477 cascade 3
 *   admiralcascade@gmail.com                                               *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
5
 *                                                                          *
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   *
8
 *   the Free Software Foundation; either version 2 of the License.         *
9
 *                                                                          *
10
 *   This program is distributed in the hope that it will be useful,        *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
13
 *   GNU General Public License for more details.                           *
14
 *                                                                          *
15
 *   You should have received a copy of the GNU General Public License      *
16
 *   along with this program; if not, write to the                          *
17
 *   Free Software Foundation, Inc.,                                        *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
19
 ****************************************************************************/
20
 
800 - 21
#include "main.h"
477 cascade 22
#include <avr/io.h>
23
#include <avr/interrupt.h>
24
#include "ppm.h"
25
#include "max7456_software_spi.h" // clearing
26
 
514 cascade 27
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
28
 
477 cascade 29
volatile uint16_t old_timer1 = 0, ppm = 0;
30
 
31
/**
32
 * init ppm, including timer1 for measurement
33
 */
34
void ppm_init() {
761 - 35
    PORTE |= (1 << PORTE0); // enable pullup on INT0 pin
36
    GICR |= (1 << INT2); // External Interrupt Request 2 Enable
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
477 cascade 39
}
40
 
41
/**
42
 * Handle INT2 interrupts that occur on changing edges of ppm signal
43
 */
44
ISR(INT2_vect) {
761 - 45
    // since the pin might get bogus reads we wait for 123 signals
46
    static uint8_t valid_ppm_to_go = 123;
47
    if (EMCUCR & (1 << ISC2)) { // rising
48
        old_timer1 = TCNT1;
49
        EMCUCR &= ~(1 << ISC2); // next one is falling
50
    } else {
51
        if (valid_ppm_to_go) {
52
            valid_ppm_to_go--;
53
        } else {
1951 - 54
                        if (TCNT1 > old_timer1 + 256) {
55
                ppm = TCNT1 - old_timer1;
56
                ppm -= 256;
57
                        } else {
58
                                ppm = 0;
59
                        }
761 - 60
            if (ppm < 128) { // we want HUD
61
                if (!(COSD_FLAGS_MODES & COSD_FLAG_HUD)) {
62
                    COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
63
                }
64
                COSD_FLAGS_MODES |= COSD_FLAG_HUD;
65
            } else { // we do not want hud
66
                COSD_FLAGS_MODES &= ~COSD_FLAG_HUD;
67
            }
68
        }
69
        EMCUCR |= (1 << ISC2); // next one is rising
70
    }
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
1771 - 73
    //PORTC ^= (1 << PC3); // LED4_TOGGLE // debug
800 - 74
    //uptime = ppm;
477 cascade 75
}
514 cascade 76
 
77
#endif