Subversion Repositories Projects

Rev

Rev 1199 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1199 - 1
/****************************************************************************
1437 - 2
 *   Copyright (C) 2011-2012 by Claas Anders "CaScAdE" Rathje               *
1199 - 3
 *   admiralcascade@gmail.com                                               *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/                 *
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
 
21
#include "main.h"
22
 
23
uint8_t main_mode = 0;
24
volatile uint8_t CEPILEPSYFLAGS = 0;
25
 
26
const uint8_t COLORS [][6] = {
27
    { 0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b10101010}, // color one
28
    { 0b01010101, 0b01010101, 0b01010101, 0b01010101, 0b01010101, 0b01010101}, // color one
29
    { 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111} // both colors
30
};
31
 
32
void pin_init(void) {
33
#if HWVERSION == EPI10AQ41
34
    DDRB |= (1 << PB1) | (1 << PB2); // LEDs output
35
    DDRD |= ((1 << PD6)); // S6 output, unused for now
36
#elif HWVERSION == EPI10
37
    DDRD |= (1 << PD7) | (1 << PD3); // LEDs output
38
#else
39
    // hardware 1.1
40
    DDRD |= (1 << PD7); // dual led port output
41
#endif  
42
}
43
 
44
 
45
// random init
46
 
47
unsigned short get_seed(void) {
48
    unsigned short seed = 0;
49
    unsigned short *p = (unsigned short*)(RAMEND + 1);
50
    extern unsigned short __heap_start;
51
 
52
    while (p >= &__heap_start + 1)
53
        seed ^= *(--p);
54
 
55
    return seed;
56
}
57
 
58
/* ##########################################################################
59
 * MAIN
60
 * ##########################################################################*/
61
int main(void) {
62
 
63
    LEDRED_ON // boot
64
 
65
    clear();
66
 
67
 
68
 
69
    pin_init();
70
    led_out_init();
71
    timer0_init();
72
    timer1_init();
73
    usart0_init();
74
#ifdef __AVR_ATmega644P__
75
    //usart1_init();
76
#endif
77
    buttons_init();
78
    load_eeprom();
79
 
80
 
81
    // enable interrupts
82
    sei();
83
 
84
 
85
    unsigned short seed = get_seed();
86
    srand(seed);
87
 
88
 
89
    // selftest
90
    //while (1) {
91
    /*for (uint8_t times = 0; times < 5; times++) {
92
        for (uint8_t i = 0; i < 48; i++) {
93
            setLed(animation, i, 1);
94
            _delay_ms(100);
95
            animation[i] = 0;
96
        }
97
    }*/
98
    //}
99
 
100
    LEDRED_OFF // finished boot
101
    LEDGREEN_ON
102
 
103
 
104
        // clear serial screen
105
        //usart0_puts("\x1B[2J\x1B[H");
106
        /*usart0_puts_pgm(PSTR("C-Epilepsy came to say hello...\r\n"));
107
        usart0_puts_pgm(PSTR("\tVersion: "));
108
        usart0_puts_pgm(PSTR(BUILDDATE));
109
        #ifdef __AVR_ATmega644P__
110
            usart0_puts_pgm(PSTR(" atmega644p"));
111
        #endif
112
        usart0_puts_pgm(PSTR("\r\n"));*/
113
 
114
 
115
    while (1) {
116
        switch (main_mode) {
117
            case 0:
118
                player();
119
                break;
120
            case 1:
121
                nc_handler();
122
                break;
123
        }
124
 
125
        if (mode_pressed()) {
126
            main_mode = (main_mode + 1) % 2; // % number of modes available
127
            blinkNumer(animation, main_mode + 1, 5);
128
        }
129
 
130
    }
131
 
132
    return 0;
133
}