Compare commits

..

No commits in common. "bcc4cb82913ae535f3559eaccda19cab51c6b370" and "2a528c09760148db4f30864d91a741dd78e9190e" have entirely different histories.

2 changed files with 9 additions and 11 deletions

View File

@ -66,8 +66,8 @@ install: all
install -m 0644 inc/* $(INC_INSTALL_DIR)
uninstall:
rm -f $(LIB_INSTALL_DIR)/$(STATIC_LIB_FILE)
rm -f $(LIB_INSTALL_DIR)/$(DYNAMIC_LIB_FILE)
rm -f $(LIB_INSTALL_DIR)/$(STATIC_LIB)
rm -f $(LIB_INSTALL_DIR)/$(DYNAMIC_LIB)
rm -f $(addprefix $(INC_INSTALL_DIR)/,$(shell ls inc))
rm -rf $(INC_INSTALL_DIR)

View File

@ -24,8 +24,6 @@ int i2c_open(const struct i2c_bb *i2c)
res = gpio_open(i2c->sda);
res |= gpio_open(i2c->scl);
res |= gpio_write(i2c->sda, 1);
res |= gpio_write(i2c->scl, 1);
return res;
}
@ -53,7 +51,7 @@ int i2c_read(const struct i2c_bb *i2c, uint8_t slave_addr, char *buffer, unsigne
}
start_condition(i2c);
write_byte(i2c, (slave_addr << 1) | 1);
write_byte(i2c, (slave_addr & 0x80));
for(i = 0; i < len; i++) {
buffer[i] = read_byte(i2c, true);
}
@ -74,7 +72,7 @@ int i2c_write(const struct i2c_bb *i2c, uint8_t slave_addr, const char *buffer,
}
start_condition(i2c);
write_byte(i2c, slave_addr << 1);
write_byte(i2c, (slave_addr & 0x7F));
for(i = 0; i < len; i++) {
write_byte(i2c, buffer[i]);
}
@ -138,7 +136,7 @@ static uint8_t read_byte(const struct i2c_bb *i2c, bool ack)
if(ack) {
write_bit(i2c, 0);
} else {
write_bit(i2c, 1);
write_bit(i2c, 0);
}
return res;
@ -148,15 +146,15 @@ static void write_bit(const struct i2c_bb *i2c, uint8_t bit)
{
assert( NULL != i2c);
if(bit > 0) {
if((bit & 0x01) > 0) {
gpio_write(i2c->sda, 1);
} else {
gpio_write(i2c->sda, 0);
gpio_write(i2c->sda, 1);
}
usleep(5);
gpio_write(i2c->scl, 1);
usleep(5);
gpio_write(i2c->scl, 0);
gpio_write(i2c->scl, 1);
}
static uint8_t read_bit(const struct i2c_bb *i2c)
@ -170,7 +168,7 @@ static uint8_t read_bit(const struct i2c_bb *i2c)
gpio_write(i2c->scl, 1);
usleep(5);
gpio_read(i2c->sda, &res);
gpio_write(i2c->scl, 0);
gpio_write(i2c->scl, 1);
return (uint8_t) res;
}