forked from iPodLinux-Community/Floydzilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clickwheel.c
161 lines (147 loc) · 3.29 KB
/
clickwheel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Clickwheel Services for iPodLinux
* Copyright (C) 2005 Jonathan Bettencourt (jonrelay)
*
* Somebody please help me fill in these functions for the other gens!
* (I know 1g, 2g, 3g, 1g mini won't report clickwheel position, but
* they can still return clickwheel down.)
*
* 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 program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "pz.h"
#include "ipod.h"
#define clickwheel_inl(p) (*(volatile unsigned long *) (p))
static GR_TIMER_ID clickwheel_timer = 0;
static int clickwheel_ps = -1;
/* MESS WITH THIS STUFF */
int clickwheel_ipod_gen(void)
{
#ifdef IPOD
return (ipod_get_hw_version() / 10000);
#else
return 0;
#endif
}
int clickwheel_down(void)
{
#ifdef IPOD
int in, st;
switch (clickwheel_ipod_gen()) {
case 1: /* 1st gen */
case 2: /* 2nd gen */
case 3: /* 3rd gen */
case 4: /* 1st gen mini */
return 0;
break;
case 5: /* 4th gen */
case 6: /* 2nd gen mini */
case 7: /* photo/color */
in = clickwheel_inl(0x7000C140);
st = (in & 0xFF000000) >> 24;
return (st == 0xC0);
break;
case 12: /* nano */
return 0;
break;
default:
return 0;
break;
}
#else
return 0;
#endif
}
int clickwheel_position(void)
{
#ifdef IPOD
int in, st, touch;
switch (clickwheel_ipod_gen()) {
case 1: /* 1st gen */
case 2: /* 2nd gen */
case 3: /* 3rd gen */
case 4: /* 1st gen mini */
return -1;
break;
case 5: /* 4th gen */
case 6: /* 2nd gen mini */
case 7: /* photo/color */
in = clickwheel_inl(0x7000C140);
st = (in & 0xFF000000) >> 24;
if (st == 0xC0) {
touch = (in & 0x007F0000) >> 16;
return touch;
} else {
return -1;
}
break;
case 12: /* nano */
return -1;
break;
default:
return -1;
break;
}
#else
return -1;
#endif
}
/* DON'T MESS WITH THIS STUFF */
int clickwheel_octrant(void)
{
int touch = clickwheel_position();
if (touch >= 0) {
touch += 6;
touch /= 12;
if (touch > 7) { touch = 0; }
}
return touch;
}
int clickwheel_division(int n)
{
/* click wheel is evenly divisible by 2, 3, 4, 6, 8, 12, 16, 24, and 48 */
int touch = clickwheel_position();
if (touch >= 0) {
touch += (48/n);
touch /= (96/n);
if (touch >= n) { touch = 0; }
}
return touch;
}
void clickwheel_create_timer(GR_WINDOW_ID wid)
{
if (clickwheel_timer) {
GrDestroyTimer(clickwheel_timer);
}
clickwheel_ps = -1;
clickwheel_timer = GrCreateTimer(wid, 20);
}
void clickwheel_destroy_timer(void)
{
if (clickwheel_timer) {
GrDestroyTimer(clickwheel_timer);
}
clickwheel_ps = -1;
clickwheel_timer = 0;
}
int is_clickwheel_timer(GR_EVENT * event)
{
return (((GR_EVENT_TIMER *)event)->tid == clickwheel_timer);
}
int clickwheel_change(int i)
{
int x = (clickwheel_ps != i);
clickwheel_ps = i;
return x;
}