summaryrefslogtreecommitdiff
path: root/firmware/target/arm/at91sam/lyre_proto1/button-lyre_proto1.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/at91sam/lyre_proto1/button-lyre_proto1.c')
-rw-r--r--firmware/target/arm/at91sam/lyre_proto1/button-lyre_proto1.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/firmware/target/arm/at91sam/lyre_proto1/button-lyre_proto1.c b/firmware/target/arm/at91sam/lyre_proto1/button-lyre_proto1.c
new file mode 100644
index 0000000000..2d38803115
--- /dev/null
+++ b/firmware/target/arm/at91sam/lyre_proto1/button-lyre_proto1.c
@@ -0,0 +1,99 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 *
10 * Copyright (C) 2009 by Jorge Pinto
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "at91sam9260.h"
23#include "button.h"
24
25#define BUTTON_01 AT91C_PIO_PB4
26#define BUTTON_02 AT91C_PIO_PB5
27#define BUTTON_03 AT91C_PIO_PB27
28#define BUTTON_04 AT91C_PIO_PB26
29#define BUTTON_05 AT91C_PIO_PB25
30#define BUTTON_06 AT91C_PIO_PB24
31#define BUTTON_07 AT91C_PIO_PB22
32#define BUTTON_08 AT91C_PIO_PB23
33
34void button_init_device(void)
35{
36 /* Enable the periph clock for the PIO controller */
37 /* This is mandatory when PIO are configured as input */
38 AT91C_PMC_PCER = (1 << AT91C_ID_PIOB);
39
40 /* Set the PIO line in input */
41 AT91C_PIOB_ODR = (BUTTON_01 |
42 BUTTON_02 |
43 BUTTON_03 |
44 BUTTON_04 |
45 BUTTON_05 |
46 BUTTON_06 |
47 BUTTON_07 |
48 BUTTON_08);
49
50 /* Set the PIO controller in PIO mode instead of peripheral mode */
51 AT91C_PIOB_PER = (BUTTON_01 |
52 BUTTON_02 |
53 BUTTON_03 |
54 BUTTON_04 |
55 BUTTON_05 |
56 BUTTON_06 |
57 BUTTON_07 |
58 BUTTON_08);
59}
60
61bool button_hold(void)
62{
63 return (0);
64}
65
66/*
67 * Get button pressed from hardware
68 */
69int button_read_device(void)
70{
71 uint32_t buttons = AT91C_PIOB_PDSR;
72 uint32_t ret = 0;
73
74 if ((buttons & BUTTON_01) == 0)
75 ret |= BUTTON_UP;
76
77 if ((buttons & BUTTON_02) == 0)
78 ret |= BUTTON_RIGHT;
79
80 if ((buttons & BUTTON_03) == 0)
81 ret |= BUTTON_PLAY;
82
83 if ((buttons & BUTTON_04) == 0)
84 ret |= BUTTON_SELECT;
85
86 if ((buttons & BUTTON_05) == 0)
87 ret |= BUTTON_LEFT;
88
89 if ((buttons & BUTTON_06) == 0)
90 ret |= BUTTON_DOWN;
91
92 if ((buttons & BUTTON_07) == 0)
93 ret |= BUTTON_STOP;
94
95 if ((buttons & BUTTON_08) == 0)
96 ret |= BUTTON_MENU;
97
98 return ret;
99}