freemyipod r198 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r197‎ | r198 | r199 >
Date:14:03, 6 September 2010
Author:theseven
Status:new
Tags:
Comment:
Add some debugging code to the clickwheel and button drivers
Modified paths:
  • /embios/trunk/button.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/clickwheel.c (modified) (history)

Diff [purge]

Index: embios/trunk/button.c
@@ -76,6 +76,7 @@
7777
7878 void button_send_event(enum button_event eventtype, int which, int value)
7979 {
 80+ DEBUGF("Sending button event: %d, %02X, %02X", eventtype, which, value);
8081 int i;
8182 for (i = 0; i < BUTTON_MAX_HOOKS; i++)
8283 if (button_hooks[i].owner != NULL)
Index: embios/trunk/target/ipodnano2g/clickwheel.c
@@ -49,9 +49,11 @@
5050 while (true)
5151 {
5252 wakeup_wait(&clickwheel_wakeup, TIMEOUT_BLOCK);
 53+ DEBUGF("Got clickwheel packet");
5354 uint32_t mode = enter_critical_section();
5455 uint32_t data = clickwheel_packet;
5556 leave_critical_section(mode);
 57+ DEBUGF("Acquired clickwheel packet: %08X", data);
5658 if ((data & 0x800000FF) == 0x8000001A)
5759 {
5860 int newbuttons = (data >> 8) & 0x1f;
@@ -58,7 +60,10 @@
5961 int newpos = (data >> 16) & 0xff;
6062 bool newtouched = (data & 0x40000000) ? true : false;
6163
 64+ DEBUGF("This is a change packet, button state: %02X, position: %02d, touched: %d",
 65+ newbuttons, newpos, newtouched);
6266 int buttonschanged = oldbuttons ^ newbuttons;
 67+ DEBUGF("Changed buttons: %02X", buttonschanged);
6368 for (i = 0; i < 5; i++)
6469 if ((buttonschanged >> i) & 1)
6570 {
@@ -71,21 +76,35 @@
7277 if (!oldtouched) button_send_event(WHEEL_TOUCH, 0, newpos);
7378 button_send_event(WHEEL_POSITION, 0, newpos);
7479 int distance = newpos - oldpos;
75 - if (TIMEOUT_EXPIRED(lastpacket, 200000) || lastdiff * distance < 0) packets = 10;
 80+ DEBUGF("Time since last packet: %d microseconds", USEC_TIMER - lastpacket);
 81+ if (TIMEOUT_EXPIRED(lastpacket, 200000))
 82+ {
 83+ DEBUGF("Resetting accel due to timeout");
 84+ packets = 10;
 85+ }
 86+ else if (lastdiff * distance < 0)
 87+ {
 88+ DEBUGF("Resetting accel due to direction change");
 89+ packets = 10;
 90+ }
7691 else packets++;
7792 lastdiff = distance;
7893 if (packets > 200) packets = 200;
7994 if (distance < -48) distance += 96;
8095 else if (distance > 48) distance -= 96;
 96+ DEBUGF("Wheel moved %d units without accel", distance);
 97+ DEBUGF("Wheel moved %d units with accel", distance * packets);
 98+ button_send_event(WHEEL_MOVED, 0, distance);
8199 collect += distance * packets;
82 - button_send_event(WHEEL_MOVED, 0, distance);
83100 enum button_event e = collect > 0 ? WHEEL_FORWARD : WHEEL_BACKWARD;
84101 int data = (collect > 0 ? collect : -collect) / 128;
85102 if (data) button_send_event(e, 0, data);
86103 collect %= 128;
 104+ DEBUGF("Wheel moved %d steps (%d left)", data, collect);
87105 }
88106 else if (oldtouched)
89107 {
 108+ DEBUGF("Wheel was untouched");
90109 button_send_event(WHEEL_POSITION, 0, newpos);
91110 button_send_event(WHEEL_UNTOUCH, 0, newpos);
92111 collect = 0;
@@ -98,8 +117,11 @@
99118 oldtouched = newtouched;
100119 lastpacket = USEC_TIMER;
101120 }
102 - else if ((data & 0x8000FFFF) == 0x8000023A && (data & 0x1F0000))
103 - oldbuttons = (data >> 16) & 0x1F;
 121+ else if ((data & 0x8000FFFF) == 0x8000023A)
 122+ {
 123+ if (data & 0x1F0000) oldbuttons = (data >> 16) & 0x1F;
 124+ DEBUGF("This is an init packet, button state: %02X", oldbuttons);
 125+ }
104126 }
105127 }
106128