Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +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 Ankers | d282e14 | 2006-10-14 12:14:23 +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 | /* Taken from button-h10.c by Barry Wardell and reverse engineering by MrH. */ |
| 23 | |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 24 | #include "system.h" |
| 25 | #include "button.h" |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 26 | #include "backlight.h" |
Peter D'Hoye | 137ce71 | 2007-09-18 21:44:47 +0000 | [diff] [blame] | 27 | #include "powermgmt.h" |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 28 | |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 29 | #define WHEEL_REPEAT_INTERVAL 300000 |
| 30 | #define WHEEL_FAST_ON_INTERVAL 20000 |
| 31 | #define WHEEL_FAST_OFF_INTERVAL 60000 |
Linus Nielsen Feltzing | e75327b | 2007-11-19 11:05:54 +0000 | [diff] [blame] | 32 | #define WHEELCLICKS_PER_ROTATION 48 /* wheelclicks per full rotation */ |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 33 | |
| 34 | /* Clickwheel */ |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 35 | #ifndef BOOTLOADER |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 36 | static unsigned int old_wheel_value = 0; |
| 37 | static unsigned int wheel_repeat = BUTTON_NONE; |
| 38 | static unsigned int wheel_click_count = 0; |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 39 | static unsigned int wheel_delta = 0; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 40 | static int wheel_fast_mode = 0; |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 41 | static unsigned long last_wheel_usec = 0; |
| 42 | static unsigned long wheel_velocity = 0; |
| 43 | static long last_wheel_post = 0; |
| 44 | static long next_backlight_on = 0; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 45 | /* Buttons */ |
| 46 | static bool hold_button = false; |
| 47 | static bool hold_button_old = false; |
Michael Sevakis | 5c32faa | 2007-06-03 14:31:42 +0000 | [diff] [blame] | 48 | #define _button_hold() hold_button |
| 49 | #else |
| 50 | #define _button_hold() ((GPIOF_INPUT_VAL & 0x80) != 0) |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 51 | #endif /* BOOTLOADER */ |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 52 | static int int_btn = BUTTON_NONE; |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 53 | |
Michael Sevakis | ebe67b2 | 2007-06-03 15:17:01 +0000 | [diff] [blame] | 54 | void button_int(void); |
| 55 | |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 56 | void button_init_device(void) |
| 57 | { |
Barry Wardell | 331e34b | 2006-12-16 00:21:41 +0000 | [diff] [blame] | 58 | /* Enable all buttons */ |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 59 | GPIOF_OUTPUT_EN &= ~0xff; |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 60 | GPIOF_ENABLE |= 0xff; |
Michael Sevakis | 5c32faa | 2007-06-03 14:31:42 +0000 | [diff] [blame] | 61 | |
Barry Wardell | a69b53d | 2006-12-18 19:08:41 +0000 | [diff] [blame] | 62 | /* Scrollwheel light - enable control through GPIOG pin 7 and set timeout */ |
Barry Wardell | a69b53d | 2006-12-18 19:08:41 +0000 | [diff] [blame] | 63 | GPIOG_OUTPUT_EN |= 0x80; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 64 | GPIOG_ENABLE = 0x80; |
| 65 | |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 66 | #ifndef BOOTLOADER |
Michael Sevakis | ebe67b2 | 2007-06-03 15:17:01 +0000 | [diff] [blame] | 67 | /* Mask these before performing init ... because init has possibly |
| 68 | occurred before */ |
| 69 | GPIOF_INT_EN &= ~0xff; |
| 70 | GPIOH_INT_EN &= ~0xc0; |
| 71 | |
Michael Sevakis | 5c32faa | 2007-06-03 14:31:42 +0000 | [diff] [blame] | 72 | /* Get current tick before enabling button interrupts */ |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 73 | last_wheel_usec = USEC_TIMER; |
| 74 | last_wheel_post = last_wheel_usec; |
Michael Sevakis | 5c32faa | 2007-06-03 14:31:42 +0000 | [diff] [blame] | 75 | |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 76 | GPIOH_ENABLE |= 0xc0; |
| 77 | GPIOH_OUTPUT_EN &= ~0xc0; |
| 78 | |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 79 | /* Read initial buttons */ |
Michael Sevakis | ebe67b2 | 2007-06-03 15:17:01 +0000 | [diff] [blame] | 80 | button_int(); |
| 81 | GPIOF_INT_CLR = 0xff; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 82 | |
Barry Wardell | 331e34b | 2006-12-16 00:21:41 +0000 | [diff] [blame] | 83 | /* Read initial wheel value (bit 6-7 of GPIOH) */ |
| 84 | old_wheel_value = GPIOH_INPUT_VAL & 0xc0; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 85 | GPIOH_INT_LEV = (GPIOH_INT_LEV & ~0xc0) | (old_wheel_value ^ 0xc0); |
Michael Sevakis | ebe67b2 | 2007-06-03 15:17:01 +0000 | [diff] [blame] | 86 | GPIOH_INT_CLR = 0xc0; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 87 | |
Michael Sevakis | 5c32faa | 2007-06-03 14:31:42 +0000 | [diff] [blame] | 88 | /* Enable button interrupts */ |
Michael Sevakis | ebe67b2 | 2007-06-03 15:17:01 +0000 | [diff] [blame] | 89 | GPIOF_INT_EN |= 0xff; |
| 90 | GPIOH_INT_EN |= 0xc0; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 91 | |
Michael Sevakis | 5c32faa | 2007-06-03 14:31:42 +0000 | [diff] [blame] | 92 | CPU_INT_EN = HI_MASK; |
Michael Sevakis | 8768ee8 | 2007-06-17 00:07:23 +0000 | [diff] [blame] | 93 | CPU_HI_INT_EN = GPIO1_MASK; |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 94 | #endif /* BOOTLOADER */ |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | bool button_hold(void) |
| 98 | { |
Michael Sevakis | 5c32faa | 2007-06-03 14:31:42 +0000 | [diff] [blame] | 99 | return _button_hold(); |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 102 | /* clickwheel */ |
| 103 | #ifndef BOOTLOADER |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 104 | void clickwheel_int(void) |
| 105 | { |
| 106 | /* Read wheel |
| 107 | * Bits 6 and 7 of GPIOH change as follows: |
| 108 | * Clockwise rotation 01 -> 00 -> 10 -> 11 |
| 109 | * Counter-clockwise 11 -> 10 -> 00 -> 01 |
| 110 | * |
| 111 | * This is equivalent to wheel_value of: |
| 112 | * Clockwise rotation 0x40 -> 0x00 -> 0x80 -> 0xc0 |
| 113 | * Counter-clockwise 0xc0 -> 0x80 -> 0x00 -> 0x40 |
| 114 | */ |
| 115 | static const unsigned char wheel_tbl[2][4] = |
| 116 | { |
| 117 | /* 0x00 0x40 0x80 0xc0 */ /* Wheel value */ |
| 118 | { 0x40, 0xc0, 0x00, 0x80 }, /* Clockwise rotation */ |
| 119 | { 0x80, 0x00, 0xc0, 0x40 }, /* Counter-clockwise */ |
| 120 | }; |
| 121 | |
| 122 | unsigned int wheel_value; |
| 123 | |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 124 | wheel_value = GPIOH_INPUT_VAL & 0xc0; |
| 125 | GPIOH_INT_LEV = (GPIOH_INT_LEV & ~0xc0) | (wheel_value ^ 0xc0); |
Michael Sevakis | 5c32faa | 2007-06-03 14:31:42 +0000 | [diff] [blame] | 126 | GPIOH_INT_CLR = GPIOH_INT_STAT & 0xc0; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 127 | |
| 128 | if (!hold_button) |
| 129 | { |
| 130 | unsigned int btn = BUTTON_NONE; |
| 131 | |
| 132 | if (old_wheel_value == wheel_tbl[0][wheel_value >> 6]) |
Jonathan Gordon | 81ba146 | 2008-01-10 08:08:31 +0000 | [diff] [blame] | 133 | btn = BUTTON_SCROLL_FWD; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 134 | else if (old_wheel_value == wheel_tbl[1][wheel_value >> 6]) |
Jonathan Gordon | 81ba146 | 2008-01-10 08:08:31 +0000 | [diff] [blame] | 135 | btn = BUTTON_SCROLL_BACK; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 136 | |
| 137 | if (btn != BUTTON_NONE) |
| 138 | { |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 139 | int repeat = 1; /* assume repeat */ |
| 140 | unsigned long usec = USEC_TIMER; |
| 141 | unsigned v = (usec - last_wheel_usec) & 0x7fffffff; |
| 142 | |
Linus Nielsen Feltzing | e75327b | 2007-11-19 11:05:54 +0000 | [diff] [blame] | 143 | v = (v>0) ? 1000000 / v : 0; /* clicks/sec = 1000000 * clicks/usec */ |
| 144 | v = (v>0xffffff) ? 0xffffff : v; /* limit to 24 bit */ |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 145 | |
| 146 | /* some velocity filtering to smooth things out */ |
| 147 | wheel_velocity = (7*wheel_velocity + v) / 8; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 148 | |
| 149 | if (btn != wheel_repeat) |
| 150 | { |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 151 | /* direction reversals nullify all fast mode states */ |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 152 | wheel_repeat = btn; |
| 153 | repeat = |
| 154 | wheel_fast_mode = |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 155 | wheel_velocity = |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 156 | wheel_click_count = 0; |
| 157 | } |
| 158 | |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 159 | if (wheel_fast_mode != 0) |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 160 | { |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 161 | /* fast OFF happens immediately when velocity drops below |
| 162 | threshold */ |
| 163 | if (TIME_AFTER(usec, |
| 164 | last_wheel_usec + WHEEL_FAST_OFF_INTERVAL)) |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 165 | { |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 166 | /* moving out of fast mode */ |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 167 | wheel_fast_mode = 0; |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 168 | /* reset velocity */ |
| 169 | wheel_velocity = 0; |
| 170 | /* wheel_delta is always 1 in slow mode */ |
| 171 | wheel_delta = 1; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | else |
| 175 | { |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 176 | /* fast ON gets filtered to avoid inadvertent jumps to fast mode */ |
Linus Nielsen Feltzing | e75327b | 2007-11-19 11:05:54 +0000 | [diff] [blame] | 177 | if (repeat && wheel_velocity > 1000000/WHEEL_FAST_ON_INTERVAL) |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 178 | { |
| 179 | /* moving into fast mode */ |
| 180 | wheel_fast_mode = 1 << 31; |
| 181 | wheel_click_count = 0; |
Linus Nielsen Feltzing | e75327b | 2007-11-19 11:05:54 +0000 | [diff] [blame] | 182 | wheel_velocity = 1000000/WHEEL_FAST_OFF_INTERVAL; |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 183 | } |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 184 | else if (++wheel_click_count < 2) |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 185 | { |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 186 | btn = BUTTON_NONE; |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /* wheel_delta is always 1 in slow mode */ |
| 190 | wheel_delta = 1; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Michael Sevakis | 89b53bf | 2007-08-06 12:58:38 +0000 | [diff] [blame] | 193 | if (TIME_AFTER(current_tick, next_backlight_on) || |
Linus Nielsen Feltzing | e75327b | 2007-11-19 11:05:54 +0000 | [diff] [blame] | 194 | v <= 4) |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 195 | { |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 196 | /* poke backlight to turn it on or maintain it no more often |
| 197 | than every 1/4 second*/ |
Michael Sevakis | 0149264 | 2007-08-06 13:01:40 +0000 | [diff] [blame] | 198 | next_backlight_on = current_tick + HZ/4; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 199 | backlight_on(); |
Jens Arnold | 5f1ec30 | 2007-10-07 15:02:02 +0000 | [diff] [blame] | 200 | buttonlight_on(); |
Peter D'Hoye | 137ce71 | 2007-09-18 21:44:47 +0000 | [diff] [blame] | 201 | reset_poweroff_timer(); |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 202 | } |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 203 | |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 204 | if (btn != BUTTON_NONE) |
| 205 | { |
| 206 | wheel_click_count = 0; |
| 207 | |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 208 | /* generate repeats if quick enough */ |
| 209 | if (repeat && TIME_BEFORE(usec, |
| 210 | last_wheel_post + WHEEL_REPEAT_INTERVAL)) |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 211 | btn |= BUTTON_REPEAT; |
| 212 | |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 213 | last_wheel_post = usec; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 214 | |
| 215 | if (queue_empty(&button_queue)) |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 216 | { |
| 217 | queue_post(&button_queue, btn, wheel_fast_mode | |
Linus Nielsen Feltzing | e75327b | 2007-11-19 11:05:54 +0000 | [diff] [blame] | 218 | (wheel_delta << 24) | wheel_velocity*360/WHEELCLICKS_PER_ROTATION); |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 219 | /* message posted - reset delta */ |
| 220 | wheel_delta = 1; |
| 221 | } |
| 222 | else |
| 223 | { |
| 224 | /* skipped post - increment delta */ |
| 225 | if (++wheel_delta > 0x7f) |
| 226 | wheel_delta = 0x7f; |
| 227 | } |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 230 | last_wheel_usec = usec; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
| 234 | old_wheel_value = wheel_value; |
| 235 | } |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 236 | #endif /* BOOTLOADER */ |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 237 | |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 238 | /* device buttons */ |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 239 | void button_int(void) |
| 240 | { |
| 241 | unsigned char state; |
| 242 | |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 243 | int_btn = BUTTON_NONE; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 244 | |
| 245 | state = GPIOF_INPUT_VAL & 0xff; |
| 246 | |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 247 | #ifndef BOOTLOADER |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 248 | GPIOF_INT_LEV = (GPIOF_INT_LEV & ~0xff) | (state ^ 0xff); |
Michael Sevakis | 5c32faa | 2007-06-03 14:31:42 +0000 | [diff] [blame] | 249 | GPIOF_INT_CLR = GPIOF_INT_STAT; |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 250 | |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 251 | hold_button = (state & 0x80) != 0; |
Michael Sevakis | 5c32faa | 2007-06-03 14:31:42 +0000 | [diff] [blame] | 252 | #endif |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 253 | |
Michael Sevakis | 5c32faa | 2007-06-03 14:31:42 +0000 | [diff] [blame] | 254 | if (!_button_hold()) |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 255 | { |
| 256 | /* Read normal buttons */ |
| 257 | if ((state & 0x01) == 0) int_btn |= BUTTON_REC; |
| 258 | if ((state & 0x02) == 0) int_btn |= BUTTON_DOWN; |
| 259 | if ((state & 0x04) == 0) int_btn |= BUTTON_RIGHT; |
| 260 | if ((state & 0x08) == 0) int_btn |= BUTTON_LEFT; |
| 261 | if ((state & 0x10) == 0) int_btn |= BUTTON_SELECT; /* The centre button */ |
| 262 | if ((state & 0x20) == 0) int_btn |= BUTTON_UP; /* The "play" button */ |
| 263 | if ((state & 0x40) != 0) int_btn |= BUTTON_POWER; |
| 264 | } |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /* |
| 268 | * Get button pressed from hardware |
| 269 | */ |
| 270 | int button_read_device(void) |
| 271 | { |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 272 | #ifdef BOOTLOADER |
| 273 | /* Read buttons directly in the bootloader */ |
| 274 | button_int(); |
| 275 | #else |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 276 | /* light handling */ |
| 277 | if (hold_button != hold_button_old) |
| 278 | { |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 279 | hold_button_old = hold_button; |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 280 | backlight_hold_changed(hold_button); |
| 281 | } |
Michael Sevakis | 31df21c | 2007-05-25 22:41:44 +0000 | [diff] [blame] | 282 | #endif /* BOOTLOADER */ |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 283 | |
Michael Sevakis | d92e095 | 2007-05-11 08:09:49 +0000 | [diff] [blame] | 284 | /* The int_btn variable is set in the button interrupt handler */ |
| 285 | return int_btn; |
Daniel Ankers | d282e14 | 2006-10-14 12:14:23 +0000 | [diff] [blame] | 286 | } |