diff options
Diffstat (limited to 'firmware/target/arm/s3c2440/gigabeat-fx/button-meg-fx.c')
-rw-r--r-- | firmware/target/arm/s3c2440/gigabeat-fx/button-meg-fx.c | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/button-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/button-meg-fx.c new file mode 100644 index 0000000000..71d45c385c --- /dev/null +++ b/firmware/target/arm/s3c2440/gigabeat-fx/button-meg-fx.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include <stdlib.h> | ||
21 | #include "config.h" | ||
22 | #include "cpu.h" | ||
23 | #include "system.h" | ||
24 | #include "button.h" | ||
25 | #include "kernel.h" | ||
26 | #include "backlight.h" | ||
27 | #include "adc.h" | ||
28 | #include "system.h" | ||
29 | #include "backlight-target.h" | ||
30 | |||
31 | static bool headphones_detect; | ||
32 | static bool hold_button = false; | ||
33 | |||
34 | static int const remote_buttons[] = | ||
35 | { | ||
36 | BUTTON_NONE, /* Headphones connected - remote disconnected */ | ||
37 | BUTTON_SELECT, | ||
38 | BUTTON_MENU, /* could be changed to BUTTON_A */ | ||
39 | BUTTON_LEFT, | ||
40 | BUTTON_RIGHT, | ||
41 | BUTTON_UP, /* could be changed to BUTTON_VOL_UP */ | ||
42 | BUTTON_DOWN, /* could be changed to BUTTON_VOL_DOWN */ | ||
43 | BUTTON_NONE, /* Remote control attached - no buttons pressed */ | ||
44 | BUTTON_NONE, /* Nothing in the headphone socket */ | ||
45 | }; | ||
46 | |||
47 | |||
48 | |||
49 | |||
50 | |||
51 | void button_init_device(void) | ||
52 | { | ||
53 | /* Power, Remote Play & Hold switch */ | ||
54 | } | ||
55 | |||
56 | |||
57 | |||
58 | inline bool button_hold(void) | ||
59 | { | ||
60 | return (GPGDAT & (1 << 15)); | ||
61 | } | ||
62 | |||
63 | |||
64 | |||
65 | int button_read_device(void) | ||
66 | { | ||
67 | int touchpad; | ||
68 | int buttons; | ||
69 | static int lastbutton; | ||
70 | unsigned short remote_adc; | ||
71 | int btn = BUTTON_NONE; | ||
72 | bool hold_button_old; | ||
73 | |||
74 | /* normal buttons */ | ||
75 | hold_button_old = hold_button; | ||
76 | hold_button = button_hold(); | ||
77 | |||
78 | #ifndef BOOTLOADER | ||
79 | /* give BL notice if HB state chaged */ | ||
80 | if (hold_button != hold_button_old) | ||
81 | backlight_hold_changed(hold_button); | ||
82 | #endif | ||
83 | |||
84 | /* See header for ADC values when remote control buttons are pressed */ | ||
85 | /* Only one button can be sensed at a time on the remote. */ | ||
86 | /* Need to filter the remote button because the ADC is so fast */ | ||
87 | remote_adc = adc_read(ADC_HPREMOTE); | ||
88 | btn = remote_buttons[(remote_adc + 64) / 128]; | ||
89 | if (btn != lastbutton) | ||
90 | { | ||
91 | /* if the buttons dont agree twice in a row, then its none */ | ||
92 | lastbutton = btn; | ||
93 | btn = BUTTON_NONE; | ||
94 | } | ||
95 | |||
96 | /* Check for hold first - exit if asserted with no button pressed */ | ||
97 | if (hold_button) | ||
98 | return btn; | ||
99 | |||
100 | /* the side buttons - Check before doing all of the work on each bit */ | ||
101 | buttons = GPGDAT & 0x1F; | ||
102 | if (buttons) | ||
103 | { | ||
104 | if (buttons & (1 << 0)) | ||
105 | btn |= BUTTON_POWER; | ||
106 | |||
107 | if (buttons & (1 << 1)) | ||
108 | btn |= BUTTON_MENU; | ||
109 | |||
110 | if (buttons & (1 << 2)) | ||
111 | btn |= BUTTON_VOL_UP; | ||
112 | |||
113 | if (buttons & (1 << 3)) | ||
114 | btn |= BUTTON_VOL_DOWN; | ||
115 | |||
116 | if (buttons & (1 << 4)) | ||
117 | btn |= BUTTON_A; | ||
118 | } | ||
119 | |||
120 | /* the touchpad */ | ||
121 | touchpad = GPJDAT & 0x10C9; | ||
122 | if (touchpad) | ||
123 | { | ||
124 | if (touchpad & (1 << 0)) | ||
125 | btn |= BUTTON_UP; | ||
126 | |||
127 | if (touchpad & (1 << 12)) | ||
128 | btn |= BUTTON_RIGHT; | ||
129 | |||
130 | if (touchpad & (1 << 6)) | ||
131 | btn |= BUTTON_DOWN; | ||
132 | |||
133 | if (touchpad & (1 << 7)) | ||
134 | btn |= BUTTON_LEFT; | ||
135 | |||
136 | if (touchpad & (1 << 3)) | ||
137 | btn |= BUTTON_SELECT; | ||
138 | } | ||
139 | |||
140 | return btn; | ||
141 | } | ||
142 | |||
143 | |||
144 | |||
145 | bool headphones_inserted(void) | ||
146 | { | ||
147 | unsigned short remote_adc = adc_read(ADC_HPREMOTE); | ||
148 | if (remote_adc != ADC_READ_ERROR) | ||
149 | { | ||
150 | /* If there is nothing in the headphone socket, the ADC reads high */ | ||
151 | if (remote_adc < 940) | ||
152 | headphones_detect = true; | ||
153 | else | ||
154 | headphones_detect = false; | ||
155 | } | ||
156 | return headphones_detect; | ||
157 | } | ||