summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/scrollwheel-as3525.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-04-01 16:07:56 +0000
committerThomas Martitz <kugel@rockbox.org>2010-04-01 16:07:56 +0000
commitf376fd2f4aa9b27f2a6299177b4cc3c014da01f3 (patch)
treee42edd558e2deff42d3522189d92d158e861a307 /firmware/target/arm/as3525/scrollwheel-as3525.c
parent47dcf58e28930af8b468aa2151f1288e9ec334df (diff)
downloadrockbox-f376fd2f4aa9b27f2a6299177b4cc3c014da01f3.tar.gz
rockbox-f376fd2f4aa9b27f2a6299177b4cc3c014da01f3.zip
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
Diffstat (limited to 'firmware/target/arm/as3525/scrollwheel-as3525.c')
-rw-r--r--firmware/target/arm/as3525/scrollwheel-as3525.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/firmware/target/arm/as3525/scrollwheel-as3525.c b/firmware/target/arm/as3525/scrollwheel-as3525.c
new file mode 100644
index 0000000000..a9e012a31f
--- /dev/null
+++ b/firmware/target/arm/as3525/scrollwheel-as3525.c
@@ -0,0 +1,124 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009-2010 by Thomas Martitz
11 *
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.
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#include "config.h"
23#include "button.h"
24#include "kernel.h"
25#include "backlight.h"
26
27void scrollwheel(unsigned int wheel_value)
28{
29#ifndef BOOTLOADER
30 /* current wheel values, parsed from dbop and the resulting button */
31 unsigned btn = BUTTON_NONE;
32 /* old wheel values */
33 static unsigned old_wheel_value = 0;
34 static unsigned old_btn = BUTTON_NONE;
35
36 /*
37 * Getting BUTTON_REPEAT works like this: Remember when the btn value was
38 * posted to the button_queue last, and if it was recent enough, generate
39 * BUTTON_REPEAT
40 */
41 static long last_wheel_post = 0;
42
43 /*
44 * Providing wheel acceleration works as follows: We increment accel
45 * by 2 if the wheel was turned, and decrement it by 1 each tick
46 * (no matter if it was turned), that means: the longer and faster you turn,
47 * the higher accel will be. accel>>2 will actually posted to the button_queue
48 */
49 static int accel = 0;
50 /* We only post every 4th action, as this matches better with the physical
51 * clicks of the wheel */
52 static int counter = 0;
53 /* Read wheel
54 * Bits 13 and 14 of DBOP_DIN change as follows (Gray Code):
55 * Clockwise rotation 00 -> 01 -> 11 -> 10 -> 00
56 * Counter-clockwise 00 -> 10 -> 11 -> 01 -> 00
57 *
58 * For easy look-up, actual wheel values act as indicies also,
59 * which is why the table seems to be not ordered correctly
60 */
61 static const unsigned char wheel_tbl[2][4] =
62 {
63 { 2, 0, 3, 1 }, /* Clockwise rotation */
64 { 1, 3, 0, 2 }, /* Counter-clockwise */
65 };
66
67 if(button_hold())
68 {
69 accel = counter = 0;
70 return;
71 }
72
73 if (old_wheel_value == wheel_tbl[0][wheel_value])
74 btn = BUTTON_SCROLL_FWD;
75 else if (old_wheel_value == wheel_tbl[1][wheel_value])
76 btn = BUTTON_SCROLL_BACK;
77 else if (old_wheel_value != wheel_value && accel > ACCEL_INCREMENT)
78 { /* if no button is read and wheel_value changed, assume old_btn */
79 btn = old_btn;
80 }
81 /* else btn = BUTTON_NONE */
82
83 if (btn != BUTTON_NONE)
84 {
85 if (btn != old_btn)
86 {
87 /* direction reversals nullify acceleration and counters */
88 old_btn = btn;
89 accel = counter = 0;
90 }
91 /* wheel_delta will cause lists to jump over items,
92 * we want this for fast scrolling, but we must keep it accurate
93 * for slow scrolling */
94 int wheel_delta = 0;
95 /* generate BUTTON_REPEAT if quick enough, scroll slightly faster too*/
96 if (TIME_BEFORE(current_tick, last_wheel_post + WHEEL_REPEAT_INTERVAL))
97 {
98 btn |= BUTTON_REPEAT;
99 wheel_delta = accel>>ACCEL_SHIFT;
100 }
101
102 accel += ACCEL_INCREMENT;
103
104 /* the wheel is more reliable if we don't send every change,
105 * every WHEEL_COUNTER_DIVth is basically one "physical click"
106 * which should make up 1 item in lists */
107 if (++counter >= WHEEL_COUNTER_DIV && queue_empty(&button_queue))
108 {
109 buttonlight_on();
110 backlight_on();
111 queue_post(&button_queue, btn, ((wheel_delta+1)<<24));
112 /* message posted - reset count and remember post */
113 counter = 0;
114 last_wheel_post = current_tick;
115 }
116 }
117 if (accel > 0)
118 accel--;
119
120 old_wheel_value = wheel_value;
121#else
122 (void)wheel_value
123#endif
124}