Fix typo and correct punctuation
[maemo-rb.git] / firmware / target / arm / philips / hdd6330 / button-hdd6330.c
blobab06c0cf1ab0ef4574794f355fea82f00a2c8ac4
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Mark Arigo
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "system.h"
23 #include "button.h"
24 #include "backlight.h"
25 #include "synaptics-mep.h"
27 /*#define LOGF_ENABLE*/
28 #include "logf.h"
30 static int int_btn = BUTTON_NONE;
33 * Generate a click sound from the player (not in headphones yet)
34 * TODO: integrate this with the "key click" option
36 void button_click(void)
38 GPO32_ENABLE |= 0x2000;
39 GPO32_VAL |= 0x2000;
40 udelay(1000);
41 GPO32_VAL &= ~0x2000;
44 #ifndef BOOTLOADER
45 void button_init_device(void)
47 /* The touchpad is powered on and initialized in power-hdd1630.c
48 since it needs to be ready for both buttons and button lights. */
52 * Button interrupt handler
54 void button_int(void)
56 char data[4];
57 int val;
59 int_btn = BUTTON_NONE;
61 val = touchpad_read_device(data, 4);
63 if (val == MEP_BUTTON_HEADER)
65 /* Buttons packet */
66 if (data[1] & 0x1)
67 int_btn |= BUTTON_LEFT;
68 if (data[1] & 0x2)
69 int_btn |= BUTTON_RIGHT;
71 else if (val == MEP_ABSOLUTE_HEADER)
73 /* Absolute packet - the finger is on the vertical strip.
74 Position ranges from 1-4095, with 1 at the bottom. */
75 val = ((data[1] >> 4) << 8) | data[2]; /* position */
77 if ((val > 0) && (val <= 1365))
78 int_btn |= BUTTON_DOWN;
79 else if ((val > 1365) && (val <= 2730))
80 int_btn |= BUTTON_SELECT;
81 else if ((val > 2730) && (val <= 4095))
82 int_btn |= BUTTON_UP;
85 #else
86 void button_init_device(void){}
87 #endif /* bootloader */
89 bool button_hold(void)
91 return !(GPIOJ_INPUT_VAL & 0x8);
95 * Get button pressed from hardware
97 int button_read_device(void)
99 static int btn_old = BUTTON_NONE;
100 int btn = int_btn;
102 /* Hold */
103 if(button_hold())
104 return BUTTON_NONE;
106 /* Device buttons */
107 if (!(GPIOA_INPUT_VAL & 0x01)) btn |= BUTTON_MENU;
108 if (!(GPIOA_INPUT_VAL & 0x02)) btn |= BUTTON_VOL_UP;
109 if (!(GPIOA_INPUT_VAL & 0x04)) btn |= BUTTON_VOL_DOWN;
110 if (!(GPIOA_INPUT_VAL & 0x08)) btn |= BUTTON_VIEW;
111 if (!(GPIOD_INPUT_VAL & 0x20)) btn |= BUTTON_PLAYLIST;
112 if (!(GPIOD_INPUT_VAL & 0x40)) btn |= BUTTON_POWER;
114 if ((btn != btn_old) && (btn != BUTTON_NONE))
115 button_click();
117 btn_old = btn;
119 return btn;
122 bool headphones_inserted(void)
124 return (GPIOE_INPUT_VAL & 0x80) ? true : false;