Compare commits

...

2 Commits

Author SHA1 Message Date
Thomas Klaehn
bcc4cb8291 wip 2019-07-25 08:25:10 +02:00
Thomas Klaehn
695bf90c03 wip 2019-07-23 16:12:10 +02:00
2 changed files with 11 additions and 9 deletions

View File

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

View File

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