Subversion Repositories Projects

Rev

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 "led_out.h"
21
#include "led_out.h"
22
 
22
 
23
#define ROWPORT PORTA
23
#define ROWPORT PORTA
24
#define COLPORT PORTC
24
#define COLPORT PORTC
25
#define COLBASE (1 << PC2)
25
#define COLBASE (1 << PC2)
26
 
26
 
27
 
27
 
28
 
28
 
29
uint8_t col = 0;
29
uint8_t col = 0;
30
uint8_t delay = 0;
30
uint8_t delay = 0;
31
 
31
 
32
uint8_t on = 0; // on-round or off-round
32
uint8_t on = 0; // on-round or off-round
33
 
33
 
34
uint8_t animation[7];
34
uint8_t animation[7];
35
volatile uint8_t animation_locked = 0;
35
volatile uint8_t animation_locked = 0;
36
 
36
 
37
#define TIMESON         7 // time slices to stay on
37
#define TIMESON         7 // time slices to stay on
38
#define TIMESOFF        3 // time slices to stay off
38
#define TIMESOFF        3 // time slices to stay off
39
 
39
 
40
void led_out_init() {
40
void led_out_init() {
41
    DDRA |= 0xFF; // Z0-Z7 output
41
    DDRA |= 0xFF; // Z0-Z7 output
42
    DDRC |= ((1 << PC2) | (1 << PC3) | (1 << PC4) | (1 << PC5) | (1 << PC6) | (1 << PC7)); // S0-S5 output
42
    DDRC |= ((1 << PC2) | (1 << PC3) | (1 << PC4) | (1 << PC5) | (1 << PC6) | (1 << PC7)); // S0-S5 output
43
}
43
}
44
 
44
 
45
void inline led_timer_callback() {
45
void inline led_timer_callback() {
46
    if (!animation_locked) {
46
    if (!animation_locked) {
47
        // the Epilepsy was not build for powering the LEDs constantly, so we force a dim
47
        // the Epilepsy was not build for powering the LEDs constantly, so we force a dim
48
        delay--;
48
        delay--;
49
 
49
 
50
        // only after
50
        // only after
51
        if (!delay) {
51
        if (!delay) {
52
            if (on) {
52
            if (on) {
53
                // time is up, go dark
53
                // time is up, go dark
54
                ROWPORT = 0;
54
                ROWPORT = 0;
55
                COLPORT &= ~(COLBASE << col);
55
                COLPORT &= ~(COLBASE << col);
56
 
56
 
57
                // controll next col in next round
57
                // controll next col in next round
58
                col = (col + 1) % 6;
58
                col = (col + 1) % 6;
59
 
59
 
60
                delay = TIMESOFF;
60
                delay = TIMESOFF;
61
            } else {
61
            } else {
62
                COLPORT |= (COLBASE << col);
62
                COLPORT |= (COLBASE << col);
63
 
63
 
64
                // hardware EPI10AQ41 has the rows reversed
64
                // hardware EPI10AQ41 has the rows reversed
65
                // to convert old animations use
65
                // to convert old animations use
66
                // http://www.mylifesucks.de/tools/epireverse/
66
                // http://www.mylifesucks.de/tools/epireverse/
67
#if HWVERSION == EPI10AQ41
67
#if HWVERSION == EPI10AQ41
68
                uint8_t reverse = 0;
68
                uint8_t reverse = 0;
69
                for (uint8_t mask = 128; mask; mask >>= 1) {
69
                for (uint8_t mask = 128; mask; mask >>= 1) {
70
                    reverse >>= 1;
70
                    reverse >>= 1;
71
                    if (animation[col] & mask) {
71
                    if (animation[col] & mask) {
72
                        reverse |= 128;
72
                        reverse |= 128;
73
                    }
73
                    }
74
                }
74
                }
75
                ROWPORT = reverse;
75
                ROWPORT = reverse;
76
#else
76
#else
77
                ROWPORT = animation[col];
77
                ROWPORT = animation[col];
78
#endif
78
#endif
79
                delay = TIMESON;
79
                delay = TIMESON;
80
            }
80
            }
81
 
81
 
82
            on = !on;
82
            on = !on;
83
        }
83
        }
84
    }
84
    }
85
}
85
}
86
 
86
 
87
 
87