blob: 7c29c748611b1d71dd88b547f4f6571cc2049e24 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2008 by Thomas Martitz
* Copyright (C) 2008 by Dominik Wenger
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "config.h"
#include "system.h"
#include "kernel.h"
#include "button.h"
#include "backlight.h"
#include "dbop-as3525.h"
extern void scrollwheel(unsigned wheel_value);
#if defined(SANSA_FUZE)
#define DBOP_BIT15_BUTTON BUTTON_HOME
#endif
#ifdef SANSA_E200V2
#define DBOP_BIT15_BUTTON BUTTON_REC
#endif
/* Buttons */
static bool hold_button = false;
#ifndef BOOTLOADER
static bool hold_button_old = false;
#endif
void button_init_device(void)
{
GPIOA_DIR |= (1<<1);
GPIOA_PIN(1) = (1<<1);
}
bool button_hold(void)
{
return hold_button;
}
unsigned short button_read_dbop(void)
{
unsigned dbop_din = dbop_read_input();
#if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER)
/* scroll wheel handling */
scrollwheel((dbop_din >> 13) & (1<<1|1<<0));
#endif
return dbop_din;
}
/*
* Get button pressed from hardware
*/
int button_read_device(void)
{
#ifdef SANSA_FUZE
static unsigned power_counter = 0;
#endif
unsigned short dbop_din;
int btn = BUTTON_NONE;
dbop_din = button_read_dbop();
/* hold button handling */
hold_button = ((dbop_din & (1<<12)) != 0);
#ifndef BOOTLOADER
/* light handling */
if (hold_button != hold_button_old)
{
hold_button_old = hold_button;
backlight_hold_changed(hold_button);
}
#endif /* BOOTLOADER */
if (hold_button) {
#ifdef SANSA_FUZE
power_counter = HZ;
#endif
return 0;
}
/* push button handling */
if ((dbop_din & (1 << 2)) == 0)
btn |= BUTTON_UP;
if ((dbop_din & (1 << 3)) == 0)
btn |= BUTTON_LEFT;
if ((dbop_din & (1 << 4)) == 0)
btn |= BUTTON_SELECT;
if ((dbop_din & (1 << 5)) == 0)
btn |= BUTTON_RIGHT;
if ((dbop_din & (1 << 6)) == 0)
btn |= BUTTON_DOWN;
if ((dbop_din & (1 << 8)) != 0)
btn |= BUTTON_POWER;
if ((dbop_din & (1 << 15)) == 0)
btn |= DBOP_BIT15_BUTTON;
#ifdef SANSA_FUZE
/* read power on bit 8, but not if hold button was just released, since
* you basically always hit power due to the slider mechanism after releasing
* (fuze only)
*/
if (power_counter > 0) {
power_counter--;
btn &= ~BUTTON_POWER;
}
#endif
return btn;
}
|