36
36
37
37
#include "ws2812_new.h"
38
38
#include "keypad.h"
39
- #include "ani.h"
40
39
#include "usb_serial.h"
40
+ #include "ani.h"
41
41
42
42
static void enable_sys_tick (uint32_t ticks )
43
43
{
@@ -49,11 +49,7 @@ static void enable_sys_tick(uint32_t ticks)
49
49
volatile uint32_t tick = 0 ;
50
50
void SysTick_Handler (void )
51
51
{
52
- if ( (tick & 3 ) == 0 )
53
- ws2812_write ();
54
-
55
- keypad_poll ();
56
-
52
+ ws2812_write ();
57
53
tick += 1 ;
58
54
}
59
55
@@ -70,10 +66,10 @@ static void init(void)
70
66
set_animation (OFF );
71
67
72
68
usb_serial_init ();
73
- enable_sys_tick (F_SYS_TICK_CLK /4000 );
69
+ enable_sys_tick (F_SYS_TICK_CLK /1600 );
74
70
}
75
71
76
- static const uint16_t keymap [N_KEYS ] = KEY_MAPPING ;
72
+ static const uint8_t keymap [N_KEYS ] = KEY_MAPPING ;
77
73
78
74
static volatile uint8_t key_event [N_KEYS ];
79
75
@@ -96,24 +92,35 @@ int main(void)
96
92
97
93
for (;;)
98
94
{
99
- f = ws2812_get_frame ();
95
+ keypad_poll ();
100
96
usb_serial_poll ();
97
+ f = ws2812_get_frame ();
101
98
102
- if (f != NULL && (tick - t_last > 16 ) )
99
+ if (f != NULL && (tick - t_last > 4 ) )
103
100
{
104
101
prepare_next_frame (f );
105
102
ws2812_swap_frame ();
106
- t_last += 16 ;
103
+ t_last += 4 ;
107
104
}
108
105
109
- int key ;
106
+ int key , n_written , off = 0 ;
107
+ uint8_t outbuf [N_KEYS ];
108
+ uint8_t ixbuf [N_KEYS ];
109
+
110
110
for (key = 0 ; key < N_KEYS ; key ++ )
111
- {
112
111
if (key_event [key ])
113
112
{
114
- usb_serial_putchar (keymap [key ]);
115
- key_event [key ] = 0 ;
113
+ ixbuf [off ] = key ;
114
+ outbuf [off ] = keymap [key ];
115
+ off += 1 ;
116
116
}
117
+
118
+ if (off > 0 )
119
+ {
120
+ n_written = usb_serial_write_noblock (outbuf , off );
121
+
122
+ for (off = 0 ; off < n_written ; off ++ )
123
+ key_event [ixbuf [off ]] = 0 ;
117
124
}
118
125
119
126
switch (usb_serial_getchar ())
0 commit comments