2008-01-14 22:04:48 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 by Rob Purchase
|
|
|
|
*
|
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.
|
2008-01-14 22:04:48 +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 "button.h"
|
|
|
|
#include "adc.h"
|
2008-06-30 19:38:19 +00:00
|
|
|
#include "backlight.h"
|
2009-10-15 20:13:29 +00:00
|
|
|
#include "touchscreen-target.h"
|
|
|
|
#include <stdlib.h>
|
2008-04-27 13:30:11 +00:00
|
|
|
|
2008-01-14 22:04:48 +00:00
|
|
|
void button_init_device(void)
|
|
|
|
{
|
2008-04-27 13:30:11 +00:00
|
|
|
/* Configure GPIOA 4 (POWER) and 8 (HOLD) for input */
|
|
|
|
GPIOA_DIR &= ~0x110;
|
2009-10-08 15:47:43 +00:00
|
|
|
|
2008-04-27 13:30:11 +00:00
|
|
|
/* Configure GPIOB 4 (button pressed) for input */
|
|
|
|
GPIOB_DIR &= ~0x10;
|
|
|
|
|
2009-10-15 20:13:29 +00:00
|
|
|
touchscreen_init_device();
|
2008-01-14 22:04:48 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 15:55:19 +00:00
|
|
|
bool button_hold(void)
|
|
|
|
{
|
|
|
|
return (GPIOA & 0x8) ? false : true;
|
|
|
|
}
|
|
|
|
|
2008-04-27 13:30:11 +00:00
|
|
|
int button_read_device(int *data)
|
2008-01-14 22:04:48 +00:00
|
|
|
{
|
|
|
|
int btn = BUTTON_NONE;
|
|
|
|
int adc;
|
2009-08-14 23:08:50 +00:00
|
|
|
static int old_data = 0;
|
2009-07-22 22:59:08 +00:00
|
|
|
|
|
|
|
static bool hold_button = false;
|
|
|
|
bool hold_button_old;
|
2009-09-26 17:31:30 +00:00
|
|
|
|
2009-08-14 23:08:50 +00:00
|
|
|
*data = old_data;
|
2009-07-22 22:59:08 +00:00
|
|
|
|
|
|
|
hold_button_old = hold_button;
|
|
|
|
hold_button = button_hold();
|
|
|
|
|
|
|
|
#ifndef BOOTLOADER
|
|
|
|
if (hold_button != hold_button_old)
|
|
|
|
backlight_hold_changed(hold_button);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (hold_button)
|
|
|
|
return BUTTON_NONE;
|
2008-01-14 22:04:48 +00:00
|
|
|
|
|
|
|
if (GPIOB & 0x4)
|
|
|
|
{
|
|
|
|
adc = adc_read(ADC_BUTTONS);
|
|
|
|
|
2008-01-22 23:19:12 +00:00
|
|
|
/* The following contains some arbitrary, but working, guesswork */
|
2008-01-14 22:04:48 +00:00
|
|
|
if (adc < 0x038) {
|
|
|
|
btn |= (BUTTON_MINUS | BUTTON_PLUS | BUTTON_MENU);
|
|
|
|
} else if (adc < 0x048) {
|
|
|
|
btn |= (BUTTON_MINUS | BUTTON_PLUS);
|
|
|
|
} else if (adc < 0x058) {
|
|
|
|
btn |= (BUTTON_PLUS | BUTTON_MENU);
|
|
|
|
} else if (adc < 0x070) {
|
|
|
|
btn |= BUTTON_PLUS;
|
|
|
|
} else if (adc < 0x090) {
|
|
|
|
btn |= (BUTTON_MINUS | BUTTON_MENU);
|
|
|
|
} else if (adc < 0x150) {
|
|
|
|
btn |= BUTTON_MINUS;
|
|
|
|
} else if (adc < 0x200) {
|
|
|
|
btn |= BUTTON_MENU;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-15 20:13:29 +00:00
|
|
|
btn |= touchscreen_read_device(data, &old_data);
|
2009-10-08 15:47:43 +00:00
|
|
|
|
2008-01-14 22:04:48 +00:00
|
|
|
if (!(GPIOA & 0x4))
|
|
|
|
btn |= BUTTON_POWER;
|
2009-10-08 15:47:43 +00:00
|
|
|
|
2009-09-26 17:31:30 +00:00
|
|
|
if (btn & BUTTON_TOUCHSCREEN && !is_backlight_on(true))
|
2009-08-14 23:08:50 +00:00
|
|
|
old_data = *data = 0;
|
2009-10-08 15:47:43 +00:00
|
|
|
|
2008-01-14 22:04:48 +00:00
|
|
|
return btn;
|
|
|
|
}
|