Subversion Repositories freemyipod

Rev

Rev 841 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 841 Rev 968
Line 26... Line 26...
26
#include "button.h"
26
#include "button.h"
27
#include "thread.h"
27
#include "thread.h"
28
#include "timer.h"
28
#include "timer.h"
29
#include "s5l8702.h"
29
#include "s5l8702.h"
30
#include "contextswitch.h"
30
#include "contextswitch.h"
-
 
31
#ifdef TARGET_ipodclassic
-
 
32
#include "fat.h"
-
 
33
#include "storage_ata.h"
-
 
34
#include "../ipodclassic/storage_ata-target.h"
-
 
35
#endif
31
 
36
 
32
 
37
 
33
static struct wakeup clickwheel_wakeup IBSS_ATTR;
38
static struct wakeup clickwheel_wakeup IBSS_ATTR;
-
 
39
static struct wakeup clickwheel_init_wakeup INITDATA_ATTR;
34
static volatile uint32_t clickwheel_packet IBSS_ATTR;
40
static volatile uint32_t clickwheel_packet IBSS_ATTR;
35
static struct scheduler_thread clickwheel_thread_handle;
41
static struct scheduler_thread clickwheel_thread_handle;
36
static uint32_t clickwheel_stack[0x100] STACK_ATTR;
42
static uint32_t clickwheel_stack[0x100] STACK_ATTR;
-
 
43
static bool wheel_initialized IBSS_ATTR;
37
static bool oldtouched IBSS_ATTR;
44
static bool oldtouched IBSS_ATTR;
38
static int oldpos IBSS_ATTR;
45
static int oldpos IBSS_ATTR;
39
static int oldbuttons IBSS_ATTR;
46
static int oldbuttons IBSS_ATTR;
40
static uint32_t lastpacket IBSS_ATTR;
47
static int lastpacket IBSS_ATTR;
41
static int packets IBSS_ATTR;
48
static int packets IBSS_ATTR;
42
static int collect IBSS_ATTR;
49
static int collect IBSS_ATTR;
43
static int lastdiff IBSS_ATTR;
50
static int lastdiff IBSS_ATTR;
44
 
51
 
45
 
52
 
Line 53... Line 60...
53
        DEBUGF("Got clickwheel packet");
60
        DEBUGF("Got clickwheel packet");
54
        uint32_t mode = enter_critical_section();
61
        uint32_t mode = enter_critical_section();
55
        uint32_t data = clickwheel_packet;
62
        uint32_t data = clickwheel_packet;
56
        leave_critical_section(mode);
63
        leave_critical_section(mode);
57
        DEBUGF("Acquired clickwheel packet: %08X", data);
64
        DEBUGF("Acquired clickwheel packet: %08X", data);
-
 
65
        int newbuttons = (data >> 8) & 0x1f;
58
        if ((data & 0x800000FF) == 0x8000001A)
66
        if ((data & 0x800000FF) == 0x8000001A)
59
        {
67
        {
60
            int newbuttons = (data >> 8) & 0x1f;
-
 
61
            int newpos = (data >> 16) & 0xff;
68
            int newpos = (data >> 16) & 0xff;
62
            bool newtouched = (data & 0x40000000) ? true : false;
69
            bool newtouched = (data & 0x40000000) ? true : false;
63
 
70
 
64
            DEBUGF("This is a change packet, button state: %02X, position: %02d, touched: %d",
71
            DEBUGF("This is a change packet, button state: %02X, position: %02d, touched: %d",
65
                   newbuttons, newpos, newtouched);
72
                   newbuttons, newpos, newtouched);
-
 
73
                   
66
            int buttonschanged = oldbuttons ^ newbuttons;
74
            int buttonschanged = oldbuttons ^ newbuttons;
67
            DEBUGF("Changed buttons: %02X", buttonschanged);
75
            DEBUGF("Changed buttons: %02X", buttonschanged);
68
            for (i = 0; i < 5; i++)
76
            for (i = 0; i < 5; i++)
69
                if ((buttonschanged >> i) & 1)
77
                if ((buttonschanged >> i) & 1)
70
                {
78
                {
Line 113... Line 121...
113
                collect = 0;
121
                collect = 0;
114
                packets = 0;
122
                packets = 0;
115
                lastdiff = 0;
123
                lastdiff = 0;
116
            }
124
            }
117
 
125
 
118
            oldbuttons = newbuttons;
-
 
119
            oldpos = newpos;
126
            oldpos = newpos;
120
            oldtouched = newtouched;
127
            oldtouched = newtouched;
121
            lastpacket = USEC_TIMER;
128
            lastpacket = USEC_TIMER;
122
        }
129
        }
123
        else if ((data & 0x8000FFFF) == 0x8000023A)
130
        else if ((data & 0x8000FFFF) == 0x8000023A)
124
        {
131
        {
125
            if (data & 0x1F0000) oldbuttons = (data >> 16) & 0x1F;
132
            if (data & 0x1F0000) newbuttons = (data >> 16) & 0x1F;
126
            DEBUGF("This is an init packet, button state: %02X", oldbuttons);
133
            DEBUGF("This is an init packet, button state: %02X", newbuttons);
-
 
134
            if (!wheel_initialized)
-
 
135
            {
-
 
136
                wheel_initialized = true;
-
 
137
                wakeup_signal(&clickwheel_init_wakeup);
-
 
138
            }
127
        }
139
        }
-
 
140
 
-
 
141
        #ifdef TARGET_ipodclassic
-
 
142
            if (newbuttons == 0x11 && oldbuttons != 0x11)
-
 
143
            {
-
 
144
                ata_lock_exclusive(TIMEOUT_BLOCK);
-
 
145
                flush_fat(true);
-
 
146
                ata_sleepnow();
-
 
147
            }
-
 
148
            else if (newbuttons != 0x11 && oldbuttons == 0x11)
-
 
149
                ata_unlock_exclusive();
-
 
150
#endif
-
 
151
                   
-
 
152
        oldbuttons = newbuttons;
128
    }
153
    }
129
}
154
}
130
 
155
 
131
 
156
 
132
void clickwheel_init()
157
int clickwheel_init()
133
{
158
{
134
    wakeup_init(&clickwheel_wakeup);
159
    wakeup_init(&clickwheel_wakeup);
-
 
160
    wakeup_init(&clickwheel_init_wakeup);
-
 
161
    wheel_initialized = false;
135
    oldtouched = false;
162
    oldtouched = false;
136
    oldbuttons = 0;
163
    oldbuttons = 0;
137
    lastpacket = 0;
164
    lastpacket = 0;
138
    collect = 0;
165
    collect = 0;
139
    lastdiff = 0;
166
    lastdiff = 0;
Line 148... Line 175...
148
    WHEELTX = 0x8000023A;
175
    WHEELTX = 0x8000023A;
149
    WHEEL04 |= 1;
176
    WHEEL04 |= 1;
150
    thread_create(&clickwheel_thread_handle, "Clickwheel dispatcher", clickwheel_thread,
177
    thread_create(&clickwheel_thread_handle, "Clickwheel dispatcher", clickwheel_thread,
151
                  clickwheel_stack, sizeof(clickwheel_stack), OS_THREAD, 200, true,
178
                  clickwheel_stack, sizeof(clickwheel_stack), OS_THREAD, 200, true,
152
                  NULL, NULL, NULL, NULL);
179
                  NULL, NULL, NULL, NULL);
-
 
180
    wakeup_wait(&clickwheel_init_wakeup, 100000);
-
 
181
    if (!wheel_initialized) RET_ERR(0);
-
 
182
    return 0;
153
}
183
}
154
 
184
 
155
void INT_WHEEL(void) ICODE_ATTR;
185
void INT_WHEEL(void) ICODE_ATTR;
156
void INT_WHEEL()
186
void INT_WHEEL()
157
{
187
{