From 4893072499b229d0d2c57287f1e335ae5d837db5 Mon Sep 17 00:00:00 2001 From: lilian Date: Thu, 1 Dec 2016 12:48:16 +0100 Subject: [PATCH] custom delay --- extras/i2c/i2c.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/extras/i2c/i2c.c b/extras/i2c/i2c.c index 2d31e8e..a41dff7 100644 --- a/extras/i2c/i2c.c +++ b/extras/i2c/i2c.c @@ -24,14 +24,13 @@ #include #include // sdk_os_delay_us +#include #include "i2c.h" // I2C driver for ESP8266 written for use with esp-open-rtos // Based on https://en.wikipedia.org/wiki/I²C#Example_of_bit-banging_the_I.C2.B2C_Master_protocol - -// With calling overhead, we end up at ~100kbit/s -#define CLK_HALF_PERIOD_US (1) +// With calling overhead, we end up at ~320kbit/s #define CLK_STRETCH (10) @@ -59,7 +58,14 @@ void i2c_init(uint8_t scl_pin, uint8_t sda_pin) static inline void i2c_delay(void) { - sdk_os_delay_us(CLK_HALF_PERIOD_US); + if (sdk_system_get_cpu_freq() == SYS_CPU_160MHZ) + { + for (volatile uint8_t __j = 0 ; __j < 5 ; __j++) {} ; + } + else + { + for (volatile uint8_t __j = 0 ; __j < 0 ; __j++) {} ; + } } // Set SCL as input, allowing it to float high, and return current