2006-10-05 10:58:51 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Daniel Stenberg
|
|
|
|
*
|
|
|
|
* iPod driver based on code from the ipodlinux project - http://ipodlinux.org
|
|
|
|
* Adapted for Rockbox in December 2005
|
|
|
|
* Original file: linux/arch/armnommu/mach-ipod/keyboard.c
|
|
|
|
* Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rockbox button functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "adc.h"
|
|
|
|
#include "serial.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "powermgmt.h"
|
2007-08-15 17:53:23 +00:00
|
|
|
#include "hwcompat.h"
|
2006-10-05 10:58:51 +00:00
|
|
|
|
2007-08-18 09:47:19 +00:00
|
|
|
static int int_btn = BUTTON_NONE;
|
|
|
|
#ifdef IPOD_1G2G
|
|
|
|
/* The 1st Gen wheel draws ~12mA when enabled permanently. Therefore
|
|
|
|
* we only enable it for a very short time to check for changes every
|
|
|
|
* tick, and only keep it enabled if there is activity. */
|
|
|
|
#define WHEEL_TIMEOUT (HZ/4)
|
|
|
|
static int wheel_timeout = 0;
|
|
|
|
#endif
|
2007-07-29 08:03:21 +00:00
|
|
|
|
2006-10-05 10:58:51 +00:00
|
|
|
/* iPod 3G and mini 1G, mini 2G uses iPod 4G code */
|
|
|
|
void handle_scroll_wheel(int new_scroll, int was_hold, int reverse)
|
|
|
|
{
|
|
|
|
int wheel_keycode = BUTTON_NONE;
|
|
|
|
static int prev_scroll = -1;
|
|
|
|
static int direction = 0;
|
|
|
|
static int count = 0;
|
|
|
|
static int scroll_state[4][4] = {
|
|
|
|
{0, 1, -1, 0},
|
|
|
|
{-1, 0, 0, 1},
|
|
|
|
{1, 0, 0, -1},
|
|
|
|
{0, -1, 1, 0}
|
|
|
|
};
|
2007-08-18 09:47:19 +00:00
|
|
|
|
|
|
|
#ifdef IPOD_1G2G
|
|
|
|
wheel_timeout = WHEEL_TIMEOUT;
|
|
|
|
#endif
|
2006-10-05 10:58:51 +00:00
|
|
|
|
|
|
|
if ( prev_scroll == -1 ) {
|
|
|
|
prev_scroll = new_scroll;
|
|
|
|
}
|
|
|
|
else if (direction != scroll_state[prev_scroll][new_scroll]) {
|
|
|
|
direction = scroll_state[prev_scroll][new_scroll];
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
else if (!was_hold) {
|
|
|
|
backlight_on();
|
2007-01-19 07:33:23 +00:00
|
|
|
reset_poweroff_timer();
|
2006-10-05 10:58:51 +00:00
|
|
|
if (++count == 6) { /* reduce sensitivity */
|
|
|
|
count = 0;
|
|
|
|
switch (direction) {
|
|
|
|
case 1:
|
|
|
|
if (reverse) {
|
|
|
|
/* 'r' keypress */
|
|
|
|
wheel_keycode = BUTTON_SCROLL_FWD;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* 'l' keypress */
|
|
|
|
wheel_keycode = BUTTON_SCROLL_BACK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
if (reverse) {
|
|
|
|
/* 'l' keypress */
|
|
|
|
wheel_keycode = BUTTON_SCROLL_BACK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* 'r' keypress */
|
|
|
|
wheel_keycode = BUTTON_SCROLL_FWD;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* only happens if we get out of sync */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wheel_keycode != BUTTON_NONE && queue_empty(&button_queue))
|
2006-12-19 16:50:07 +00:00
|
|
|
queue_post(&button_queue, wheel_keycode, 0);
|
2006-10-05 10:58:51 +00:00
|
|
|
prev_scroll = new_scroll;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipod_3g_button_read(void)
|
|
|
|
{
|
|
|
|
unsigned char source, state;
|
2007-07-29 08:03:21 +00:00
|
|
|
static bool was_hold = false;
|
2006-10-05 10:58:51 +00:00
|
|
|
int btn = BUTTON_NONE;
|
2007-07-27 09:57:27 +00:00
|
|
|
|
|
|
|
#ifdef IPOD_3G
|
2007-07-29 08:03:21 +00:00
|
|
|
/* The following delay was 250 in the ipodlinux source,
|
|
|
|
* but 50 seems to work fine. 250 causes the wheel to stop
|
|
|
|
* working when spinning it real fast. */
|
|
|
|
udelay(50);
|
2007-07-27 09:57:27 +00:00
|
|
|
#endif
|
2006-10-05 10:58:51 +00:00
|
|
|
|
|
|
|
/* get source of interupts */
|
|
|
|
source = GPIOA_INT_STAT;
|
2007-07-29 08:03:21 +00:00
|
|
|
|
2006-10-05 10:58:51 +00:00
|
|
|
/* get current keypad status */
|
|
|
|
state = GPIOA_INPUT_VAL;
|
2007-07-29 08:03:21 +00:00
|
|
|
|
|
|
|
/* toggle interrupt level */
|
2006-10-05 10:58:51 +00:00
|
|
|
GPIOA_INT_LEV = ~state;
|
|
|
|
|
2007-07-27 09:57:27 +00:00
|
|
|
#ifdef IPOD_3G
|
2006-10-05 10:58:51 +00:00
|
|
|
if (was_hold && source == 0x40 && state == 0xbf) {
|
|
|
|
/* ack any active interrupts */
|
|
|
|
GPIOA_INT_CLR = source;
|
|
|
|
return BUTTON_NONE;
|
|
|
|
}
|
2007-07-29 08:03:21 +00:00
|
|
|
was_hold = false;
|
2006-10-05 10:58:51 +00:00
|
|
|
|
|
|
|
if ((state & 0x20) == 0) {
|
|
|
|
/* 3g hold switch is active low */
|
2007-07-29 08:03:21 +00:00
|
|
|
was_hold = true;
|
2006-10-05 10:58:51 +00:00
|
|
|
/* hold switch on 3g causes all outputs to go low */
|
|
|
|
/* we shouldn't interpret these as key presses */
|
|
|
|
GPIOA_INT_CLR = source;
|
|
|
|
return BUTTON_NONE;
|
|
|
|
}
|
2007-07-27 09:57:27 +00:00
|
|
|
#elif defined IPOD_1G2G
|
2007-07-29 08:03:21 +00:00
|
|
|
if (state & 0x20) {
|
|
|
|
/* 1g/2g hold switch is active high */
|
|
|
|
GPIOA_INT_CLR = source;
|
|
|
|
return BUTTON_NONE;
|
|
|
|
}
|
2007-07-27 09:57:27 +00:00
|
|
|
#endif
|
2006-10-05 10:58:51 +00:00
|
|
|
if ((state & 0x1) == 0) {
|
|
|
|
btn |= BUTTON_RIGHT;
|
|
|
|
}
|
|
|
|
if ((state & 0x2) == 0) {
|
|
|
|
btn |= BUTTON_SELECT;
|
|
|
|
}
|
|
|
|
if ((state & 0x4) == 0) {
|
|
|
|
btn |= BUTTON_PLAY;
|
|
|
|
}
|
|
|
|
if ((state & 0x8) == 0) {
|
|
|
|
btn |= BUTTON_LEFT;
|
|
|
|
}
|
|
|
|
if ((state & 0x10) == 0) {
|
|
|
|
btn |= BUTTON_MENU;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source & 0xc0) {
|
|
|
|
handle_scroll_wheel((state & 0xc0) >> 6, was_hold, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ack any active interrupts */
|
|
|
|
GPIOA_INT_CLR = source;
|
|
|
|
|
|
|
|
return btn;
|
|
|
|
}
|
|
|
|
|
2007-07-29 08:03:21 +00:00
|
|
|
void ipod_3g_button_int(void)
|
|
|
|
{
|
|
|
|
CPU_INT_CLR = GPIO_MASK;
|
|
|
|
int_btn = ipod_3g_button_read();
|
|
|
|
CPU_INT_EN = GPIO_MASK;
|
|
|
|
}
|
|
|
|
|
2006-10-05 10:58:51 +00:00
|
|
|
void button_init_device(void)
|
|
|
|
{
|
2007-07-29 08:03:21 +00:00
|
|
|
GPIOA_ENABLE = 0xff;
|
|
|
|
GPIOA_OUTPUT_EN = 0;
|
|
|
|
|
2006-10-05 10:58:51 +00:00
|
|
|
GPIOA_INT_LEV = ~GPIOA_INPUT_VAL;
|
|
|
|
GPIOA_INT_CLR = GPIOA_INT_STAT;
|
2007-07-29 08:03:21 +00:00
|
|
|
|
2007-08-15 17:53:23 +00:00
|
|
|
#ifdef IPOD_1G2G
|
|
|
|
if ((IPOD_HW_REVISION >> 16) == 1)
|
|
|
|
{ /* enable scroll wheel */
|
|
|
|
GPIOB_ENABLE |= 0x01;
|
|
|
|
GPIOB_OUTPUT_EN |= 0x01;
|
|
|
|
GPIOB_OUTPUT_VAL |= 0x01;
|
|
|
|
}
|
|
|
|
#endif
|
2006-10-05 10:58:51 +00:00
|
|
|
GPIOA_INT_EN = 0xff;
|
2007-07-29 08:03:21 +00:00
|
|
|
|
|
|
|
CPU_INT_EN = GPIO_MASK;
|
2006-10-05 10:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get button pressed from hardware
|
|
|
|
*/
|
|
|
|
int button_read_device(void)
|
|
|
|
{
|
|
|
|
static bool hold_button = false;
|
|
|
|
bool hold_button_old;
|
2007-08-18 09:47:19 +00:00
|
|
|
#ifdef IPOD_1G2G
|
|
|
|
static unsigned char last_wheel_value = 0;
|
|
|
|
unsigned char wheel_value;
|
|
|
|
|
|
|
|
if ((IPOD_HW_REVISION >> 16) == 1)
|
|
|
|
{
|
|
|
|
if (!hold_button && (wheel_timeout == 0))
|
|
|
|
{
|
|
|
|
GPIOB_OUTPUT_VAL |= 0x01; /* enable wheel */
|
|
|
|
udelay(50); /* let the voltage settle */
|
|
|
|
wheel_value = GPIOA_INPUT_VAL >> 6;
|
|
|
|
if (wheel_value != last_wheel_value)
|
|
|
|
{
|
|
|
|
last_wheel_value = wheel_value;
|
|
|
|
wheel_timeout = WHEEL_TIMEOUT; /* keep wheel enabled */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wheel_timeout)
|
|
|
|
wheel_timeout--;
|
|
|
|
else
|
|
|
|
GPIOB_OUTPUT_VAL &= ~0x01; /* disable wheel */
|
|
|
|
}
|
|
|
|
#endif
|
2006-10-05 10:58:51 +00:00
|
|
|
|
|
|
|
/* normal buttons */
|
|
|
|
hold_button_old = hold_button;
|
|
|
|
hold_button = button_hold();
|
|
|
|
|
|
|
|
if (hold_button != hold_button_old)
|
|
|
|
backlight_hold_changed(hold_button);
|
2007-08-18 09:47:19 +00:00
|
|
|
|
2007-07-29 08:03:21 +00:00
|
|
|
return int_btn;
|
2006-10-05 10:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool button_hold(void)
|
|
|
|
{
|
2007-07-27 12:05:54 +00:00
|
|
|
#ifdef IPOD_1G2G
|
|
|
|
return (GPIOA_INPUT_VAL & 0x20);
|
|
|
|
#else
|
|
|
|
return !(GPIOA_INPUT_VAL & 0x20);
|
|
|
|
#endif
|
2006-10-05 10:58:51 +00:00
|
|
|
}
|
2006-10-07 12:19:34 +00:00
|
|
|
|
|
|
|
bool headphones_inserted(void)
|
|
|
|
{
|
|
|
|
return (GPIOC_INPUT_VAL & 0x1)?true:false;
|
|
|
|
}
|