1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 Bertrik Sikken
11 * Copyright (C) 2008 François Dinel
12 * Copyright (C) 2008 Rafaël Carré
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
24 #include "button-target.h"
27 #include "backlight.h"
30 /* The Sansa Clip uses a button matrix that is scanned by selecting one of
31 three rows and reading back the button states from the columns.
33 In this driver, the row is changed at each call (i.e. once per tick).
34 In one tick, column data from one row is read back and then the next row
35 is selected for the following tick. This mechanism ensures that there is
36 plenty time between selecting a row and reading the columns, avoiding the
37 need for explicit delays.
41 void button_init_device(void)
43 GPIOA_DIR
&= ~((1<<7) | (1<<3));
44 GPIOB_DIR
&= ~((1<<2) | (1<<1) | (1<<0));
48 GPIOC_DIR
|= ((1<<6) | (1<<5) | (1<<4));
50 /* get initial readings */
56 int button_read_device(void)
59 static int buttons
= 0;
60 static unsigned power_counter
= 0;
68 /* direct GPIO connections */
69 /* read power, but not if hold button was just released, since
70 * you basically always hit power due to the slider mechanism after
71 * releasing hold (wait 1 sec) */
75 if (GPIOA_PIN(7) && !power_counter
)
76 buttons
|= BUTTON_POWER
;
78 buttons
&= ~BUTTON_POWER
;
80 /* This is a keypad using C4-C6 as columns and B0-B2 as rows */
84 buttons
&= ~(BUTTON_VOL_UP
| BUTTON_UP
);
86 (void)GPIOB_PIN(0); /* C4B0 is unused */
89 buttons
|= BUTTON_VOL_UP
;
95 GPIOC_PIN(5) = (1<<5);
100 buttons
&= ~(BUTTON_LEFT
| BUTTON_SELECT
| BUTTON_RIGHT
);
103 buttons
|= BUTTON_LEFT
;
106 buttons
|= BUTTON_SELECT
;
109 buttons
|= BUTTON_RIGHT
;
112 GPIOC_PIN(6) = (1<<6);
117 buttons
&= ~(BUTTON_DOWN
| BUTTON_VOL_DOWN
| BUTTON_HOME
);
120 buttons
|= BUTTON_DOWN
;
123 buttons
|= BUTTON_VOL_DOWN
;
126 buttons
|= BUTTON_HOME
;
129 GPIOC_PIN(4) = (1<<4);
139 bool button_hold(void)
142 static bool hold_button_old
= false;
144 bool hold_button
= (GPIOA_PIN(3) != 0);
148 if (hold_button
!= hold_button_old
)
150 hold_button_old
= hold_button
;
151 backlight_hold_changed(hold_button
);
153 #endif /* BOOTLOADER */