Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Marc Guay | b362b7f | 2008-06-21 16:07:59 +0000 | [diff] [blame] | 8 | * $Id$ |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 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. |
Marc Guay | b93667b | 2008-06-21 15:18:36 +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 | void button_init_device(void) |
| 28 | { |
| 29 | GPIOA_DIR |= 0xC; |
| 30 | } |
| 31 | |
| 32 | int button_read_device(void) |
| 33 | { |
| 34 | int btn = BUTTON_NONE; |
| 35 | |
| 36 | if (!button_hold()){ |
| 37 | GPIOA |= 0x4; |
| 38 | GPIOA &= ~0x8; |
| 39 | |
| 40 | int i=20; while (i--); |
| 41 | |
| 42 | if (GPIOA & 0x10) btn |= BUTTON_PLAYPAUSE; /* up */ |
| 43 | if (GPIOA & 0x20) btn |= BUTTON_RIGHT; |
| 44 | if (GPIOA & 0x40) btn |= BUTTON_LEFT; |
| 45 | |
| 46 | GPIOA |= 0x8; |
| 47 | GPIOA &= ~0x4; |
| 48 | |
| 49 | i=20; while (i--); |
| 50 | |
| 51 | if (GPIOA & 0x10) btn |= BUTTON_VOLUP; |
| 52 | if (GPIOA & 0x20) btn |= BUTTON_VOLDOWN; |
| 53 | if (GPIOA & 0x40) btn |= BUTTON_REPEATAB; /* down */ |
| 54 | |
| 55 | if (GPIOA & 0x80) btn |= BUTTON_SELECT; |
| 56 | if (GPIOA & 0x100) btn |= BUTTON_MENU; |
| 57 | } |
| 58 | return btn; |
| 59 | } |
| 60 | |
| 61 | bool button_hold(void) |
| 62 | { |
| 63 | return (GPIOA & 0x2); |
| 64 | } |