Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2007 by Dave Chapman |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #include "config.h" |
| 23 | #include "cpu.h" |
| 24 | #include "button.h" |
| 25 | #include "adc.h" |
| 26 | |
| 27 | /* |
| 28 | |
| 29 | Results of button testing (viewing ADC values whilst pressing buttons): |
| 30 | |
| 31 | HOLD: GPIOB & 0x0200 (0=hold active, 0x0200 = hold inactive) |
| 32 | |
| 33 | ADC[1]: (approx values) |
| 34 | |
| 35 | Idle - 0x3ff |
| 36 | MENU - unknown |
| 37 | |
| 38 | REPEAT/AB - 0x03? |
| 39 | LEFT - 0x07?-0x08? |
| 40 | SELECT - 0x0c? |
| 41 | RIGHT - 0x11? |
| 42 | |
| 43 | PLAY/PAUSE - 0x17?-0x018? |
| 44 | VOL UP - 0x1e?-0x01f? |
| 45 | VOL DOWN - 0x26? |
| 46 | |
| 47 | */ |
| 48 | |
| 49 | void button_init_device(void) |
| 50 | { |
| 51 | /* Nothing to do */ |
| 52 | } |
| 53 | |
| 54 | int button_read_device(void) |
| 55 | { |
| 56 | int btn = BUTTON_NONE; |
| 57 | int adc; |
| 58 | |
| 59 | /* TODO - determine how to detect BUTTON_MENU - it doesn't appear to |
| 60 | be connected to a GPIO or to an ADC |
| 61 | */ |
| 62 | |
| 63 | adc = adc_read(ADC_BUTTONS); |
| 64 | |
| 65 | if (adc < 0x384) { |
| 66 | if (adc < 0x140) { |
| 67 | if (adc < 0x96) { |
| 68 | if (adc < 0x50) { |
| 69 | btn |= BUTTON_REPEATAB; /* 0x00..0x4f */ |
| 70 | } else { |
| 71 | btn |= BUTTON_LEFT; /* 0x50..0x95 */ |
| 72 | } |
| 73 | } else { |
| 74 | if (adc < 0xe0) { |
| 75 | btn |= BUTTON_SELECT; /* 0x96..0xdf */ |
| 76 | } else { |
| 77 | btn |= BUTTON_RIGHT; /* 0xe0..0x13f */ |
| 78 | } |
| 79 | } |
| 80 | } else { |
| 81 | if (adc < 0x208) { |
| 82 | if (adc < 0x1b0) { |
| 83 | btn |= BUTTON_PLAYPAUSE; /* 0x140..0x1af */ |
| 84 | } else { |
| 85 | btn |= BUTTON_VOLUP; /* 0x1b0..0x207 */ |
| 86 | } |
| 87 | } else { |
| 88 | btn |= BUTTON_VOLDOWN; /* 0x209..0x383 */ |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return btn; |
| 94 | } |
| 95 | |
| 96 | bool button_hold(void) |
| 97 | { |
| 98 | return (GPIOB & 0x200)?false:true; |
| 99 | } |