--- piezo.c	2006-07-24 17:42:36.000000000 +0200
+++ ../../../../rockbox/firmware/drivers/piezo.c	2006-07-25 00:48:36.000000000 +0200
@@ -4,11 +4,13 @@
 #include "usb.h"
 #include "logf.h"
 #include "piezo.h"
+#include "timer.h"
 
 static long piezo_stack[DEFAULT_STACK_SIZE/sizeof(long)];
 static const char piezo_thread_name[] = "piezo";
 static struct event_queue piezo_queue;
 unsigned int duration;
+unsigned int piezo_timer_start;
 bool beeping;
 
 enum {
@@ -42,6 +44,26 @@
     piezo_hw_stop();
 }
 */
+static void piezo_stop_timer(void)
+{
+    if (USEC_TIMER-piezo_timer_start<duration)
+       return;//seep a little more
+    if (beeping)
+       piezo_hw_stop();
+    beeping = false;
+    queue_clear(&piezo_queue);
+    timer_unregister();
+}
+static void piezo_stop_timer_unregister(void)
+{
+    logf("PIZTUR");
+    if (beeping)
+       piezo_hw_stop();
+    beeping = false;
+    queue_clear(&piezo_queue);
+    timer_unregister();
+}
+
 
 void piezo_thread(void)
 {
@@ -61,14 +83,11 @@
 /*                logf("PIEZO: beep_for start");*/
                 piezo_hw_tick((int)ev.data);
                 beeping = true;
-                udelay(duration);
-		//sleep(duration);
-                if (beeping)
-                    piezo_hw_stop();
-                beeping = false;
-/*                logf("PIEZO: beep_for end");*/
-                /* remove anything that appeared while sleeping */
-                queue_clear(&piezo_queue);
+                piezo_timer_start=USEC_TIMER;
+                if(!timer_register(0, piezo_stop_timer_unregister, duration, 0, piezo_stop_timer)){//ipod has ms cycles
+                   //didn't get a timer
+                   piezo_hw_stop();
+                }
                 break;
             case Q_PIEZO_STOP:
                 if (beeping)
@@ -91,6 +110,7 @@
     }
 }
 
+
 void piezo_play(int inv_freq)
 {
     queue_post(&piezo_queue, Q_PIEZO_BEEP, (int *)inv_freq);
@@ -124,4 +144,4 @@
     piezo_hw_init();
     queue_init(&piezo_queue);
     create_thread(piezo_thread, piezo_stack, sizeof(piezo_stack), piezo_thread_name);
-}
\ No newline at end of file
+}
