From e5e41c3a82bfd546a686a758ca3a382d0173a3e2 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Mon, 13 Apr 2009 10:28:06 +0000 Subject: FS#10120 - fuze/e200v2: poll the wheel more often (every 5ms). This makes the scrollwheel behavior nearly perfect (decent acceleration, no direction changes if you turn to fast). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20699 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/as3525/kernel-as3525.c | 22 ++++++++++ .../target/arm/as3525/sansa-e200v2/button-e200v2.c | 16 ++++--- .../target/arm/as3525/sansa-fuze/button-fuze.c | 49 ++++++++++------------ 3 files changed, 55 insertions(+), 32 deletions(-) diff --git a/firmware/target/arm/as3525/kernel-as3525.c b/firmware/target/arm/as3525/kernel-as3525.c index 3252e5abd1..986ceb3189 100644 --- a/firmware/target/arm/as3525/kernel-as3525.c +++ b/firmware/target/arm/as3525/kernel-as3525.c @@ -24,12 +24,29 @@ #include "panic.h" #include "timer-target.h" +#ifdef HAVE_SCROLLWHEEL +/* The scrollwheel is polled every 5 ms (the tick tasks only every 10) */ +extern void button_read_dbop(void); +static volatile int poll_scrollwheel = 0; + +void INT_TIMER2(void) +{ + if (!poll_scrollwheel) + call_tick_tasks(); /* Run through the list of tick tasks */ + else + button_read_dbop(); + + poll_scrollwheel ^= 1; + TIMER2_INTCLR = 0; /* clear interrupt */ +} +#else void INT_TIMER2(void) { call_tick_tasks(); /* Run through the list of tick tasks */ TIMER2_INTCLR = 0; /* clear interrupt */ } +#endif void tick_start(unsigned int interval_in_ms) { @@ -37,6 +54,11 @@ void tick_start(unsigned int interval_in_ms) int prescale = 1; int cycles = TIMER_FREQ / 1000 * interval_in_ms; +#ifdef HAVE_SCROLLWHEEL + /* let the timer interrupt twice as often for the scrollwheel polling */ + cycles >>= 1; +#endif + while(cycles > 0x10000) { phi++; diff --git a/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c b/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c index 54e46f4a12..85288d2cc1 100644 --- a/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c +++ b/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c @@ -60,7 +60,7 @@ bool button_hold(void) return hold_button; } -void clickwheel(unsigned int wheel_value) +static void scrollwheel(short dbop_din) { static const unsigned char wheel_tbl[2][4] = { @@ -75,6 +75,10 @@ void clickwheel(unsigned int wheel_value) /* 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]) @@ -178,7 +182,7 @@ void clickwheel(unsigned int wheel_value) old_wheel_value = wheel_value; } -static short read_dbop(void) +short button_read_dbop(void) { /*write a red pixel */ if (!lcd_button_support()) @@ -186,7 +190,7 @@ static short read_dbop(void) /* Set up dbop for input */ while (!(DBOP_STAT & (1<<10))); /* Wait for fifo to empty */ - DBOP_CTRL |= (1<<19); + DBOP_CTRL |= (1<<19); /* Tri-state DBOP on read cycle */ DBOP_CTRL &= ~(1<<16); /* disable output (1:write enabled) */ DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */ DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */ @@ -200,8 +204,9 @@ static short read_dbop(void) DBOP_TIMPOL_01 = 0x6e167; /* Set Timing & Polarity regs 0 & 1 */ DBOP_TIMPOL_23 = 0xa167e06f; /* Set Timing & Polarity regs 2 & 3 */ DBOP_CTRL |= (1<<16); /* Enable output (0:write disable) */ - DBOP_CTRL &= ~(1<<19); + DBOP_CTRL &= ~(1<<19); /* Tri-state when no active write */ + scrollwheel(_dbop_din); return _dbop_din; } @@ -217,7 +222,7 @@ int button_read_device(void) { int btn = BUTTON_NONE; /* read buttons from dbop */ - short dbop = read_dbop(); + short dbop = button_read_dbop(); /* hold button */ if(dbop & (1<<12)) @@ -239,7 +244,6 @@ int button_read_device(void) /* handle wheel */ int wheel_value = dbop & (1<<13|1<<14); wheel_value >>= 13; - clickwheel(wheel_value); /* Set afsel, so that we can read our buttons */ GPIOC_AFSEL &= ~(1<<2|1<<3|1<<4|1<<5|1<<6); diff --git a/firmware/target/arm/as3525/sansa-fuze/button-fuze.c b/firmware/target/arm/as3525/sansa-fuze/button-fuze.c index f32776f6eb..f532a96431 100644 --- a/firmware/target/arm/as3525/sansa-fuze/button-fuze.c +++ b/firmware/target/arm/as3525/sansa-fuze/button-fuze.c @@ -49,7 +49,7 @@ void button_init_device(void) } #if !defined(BOOTLOADER) && defined(HAVE_SCROLLWHEEL) -static void scrollwheel(short dbop) +static void scrollwheel(short dbop_din) { /* current wheel values, parsed from dbop and the resulting button */ unsigned wheel_value = 0; @@ -76,7 +76,7 @@ static void scrollwheel(short dbop) { 2, 0, 3, 1 }, /* Clockwise rotation */ { 1, 3, 0, 2 }, /* Counter-clockwise */ }; - wheel_value = dbop & (1<<13|1<<14); + wheel_value = dbop_din & (1<<13|1<<14); wheel_value >>= 13; if (old_wheel_value == wheel_tbl[0][wheel_value]) @@ -90,7 +90,7 @@ static void scrollwheel(short dbop) { /* direction reversals nullify repeats */ wheel_repeat = btn; - repeat = 0; + repeat = counter = 0; } if (btn != BUTTON_NONE) { @@ -139,7 +139,7 @@ static void button_delay(void) while(i--); } -static short button_dbop(void) +short button_read_dbop(void) { /* skip home and power reading if lcd_button_support was blocked, * since the dbop bit 15 is invalid then, and use the old value instead */ @@ -150,27 +150,24 @@ static short button_dbop(void) old_home_power = (_dbop_din & (1<<15|1<<8)); } - /* Wait for fifo to empty */ - while ((DBOP_STAT & (1<<10)) == 0); - - DBOP_CTRL |= (1<<19); - DBOP_CTRL &= ~(1<<16); /* disable output */ - - DBOP_TIMPOL_01 = 0xe167e167; - DBOP_TIMPOL_23 = 0xe167006e; + /* Set up dbop for input */ + while (!(DBOP_STAT & (1<<10))); /* Wait for fifo to empty */ + DBOP_CTRL |= (1<<19); /* Tri-state DBOP on read cycle */ + DBOP_CTRL &= ~(1<<16); /* disable output (1:write enabled) */ + DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */ + DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */ button_delay(); + DBOP_CTRL |= (1<<15); /* start read */ + while (!(DBOP_STAT & (1<<16))); /* wait for valid data */ - DBOP_CTRL |= (1<<15); /* start read */ - while((DBOP_STAT & (1<<16)) == 0); /* wait for valid data */ - - _dbop_din = DBOP_DIN; /* now read */ + _dbop_din = DBOP_DIN; /* Read dbop data*/ - DBOP_TIMPOL_01 = 0x6e167; - DBOP_TIMPOL_23 = 0xa167e06f; - - DBOP_CTRL |= (1<<16); - DBOP_CTRL &= ~(1<<19); + /* Reset dbop for output */ + DBOP_TIMPOL_01 = 0x6e167; /* Set Timing & Polarity regs 0 & 1 */ + 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 */ /* write back old values if blocked */ if (old_home_power != -20) @@ -178,6 +175,10 @@ static short button_dbop(void) _dbop_din |= old_home_power & 1<<15; _dbop_din &= 0xfeff|(old_home_power & 1<<8); } +#if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER) + /* read wheel on bit 13 & 14, but sent to the button queue seperately */ + scrollwheel(_dbop_din); +#endif return _dbop_din; } @@ -233,7 +234,7 @@ static int button_gpio(void) int button_read_device(void) { int btn = BUTTON_NONE; - short dbop = button_dbop(); + short dbop = button_read_dbop(); static unsigned power_counter = 0; /* hold button */ if(dbop & (1<<12)) @@ -244,10 +245,6 @@ int button_read_device(void) else { hold_button = false; -#if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER) - /* read wheel on bit 13 & 14, but sent to the button queue seperately */ - scrollwheel(dbop); -#endif /* read power on bit 8, but not if hold button was just released, since * you basically always hit power due to the slider mechanism after releasing * hold (wait ~1 sec) */ -- cgit v1.2.3