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/SOURCES | 4 + firmware/drivers/button.c | 234 +-------------------- firmware/drivers/serial.c | 27 ++- firmware/export/button.h | 127 +---------- firmware/target/coldfire/iriver/button-target.h | 1 + firmware/target/sh/archos/fm_v2/button-fm_v2.c | 97 +++++++++ firmware/target/sh/archos/fm_v2/button-target.h | 53 +++++ firmware/target/sh/archos/ondio/button-ondio.c | 65 ++++++ firmware/target/sh/archos/ondio/button-target.h | 45 ++++ firmware/target/sh/archos/player/button-player.c | 74 +++++++ firmware/target/sh/archos/player/button-target.h | 56 +++++ .../target/sh/archos/recorder/button-recorder.c | 108 ++++++++++ firmware/target/sh/archos/recorder/button-target.h | 63 ++++++ 13 files changed, 593 insertions(+), 361 deletions(-) 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 create mode 100755 firmware/target/sh/archos/ondio/button-ondio.c create mode 100755 firmware/target/sh/archos/ondio/button-target.h create mode 100755 firmware/target/sh/archos/player/button-player.c create mode 100755 firmware/target/sh/archos/player/button-target.h create mode 100755 firmware/target/sh/archos/recorder/button-recorder.c create mode 100755 firmware/target/sh/archos/recorder/button-target.h (limited to 'firmware') diff --git a/firmware/SOURCES b/firmware/SOURCES index a6d29841ea..6bc9df231b 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -281,6 +281,7 @@ drivers/i2c.c #ifdef ARCHOS_PLAYER #ifndef SIMULATOR +target/sh/archos/player/button-player.c target/sh/archos/player/lcd-as-player.S #endif /* SIMULATOR */ #endif /* ARCHOS_PLAYER */ @@ -289,6 +290,7 @@ target/sh/archos/player/lcd-as-player.S #ifndef SIMULATOR target/sh/archos/lcd-archos-bitmap.c target/sh/archos/lcd-as-archos-bitmap.S +target/sh/archos/recorder/button-recorder.c #endif /* SIMULATOR */ #endif /* ARCHOS_RECORDER */ @@ -296,6 +298,7 @@ target/sh/archos/lcd-as-archos-bitmap.S #ifndef SIMULATOR target/sh/archos/lcd-archos-bitmap.c target/sh/archos/lcd-as-archos-bitmap.S +target/sh/archos/fm_v2/button-fm_v2.c #endif /* SIMULATOR */ #endif /* ARCHOS_FMRECORDER || ARCHOS_RECORDERV2 */ @@ -303,6 +306,7 @@ target/sh/archos/lcd-as-archos-bitmap.S #ifndef SIMULATOR target/sh/archos/lcd-archos-bitmap.c target/sh/archos/lcd-as-archos-bitmap.S +target/sh/archos/ondio/button-ondio.c #endif /* SIMULATOR */ #endif /* ARCHOS_ONDIOFM || ARCHOS_ONDIOFM */ diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 01b9174dae..deaf7f2fdd 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -9,12 +9,6 @@ * * 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. * @@ -29,25 +23,19 @@ #include #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" +#include "button-target.h" #ifdef HAVE_REMOTE_LCD #include "lcd-remote.h" #endif -#ifdef TARGET_TREE -#include "button-target.h" -#endif - struct event_queue button_queue; static long lastbtn; /* Last valid button status */ @@ -60,6 +48,9 @@ static bool filter_first_keypress; #ifdef HAVE_REMOTE_LCD static bool remote_filter_first_keypress; #endif +#endif /* CONFIG_BACKLIGHT */ +#ifdef HAVE_HEADPHONE_DETECTION +bool phones_present = false; #endif /* how long until repeat kicks in, in ticks */ @@ -71,18 +62,8 @@ static bool remote_filter_first_keypress; /* speed repeat finishes at, in ticks */ #define REPEAT_INTERVAL_FINISH 5 -/* the power-off button and number of repeated keys before shutting off */ -#if !defined(TARGET_TREE) -#define POWEROFF_BUTTON BUTTON_OFF -#define POWEROFF_COUNT 10 -#endif - static int button_read(void); -#ifdef HAVE_HEADPHONE_DETECTION -bool phones_present = false; -#endif - static void button_tick(void) { static int count = 0; @@ -99,8 +80,7 @@ static void button_tick(void) int diff; int btn; -#if (CONFIG_KEYPAD == PLAYER_PAD) || (CONFIG_KEYPAD == RECORDER_PAD) - +#ifdef HAS_SERIAL_REMOTE /* Post events for the remote control */ btn = remote_control_rx(); if(btn) @@ -180,9 +160,7 @@ static void button_tick(void) key */ #ifdef HAVE_SW_POWEROFF if ((btn == POWEROFF_BUTTON -#ifdef BUTTON_RC_STOP - || btn == BUTTON_RC_STOP -#elif defined(RC_POWEROFF_BUTTON) +#ifdef RC_POWEROFF_BUTTON || btn == RC_POWEROFF_BUTTON #endif ) && @@ -299,22 +277,8 @@ long button_get_w_tmo(int ticks) void button_init(void) { /* hardware inits */ -#ifdef TARGET_TREE button_init_device(); - -#elif CONFIG_KEYPAD == RECORDER_PAD - /* Set PB4 and PB8 as input pins */ - PBCR1 &= 0xfffc; /* PB8MD = 00 */ - PBCR2 &= 0xfcff; /* PB4MD = 00 */ - PBIOR &= ~0x0110; /* Inputs */ -#elif CONFIG_KEYPAD == PLAYER_PAD - /* set PA5 and PA11 as input pins */ - PACR1 &= 0xff3f; /* PA11MD = 00 */ - PACR2 &= 0xfbff; /* PA5MD = 0 */ - PAIOR &= ~0x0820; /* Inputs */ -#elif CONFIG_KEYPAD == ONDIO_PAD - /* nothing to initialize here */ -#endif /* CONFIG_KEYPAD */ + queue_init(&button_queue, true); button_read(); lastbtn = button_read(); @@ -409,195 +373,13 @@ void set_remote_backlight_filter_keypress(bool value) #endif #endif -/* - Archos hardware button hookup - ============================= - - Recorder / Recorder FM/V2 - ------------------------- - 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: PB8, low active (plain recorder) / AN3, low active (fm/v2) - OFF: PB4, low active (plain recorder) / AN2, high active (fm/v2) - - Player - ------ - LEFT: AN0 - MENU: AN1 - RIGHT: AN2 - PLAY: AN3 - - STOP: PA11 - ON: PA5 - - All buttons are low active - - Ondio - ----- - LEFT, RIGHT, UP, DOWN: connected to AN4 through a resistor network - - The voltage on AN4 depends on which keys (or key combo) is pressed - - OPTION: AN2, high active (assigned as MENU) - ON/OFF: AN3, low active (assigned as OFF) - -*/ - -#if CONFIG_KEYPAD == RECORDER_PAD - -#ifdef HAVE_FMADC -/* FM Recorder super-special levels */ -#define LEVEL1 150 -#define LEVEL2 385 -#define LEVEL3 545 -#define LEVEL4 700 -#define ROW2_BUTTON1 BUTTON_PLAY -#define ROW2_BUTTON3 BUTTON_RIGHT - -#else -/* plain bog standard Recorder levels */ -#define LEVEL1 250 -#define LEVEL2 500 -#define LEVEL3 700 -#define LEVEL4 900 -#define ROW2_BUTTON1 BUTTON_RIGHT -#define ROW2_BUTTON3 BUTTON_PLAY -#endif /* HAVE_FMADC */ - -#elif CONFIG_KEYPAD == ONDIO_PAD -/* Ondio levels */ -#define LEVEL1 165 -#define LEVEL2 415 -#define LEVEL3 585 -#define LEVEL4 755 - -#endif /* CONFIG_KEYPAD */ - /* * Get button pressed from hardware */ static int button_read(void) { - int btn = BUTTON_NONE; + int btn = button_read_device(); int retval; -#ifndef TARGET_TREE - int data; -#endif - -#ifdef TARGET_TREE - btn = button_read_device(); - -#elif CONFIG_KEYPAD == RECORDER_PAD -#ifndef HAVE_FMADC - static int off_button_count = 0; -#endif - - /* check F1..F3 and UP */ - data = adc_read(ADC_BUTTON_ROW1); - if (data >= LEVEL1) - { - if (data >= LEVEL3) - if (data >= LEVEL4) - btn = BUTTON_F3; - else - btn = BUTTON_UP; - else - if (data >= LEVEL2) - 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 >= LEVEL1) - { - if (data >= LEVEL3) - if (data >= LEVEL4) - btn |= BUTTON_DOWN; - else - btn |= ROW2_BUTTON3; - else - if (data >= LEVEL2) - btn |= BUTTON_LEFT; - else - btn |= ROW2_BUTTON1; - } - } - -#ifdef HAVE_FMADC - if ( adc_read(ADC_BUTTON_ON) < 512 ) - btn |= BUTTON_ON; - if ( adc_read(ADC_BUTTON_OFF) > 512 ) - btn |= BUTTON_OFF; -#else - /* check port B pins for ON and OFF */ - data = PBDR; - if ((data & 0x0100) == 0) - btn |= BUTTON_ON; - - if ((data & 0x0010) == 0) - { - /* When the batteries are low, the low-battery shutdown logic causes - * spurious OFF events due to voltage fluctuation on some units. - * Only accept OFF when read several times in sequence. */ - if (++off_button_count > 3) - btn |= BUTTON_OFF; - } - else - off_button_count = 0; -#endif - -#elif CONFIG_KEYPAD == PLAYER_PAD - /* buttons are active low */ - if (adc_read(0) < 0x180) - btn = BUTTON_LEFT; - if (adc_read(1) < 0x180) - btn |= BUTTON_MENU; - if(adc_read(2) < 0x180) - btn |= BUTTON_RIGHT; - if(adc_read(3) < 0x180) - btn |= BUTTON_PLAY; - - /* check port A pins for ON and STOP */ - data = PADR; - if ( !(data & 0x0020) ) - btn |= BUTTON_ON; - if ( !(data & 0x0800) ) - btn |= BUTTON_STOP; - -#elif CONFIG_KEYPAD == ONDIO_PAD - /* Check the 4 direction keys */ - data = adc_read(ADC_BUTTON_ROW1); - if (data >= LEVEL1) - { - if (data >= LEVEL3) - if (data >= LEVEL4) - btn = BUTTON_LEFT; - else - btn = BUTTON_RIGHT; - else - if (data >= LEVEL2) - btn = BUTTON_UP; - else - btn = BUTTON_DOWN; - } - - if(adc_read(ADC_BUTTON_OPTION) > 0x200) /* active high */ - btn |= BUTTON_MENU; - if(adc_read(ADC_BUTTON_ONOFF) < 0x120) /* active low */ - btn |= BUTTON_OFF; - -#endif /* CONFIG_KEYPAD */ #ifdef HAVE_LCD_BITMAP if (btn && flipped) diff --git a/firmware/drivers/serial.c b/firmware/drivers/serial.c index 866d7616ed..142f67e609 100644 --- a/firmware/drivers/serial.c +++ b/firmware/drivers/serial.c @@ -33,7 +33,8 @@ /* FIX: this doesn't work on iRiver or iPod yet */ /* iFP7xx has no remote */ -#ifndef HAVE_MMC /* MMC takes serial port 1, so don't mess with it */ +#if !defined(HAVE_FMADC) /* Recorder FM/V2 has no remote control pin */ \ + && !defined(HAVE_MMC) /* MMC takes serial port 1, so don't mess with it */ /* Received byte identifiers */ #define PLAY 0xC1 @@ -51,8 +52,8 @@ void serial_setup (void) SMR1 = 0x00; SCR1 = 0; BRR1 = (FREQ/(32*9600))-1; - SSR1 &= 0; /* The status bits must be read before they are cleared, - so we do an AND operation */ + and_b(0, &SSR1); /* The status bits must be read before they are cleared, + so we do an AND operation */ /* Let the hardware settle. The serial port needs to wait "at least the interval required to transmit or receive one bit" before it @@ -75,7 +76,7 @@ int remote_control_rx(void) /* Errors? Just clear'em. The receiver stops if we don't */ if(SSR1 & (SCI_ORER | SCI_FER | SCI_PER)) { - SSR1 &= ~(SCI_ORER | SCI_FER | SCI_PER); + and_b(~(SCI_ORER | SCI_FER | SCI_PER), &SSR1); last_valid_button = BUTTON_NONE; last_was_error = true; return BUTTON_NONE; @@ -84,7 +85,7 @@ int remote_control_rx(void) if(SSR1 & SCI_RDRF) { /* Read byte and clear the Rx Full bit */ btn = RDR1; - SSR1 &= ~SCI_RDRF; + and_b(~SCI_RDRF, &SSR1); if(last_was_error) { @@ -93,38 +94,36 @@ int remote_control_rx(void) } else { -#if CONFIG_KEYPAD != ONDIO_PAD switch (btn) { case STOP: last_valid_button = BUTTON_RC_STOP; break; - + case PLAY: last_valid_button = BUTTON_RC_PLAY; break; - + case VOLUP: last_valid_button = BUTTON_RC_VOL_UP; break; - + case VOLDN: last_valid_button = BUTTON_RC_VOL_DOWN; break; - + case PREV: last_valid_button = BUTTON_RC_LEFT; break; - + case NEXT: last_valid_button = BUTTON_RC_RIGHT; break; - + default: last_valid_button = BUTTON_NONE; break; } -#endif } } else @@ -142,7 +141,7 @@ int remote_control_rx(void) return ret; } -#endif /* HAVE_MMC */ +#endif /* !HAVE_FMADC && !HAVE_MMC */ #elif defined(CPU_COLDFIRE) && defined(HAVE_SERIAL) void serial_tx(const unsigned char *buf) diff --git a/firmware/export/button.h b/firmware/export/button.h index 9c0fe639a6..102d542d27 100644 --- a/firmware/export/button.h +++ b/firmware/export/button.h @@ -22,11 +22,8 @@ #include #include "config.h" -#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ - (CONFIG_KEYPAD == IRIVER_H300_PAD) -#define HAS_BUTTON_HOLD -#define HAS_REMOTE_BUTTON_HOLD -#endif +#include "button-target.h" + extern struct event_queue button_queue; void button_init (void); @@ -44,12 +41,6 @@ void set_remote_backlight_filter_keypress(bool value); #endif #endif -#ifdef HAS_BUTTON_HOLD -bool button_hold(void); -#endif -#ifdef HAS_REMOTE_BUTTON_HOLD -bool remote_button_hold(void); -#endif #ifdef HAVE_HEADPHONE_DETECTION bool headphones_inserted(void); #endif @@ -58,116 +49,10 @@ int wheel_status(void); void wheel_send_events(bool send); #endif -#define BUTTON_NONE 0x00000000 - - /* Button modifiers */ -#define BUTTON_REL 0x02000000 -#define BUTTON_REPEAT 0x04000000 - - -#ifdef TARGET_TREE -#include "button-target.h" -#else - - /* Target specific button codes */ -#if CONFIG_KEYPAD == RECORDER_PAD - - /* Recorder specific button codes */ - - /* 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) - - /* Remote control's buttons */ -#define BUTTON_RC_PLAY 0x00100000 -#define BUTTON_RC_STOP 0x00080000 - -#define BUTTON_RC_LEFT 0x00040000 -#define BUTTON_RC_RIGHT 0x00020000 -#define BUTTON_RC_VOL_UP 0x00010000 -#define BUTTON_RC_VOL_DOWN 0x00008000 - -#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_STOP\ - |BUTTON_RC_LEFT|BUTTON_RC_RIGHT\ - |BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN) - -#elif CONFIG_KEYPAD == PLAYER_PAD +#define BUTTON_NONE 0x00000000 - /* Main unit's buttons */ -#define BUTTON_ON 0x00000001 -#define BUTTON_STOP 0x00000002 - -#define BUTTON_LEFT 0x00000004 -#define BUTTON_RIGHT 0x00000008 -#define BUTTON_PLAY 0x00000010 -#define BUTTON_MENU 0x00000020 - -#define BUTTON_MAIN (BUTTON_ON|BUTTON_STOP|BUTTON_LEFT|BUTTON_RIGHT\ - |BUTTON_PLAY|BUTTON_MENU) - - /* Remote control's buttons */ -#define BUTTON_RC_PLAY 0x00100000 -#define BUTTON_RC_STOP 0x00080000 - -#define BUTTON_RC_LEFT 0x00040000 -#define BUTTON_RC_RIGHT 0x00020000 -#define BUTTON_RC_VOL_UP 0x00010000 -#define BUTTON_RC_VOL_DOWN 0x00008000 - -#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_STOP\ - |BUTTON_RC_LEFT|BUTTON_RC_RIGHT\ - |BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN) - - -#elif CONFIG_KEYPAD == ONDIO_PAD - - /* Ondio specific button codes */ - -#define BUTTON_OFF 0x00000001 -#define BUTTON_MENU 0x00000002 - -#define BUTTON_LEFT 0x00000004 -#define BUTTON_RIGHT 0x00000008 -#define BUTTON_UP 0x00000010 -#define BUTTON_DOWN 0x00000020 - -#define BUTTON_MAIN (BUTTON_OFF|BUTTON_MENU|BUTTON_LEFT|BUTTON_RIGHT\ - |BUTTON_UP|BUTTON_DOWN) - -#define BUTTON_REMOTE 0 - -#elif 0 - -/* - * Please, add the next Rockbox target's button defines here, - * using: - * - bits 0 and up: for main unit's buttons - * - bits 20 (0x00100000) and downwards for the remote buttons (if applicable) - * Don't forget to add BUTTON_MAIN and BUTTON_REMOTE masks - * Currently, main buttons on all targets are up to bit 9 (0x00000200), - * and remote buttons are down to bit 10 (0x00000400) - */ - - - -#endif /* RECORDER/PLAYER/ONDIO KEYPAD */ - -#endif /* TARGET_TREE */ +/* Button modifiers */ +#define BUTTON_REL 0x02000000 +#define BUTTON_REPEAT 0x04000000 #endif /* _BUTTON_H_ */ - diff --git a/firmware/target/coldfire/iriver/button-target.h b/firmware/target/coldfire/iriver/button-target.h index 3d3247ab80..1702706ce4 100644 --- a/firmware/target/coldfire/iriver/button-target.h +++ b/firmware/target/coldfire/iriver/button-target.h @@ -80,6 +80,7 @@ bool button_scan_enabled(void); |BUTTON_RC_SOURCE) #define POWEROFF_BUTTON BUTTON_OFF +#define RC_POWEROFF_BUTTON BUTTON_RC_STOP #define POWEROFF_COUNT 10 #endif /* _BUTTON_TARGET_H_ */ 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_ */ diff --git a/firmware/target/sh/archos/ondio/button-ondio.c b/firmware/target/sh/archos/ondio/button-ondio.c new file mode 100755 index 0000000000..c8797f743d --- /dev/null +++ b/firmware/target/sh/archos/ondio/button-ondio.c @@ -0,0 +1,65 @@ +/*************************************************************************** + * __________ __ ___. + * 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" + +/* + Ondio hardware button hookup + ============================ + + LEFT, RIGHT, UP, DOWN: connected to AN4 through a resistor network + + The voltage on AN4 depends on which keys (or key combo) is pressed + + OPTION: AN2, high active (assigned as MENU) + ON/OFF: AN3, low active (assigned as OFF) +*/ + +int button_read_device(void) +{ + int btn = BUTTON_NONE; + int data; + + /* Check the 4 direction keys */ + data = adc_read(ADC_BUTTON_ROW1); + if (data >= 165) + { + if (data >= 585) + if (data >= 755) + btn = BUTTON_LEFT; + else + btn = BUTTON_RIGHT; + else + if (data >= 415) + btn = BUTTON_UP; + else + btn = BUTTON_DOWN; + } + + if(adc_read(ADC_BUTTON_OPTION) > 0x200) /* active high */ + btn |= BUTTON_MENU; + if(adc_read(ADC_BUTTON_ONOFF) < 0x120) /* active low */ + btn |= BUTTON_OFF; + + return btn; +} diff --git a/firmware/target/sh/archos/ondio/button-target.h b/firmware/target/sh/archos/ondio/button-target.h new file mode 100755 index 0000000000..8cb24b92b0 --- /dev/null +++ b/firmware/target/sh/archos/ondio/button-target.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * __________ __ ___. + * 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" + +#define button_init_device() +int button_read_device(void); + +#define BUTTON_OFF 0x00000001 +#define BUTTON_MENU 0x00000002 + +#define BUTTON_LEFT 0x00000004 +#define BUTTON_RIGHT 0x00000008 +#define BUTTON_UP 0x00000010 +#define BUTTON_DOWN 0x00000020 + +#define BUTTON_MAIN (BUTTON_OFF|BUTTON_MENU|BUTTON_LEFT|BUTTON_RIGHT\ + |BUTTON_UP|BUTTON_DOWN) + +#define BUTTON_REMOTE 0 + +#define POWEROFF_BUTTON BUTTON_OFF +#define POWEROFF_COUNT 10 + +#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/sh/archos/player/button-player.c b/firmware/target/sh/archos/player/button-player.c new file mode 100755 index 0000000000..fbc940f7de --- /dev/null +++ b/firmware/target/sh/archos/player/button-player.c @@ -0,0 +1,74 @@ +/*************************************************************************** + * __________ __ ___. + * 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" + +/* + Player hardware button hookup + ============================= + + Player + ------ + LEFT: AN0 + MENU: AN1 + RIGHT: AN2 + PLAY: AN3 + + STOP: PA11 + ON: PA5 + + All buttons are low active +*/ + +void button_init_device(void) +{ + /* set PA5 and PA11 as input pins */ + PACR1 &= 0xff3f; /* PA11MD = 00 */ + PACR2 &= 0xfbff; /* PA5MD = 0 */ + PAIOR &= ~0x0820; /* Inputs */ +} + +int button_read_device(void) +{ + int btn = BUTTON_NONE; + int data; + + /* buttons are active low */ + if (adc_read(0) < 0x180) + btn = BUTTON_LEFT; + if (adc_read(1) < 0x180) + btn |= BUTTON_MENU; + if (adc_read(2) < 0x180) + btn |= BUTTON_RIGHT; + if (adc_read(3) < 0x180) + btn |= BUTTON_PLAY; + + /* check port A pins for ON and STOP */ + data = PADR; + if ( !(data & 0x0020) ) + btn |= BUTTON_ON; + if ( !(data & 0x0800) ) + btn |= BUTTON_STOP; + + return btn; +} diff --git a/firmware/target/sh/archos/player/button-target.h b/firmware/target/sh/archos/player/button-target.h new file mode 100755 index 0000000000..c1e0e6646b --- /dev/null +++ b/firmware/target/sh/archos/player/button-target.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * __________ __ ___. + * 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" + +#define HAS_SERIAL_REMOTE + +void button_init_device(void); +int button_read_device(void); + + /* Main unit's buttons */ +#define BUTTON_ON 0x00000001 +#define BUTTON_STOP 0x00000002 + +#define BUTTON_LEFT 0x00000004 +#define BUTTON_RIGHT 0x00000008 +#define BUTTON_PLAY 0x00000010 +#define BUTTON_MENU 0x00000020 + +#define BUTTON_MAIN (BUTTON_ON|BUTTON_STOP|BUTTON_LEFT|BUTTON_RIGHT\ + |BUTTON_PLAY|BUTTON_MENU) + + /* Remote control's buttons */ +#define BUTTON_RC_PLAY 0x00100000 +#define BUTTON_RC_STOP 0x00080000 + +#define BUTTON_RC_LEFT 0x00040000 +#define BUTTON_RC_RIGHT 0x00020000 +#define BUTTON_RC_VOL_UP 0x00010000 +#define BUTTON_RC_VOL_DOWN 0x00008000 + +#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_STOP\ + |BUTTON_RC_LEFT|BUTTON_RC_RIGHT\ + |BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN) + +#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/sh/archos/recorder/button-recorder.c b/firmware/target/sh/archos/recorder/button-recorder.c new file mode 100755 index 0000000000..dc43cce0e0 --- /dev/null +++ b/firmware/target/sh/archos/recorder/button-recorder.c @@ -0,0 +1,108 @@ +/*************************************************************************** + * __________ __ ___. + * 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 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 + + ON: PB8, low active + OFF: PB4, low 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; + static int off_button_count = 0; + + /* check F1..F3 and UP */ + data = adc_read(ADC_BUTTON_ROW1); + if (data >= 250) + { + if (data >= 700) + if (data >= 900) + btn = BUTTON_F3; + else + btn = BUTTON_UP; + else + if (data >= 500) + 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 >= 250) + { + if (data >= 700) + if (data >= 900) + btn |= BUTTON_DOWN; + else + btn |= BUTTON_PLAY; + else + if (data >= 500) + btn |= BUTTON_LEFT; + else + btn |= BUTTON_RIGHT; + } + } + + /* check port B pins for ON and OFF */ + data = PBDR; + if ((data & 0x0100) == 0) + btn |= BUTTON_ON; + + if ((data & 0x0010) == 0) + { + /* When the batteries are low, the low-battery shutdown logic causes + * spurious OFF events due to voltage fluctuation on some units. + * Only accept OFF when read several times in sequence. */ + if (++off_button_count > 3) + btn |= BUTTON_OFF; + } + else + off_button_count = 0; + + return btn; +} diff --git a/firmware/target/sh/archos/recorder/button-target.h b/firmware/target/sh/archos/recorder/button-target.h new file mode 100755 index 0000000000..77665c0ad5 --- /dev/null +++ b/firmware/target/sh/archos/recorder/button-target.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * __________ __ ___. + * 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" + +#define HAS_SERIAL_REMOTE + +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) + + /* Remote control's buttons */ +#define BUTTON_RC_PLAY 0x00100000 +#define BUTTON_RC_STOP 0x00080000 + +#define BUTTON_RC_LEFT 0x00040000 +#define BUTTON_RC_RIGHT 0x00020000 +#define BUTTON_RC_VOL_UP 0x00010000 +#define BUTTON_RC_VOL_DOWN 0x00008000 + +#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_STOP\ + |BUTTON_RC_LEFT|BUTTON_RC_RIGHT\ + |BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN) + +#endif /* _BUTTON_TARGET_H_ */ -- cgit v1.2.3