Index: firmware/SOURCES =================================================================== --- firmware/SOURCES (Revision 20699) +++ firmware/SOURCES (Arbeitskopie) @@ -1110,6 +1110,7 @@ target/arm/as3525/sansa-e200v2/button-e200v2.c target/arm/as3525/backlight-e200v2-fuze.c #ifndef BOOTLOADER +target/arm/as3525/scrollwheel-e200v2-fuze.c target/arm/powermgmt-ascodec.c target/arm/as3525/sansa-e200v2/powermgmt-e200v2.c #endif /* !BOOTLOADER */ @@ -1144,6 +1145,7 @@ target/arm/as3525/backlight-e200v2-fuze.c #ifndef BOOTLOADER target/arm/as3525/powermgmt-as3525.c +target/arm/as3525/scrollwheel-e200v2-fuze.c #endif /* !BOOTLOADER */ #endif /* !SIMULATOR */ #endif /* SANSA_FUZE */ Index: firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c =================================================================== --- firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c (Revision 20699) +++ firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c (Arbeitskopie) @@ -32,24 +32,18 @@ #define WHEELCLICKS_PER_ROTATION 48 /* wheelclicks per full rotation */ static short _dbop_din; -/* Clickwheel */ -static unsigned int old_wheel_value = 0; -static unsigned int wheel_repeat = BUTTON_NONE; -static unsigned int wheel_click_count = 0; -static unsigned int wheel_delta = 0; -static int wheel_fast_mode = 0; -static unsigned long last_wheel_usec = 0; -static unsigned long wheel_velocity = 0; -static long last_wheel_post = 0; -static long next_backlight_on = 0; -/* Buttons */ + static bool hold_button = false; #ifndef BOOTLOADER static bool hold_button_old = false; #endif extern bool lcd_button_support(void); +#ifndef BOOTLOADER +extern void scrollwheel(short dbop_din); +#endif + void button_init_device(void) { @@ -60,128 +54,6 @@ return hold_button; } -static void scrollwheel(short dbop_din) -{ - static const unsigned char wheel_tbl[2][4] = - { - { 2, 0, 3, 1 }, /* Clockwise rotation */ - { 1, 3, 0, 2 }, /* Counter-clockwise */ - }; - /* Read wheel - * Bits 13 and 14 of DBOP_DIN change as follows: - * Clockwise rotation 00 -> 01 -> 11 -> 10 -> 00 - * Counter-clockwise 00 -> 10 -> 11 -> 01 -> 00 - */ - - /* did the wheel value change? */ - unsigned int btn = BUTTON_NONE; - - unsigned wheel_value = dbop_din & (1<<13|1<<14); - wheel_value >>= 13; - - if (old_wheel_value == wheel_tbl[0][wheel_value]) - btn = BUTTON_SCROLL_FWD; - else if (old_wheel_value == wheel_tbl[1][wheel_value]) - btn = BUTTON_SCROLL_BACK; - - if (btn != BUTTON_NONE) - { - int repeat = 1; /* assume repeat */ - unsigned long usec = TIMER1_VALUE; - unsigned v = (usec - last_wheel_usec) & 0x7fffffff; - - v = (v>0) ? 1000000 / v : 0; /* clicks/sec = 1000000 * +clicks/usec */ - v = (v>0xffffff) ? 0xffffff : v; /* limit to 24 bit */ - - /* some velocity filtering to smooth things out */ - wheel_velocity = (7*wheel_velocity + v) / 8; - - if (btn != wheel_repeat) - { - /* direction reversals nullify all fast mode states */ - wheel_repeat = btn; - repeat = - wheel_fast_mode = - wheel_velocity = - wheel_click_count = 0; - } - - if (wheel_fast_mode != 0) - { - /* fast OFF happens immediately when velocity drops below - threshold */ - if (TIME_AFTER(usec, - last_wheel_usec + WHEEL_FAST_OFF_INTERVAL)) - { - /* moving out of fast mode */ - wheel_fast_mode = 0; - /* reset velocity */ - wheel_velocity = 0; - /* wheel_delta is always 1 in slow mode */ - wheel_delta = 1; - } - } - else - { - /* fast ON gets filtered to avoid inadvertent jumps to fast mode */ - if (repeat && wheel_velocity > 1000000/WHEEL_FAST_ON_INTERVAL) - { - /* moving into fast mode */ - wheel_fast_mode = 1 << 31; - wheel_click_count = 0; - wheel_velocity = 1000000/WHEEL_FAST_OFF_INTERVAL; - } - else if (++wheel_click_count < 2) - { - btn = BUTTON_NONE; - } - - /* wheel_delta is always 1 in slow mode */ - wheel_delta = 1; - } - - if (TIME_AFTER(current_tick, next_backlight_on) || - v <= 4) - { - /* poke backlight to turn it on or maintain it no more often - than every 1/4 second*/ - next_backlight_on = current_tick + HZ/4; - backlight_on(); - buttonlight_on(); - reset_poweroff_timer(); - } - - if (btn != BUTTON_NONE) - { - wheel_click_count = 0; - - /* generate repeats if quick enough */ - if (repeat && TIME_BEFORE(usec, - last_wheel_post + WHEEL_REPEAT_INTERVAL)) - btn |= BUTTON_REPEAT; - - last_wheel_post = usec; - - if (queue_empty(&button_queue)) - { - queue_post(&button_queue, btn, wheel_fast_mode | - (wheel_delta << 24) | - wheel_velocity*360/WHEELCLICKS_PER_ROTATION); - /* message posted - reset delta */ - wheel_delta = 1; - } - else - { - /* skipped post - increment delta */ - if (++wheel_delta > 0x7f) - wheel_delta = 0x7f; - } - } - last_wheel_usec = usec; - } - old_wheel_value = wheel_value; -} - short button_read_dbop(void) { /*write a red pixel */ @@ -205,8 +77,9 @@ DBOP_TIMPOL_23 = 0xa167e06f; /* Set Timing & Polarity regs 2 & 3 */ DBOP_CTRL |= (1<<16); /* Enable output (0:write disable) */ DBOP_CTRL &= ~(1<<19); /* Tri-state when no active write */ - + #ifndef BOOTLOADER scrollwheel(_dbop_din); + #endif return _dbop_din; } @@ -241,10 +114,6 @@ if (!(dbop & (1<<15))) btn |= BUTTON_REC; - /* handle wheel */ - int wheel_value = dbop & (1<<13|1<<14); - wheel_value >>= 13; - /* Set afsel, so that we can read our buttons */ GPIOC_AFSEL &= ~(1<<2|1<<3|1<<4|1<<5|1<<6); /* set dir so we can read our buttons (but reset the C pins first) */ Index: firmware/target/arm/as3525/scrollwheel-e200v2-fuze.c =================================================================== --- firmware/target/arm/as3525/scrollwheel-e200v2-fuze.c (Revision 0) +++ firmware/target/arm/as3525/scrollwheel-e200v2-fuze.c (Revision 0) @@ -0,0 +1,110 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Thomas Martitz + * Copyright (C) 2008 by Dominik Wenger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "system.h" +#include "button.h" +#include "button-target.h" +#include "backlight.h" + +#ifdef SANSA_E200V2 +#define WHEEL_SKIP_COUNT 2 +#else +#define WHEEL_SKIP_COUNT 4 +#endif + +void scrollwheel(short dbop_din) +{ + /* current wheel values, parsed from dbop and the resulting button */ + unsigned wheel_value = 0; + unsigned btn = BUTTON_NONE; + /* old wheel values */ + static unsigned old_wheel_value = 0; + static unsigned wheel_repeat = BUTTON_NONE; + + /* getting BUTTON_REPEAT works like this: We increment repeat by 2 if the + * wheel was turned, and decrement it by 1 each tick, + * that means: if you change the wheel fast enough, repeat will be >1 and + * we send BUTTON_REPEAT + */ + static int repeat = 0; + /* we omit 3 of 4 posts to the button_queue, that works better, so count */ + static int counter = 0; + /* Read wheel + * Bits 13 and 14 of DBOP_DIN change as follows: + * Clockwise rotation 00 -> 01 -> 11 -> 10 -> 00 + * Counter-clockwise 00 -> 10 -> 11 -> 01 -> 00 + */ + static const unsigned char wheel_tbl[2][4] = + { + { 2, 0, 3, 1 }, /* Clockwise rotation */ + { 1, 3, 0, 2 }, /* Counter-clockwise */ + }; + wheel_value = dbop_din & (1<<13|1<<14); + wheel_value >>= 13; + + if (old_wheel_value == wheel_tbl[0][wheel_value]) + btn = BUTTON_SCROLL_FWD; + else if (old_wheel_value == wheel_tbl[1][wheel_value]) + btn = BUTTON_SCROLL_BACK; + + if (btn != BUTTON_NONE) + { + if (btn != wheel_repeat) + { + /* direction reversals nullify repeats */ + wheel_repeat = btn; + repeat = counter = 0; + } + if (btn != BUTTON_NONE) + { + /* wheel_delta will cause lists to jump over items, + * we want this for fast scrolling, but we must keep it accurate + * for slow scrolling */ + int wheel_delta = 0; + /* generate repeats if quick enough, scroll slightly faster too*/ + if (repeat > 1) + { + btn |= BUTTON_REPEAT; + wheel_delta = repeat>>2; + } + + repeat += 2; + + /* the wheel is more reliable if we don't send ever change, + * every th is basically one "physical click" is + * 1 item in the rockbox menus */ + if (++counter >= WHEEL_SKIP_COUNT && queue_empty(&button_queue)) + { + buttonlight_on(); + backlight_on(); + queue_post(&button_queue, btn, ((wheel_delta+1)<<24)); + /* message posted - reset count */ + counter = 0; + } + } + } + if (repeat > 0) + repeat--; + else + repeat = 0; + old_wheel_value = wheel_value; +} Index: firmware/target/arm/as3525/sansa-fuze/button-fuze.c =================================================================== --- firmware/target/arm/as3525/sansa-fuze/button-fuze.c (Revision 20699) +++ firmware/target/arm/as3525/sansa-fuze/button-fuze.c (Arbeitskopie) @@ -41,6 +41,9 @@ /* in the lcd driver */ extern bool lcd_button_support(void); +#ifndef BOOTLOADER +extern void scrollwheel(short dbop_din); +#endif void button_init_device(void) { @@ -48,86 +51,6 @@ GPIOA_PIN(1) = (1<<1); } -#if !defined(BOOTLOADER) && defined(HAVE_SCROLLWHEEL) -static void scrollwheel(short dbop_din) -{ - /* current wheel values, parsed from dbop and the resulting button */ - unsigned wheel_value = 0; - unsigned btn = BUTTON_NONE; - /* old wheel values */ - static unsigned old_wheel_value = 0; - static unsigned wheel_repeat = BUTTON_NONE; - - /* getting BUTTON_REPEAT works like this: We increment repeat by 2 if the - * wheel was turned, and decrement it by 1 each tick, - * that means: if you change the wheel fast enough, repeat will be >1 and - * we send BUTTON_REPEAT - */ - static int repeat = 0; - /* we omit 3 of 4 posts to the button_queue, that works better, so count */ - static int counter = 0; - /* Read wheel - * Bits 13 and 14 of DBOP_DIN change as follows: - * Clockwise rotation 00 -> 01 -> 11 -> 10 -> 00 - * Counter-clockwise 00 -> 10 -> 11 -> 01 -> 00 - */ - static const unsigned char wheel_tbl[2][4] = - { - { 2, 0, 3, 1 }, /* Clockwise rotation */ - { 1, 3, 0, 2 }, /* Counter-clockwise */ - }; - wheel_value = dbop_din & (1<<13|1<<14); - wheel_value >>= 13; - - if (old_wheel_value == wheel_tbl[0][wheel_value]) - btn = BUTTON_SCROLL_FWD; - else if (old_wheel_value == wheel_tbl[1][wheel_value]) - btn = BUTTON_SCROLL_BACK; - - if (btn != BUTTON_NONE) - { - if (btn != wheel_repeat) - { - /* direction reversals nullify repeats */ - wheel_repeat = btn; - repeat = counter = 0; - } - if (btn != BUTTON_NONE) - { - /* wheel_delta will cause lists to jump over items, - * we want this for fast scrolling, but we must keep it accurate - * for slow scrolling */ - int wheel_delta = 0; - /* generate repeats if quick enough, scroll slightly faster too*/ - if (repeat > 1) - { - btn |= BUTTON_REPEAT; - wheel_delta = repeat>>2; - } - - repeat += 2; - - /* the wheel is more reliable if we don't send ever change, - * every 4th is basically one "physical click" is 1 item in - * the rockbox menus */ - if (++counter >= 4 && queue_empty(&button_queue)) - { - buttonlight_on(); - backlight_on(); - queue_post(&button_queue, btn, ((wheel_delta+1)<<24)); - /* message posted - reset count */ - counter = 0; - } - } - } - if (repeat > 0) - repeat--; - else - repeat = 0; - old_wheel_value = wheel_value; -} -#endif /* !defined(BOOTLOADER) && defined(SCROLLWHEEL) */ - bool button_hold(void) { return hold_button;