blob: 547d71accea1b18d3e275c8f02ad6a5050d00cdb (
plain) (
blame)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*
* Copyright © 2011 Keith Packard <keithp@keithp.com>
*
* 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; version 2 of the License.
*
* 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "ao.h"
volatile __xdata struct ao_fifo ao_button_fifo;
#define BUTTON_1_PIN (P0_4)
#define BUTTON_1_MASK (1 << 4) /* P0_4 */
#define BUTTON_2_PIN (P2_3)
#define BUTTON_2_MASK (1 << 3) /* P2_3 */
#define BUTTON_3_PIN (P2_4)
#define BUTTON_3_MASK (1 << 4) /* P2_4 */
static void
ao_button_insert(char n)
{
ao_fifo_insert(ao_button_fifo, n);
ao_wakeup(&ao_button_fifo);
}
char
ao_button_get(void) __critical
{
char b;
while (ao_fifo_empty(ao_button_fifo))
ao_sleep(&ao_button_fifo);
ao_fifo_remove(ao_button_fifo, b);
return b;
}
void
ao_p2_isr(void)
{
if (P2IFG & BUTTON_2_MASK)
ao_button_insert(2);
if (P2IFG & BUTTON_3_MASK)
ao_button_insert(3);
P2IFG = 0;
}
void
ao_p0_isr(void) ao_arch_interrupt(13)
{
P0IF = 0;
if (P0IFG & BUTTON_1_MASK)
ao_button_insert(1);
P0IFG = 0;
}
void
ao_button_init(void)
{
/* Pins are configured as inputs with pull-up by default */
/* Enable interrupts for P2_0 - P2_4
* Enable interrupts for P0_4 - P0_7
* Set P2 interrupts to falling edge
* Set P0 interrupts to falling edge
*/
PICTL |= PICTL_P2IEN | PICTL_P0IENH | PICTL_P2ICON | PICTL_P0ICON;
/* Enable interrupts for P0 inputs */
IEN1 |= IEN1_P0IE;
/* Enable interrupts for P2 inputs */
IEN2 |= IEN2_P2IE;
}
|