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