From 897e57102e295986829c76efd29afba31fa59dc2 Mon Sep 17 00:00:00 2001 From: kugel Date: Thu, 1 Apr 2010 16:07:56 +0000 Subject: [PATCH] Fuzev2: Scrollwheel works like a charm :) Move scrollwheel parsing function into separate file as it's reused. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25425 a1c6a512-1295-4272-9138-f99709370657 --- firmware/SOURCES | 3 + firmware/export/config/sansafuzev2.h | 8 +- .../button-fuzev2.c => button-e200v2-fuze.c} | 151 ++++++++++----------- firmware/target/arm/as3525/kernel-as3525.c | 2 +- .../target/arm/as3525/sansa-e200v2/button-target.h | 6 + .../target/arm/as3525/sansa-fuze/button-target.h | 7 + .../target/arm/as3525/sansa-fuzev2/button-fuzev2.c | 38 +++++- .../target/arm/as3525/sansa-fuzev2/button-target.h | 6 + .../{button-e200v2-fuze.c => scrollwheel-as3525.c} | 120 +--------------- 9 files changed, 139 insertions(+), 202 deletions(-) copy firmware/target/arm/as3525/{sansa-fuzev2/button-fuzev2.c => button-e200v2-fuze.c} (50%) copy firmware/target/arm/as3525/{button-e200v2-fuze.c => scrollwheel-as3525.c} (61%) diff --git a/firmware/SOURCES b/firmware/SOURCES index 0d845f2b3..b5151c395 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -408,6 +408,9 @@ target/arm/pnx0101/timer-pnx0101.c target/arm/as3525/system-as3525.c target/arm/as3525/kernel-as3525.c target/arm/as3525/timer-as3525.c +#ifdef HAVE_SCROLLWHEEL +target/arm/as3525/scrollwheel-as3525.c +#endif #if CONFIG_CPU == AS3525 target/arm/as3525/sd-as3525.c #else /* AS3535v2 */ diff --git a/firmware/export/config/sansafuzev2.h b/firmware/export/config/sansafuzev2.h index b71f85200..88d7650ca 100644 --- a/firmware/export/config/sansafuzev2.h +++ b/firmware/export/config/sansafuzev2.h @@ -127,13 +127,13 @@ #define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING /* define this if the unit uses a scrollwheel for navigation */ -//#define HAVE_SCROLLWHEEL +#define HAVE_SCROLLWHEEL /* define to activate advanced wheel acceleration code */ -//#define HAVE_WHEEL_ACCELERATION +#define HAVE_WHEEL_ACCELERATION /* define from which rotation speed [degree/sec] on the acceleration starts */ -//#define WHEEL_ACCEL_START 540 +#define WHEEL_ACCEL_START 540 /* define type of acceleration (1 = ^2, 2 = ^3, 3 = ^4) */ -//#define WHEEL_ACCELERATION 1 +#define WHEEL_ACCELERATION 1 /* define this if you have a flash memory storage */ #define HAVE_FLASH_STORAGE diff --git a/firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c b/firmware/target/arm/as3525/button-e200v2-fuze.c similarity index 50% copy from firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c copy to firmware/target/arm/as3525/button-e200v2-fuze.c index 0a6d2c919..2cbdcf513 100644 --- a/firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c +++ b/firmware/target/arm/as3525/button-e200v2-fuze.c @@ -7,7 +7,8 @@ * \/ \/ \/ \/ \/ * $Id$ * - * Copyright (C) 2010 by Thomas Martitz + * 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 @@ -22,83 +23,62 @@ #include "config.h" #include "system.h" #include "button.h" +#include "button-target.h" #include "backlight.h" +#include "dbop-as3525.h" -/* - * TODO: Scrollwheel! - */ - -#ifdef HAS_BUTTON_HOLD -static bool hold_button = false; +extern void scrollwheel(unsigned wheel_value); + +#if defined(SANSA_FUZE) +#define DBOP_BIT15_BUTTON BUTTON_HOME #endif + +#ifdef SANSA_E200V2 +#define DBOP_BIT15_BUTTON BUTTON_REC +#endif + +/* Buttons */ +static bool hold_button = false; +#ifndef BOOTLOADER +static bool hold_button_old = false; +#endif + void button_init_device(void) { + GPIOA_DIR |= (1<<1); + GPIOA_PIN(1) = (1<<1); +} + +bool button_hold(void) +{ + return hold_button; +} + +unsigned short button_read_dbop(void) +{ + unsigned dbop_din = dbop_read_input(); +#if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER) + /* scroll wheel handling */ + scrollwheel((dbop_din >> 13) & (1<<1|1<<0)); +#endif + return dbop_din; } /* * Get button pressed from hardware */ - int button_read_device(void) { - int btn = 0; - volatile int delay; - static bool hold_button_old = false; - static long power_counter = 0; - unsigned gpiod = GPIOD_DATA; - unsigned gpioa_dir = GPIOA_DIR; - unsigned gpiod6; - for(delay = 500; delay; delay--) nop; - CCU_IO &= ~(1<<12); - for(delay=8;delay;delay--) nop; - GPIOB_DIR |= 1<<3; - GPIOB_PIN(3) = 1<<3; - GPIOC_DIR = 0; - GPIOB_DIR &= ~(1<<1); - GPIOB_DIR |= 1<<0; - GPIOB_PIN(0) = 1; - for(delay = 500; delay; delay--) - nop; - gpiod6 = GPIOD_PIN(6); - GPIOB_PIN(0) = 0; - for(delay = 240; delay; delay--) - nop; - GPIOD_DIR = 0xff; - GPIOA_DIR &= ~(1<<6|1<<7); - GPIOD_DATA = 0; - GPIOD_DIR = 0; - if (GPIOC_PIN(1) & 1<<1) - btn |= BUTTON_DOWN; - if (GPIOC_PIN(2) & 1<<2) - btn |= BUTTON_UP; - if (GPIOC_PIN(3) & 1<<3) - btn |= BUTTON_LEFT; - if (GPIOC_PIN(4) & 1<<4) - btn |= BUTTON_SELECT; - if (GPIOC_PIN(5) & 1<<5) - btn |= BUTTON_RIGHT; - if (GPIOB_PIN(1) & 1<<1) - btn |= BUTTON_HOME; - if (gpiod6 & 1<<6) - { /* power/hold is on the same pin. we know it's hold if the bit isn't - * set now anymore */ - if (GPIOD_PIN(6) & 1<<6) - { - hold_button = false; - btn |= BUTTON_POWER; - } - else - { - hold_button = true; - } - } +#ifdef SANSA_FUZE + static unsigned power_counter = 0; +#endif + unsigned short dbop_din; + int btn = BUTTON_NONE; + + dbop_din = button_read_dbop(); - GPIOD_DIR = 0xff; - GPIOD_DATA = gpiod; - GPIOA_DIR = gpioa_dir; - GPIOD_DIR = 0; - CCU_IO |= 1<<12; -#ifdef HAS_BUTTON_HOLD + /* hold button handling */ + hold_button = ((dbop_din & (1<<12)) != 0); #ifndef BOOTLOADER /* light handling */ if (hold_button != hold_button_old) @@ -106,30 +86,41 @@ int button_read_device(void) hold_button_old = hold_button; backlight_hold_changed(hold_button); } -#else - (void)hold_button_old; -#endif - if (hold_button) - { +#endif /* BOOTLOADER */ + if (hold_button) { +#ifdef SANSA_FUZE power_counter = HZ; +#endif return 0; } - /* read power, but not if hold button was just released, since + + /* push button handling */ + if ((dbop_din & (1 << 2)) == 0) + btn |= BUTTON_UP; + if ((dbop_din & (1 << 3)) == 0) + btn |= BUTTON_LEFT; + if ((dbop_din & (1 << 4)) == 0) + btn |= BUTTON_SELECT; + if ((dbop_din & (1 << 5)) == 0) + btn |= BUTTON_RIGHT; + if ((dbop_din & (1 << 6)) == 0) + btn |= BUTTON_DOWN; + if ((dbop_din & (1 << 8)) != 0) + btn |= BUTTON_POWER; + if ((dbop_din & (1 << 15)) == 0) + btn |= DBOP_BIT15_BUTTON; + +#ifdef SANSA_FUZE + /* 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 * (fuze only) */ - else if (power_counter > 0) - { - power_counter--; + if (power_counter > 0) { + power_counter--; btn &= ~BUTTON_POWER; } #endif + return btn; } -#ifdef HAS_BUTTON_HOLD -bool button_hold(void) -{ - return hold_button; -} -#endif diff --git a/firmware/target/arm/as3525/kernel-as3525.c b/firmware/target/arm/as3525/kernel-as3525.c index 4c421e50f..ebaef71c9 100644 --- a/firmware/target/arm/as3525/kernel-as3525.c +++ b/firmware/target/arm/as3525/kernel-as3525.c @@ -44,7 +44,7 @@ static inline void do_scrollwheel(void) else { if (!button_hold()) - button_read_dbop(); /* Read the scrollwheel */ + get_scrollwheel(); /* Read the scrollwheel */ } poll_scrollwheel ^= 1; diff --git a/firmware/target/arm/as3525/sansa-e200v2/button-target.h b/firmware/target/arm/as3525/sansa-e200v2/button-target.h index b1feb58ca..7a0e9e50f 100644 --- a/firmware/target/arm/as3525/sansa-e200v2/button-target.h +++ b/firmware/target/arm/as3525/sansa-e200v2/button-target.h @@ -31,6 +31,12 @@ bool button_hold(void); void button_init_device(void); int button_read_device(void); unsigned short button_read_dbop(void); +#define get_scrollwheel button_read_dbop + +#define WHEEL_REPEAT_INTERVAL (HZ/5) +#define WHEEL_COUNTER_DIV 2 +#define ACCEL_INCREMENT 3 +#define ACCEL_SHIFT 1 /* Sandisk Sansa E200 button codes */ diff --git a/firmware/target/arm/as3525/sansa-fuze/button-target.h b/firmware/target/arm/as3525/sansa-fuze/button-target.h index 6dcd37460..2cee93723 100644 --- a/firmware/target/arm/as3525/sansa-fuze/button-target.h +++ b/firmware/target/arm/as3525/sansa-fuze/button-target.h @@ -31,6 +31,13 @@ void button_init_device(void); bool button_hold(void); int button_read_device(void); unsigned short button_read_dbop(void); +#define get_scrollwheel button_read_dbop + +#define WHEEL_REPEAT_INTERVAL (HZ/5) +#define WHEEL_COUNTER_DIV 4 +#define ACCEL_INCREMENT 2 +#define ACCEL_SHIFT 2 + /* Sandisk Sansa Fuze button codes */ /* Main unit's buttons */ diff --git a/firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c b/firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c index 0a6d2c919..4848d9e7d 100644 --- a/firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c +++ b/firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c @@ -24,21 +24,50 @@ #include "button.h" #include "backlight.h" -/* - * TODO: Scrollwheel! - */ - +extern void scrollwheel(unsigned wheel_value); + #ifdef HAS_BUTTON_HOLD static bool hold_button = false; #endif void button_init_device(void) +{ /* activate the wheel */ + volatile int i; + GPIOB_DIR |= 1<<4; + for(i = 20; i; i--) nop; + GPIOB_PIN(4) = 0x10; +} + +unsigned read_GPIOA_67(void) { + unsigned ret = 0; + volatile int i; + DBOP_CTRL |= 1<<19; + for(i = 20; i; i--) nop; + GPIOA_DIR &= ~0xc0; + for(i = 20; i; i--) nop; + if (GPIOA_PIN(6) != 0) + ret = 1<<0; + for(i = 20; i; i--) nop; + if (GPIOA_PIN(7) != 0) + ret |= 1<<1; + DBOP_CTRL &= ~(1<<19); + for(i = 20; i; i--) nop; + return ret; +} + +void get_scrollwheel(void) +{ +#if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER) + /* scroll wheel handling */ + scrollwheel(read_GPIOA_67()); +#endif } /* * Get button pressed from hardware */ + int button_read_device(void) { int btn = 0; @@ -48,6 +77,7 @@ int button_read_device(void) unsigned gpiod = GPIOD_DATA; unsigned gpioa_dir = GPIOA_DIR; unsigned gpiod6; + get_scrollwheel(); for(delay = 500; delay; delay--) nop; CCU_IO &= ~(1<<12); for(delay=8;delay;delay--) nop; diff --git a/firmware/target/arm/as3525/sansa-fuzev2/button-target.h b/firmware/target/arm/as3525/sansa-fuzev2/button-target.h index 6dcd37460..14f3db18f 100644 --- a/firmware/target/arm/as3525/sansa-fuzev2/button-target.h +++ b/firmware/target/arm/as3525/sansa-fuzev2/button-target.h @@ -31,6 +31,12 @@ void button_init_device(void); bool button_hold(void); int button_read_device(void); unsigned short button_read_dbop(void); +void get_scrollwheel(void); + +#define WHEEL_REPEAT_INTERVAL (HZ/5) +#define WHEEL_COUNTER_DIV 4 +#define ACCEL_INCREMENT 2 +#define ACCEL_SHIFT 2 /* Sandisk Sansa Fuze button codes */ /* Main unit's buttons */ diff --git a/firmware/target/arm/as3525/button-e200v2-fuze.c b/firmware/target/arm/as3525/scrollwheel-as3525.c similarity index 61% copy from firmware/target/arm/as3525/button-e200v2-fuze.c copy to firmware/target/arm/as3525/scrollwheel-as3525.c index 2a75fa1e6..a9e012a31 100644 --- a/firmware/target/arm/as3525/button-e200v2-fuze.c +++ b/firmware/target/arm/as3525/scrollwheel-as3525.c @@ -7,8 +7,7 @@ * \/ \/ \/ \/ \/ * $Id$ * - * Copyright (C) 2008 by Thomas Martitz - * Copyright (C) 2008 by Dominik Wenger + * Copyright (C) 2009-2010 by Thomas Martitz * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -21,44 +20,13 @@ ****************************************************************************/ #include "config.h" -#include "system.h" #include "button.h" -#include "button-target.h" +#include "kernel.h" #include "backlight.h" -#include "dbop-as3525.h" - -#if defined(SANSA_FUZE) || defined(SANSA_FUZEV2) -#define DBOP_BIT15_BUTTON BUTTON_HOME -#define WHEEL_REPEAT_INTERVAL (HZ/5) -#define WHEEL_COUNTER_DIV 4 -#define ACCEL_INCREMENT 2 -#define ACCEL_SHIFT 2 -#endif - -#ifdef SANSA_E200V2 -#define DBOP_BIT15_BUTTON BUTTON_REC -#define WHEEL_REPEAT_INTERVAL (HZ/5) -#define WHEEL_COUNTER_DIV 2 -#define ACCEL_INCREMENT 3 -#define ACCEL_SHIFT 1 -#endif - -/* Buttons */ -static bool hold_button = false; -#ifndef BOOTLOADER -static bool hold_button_old = false; -#endif - -void button_init_device(void) -{ - GPIOA_DIR |= (1<<1); - GPIOA_PIN(1) = (1<<1); -} - -#if !defined(BOOTLOADER) && defined(HAVE_SCROLLWHEEL) -static void scrollwheel(unsigned int wheel_value) +void scrollwheel(unsigned int wheel_value) { +#ifndef BOOTLOADER /* current wheel values, parsed from dbop and the resulting button */ unsigned btn = BUTTON_NONE; /* old wheel values */ @@ -96,7 +64,7 @@ static void scrollwheel(unsigned int wheel_value) { 1, 3, 0, 2 }, /* Counter-clockwise */ }; - if(hold_button) + if(button_hold()) { accel = counter = 0; return; @@ -150,81 +118,7 @@ static void scrollwheel(unsigned int wheel_value) accel--; old_wheel_value = wheel_value; -} -#endif /* !defined(BOOTLOADER) && defined(SCROLLWHEEL) */ - -bool button_hold(void) -{ - return hold_button; -} - -unsigned short button_read_dbop(void) -{ - unsigned dbop_din = dbop_read_input(); -#if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER) - /* scroll wheel handling */ - scrollwheel((dbop_din >> 13) & (1<<1|1<<0)); +#else + (void)wheel_value #endif - return dbop_din; } - -/* - * Get button pressed from hardware - */ -int button_read_device(void) -{ -#ifdef SANSA_FUZE - static unsigned power_counter = 0; -#endif - unsigned short dbop_din; - int btn = BUTTON_NONE; - - dbop_din = button_read_dbop(); - - /* hold button handling */ - hold_button = ((dbop_din & (1<<12)) != 0); -#ifndef BOOTLOADER - /* light handling */ - if (hold_button != hold_button_old) - { - hold_button_old = hold_button; - backlight_hold_changed(hold_button); - } -#endif /* BOOTLOADER */ - if (hold_button) { -#ifdef SANSA_FUZE - power_counter = HZ; -#endif - return 0; - } - - /* push button handling */ - if ((dbop_din & (1 << 2)) == 0) - btn |= BUTTON_UP; - if ((dbop_din & (1 << 3)) == 0) - btn |= BUTTON_LEFT; - if ((dbop_din & (1 << 4)) == 0) - btn |= BUTTON_SELECT; - if ((dbop_din & (1 << 5)) == 0) - btn |= BUTTON_RIGHT; - if ((dbop_din & (1 << 6)) == 0) - btn |= BUTTON_DOWN; - if ((dbop_din & (1 << 8)) != 0) - btn |= BUTTON_POWER; - if ((dbop_din & (1 << 15)) == 0) - btn |= DBOP_BIT15_BUTTON; - -#ifdef SANSA_FUZE - /* 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 - * (fuze only) - */ - if (power_counter > 0) { - power_counter--; - btn &= ~BUTTON_POWER; - } -#endif - - return btn; -} - -- 2.11.4.GIT