2008-11-01 10:29:23 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-12-31 21:02:56 +00:00
|
|
|
* Copyright (C) 2008 by Thomas Martitz
|
|
|
|
* Copyright (C) 2008 by Dominik Wenger
|
2008-11-01 10:29:23 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-01-06 23:41:36 +00:00
|
|
|
#include "config.h"
|
2008-11-01 10:29:23 +00:00
|
|
|
#include "system.h"
|
2014-01-05 19:32:09 +00:00
|
|
|
#include "kernel.h"
|
2008-11-01 10:29:23 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "backlight.h"
|
2010-01-06 23:41:36 +00:00
|
|
|
#include "dbop-as3525.h"
|
2008-11-01 10:29:23 +00:00
|
|
|
|
2010-04-01 16:07:56 +00:00
|
|
|
extern void scrollwheel(unsigned wheel_value);
|
2009-06-22 22:24:58 +00:00
|
|
|
|
2010-04-01 16:07:56 +00:00
|
|
|
#if defined(SANSA_FUZE)
|
2009-06-22 22:24:58 +00:00
|
|
|
#define DBOP_BIT15_BUTTON BUTTON_HOME
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SANSA_E200V2
|
|
|
|
#define DBOP_BIT15_BUTTON BUTTON_REC
|
|
|
|
#endif
|
2009-06-02 01:31:16 +00:00
|
|
|
|
2008-11-01 10:29:23 +00:00
|
|
|
/* Buttons */
|
|
|
|
static bool hold_button = false;
|
2009-02-19 21:20:42 +00:00
|
|
|
#ifndef BOOTLOADER
|
2008-11-01 10:29:23 +00:00
|
|
|
static bool hold_button_old = false;
|
2009-02-19 21:20:42 +00:00
|
|
|
#endif
|
2008-11-01 10:29:23 +00:00
|
|
|
|
|
|
|
void button_init_device(void)
|
|
|
|
{
|
2010-01-03 10:19:43 +00:00
|
|
|
GPIOA_DIR |= (1<<1);
|
2009-02-19 21:20:42 +00:00
|
|
|
GPIOA_PIN(1) = (1<<1);
|
2008-12-31 21:02:56 +00:00
|
|
|
}
|
|
|
|
|
2008-11-01 10:29:23 +00:00
|
|
|
bool button_hold(void)
|
|
|
|
{
|
2008-12-31 21:02:56 +00:00
|
|
|
return hold_button;
|
2008-11-01 10:29:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 20:11:01 +00:00
|
|
|
unsigned short button_read_dbop(void)
|
2008-12-31 21:02:56 +00:00
|
|
|
{
|
2010-01-06 23:41:36 +00:00
|
|
|
unsigned dbop_din = dbop_read_input();
|
2009-04-13 10:28:06 +00:00
|
|
|
#if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER)
|
2010-01-06 23:41:36 +00:00
|
|
|
/* scroll wheel handling */
|
|
|
|
scrollwheel((dbop_din >> 13) & (1<<1|1<<0));
|
2009-04-13 10:28:06 +00:00
|
|
|
#endif
|
2010-01-06 23:41:36 +00:00
|
|
|
return dbop_din;
|
2008-12-31 21:02:56 +00:00
|
|
|
}
|
2009-02-17 02:36:48 +00:00
|
|
|
|
2008-11-01 10:29:23 +00:00
|
|
|
/*
|
|
|
|
* Get button pressed from hardware
|
|
|
|
*/
|
|
|
|
int button_read_device(void)
|
|
|
|
{
|
2009-06-22 22:24:58 +00:00
|
|
|
#ifdef SANSA_FUZE
|
2009-03-13 16:18:56 +00:00
|
|
|
static unsigned power_counter = 0;
|
2009-06-22 22:24:58 +00:00
|
|
|
#endif
|
2010-01-06 23:41:36 +00:00
|
|
|
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)
|
2009-02-19 21:20:42 +00:00
|
|
|
{
|
2010-01-06 23:41:36 +00:00
|
|
|
hold_button_old = hold_button;
|
|
|
|
backlight_hold_changed(hold_button);
|
|
|
|
}
|
|
|
|
#endif /* BOOTLOADER */
|
|
|
|
if (hold_button) {
|
2009-06-22 22:24:58 +00:00
|
|
|
#ifdef SANSA_FUZE
|
2009-03-13 16:18:56 +00:00
|
|
|
power_counter = HZ;
|
2009-06-22 22:24:58 +00:00
|
|
|
#endif
|
2010-01-06 23:41:36 +00:00
|
|
|
return 0;
|
2009-02-19 21:20:42 +00:00
|
|
|
}
|
2010-01-06 23:41:36 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2009-06-22 22:24:58 +00:00
|
|
|
#ifdef SANSA_FUZE
|
2009-02-19 21:20:42 +00:00
|
|
|
/* 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
|
2009-06-22 22:24:58 +00:00
|
|
|
* (fuze only)
|
2010-01-06 23:41:36 +00:00
|
|
|
*/
|
|
|
|
if (power_counter > 0) {
|
2009-03-13 16:18:56 +00:00
|
|
|
power_counter--;
|
2010-01-06 23:41:36 +00:00
|
|
|
btn &= ~BUTTON_POWER;
|
2009-02-19 21:20:42 +00:00
|
|
|
}
|
2010-01-06 23:41:36 +00:00
|
|
|
#endif
|
2008-11-01 10:29:23 +00:00
|
|
|
|
2009-02-19 21:20:42 +00:00
|
|
|
return btn;
|
2008-11-01 10:29:23 +00:00
|
|
|
}
|