2006-08-12 08:01:54 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +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.
|
2006-08-12 08:01:54 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "adc.h"
|
2007-01-07 06:56:24 +00:00
|
|
|
#include "backlight-target.h"
|
2006-08-12 08:01:54 +00:00
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
static bool headphones_detect;
|
2007-01-17 20:24:06 +00:00
|
|
|
static bool hold_button = false;
|
2006-12-29 02:49:12 +00:00
|
|
|
|
2008-05-29 21:27:44 +00:00
|
|
|
#define TOUCHPAD_SENS_NORMAL ((1 << 12) | /* right++ */ \
|
|
|
|
(1 << 7) | /* left++ */ \
|
|
|
|
(1 << 6) | /* down++*/ \
|
|
|
|
(1 << 0) | /* up++ */ \
|
|
|
|
(1 << 3)) /* center */
|
|
|
|
|
|
|
|
#define TOUCHPAD_SENS_HIGH (((1 << 12) | (1 << 11)) | /* right++, right+ */ \
|
|
|
|
((1 << 8) | (1 << 7)) | /* left+, left++ */ \
|
|
|
|
((1 << 6) | (1 << 5)) | /* down++, down+ */ \
|
|
|
|
((1 << 1) | (1 << 0)) | /* up+, up++ */ \
|
|
|
|
(1 << 3)) /* Center */
|
|
|
|
|
|
|
|
static int touchpad_mask = TOUCHPAD_SENS_NORMAL;
|
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
static int const remote_buttons[] =
|
|
|
|
{
|
2007-05-20 11:42:04 +00:00
|
|
|
BUTTON_NONE, /* Headphones connected - remote disconnected */
|
|
|
|
BUTTON_RC_PLAY,
|
|
|
|
BUTTON_RC_DSP,
|
|
|
|
BUTTON_RC_REW,
|
|
|
|
BUTTON_RC_FF,
|
|
|
|
BUTTON_RC_VOL_UP,
|
|
|
|
BUTTON_RC_VOL_DOWN,
|
|
|
|
BUTTON_NONE, /* Remote control attached - no buttons pressed */
|
|
|
|
BUTTON_NONE, /* Nothing in the headphone socket */
|
2006-12-29 02:49:12 +00:00
|
|
|
};
|
|
|
|
|
2006-08-12 08:01:54 +00:00
|
|
|
void button_init_device(void)
|
|
|
|
{
|
2008-04-23 00:08:59 +00:00
|
|
|
/* Some button inputs need the internal pullups disabled to function */
|
|
|
|
GPGUP|=0x031F;
|
|
|
|
GPJUP|=0x1FFF;
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
inline bool button_hold(void)
|
2006-08-12 08:01:54 +00:00
|
|
|
{
|
|
|
|
return (GPGDAT & (1 << 15));
|
|
|
|
}
|
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
int button_read_device(void)
|
|
|
|
{
|
|
|
|
int touchpad;
|
|
|
|
int buttons;
|
|
|
|
static int lastbutton;
|
|
|
|
unsigned short remote_adc;
|
2006-12-29 15:44:43 +00:00
|
|
|
int btn = BUTTON_NONE;
|
2007-01-17 20:24:06 +00:00
|
|
|
bool hold_button_old;
|
|
|
|
|
|
|
|
/* normal buttons */
|
|
|
|
hold_button_old = hold_button;
|
|
|
|
hold_button = button_hold();
|
|
|
|
|
|
|
|
#ifndef BOOTLOADER
|
|
|
|
/* give BL notice if HB state chaged */
|
|
|
|
if (hold_button != hold_button_old)
|
|
|
|
backlight_hold_changed(hold_button);
|
|
|
|
#endif
|
2006-12-29 02:49:12 +00:00
|
|
|
|
|
|
|
/* See header for ADC values when remote control buttons are pressed */
|
|
|
|
/* Only one button can be sensed at a time on the remote. */
|
|
|
|
/* Need to filter the remote button because the ADC is so fast */
|
|
|
|
remote_adc = adc_read(ADC_HPREMOTE);
|
2008-01-27 21:13:04 +00:00
|
|
|
|
|
|
|
if (remote_adc != ADC_READ_ERROR)
|
|
|
|
{
|
|
|
|
/* If there is nothing in the headphone socket, the ADC reads high */
|
|
|
|
if (remote_adc < 940)
|
|
|
|
headphones_detect = true;
|
|
|
|
else
|
|
|
|
headphones_detect = false;
|
|
|
|
}
|
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
btn = remote_buttons[(remote_adc + 64) / 128];
|
|
|
|
if (btn != lastbutton)
|
|
|
|
{
|
|
|
|
/* if the buttons dont agree twice in a row, then its none */
|
|
|
|
lastbutton = btn;
|
|
|
|
btn = BUTTON_NONE;
|
2007-10-07 15:02:02 +00:00
|
|
|
buttonlight_on();
|
2006-12-29 02:49:12 +00:00
|
|
|
}
|
2006-12-29 15:44:43 +00:00
|
|
|
|
|
|
|
/* Check for hold first - exit if asserted with no button pressed */
|
2007-01-17 20:24:06 +00:00
|
|
|
if (hold_button)
|
2006-12-29 15:44:43 +00:00
|
|
|
return btn;
|
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
/* the side buttons - Check before doing all of the work on each bit */
|
|
|
|
buttons = GPGDAT & 0x1F;
|
|
|
|
if (buttons)
|
|
|
|
{
|
2008-05-29 22:22:44 +00:00
|
|
|
btn |= buttons;
|
2007-10-07 15:02:02 +00:00
|
|
|
buttonlight_on();
|
2006-12-29 02:49:12 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 17:16:12 +00:00
|
|
|
/* the touchpad - only watch the lines we actually read */
|
2008-05-29 21:27:44 +00:00
|
|
|
touchpad = GPJDAT & touchpad_mask;
|
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
if (touchpad)
|
|
|
|
{
|
2008-05-17 17:16:12 +00:00
|
|
|
if (touchpad & (1 << 3))
|
|
|
|
{
|
|
|
|
btn |= BUTTON_SELECT;
|
2008-05-29 21:27:44 +00:00
|
|
|
/* Desensitize all but outer detectors and still allow a combo if
|
|
|
|
* that's really intended. */
|
|
|
|
touchpad &= TOUCHPAD_SENS_NORMAL;
|
2008-05-17 17:16:12 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 21:27:44 +00:00
|
|
|
/* Simply include all lines in checks since "touchpad" has been
|
|
|
|
* masked to desired sensitivity already - allows any mask to be
|
|
|
|
* used without changing this code. */
|
|
|
|
if (touchpad & ((1 << 2) | (1 << 1) | (1 << 0)))
|
2006-12-29 02:49:12 +00:00
|
|
|
btn |= BUTTON_UP;
|
2006-08-12 08:01:54 +00:00
|
|
|
|
2008-05-29 21:27:44 +00:00
|
|
|
if (touchpad & ((1 << 12) | (1 << 11) | (1 << 10)))
|
2006-12-29 02:49:12 +00:00
|
|
|
btn |= BUTTON_RIGHT;
|
2006-08-12 08:01:54 +00:00
|
|
|
|
2008-05-29 21:27:44 +00:00
|
|
|
if (touchpad & ((1 << 6) | (1 << 5) | (1 << 4)))
|
2006-12-29 02:49:12 +00:00
|
|
|
btn |= BUTTON_DOWN;
|
2006-08-12 08:01:54 +00:00
|
|
|
|
2008-05-29 21:27:44 +00:00
|
|
|
if (touchpad & ((1 << 9) | (1 << 8) | (1 << 7)))
|
2006-12-29 02:49:12 +00:00
|
|
|
btn |= BUTTON_LEFT;
|
2006-08-12 08:01:54 +00:00
|
|
|
|
2007-10-07 15:02:02 +00:00
|
|
|
buttonlight_on();
|
2006-12-29 02:49:12 +00:00
|
|
|
}
|
|
|
|
|
2006-08-12 08:01:54 +00:00
|
|
|
return btn;
|
|
|
|
}
|
|
|
|
|
2008-05-29 21:27:44 +00:00
|
|
|
void touchpad_set_sensitivity(int level)
|
|
|
|
{
|
|
|
|
static const int masks[] =
|
|
|
|
{
|
|
|
|
TOUCHPAD_SENS_NORMAL,
|
|
|
|
TOUCHPAD_SENS_HIGH
|
|
|
|
};
|
|
|
|
|
|
|
|
if ((unsigned)level >= ARRAYLEN(masks))
|
|
|
|
level = 0;
|
|
|
|
|
|
|
|
touchpad_mask = masks[level];
|
|
|
|
}
|
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
bool headphones_inserted(void)
|
|
|
|
{
|
|
|
|
return headphones_detect;
|
|
|
|
}
|