Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 by Barry Wardell |
| 11 | * |
| 12 | * All files in this archive are subject to the GNU General Public License. |
| 13 | * See the file COPYING in the source tree root for full license agreement. |
| 14 | * |
| 15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 16 | * KIND, either express or implied. |
| 17 | * |
| 18 | ****************************************************************************/ |
| 19 | |
| 20 | /* Custom written for the H10 based on analysis of the GPIO data */ |
| 21 | |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include "config.h" |
| 25 | #include "cpu.h" |
| 26 | #include "system.h" |
| 27 | #include "button.h" |
| 28 | #include "kernel.h" |
| 29 | #include "backlight.h" |
| 30 | #include "adc.h" |
| 31 | #include "system.h" |
| 32 | |
| 33 | |
| 34 | void button_init_device(void) |
| 35 | { |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 36 | /* No hardware initialisation required as it is done by the bootloader */ |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | bool button_hold(void) |
| 40 | { |
| 41 | return (GPIOA_INPUT_VAL & 0x40)?false:true; |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | * Get button pressed from hardware |
| 46 | */ |
| 47 | int button_read_device(void) |
| 48 | { |
| 49 | int btn = BUTTON_NONE; |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 50 | unsigned char state; |
| 51 | static bool hold_button = false; |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 52 | |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 53 | #if 0 |
| 54 | /* light handling */ |
| 55 | if (hold_button && !button_hold()) |
| 56 | { |
| 57 | backlight_on(); |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | hold_button = button_hold(); |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 62 | if (!hold_button) |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 63 | { |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 64 | /* Read normal buttons */ |
| 65 | state = GPIOA_INPUT_VAL & 0xf8; |
| 66 | if ((state & 0x8) == 0) btn |= BUTTON_FF; |
| 67 | if ((state & 0x10) == 0) btn |= BUTTON_PLAY; |
| 68 | if ((state & 0x20) == 0) btn |= BUTTON_REW; |
| 69 | if ((state & 0x40) == 0) btn |= BUTTON_RIGHT; |
| 70 | if ((state & 0x80) == 0) btn |= BUTTON_LEFT; |
| 71 | |
| 72 | /* Read power button */ |
| 73 | if ((GPIOB_INPUT_VAL & 0x1) == 0) btn |= BUTTON_POWER; |
| 74 | |
| 75 | /* Read scroller */ |
| 76 | if ( ((GPIOC_INPUT_VAL & 0x4)==1) && ((GPIOD_INPUT_VAL & 0x10)==1) ) |
| 77 | { |
| 78 | /* Scroller is pressed */ |
| 79 | } |
| 80 | } |
| 81 | |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 82 | return btn; |
| 83 | } |