Skip to content
Snippets Groups Projects
Unverified Commit ea5d61f9 authored by Peter Kietzmann's avatar Peter Kietzmann Committed by GitHub
Browse files

Merge pull request #8018 from smlng/nrf51/fix_i2c

nrf51: fix returns and error codes in periph/i2c
parents e60a7504 1540ec05
No related branches found
No related tags found
No related merge requests found
......@@ -67,9 +67,13 @@ static int error(i2c_t bus)
static int write(i2c_t bus, uint8_t addr, const void *data, int len, int stop)
{
assert(len > 0);
if (!(bus < I2C_NUMOF)) {
return -1;
}
uint8_t *buf = (uint8_t *)data;
assert((bus <= I2C_NUMOF) && (len > 0));
DEBUG("i2c: writing %i byte to the bus\n", len);
dev(bus)->ADDRESS = (addr & 0x7f);
......@@ -98,7 +102,7 @@ static int write(i2c_t bus, uint8_t addr, const void *data, int len, int stop)
int i2c_init_master(i2c_t bus, i2c_speed_t speed)
{
if (bus >= I2C_NUMOF) {
if (!(bus < I2C_NUMOF)) {
return -1;
}
if (speed & INVALID_SPEED_MASK) {
......@@ -128,14 +132,18 @@ int i2c_init_master(i2c_t bus, i2c_speed_t speed)
int i2c_acquire(i2c_t bus)
{
assert(bus <= I2C_NUMOF);
if (!(bus < I2C_NUMOF)) {
return -1;
}
mutex_lock(&locks[bus]);
return 0;
}
int i2c_release(i2c_t bus)
{
assert(bus <= I2C_NUMOF);
if (!(bus < I2C_NUMOF)) {
return -1;
}
mutex_unlock(&locks[bus]);
return 0;
}
......@@ -147,9 +155,12 @@ int i2c_read_byte(i2c_t bus, uint8_t address, void *data)
int i2c_read_bytes(i2c_t bus, uint8_t address, void *data, int length)
{
assert(length > 0);
if (!(bus < I2C_NUMOF)) {
return -1;
}
uint8_t *in_buf = (uint8_t *)data;
assert((bus <= I2C_NUMOF) && (length > 0));
DEBUG("[i2c] reading %i byte from the bus\n", length);
/* set the client address */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment