SA9200: Implement the backlight hold handling.
[kugel-rb.git] / firmware / target / arm / philips / sa9200 / button-sa9200.c
blobe3d569f4220cb3bcac300b29c0cb717e30228388
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;
32 #ifndef BOOTLOADER
33 static bool hold_button_old = false;
35 void button_init_device(void)
37 /* The touchpad is powered on and initialized in power-sa9200.c
38 since it needs to be ready for both buttons and button lights. */
42 * Button interrupt handler
44 void button_int(void)
46 char data[4];
47 int val;
49 int_btn = BUTTON_NONE;
51 val = touchpad_read_device(data, 4);
53 if (val == MEP_BUTTON_HEADER)
55 /* Buttons packet */
56 if (data[1] & 0x1) int_btn |= BUTTON_RIGHT;
57 if (data[1] & 0x2) int_btn |= BUTTON_NEXT;
58 if (data[1] & 0x4) int_btn |= BUTTON_PREV;
59 if (data[1] & 0x8) int_btn |= BUTTON_LEFT;
60 if (data[2] & 0x1) int_btn |= BUTTON_MENU;
62 else if (val == MEP_ABSOLUTE_HEADER)
64 /* Absolute packet - the finger is on the vertical strip.
65 Position ranges from 1-4095, with 1 at the bottom. */
66 val = ((data[1] >> 4) << 8) | data[2]; /* position */
68 if ((val > 0) && (val <= 1365))
69 int_btn |= BUTTON_DOWN;
70 else if ((val > 1365) && (val <= 2730))
71 int_btn |= BUTTON_PLAY;
72 else if ((val > 2730) && (val <= 4095))
73 int_btn |= BUTTON_UP;
76 #else
77 void button_init_device(void)
80 #endif /* BOOTLOADER */
82 bool button_hold(void)
84 return !(GPIOL_INPUT_VAL & 0x40);
88 * Get button pressed from hardware
90 int button_read_device(void)
92 int btn = int_btn;
93 bool hold = !(GPIOL_INPUT_VAL & 0x40);
95 #ifndef BOOTLOADER
96 /* Backlight hold handling */
97 if (hold != hold_button_old)
99 hold_button_old = hold;
100 backlight_hold_changed(hold);
102 #endif
104 if (hold)
105 return BUTTON_NONE;
107 if (!(GPIOB_INPUT_VAL & 0x20)) btn |= BUTTON_POWER;
108 if (!(GPIOF_INPUT_VAL & 0x10)) btn |= BUTTON_VOL_UP;
109 if (!(GPIOF_INPUT_VAL & 0x04)) btn |= BUTTON_VOL_DOWN;
111 return btn;
114 bool headphones_inserted(void)
116 return (GPIOB_INPUT_VAL & 0x10) ? false : true;