summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/mpio/hd200/button-hd200.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/mpio/hd200/button-hd200.c')
-rw-r--r--firmware/target/coldfire/mpio/hd200/button-hd200.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/firmware/target/coldfire/mpio/hd200/button-hd200.c b/firmware/target/coldfire/mpio/hd200/button-hd200.c
new file mode 100644
index 0000000000..b40c3324e1
--- /dev/null
+++ b/firmware/target/coldfire/mpio/hd200/button-hd200.c
@@ -0,0 +1,123 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
9 *
10 * Copyright (C) 2010 Marcin Bukat
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 "config.h"
23#include "cpu.h"
24#include "system.h"
25#include "button.h"
26#include "backlight.h"
27#include "adc.h"
28
29void button_init_device(void)
30{
31 /* Set GPIO36, GPIO56 as general purpose inputs */
32 or_l((1<<4)|(1<<24),&GPIO1_FUNCTION);
33 and_l(~((1<<4)|(1<<24)),&GPIO1_ENABLE);
34}
35
36bool button_hold(void)
37{
38 /* GPIO36 active high */
39 return (GPIO1_READ & (1<<4))?true:false;
40}
41
42
43/*
44 * Get button pressed from hardware
45 */
46int button_read_device(void)
47{
48 int btn = BUTTON_NONE;
49 int data = 0;
50 static bool hold_button = false;
51
52 /* for moving average filter */
53 static unsigned short button_filter[4];
54 static unsigned char index;
55
56 bool hold_button_old;
57
58 /* normal buttons */
59 hold_button_old = hold_button;
60 hold_button = button_hold();
61
62
63#ifndef BOOTLOADER
64 if (hold_button != hold_button_old)
65 backlight_hold_changed(hold_button);
66#endif
67
68 if (!hold_button)
69 {
70
71 /* simple moving average filter with 4 item window */
72 button_filter[index&0x03] = adc_scan(ADC_BUTTONS);
73 index++;
74
75 data = (button_filter[0]+button_filter[1] \
76 +button_filter[2]+button_filter[3])>>2;
77
78
79 if (data < 2250) // valid button
80 {
81 if (data < 900) /* middle */
82 {
83 if (data < 500)
84 {
85 if (data > 200)
86 /* 200 - 500 */
87 btn = BUTTON_REC;
88 }
89 else /* 900 - 500 */
90 btn = BUTTON_VOL_DOWN;
91 }
92 else /* 2250 - 900 */
93 {
94 if (data < 1600)
95 {
96 /* 1600 - 900 */
97 if (data < 1200)
98 /* 1200 - 900 */
99 btn = BUTTON_VOL_UP;
100 else /* 1600 - 1200 */
101 btn = BUTTON_NEXT;
102 }
103 else /* 1600 - 2250 */
104 {
105 if (data < 1900)
106 /* 1900 - 1600 */
107 btn = BUTTON_PREV;
108 else /* 1900 - 2250 */
109 btn = BUTTON_SELECT;
110 }
111 }
112 }
113 }
114
115
116 data = GPIO1_READ;
117
118 /* GPIO56 active high main PLAY/PAUSE/ON */
119 if (!hold_button && ((data & (1<<24))))
120 btn |= BUTTON_PLAY;
121
122 return btn;
123}