/
button.c
41 lines (38 loc) · 1.11 KB
/
button.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
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/eeprom.h>
#include <avr/pgmspace.h>
//=============================================================================
#include "button.h"
#include "events.h"
#include "rtos.h"
#include "pins.h"
//=============================================================================
void KBD_init(void)
{
DDR(BEEPER) |= BEEPER_LINE;
PORT(BEEPER) &= ~BEEPER_LINE;
DDR(BUTTON_1) &= ~BUTTON_1_LINE;
PORT(BUTTON_1) |= BUTTON_1_LINE;
}
//=============================================================================
void KBD_poll(void)
{
static uint16_t state1 = 0; //holds present state
static uint16_t cntLong = 0;
state1 = (state1 << 1) | (! bit_is_clear(PIN(BUTTON_SET), BUTTON_SET_LINE)) | 0xE000;
if (state1 == 0xF000) {
if (bit_is_clear(PIN(BUTTON_SET), BUTTON_SET_LINE)) {
cntLong++;
if (cntLong >= LONG_PRESS) {
state1 = 0;
cntLong = 0;
RTOS_setTask(EVENT_KEY_SET_LONG, 0, 0);
}
} else {
RTOS_setTask(EVENT_KEY_SET, 0, 0);
}
}
}
//=============================================================================