Exchange usleep with wait.
This commit is contained in:
parent
fcdc3125c7
commit
9856e38e81
27
src/i2c.c
27
src/i2c.c
@ -14,6 +14,7 @@ static void write_bit(const struct i2c_bb *i2c, uint8_t bit);
|
||||
static uint8_t read_bit(const struct i2c_bb *i2c);
|
||||
static void start_condition(const struct i2c_bb *i2c);
|
||||
static void stop_condition(const struct i2c_bb *i2c);
|
||||
static void wait(void);
|
||||
static bool write_byte(const struct i2c_bb *i2c, uint8_t byte);
|
||||
static uint8_t read_byte(const struct i2c_bb *i2c, bool ack);
|
||||
|
||||
@ -93,11 +94,11 @@ static void start_condition(const struct i2c_bb *i2c)
|
||||
|
||||
gpio_write(i2c->pin_scl, 1);
|
||||
gpio_write(i2c->pin_sda, 1);
|
||||
usleep(5);
|
||||
wait();
|
||||
gpio_write(i2c->pin_sda, 0);
|
||||
usleep(5);
|
||||
wait();
|
||||
gpio_write(i2c->pin_scl, 0);
|
||||
usleep(5);
|
||||
wait();
|
||||
}
|
||||
|
||||
static void stop_condition(const struct i2c_bb *i2c)
|
||||
@ -105,11 +106,16 @@ static void stop_condition(const struct i2c_bb *i2c)
|
||||
assert( NULL != i2c);
|
||||
|
||||
gpio_write(i2c->pin_sda, 0);
|
||||
usleep(5);
|
||||
wait();
|
||||
gpio_write(i2c->pin_scl, 1);
|
||||
usleep(5);
|
||||
wait();
|
||||
gpio_write(i2c->pin_sda, 1);
|
||||
usleep(5);
|
||||
wait();
|
||||
}
|
||||
|
||||
static void wait(void)
|
||||
{
|
||||
asm volatile("nop");
|
||||
}
|
||||
|
||||
static bool write_byte(const struct i2c_bb *i2c, uint8_t byte)
|
||||
@ -157,9 +163,9 @@ static void write_bit(const struct i2c_bb *i2c, uint8_t bit)
|
||||
}
|
||||
gpio_write(i2c->pin_sda, value);
|
||||
|
||||
usleep(5);
|
||||
wait();
|
||||
gpio_write(i2c->pin_scl, 1);
|
||||
usleep(5);
|
||||
wait();
|
||||
gpio_write(i2c->pin_scl, 0);
|
||||
}
|
||||
|
||||
@ -170,10 +176,10 @@ static uint8_t read_bit(const struct i2c_bb *i2c)
|
||||
assert(NULL != i2c);
|
||||
|
||||
gpio_write(i2c->pin_sda, 1);
|
||||
usleep(5);
|
||||
wait();
|
||||
gpio_write(i2c->pin_scl, 1);
|
||||
gpio_direction(i2c->pin_sda, 0);
|
||||
usleep(5);
|
||||
wait();
|
||||
res = gpio_read(i2c->pin_sda);
|
||||
gpio_write(i2c->pin_scl, 0);
|
||||
gpio_direction(i2c->pin_sda, 1);
|
||||
@ -184,3 +190,4 @@ static uint8_t read_bit(const struct i2c_bb *i2c)
|
||||
|
||||
return (uint8_t) res;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user