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