Telechips I2C: Scale the busy-wait delay based on FREQ, reducing wasted CPU cycles when unboosted (eg. when reading from the D2 touchscreen).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19293 a1c6a512-1295-4272-9138-f99709370657
diff --git a/firmware/target/arm/i2c-telechips.c b/firmware/target/arm/i2c-telechips.c
index b84fbe4..fb341c7 100644
--- a/firmware/target/arm/i2c-telechips.c
+++ b/firmware/target/arm/i2c-telechips.c
@@ -24,8 +24,13 @@
#include "i2c.h"
#include "i2c-target.h"
-/* arbitrary delay loop */
-#define DELAY do { int _x; for(_x=0;_x<40;_x++);} while (0)
+/* Delay loop based on CPU frequency (FREQ>>22 is 7..45 for 32MHz..192MHz) */
+static inline void delay_loop(void)
+{
+ unsigned long x;
+ for (x = (unsigned)(FREQ>>22); x; x--);
+}
+#define DELAY delay_loop()
static struct mutex i2c_mtx;