3
3
4
4
#include "leddrv.h"
5
5
#include "button.h"
6
+ #include "fb.h"
6
7
7
8
#define FB_WIDTH (LED_COLS * 4)
8
9
#define SCROLL_IRATIO (16)
9
- #define FB_NUM_SPARE (8)
10
10
#define SCAN_F (2000)
11
11
#define SCAN_T (FREQ_SYS / SCAN_F)
12
12
@@ -23,8 +23,6 @@ enum MODES {
23
23
};
24
24
#define BRIGHTNESS_LEVELS (4)
25
25
26
- uint16_t fb [FB_NUM_SPARE ][FB_WIDTH ];
27
-
28
26
uint8_t test_font [][11 ] = {
29
27
0x00 , 0xFE , 0x66 , 0x62 , 0x68 , 0x78 , 0x68 , 0x60 , 0x60 , 0xF0 , 0x00 , // F
30
28
0x00 , 0x7C , 0xC6 , 0xC6 , 0xC6 , 0xC6 , 0xC6 , 0xC6 , 0xC6 , 0x7C , 0x00 , // O
@@ -49,9 +47,7 @@ void draw2fb(uint16_t *fb, int c, int col)
49
47
}
50
48
}
51
49
52
- volatile int fb_sel , fb_num ;
53
50
volatile int mode , brightness ;
54
- volatile uint64_t tick ;
55
51
56
52
__HIGH_CODE
57
53
static void change_brightness ()
@@ -67,46 +63,50 @@ static void change_mode()
67
63
}
68
64
69
65
__HIGH_CODE
70
- static void change_fb ()
66
+ static void fb_transition ()
71
67
{
72
- NEXT_STATE (fb_sel , 0 , fb_num );
68
+ fblist_gonext ();
69
+ }
70
+
71
+ void draw_testfb ()
72
+ {
73
+
74
+ fb_t * curr_fb = fblist_currentfb ();
75
+ curr_fb -> modes = LEFT ;
76
+
77
+ for (int i = 0 ; i < 8 ; i ++ ) {
78
+ draw2fb (curr_fb -> buf , i , 8 * (i + 4 ));
79
+ }
80
+
81
+ fb_t * fb_next = fb_new (8 * 12 );
82
+ fblist_append (fb_next );
83
+ fb_next -> modes = LEFT ;
84
+
85
+ for (int i = 4 ; i < 12 ; i ++ ) {
86
+ draw2fb (fb_next -> buf , i % 8 , 8 * (i + 1 ));
87
+ }
73
88
}
74
89
75
90
int main ()
76
91
{
77
92
SetSysClock (CLK_SOURCE_PLL_60MHz );
78
93
79
94
led_init ();
80
- draw2fb (fb [0 ], 0 , 8 * (5 - 1 ));
81
- draw2fb (fb [0 ], 1 , 8 * (6 - 1 ));
82
- draw2fb (fb [0 ], 2 , 8 * (7 - 1 ));
83
- draw2fb (fb [0 ], 3 , 8 * (8 - 1 ));
84
- draw2fb (fb [0 ], 4 , 8 * (9 - 1 ));
85
- draw2fb (fb [0 ], 5 , 8 * (10 - 1 ));
86
- draw2fb (fb [0 ], 6 , 8 * (11 - 1 ));
87
- draw2fb (fb [0 ], 7 , 8 * (12 - 1 ));
88
-
89
- draw2fb (fb [1 ], 4 , 8 * 5 );
90
- draw2fb (fb [1 ], 5 , 8 * 6 );
91
- draw2fb (fb [1 ], 6 , 8 * 7 );
92
- draw2fb (fb [1 ], 7 , 8 * 8 );
93
- draw2fb (fb [1 ], 0 , 8 * 9 );
94
- draw2fb (fb [1 ], 1 , 8 * 10 );
95
- draw2fb (fb [1 ], 2 , 8 * 11 );
96
- draw2fb (fb [1 ], 3 , 8 * 12 );
97
- fb_num = 2 ;
98
-
99
95
TMR0_TimerInit (SCAN_T / 2 );
100
96
TMR0_ITCfg (ENABLE , TMR0_3_IT_CYC_END );
101
97
PFIC_EnableIRQ (TMR0_IRQn );
102
98
99
+ fblist_init (FB_WIDTH );
100
+
101
+ draw_testfb ();
102
+
103
103
btn_init ();
104
104
btn_onOnePress (KEY1 , change_mode );
105
- btn_onOnePress (KEY2 , change_fb );
105
+ btn_onOnePress (KEY2 , fb_transition );
106
106
btn_onLongPress (KEY1 , change_brightness );
107
107
108
108
while (1 ) {
109
- int i = 0 ;
109
+ uint32_t i = 0 ;
110
110
while (isPressed (KEY2 )) {
111
111
i ++ ;
112
112
if (i > 10 ) {
@@ -121,16 +121,19 @@ __INTERRUPT
121
121
__HIGH_CODE
122
122
void TMR0_IRQHandler (void )
123
123
{
124
- static int i , scroll ;
124
+ static int i ;
125
125
126
126
if (TMR0_GetITFlag (TMR0_3_IT_CYC_END )) {
127
127
128
+ fb_t * fb = fblist_currentfb ();
128
129
i += 1 ;
129
130
if (i >= LED_COLS ) {
130
131
i = 0 ;
131
- scroll ++ ;
132
- if (scroll >= (FB_WIDTH - LED_COLS )* SCROLL_IRATIO ) {
133
- scroll = 0 ;
132
+ if ((fb -> modes & 0x0f ) == LEFT ) {
133
+ fb -> scroll ++ ;
134
+ if (fb -> scroll >= (fb -> width - LED_COLS )* SCROLL_IRATIO ) {
135
+ fb -> scroll = 0 ;
136
+ }
134
137
}
135
138
}
136
139
@@ -139,8 +142,8 @@ void TMR0_IRQHandler(void)
139
142
leds_releaseall ();
140
143
} else {
141
144
led_write2dcol (i /2 ,
142
- fb [ fb_sel ][ i + scroll /SCROLL_IRATIO ],
143
- fb [ fb_sel ][ i + scroll /SCROLL_IRATIO + 1 ]);
145
+ fb -> buf [ i + fb -> scroll /SCROLL_IRATIO ],
146
+ fb -> buf [ i + fb -> scroll /SCROLL_IRATIO + 1 ]);
144
147
}
145
148
146
149
TMR0_ClearITFlag (TMR0_3_IT_CYC_END );
0 commit comments