Sansa c200v2: update DBOP button reading mechanism, this enables readout of the volum...
[maemo-rb.git] / firmware / target / arm / as3525 / sansa-c200v2 / button-c200v2.c
blobb7ce7330c0d2db3778ee9f702e11a480a4820502
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: button-e200v2.c 19035 2008-11-07 05:31:05Z jdgordon $
10 * Copyright (C) 2006 by Barry Wardell
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-target.h"
24 #include "button.h"
25 #include "backlight.h"
26 #include "powermgmt.h"
29 static unsigned short _dbop_din = 0xFFFF;
31 /* in the lcd driver */
32 extern unsigned short int lcd_dbop_input(void);
34 static bool hold_button = false;
35 #ifndef BOOTLOADER
36 static bool hold_button_old = false;
37 #endif
39 /* for the debug menu */
40 unsigned short button_dbop_data(void)
42 return _dbop_din;
45 void button_init_device(void)
47 GPIOA_DIR &= ~(1<<3);
50 bool button_hold(void)
52 return hold_button;
56 * Get button pressed from hardware
58 int button_read_device(void)
60 int btn = BUTTON_NONE;
62 _dbop_din = lcd_dbop_input();
64 /* hold button handling */
65 hold_button = ((_dbop_din & (1<<12)) == 0);
66 #ifndef BOOTLOADER
67 /* light handling */
68 if (hold_button != hold_button_old)
70 hold_button_old = hold_button;
71 backlight_hold_changed(hold_button);
73 #endif /* BOOTLOADER */
74 if (hold_button) {
75 return 0;
78 /* direct GPIO connections */
79 if (GPIOA_PIN(3))
80 btn |= BUTTON_POWER;
82 /* DBOP buttons */
83 if(!(_dbop_din & (1<<2)))
84 btn |= BUTTON_LEFT;
85 if(!(_dbop_din & (1<<3)))
86 btn |= BUTTON_DOWN;
87 if(!(_dbop_din & (1<<4)))
88 btn |= BUTTON_SELECT;
89 if(!(_dbop_din & (1<<5)))
90 btn |= BUTTON_UP;
91 if(!(_dbop_din & (1<<6)))
92 btn |= BUTTON_RIGHT;
93 if(!(_dbop_din & (1<<13)))
94 btn |= BUTTON_VOL_UP;
95 if(!(_dbop_din & (1<<14)))
96 btn |= BUTTON_VOL_DOWN;
97 if(!(_dbop_din & (1<<15)))
98 btn |= BUTTON_REC;
100 return btn;