forked from google/mozc-devices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspace.c
66 lines (55 loc) · 1.77 KB
/
space.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright 2012 Google Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
/*
* USB space key.
* Connect a nomally-open switch to PB0. The device works as a space bar.
*/
#include <avr/io.h>
#include <avr/wdt.h>
#include <util/delay.h> /* for _delay_ms() */
#include "usb_keyboard.h"
int __attribute__((noreturn)) main(void)
{
PORTB = 0xff;
wdt_enable(WDTO_1S);
initUsbKeyboard();
/* sets up timer for button polling interval */
/* timer 1 CTC mode, counts up at f[clock]/8 [Hz] */
TCCR1B = (1 << WGM12) | (1 << CS11);
TCNT1 = 0;
OCR1A = F_CPU / 8 / 100; /* 100Hz, T=10 milliseconds */
uchar key = 0;
uchar lastKey = 0;
while(1) { /* main event loop */
wdt_reset();
usbPoll();
/* samples the key input every 10 milliseconds to avoid chattering */
if (bit_is_clear(TIFR, OCF1A)) {
continue;
}
TIFR |= _BV(OCF1A); /* clear OCF1A */
if(usbInterruptIsReady()){
key = bit_is_clear(PINB, PINB0) ? KEYCODE_SPACE : KEYCODE_NONE;
if (key != lastKey) {
lastKey = key;
prepareInterruptReport(key);
}
}
}
}