blob: 53b159a2ecac673bcabc00497758e0bbc5451d0c [file] [log] [blame]
Daniel Stenberg86bff1c2006-08-03 20:18:31 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Barry Wardell
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Daniel Stenberg86bff1c2006-08-03 20:18:31 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22/* Custom written for the H10 based on analysis of the GPIO data */
23
24
25#include <stdlib.h>
26#include "config.h"
27#include "cpu.h"
28#include "system.h"
29#include "button.h"
30#include "kernel.h"
31#include "backlight.h"
32#include "adc.h"
33#include "system.h"
34
35
36void button_init_device(void)
37{
Barry Wardell0b1ae732006-09-13 23:38:16 +000038 /* Enable REW, FF, Play, Left, Right, Hold buttons */
Jens Arnold05784b52007-11-27 20:23:12 +000039 GPIO_SET_BITWISE(GPIOA_ENABLE, 0xfc);
Barry Wardell0b1ae732006-09-13 23:38:16 +000040
41 /* Enable POWER button */
Jens Arnold05784b52007-11-27 20:23:12 +000042 GPIO_SET_BITWISE(GPIOB_ENABLE, 0x01);
Barry Wardell0b1ae732006-09-13 23:38:16 +000043
Barry Wardella27c1832006-09-04 20:09:17 +000044 /* We need to output to pin 6 of GPIOD when reading the scroll pad value */
Jens Arnold05784b52007-11-27 20:23:12 +000045 GPIO_SET_BITWISE(GPIOD_ENABLE, 0x40);
46 GPIO_SET_BITWISE(GPIOD_OUTPUT_EN, 0x40);
47 GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x40);
Daniel Stenberg86bff1c2006-08-03 20:18:31 +000048}
49
50bool button_hold(void)
51{
Barry Wardell82695412006-08-26 15:48:17 +000052 return (GPIOA_INPUT_VAL & 0x4)?false:true;
Daniel Stenberg86bff1c2006-08-03 20:18:31 +000053}
54
Barry Wardellb692fb12006-09-29 15:59:08 +000055bool remote_button_hold(void)
56{
Barry Wardell1d1a17c2007-10-16 10:48:16 +000057 return adc_scan(ADC_REMOTE) < 0x2B;
Barry Wardellb692fb12006-09-29 15:59:08 +000058}
59
Daniel Stenberg86bff1c2006-08-03 20:18:31 +000060/*
61 * Get button pressed from hardware
62 */
63int button_read_device(void)
64{
65 int btn = BUTTON_NONE;
Barry Wardellb692fb12006-09-29 15:59:08 +000066 int data;
Hristo Kovachev12041362006-08-11 09:51:04 +000067 unsigned char state;
68 static bool hold_button = false;
Barry Wardellb692fb12006-09-29 15:59:08 +000069 static bool remote_hold_button = false;
Barry Wardell0b1ae732006-09-13 23:38:16 +000070 bool hold_button_old;
Barry Wardellb692fb12006-09-29 15:59:08 +000071 bool remote_hold_button_old;
Barry Wardell0b1ae732006-09-13 23:38:16 +000072
73 /* Hold */
74 hold_button_old = hold_button;
75 hold_button = button_hold();
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000076
Barry Wardell8ccedc92006-09-10 17:59:59 +000077#ifndef BOOTLOADER
Daniel Stenberg86bff1c2006-08-03 20:18:31 +000078 /* light handling */
Barry Wardell0b1ae732006-09-13 23:38:16 +000079 if (hold_button != hold_button_old)
Daniel Stenberg86bff1c2006-08-03 20:18:31 +000080 {
Barry Wardell2937c502006-09-10 13:18:33 +000081 backlight_hold_changed(hold_button);
Daniel Stenberg86bff1c2006-08-03 20:18:31 +000082 }
Barry Wardell8ccedc92006-09-10 17:59:59 +000083#endif
Daniel Stenberg86bff1c2006-08-03 20:18:31 +000084
Barry Wardellb692fb12006-09-29 15:59:08 +000085 /* device buttons */
Hristo Kovachev12041362006-08-11 09:51:04 +000086 if (!hold_button)
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000087 {
Hristo Kovachev12041362006-08-11 09:51:04 +000088 /* Read normal buttons */
89 state = GPIOA_INPUT_VAL & 0xf8;
90 if ((state & 0x8) == 0) btn |= BUTTON_FF;
91 if ((state & 0x10) == 0) btn |= BUTTON_PLAY;
92 if ((state & 0x20) == 0) btn |= BUTTON_REW;
93 if ((state & 0x40) == 0) btn |= BUTTON_RIGHT;
94 if ((state & 0x80) == 0) btn |= BUTTON_LEFT;
95
96 /* Read power button */
Barry Wardell82695412006-08-26 15:48:17 +000097 if (GPIOB_INPUT_VAL & 0x1) btn |= BUTTON_POWER;
Hristo Kovachev12041362006-08-11 09:51:04 +000098
99 /* Read scroller */
Barry Wardella27c1832006-09-04 20:09:17 +0000100 if ( GPIOD_INPUT_VAL & 0x20 )
Hristo Kovachev12041362006-08-11 09:51:04 +0000101 {
Jens Arnold05784b52007-11-27 20:23:12 +0000102 GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x40);
Peter D'Hoye0d5451e2007-08-21 23:37:26 +0000103 udelay(250);
Barry Wardellb692fb12006-09-29 15:59:08 +0000104 data = adc_scan(ADC_SCROLLPAD);
Jens Arnold05784b52007-11-27 20:23:12 +0000105 GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x40);
Barry Wardella27c1832006-09-04 20:09:17 +0000106
Barry Wardell1d1a17c2007-10-16 10:48:16 +0000107 if(data < 0x224)
Barry Wardella27c1832006-09-04 20:09:17 +0000108 {
109 btn |= BUTTON_SCROLL_DOWN;
110 } else {
111 btn |= BUTTON_SCROLL_UP;
112 }
Hristo Kovachev12041362006-08-11 09:51:04 +0000113 }
114 }
115
Barry Wardellb692fb12006-09-29 15:59:08 +0000116 /* remote buttons */
117 remote_hold_button_old = remote_hold_button;
118
119 data = adc_scan(ADC_REMOTE);
Barry Wardell1d1a17c2007-10-16 10:48:16 +0000120 remote_hold_button = data < 0x2B;
Barry Wardellb692fb12006-09-29 15:59:08 +0000121
122#ifndef BOOTLOADER
123 if (remote_hold_button != remote_hold_button_old)
124 backlight_hold_changed(remote_hold_button);
125#endif
126
127 if(!remote_hold_button)
128 {
129 if (data < 0x3FF)
130 {
Barry Wardell1d1a17c2007-10-16 10:48:16 +0000131 if(data < 0x204)
132 if(data < 0x155)
Barry Wardellb692fb12006-09-29 15:59:08 +0000133 btn |= BUTTON_RC_FF;
134 else
135 btn |= BUTTON_RC_REW;
136 else
Barry Wardell1d1a17c2007-10-16 10:48:16 +0000137 if(data < 0x2D0)
Barry Wardellb692fb12006-09-29 15:59:08 +0000138 btn |= BUTTON_RC_VOL_DOWN;
139 else
140 btn |= BUTTON_RC_VOL_UP;
141 }
142 }
143
144 /* remote play button should be dead if hold */
145 if (!remote_hold_button && !(GPIOA_INPUT_VAL & 0x1))
146 btn |= BUTTON_RC_PLAY;
147
Daniel Stenberg86bff1c2006-08-03 20:18:31 +0000148 return btn;
149}