From 0e6dd7efcd21d48665b5a799fe081a75cdcb960f Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Mon, 27 Nov 2006 02:16:32 +0000 Subject: Moved archos button reading to target tree. * Cleanup of button.[ch]. * Deactivated serial remote code for recorder FM/V2 as there is no remote pin, saving ~500 bytes of code. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11612 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/sh/archos/fm_v2/button-fm_v2.c | 97 +++++++++++++++++++++++++ firmware/target/sh/archos/fm_v2/button-target.h | 53 ++++++++++++++ 2 files changed, 150 insertions(+) create mode 100755 firmware/target/sh/archos/fm_v2/button-fm_v2.c create mode 100755 firmware/target/sh/archos/fm_v2/button-target.h (limited to 'firmware/target/sh/archos/fm_v2') diff --git a/firmware/target/sh/archos/fm_v2/button-fm_v2.c b/firmware/target/sh/archos/fm_v2/button-fm_v2.c new file mode 100755 index 0000000000..c430cf864b --- /dev/null +++ b/firmware/target/sh/archos/fm_v2/button-fm_v2.c @@ -0,0 +1,97 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Jens Arnold + * + * 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. + * + ****************************************************************************/ + +#include "config.h" +#include "system.h" +#include "button.h" +#include "backlight.h" +#include "adc.h" + +/* + Recorder FM/V2 hardware button hookup + ===================================== + + F1, F2, F3, UP: connected to AN4 through a resistor network + DOWN, PLAY, LEFT, RIGHT: likewise connected to AN5 + + The voltage on AN4/ AN5 depends on which keys (or key combo) is pressed + FM/V2 has PLAY and RIGHT switched compared to plain recorder + + ON: AN3, low active + OFF: AN2, high active +*/ + +void button_init_device(void) +{ + /* Set PB4 and PB8 as input pins */ + PBCR1 &= 0xfffc; /* PB8MD = 00 */ + PBCR2 &= 0xfcff; /* PB4MD = 00 */ + PBIOR &= ~0x0110; /* Inputs */ +} + +int button_read_device(void) +{ + int btn = BUTTON_NONE; + int data; + + /* check F1..F3 and UP */ + data = adc_read(ADC_BUTTON_ROW1); + if (data >= 150) + { + if (data >= 545) + if (data >= 700) + btn = BUTTON_F3; + else + btn = BUTTON_UP; + else + if (data >= 385) + btn = BUTTON_F2; + else + btn = BUTTON_F1; + } + + /* Some units have mushy keypads, so pressing UP also activates + the Left/Right buttons. Let's combat that by skipping the AN5 + checks when UP is pressed. */ + if(!(btn & BUTTON_UP)) + { + /* check DOWN, PLAY, LEFT, RIGHT */ + data = adc_read(ADC_BUTTON_ROW2); + if (data >= 150) + { + if (data >= 545) + if (data >= 700) + btn |= BUTTON_DOWN; + else + btn |= BUTTON_RIGHT; + else + if (data >= 385) + btn |= BUTTON_LEFT; + else + btn |= BUTTON_PLAY; + } + } + + if ( adc_read(ADC_BUTTON_ON) < 512 ) + btn |= BUTTON_ON; + if ( adc_read(ADC_BUTTON_OFF) > 512 ) + btn |= BUTTON_OFF; + + return btn; +} diff --git a/firmware/target/sh/archos/fm_v2/button-target.h b/firmware/target/sh/archos/fm_v2/button-target.h new file mode 100755 index 0000000000..3e7b7c6801 --- /dev/null +++ b/firmware/target/sh/archos/fm_v2/button-target.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Jens Arnold + * + * 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. + * + ****************************************************************************/ + +#ifndef _BUTTON_TARGET_H_ +#define _BUTTON_TARGET_H_ + +#include +#include "config.h" + +void button_init_device(void); +int button_read_device(void); + + /* Main unit's buttons */ +#define BUTTON_ON 0x00000001 +#define BUTTON_OFF 0x00000002 + +#define BUTTON_LEFT 0x00000004 +#define BUTTON_RIGHT 0x00000008 +#define BUTTON_UP 0x00000010 +#define BUTTON_DOWN 0x00000020 + +#define BUTTON_PLAY 0x00000040 + +#define BUTTON_F1 0x00000080 +#define BUTTON_F2 0x00000100 +#define BUTTON_F3 0x00000200 + +#define BUTTON_MAIN (BUTTON_ON|BUTTON_OFF|BUTTON_LEFT|BUTTON_RIGHT\ + |BUTTON_UP|BUTTON_DOWN|BUTTON_PLAY\ + |BUTTON_F1|BUTTON_F2|BUTTON_F3) + +#define BUTTON_REMOTE 0 + +#define POWEROFF_BUTTON BUTTON_OFF +#define POWEROFF_COUNT 10 + +#endif /* _BUTTON_TARGET_H_ */ -- cgit v1.2.3