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 | * |
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. |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +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 | /* Custom written for the H10 based on analysis of the GPIO data */ |
| 23 | |
| 24 | |
| 25 | #include <stdlib.h> |
| 26 | #include "config.h" |
| 27 | #include "cpu.h" |
| 28 | #include "system.h" |
| 29 | #include "button.h" |
| 30 | #include "kernel.h" |
| 31 | #include "backlight.h" |
| 32 | #include "adc.h" |
| 33 | #include "system.h" |
| 34 | |
| 35 | |
| 36 | void button_init_device(void) |
| 37 | { |
Barry Wardell | 0b1ae73 | 2006-09-13 23:38:16 +0000 | [diff] [blame] | 38 | /* Enable REW, FF, Play, Left, Right, Hold buttons */ |
Jens Arnold | 05784b5 | 2007-11-27 20:23:12 +0000 | [diff] [blame] | 39 | GPIO_SET_BITWISE(GPIOA_ENABLE, 0xfc); |
Barry Wardell | 0b1ae73 | 2006-09-13 23:38:16 +0000 | [diff] [blame] | 40 | |
| 41 | /* Enable POWER button */ |
Jens Arnold | 05784b5 | 2007-11-27 20:23:12 +0000 | [diff] [blame] | 42 | GPIO_SET_BITWISE(GPIOB_ENABLE, 0x01); |
Barry Wardell | 0b1ae73 | 2006-09-13 23:38:16 +0000 | [diff] [blame] | 43 | |
Barry Wardell | a27c183 | 2006-09-04 20:09:17 +0000 | [diff] [blame] | 44 | /* We need to output to pin 6 of GPIOD when reading the scroll pad value */ |
Jens Arnold | 05784b5 | 2007-11-27 20:23:12 +0000 | [diff] [blame] | 45 | GPIO_SET_BITWISE(GPIOD_ENABLE, 0x40); |
| 46 | GPIO_SET_BITWISE(GPIOD_OUTPUT_EN, 0x40); |
| 47 | GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x40); |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | bool button_hold(void) |
| 51 | { |
Barry Wardell | 8269541 | 2006-08-26 15:48:17 +0000 | [diff] [blame] | 52 | return (GPIOA_INPUT_VAL & 0x4)?false:true; |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Barry Wardell | b692fb1 | 2006-09-29 15:59:08 +0000 | [diff] [blame] | 55 | bool remote_button_hold(void) |
| 56 | { |
Barry Wardell | 1d1a17c | 2007-10-16 10:48:16 +0000 | [diff] [blame] | 57 | return adc_scan(ADC_REMOTE) < 0x2B; |
Barry Wardell | b692fb1 | 2006-09-29 15:59:08 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 60 | /* |
| 61 | * Get button pressed from hardware |
| 62 | */ |
| 63 | int button_read_device(void) |
| 64 | { |
| 65 | int btn = BUTTON_NONE; |
Barry Wardell | b692fb1 | 2006-09-29 15:59:08 +0000 | [diff] [blame] | 66 | int data; |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 67 | unsigned char state; |
| 68 | static bool hold_button = false; |
Barry Wardell | b692fb1 | 2006-09-29 15:59:08 +0000 | [diff] [blame] | 69 | static bool remote_hold_button = false; |
Barry Wardell | 0b1ae73 | 2006-09-13 23:38:16 +0000 | [diff] [blame] | 70 | bool hold_button_old; |
Barry Wardell | b692fb1 | 2006-09-29 15:59:08 +0000 | [diff] [blame] | 71 | bool remote_hold_button_old; |
Barry Wardell | 0b1ae73 | 2006-09-13 23:38:16 +0000 | [diff] [blame] | 72 | |
| 73 | /* Hold */ |
| 74 | hold_button_old = hold_button; |
| 75 | hold_button = button_hold(); |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 76 | |
Barry Wardell | 8ccedc9 | 2006-09-10 17:59:59 +0000 | [diff] [blame] | 77 | #ifndef BOOTLOADER |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 78 | /* light handling */ |
Barry Wardell | 0b1ae73 | 2006-09-13 23:38:16 +0000 | [diff] [blame] | 79 | if (hold_button != hold_button_old) |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 80 | { |
Barry Wardell | 2937c50 | 2006-09-10 13:18:33 +0000 | [diff] [blame] | 81 | backlight_hold_changed(hold_button); |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 82 | } |
Barry Wardell | 8ccedc9 | 2006-09-10 17:59:59 +0000 | [diff] [blame] | 83 | #endif |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 84 | |
Barry Wardell | b692fb1 | 2006-09-29 15:59:08 +0000 | [diff] [blame] | 85 | /* device buttons */ |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 86 | if (!hold_button) |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 87 | { |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 88 | /* Read normal buttons */ |
| 89 | state = GPIOA_INPUT_VAL & 0xf8; |
| 90 | if ((state & 0x8) == 0) btn |= BUTTON_FF; |
| 91 | if ((state & 0x10) == 0) btn |= BUTTON_PLAY; |
| 92 | if ((state & 0x20) == 0) btn |= BUTTON_REW; |
| 93 | if ((state & 0x40) == 0) btn |= BUTTON_RIGHT; |
| 94 | if ((state & 0x80) == 0) btn |= BUTTON_LEFT; |
| 95 | |
| 96 | /* Read power button */ |
Barry Wardell | 8269541 | 2006-08-26 15:48:17 +0000 | [diff] [blame] | 97 | if (GPIOB_INPUT_VAL & 0x1) btn |= BUTTON_POWER; |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 98 | |
| 99 | /* Read scroller */ |
Barry Wardell | a27c183 | 2006-09-04 20:09:17 +0000 | [diff] [blame] | 100 | if ( GPIOD_INPUT_VAL & 0x20 ) |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 101 | { |
Jens Arnold | 05784b5 | 2007-11-27 20:23:12 +0000 | [diff] [blame] | 102 | GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x40); |
Peter D'Hoye | 0d5451e | 2007-08-21 23:37:26 +0000 | [diff] [blame] | 103 | udelay(250); |
Barry Wardell | b692fb1 | 2006-09-29 15:59:08 +0000 | [diff] [blame] | 104 | data = adc_scan(ADC_SCROLLPAD); |
Jens Arnold | 05784b5 | 2007-11-27 20:23:12 +0000 | [diff] [blame] | 105 | GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x40); |
Barry Wardell | a27c183 | 2006-09-04 20:09:17 +0000 | [diff] [blame] | 106 | |
Barry Wardell | 1d1a17c | 2007-10-16 10:48:16 +0000 | [diff] [blame] | 107 | if(data < 0x224) |
Barry Wardell | a27c183 | 2006-09-04 20:09:17 +0000 | [diff] [blame] | 108 | { |
| 109 | btn |= BUTTON_SCROLL_DOWN; |
| 110 | } else { |
| 111 | btn |= BUTTON_SCROLL_UP; |
| 112 | } |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
Barry Wardell | b692fb1 | 2006-09-29 15:59:08 +0000 | [diff] [blame] | 116 | /* remote buttons */ |
| 117 | remote_hold_button_old = remote_hold_button; |
| 118 | |
| 119 | data = adc_scan(ADC_REMOTE); |
Barry Wardell | 1d1a17c | 2007-10-16 10:48:16 +0000 | [diff] [blame] | 120 | remote_hold_button = data < 0x2B; |
Barry Wardell | b692fb1 | 2006-09-29 15:59:08 +0000 | [diff] [blame] | 121 | |
| 122 | #ifndef BOOTLOADER |
| 123 | if (remote_hold_button != remote_hold_button_old) |
| 124 | backlight_hold_changed(remote_hold_button); |
| 125 | #endif |
| 126 | |
| 127 | if(!remote_hold_button) |
| 128 | { |
| 129 | if (data < 0x3FF) |
| 130 | { |
Barry Wardell | 1d1a17c | 2007-10-16 10:48:16 +0000 | [diff] [blame] | 131 | if(data < 0x204) |
| 132 | if(data < 0x155) |
Barry Wardell | b692fb1 | 2006-09-29 15:59:08 +0000 | [diff] [blame] | 133 | btn |= BUTTON_RC_FF; |
| 134 | else |
| 135 | btn |= BUTTON_RC_REW; |
| 136 | else |
Barry Wardell | 1d1a17c | 2007-10-16 10:48:16 +0000 | [diff] [blame] | 137 | if(data < 0x2D0) |
Barry Wardell | b692fb1 | 2006-09-29 15:59:08 +0000 | [diff] [blame] | 138 | btn |= BUTTON_RC_VOL_DOWN; |
| 139 | else |
| 140 | btn |= BUTTON_RC_VOL_UP; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /* remote play button should be dead if hold */ |
| 145 | if (!remote_hold_button && !(GPIOA_INPUT_VAL & 0x1)) |
| 146 | btn |= BUTTON_RC_PLAY; |
| 147 | |
Daniel Stenberg | 86bff1c | 2006-08-03 20:18:31 +0000 | [diff] [blame] | 148 | return btn; |
| 149 | } |