mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			I2C API refactoring
Now the I2C send/receive functions in the mbed HAL return the number of bytes actually transferred or an error code (a negative value). The public API remains unchanged.pull/9/head
							parent
							
								
									b464564dc1
								
							
						
					
					
						commit
						bfeb47f523
					
				| 
						 | 
				
			
			@ -52,9 +52,9 @@ int I2C::write(int address, const char* data, int length, bool repeated) {
 | 
			
		|||
    aquire();
 | 
			
		||||
 | 
			
		||||
    int stop = (repeated) ? 0 : 1;
 | 
			
		||||
    int retval = i2c_write(&_i2c, address, data, length, stop);
 | 
			
		||||
    int written = i2c_write(&_i2c, address, data, length, stop);
 | 
			
		||||
 | 
			
		||||
    return retval;
 | 
			
		||||
    return length != written;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int I2C::write(int data) {
 | 
			
		||||
| 
						 | 
				
			
			@ -66,9 +66,9 @@ int I2C::read(int address, char* data, int length, bool repeated) {
 | 
			
		|||
    aquire();
 | 
			
		||||
 | 
			
		||||
    int stop = (repeated) ? 0 : 1;
 | 
			
		||||
    int retval = i2c_read(&_i2c, address, data, length, stop);
 | 
			
		||||
    int read = i2c_read(&_i2c, address, data, length, stop);
 | 
			
		||||
 | 
			
		||||
    return retval;
 | 
			
		||||
    return length != read;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int I2C::read(int ack) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,7 +39,7 @@ int I2CSlave::receive(void) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
int I2CSlave::read(char *data, int length) {
 | 
			
		||||
    return i2c_slave_read(&_i2c, data, length);
 | 
			
		||||
    return i2c_slave_read(&_i2c, data, length) != length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int I2CSlave::read(void) {
 | 
			
		||||
| 
						 | 
				
			
			@ -47,7 +47,7 @@ int I2CSlave::read(void) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
int I2CSlave::write(const char *data, int length) {
 | 
			
		||||
    return i2c_slave_write(&_i2c, data, length);
 | 
			
		||||
    return i2c_slave_write(&_i2c, data, length) != length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int I2CSlave::write(int data) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,6 +26,11 @@ extern "C" {
 | 
			
		|||
 | 
			
		||||
typedef struct i2c_s i2c_t;
 | 
			
		||||
 | 
			
		||||
enum {
 | 
			
		||||
  I2C_ERROR_NO_SLAVE = -1,
 | 
			
		||||
  I2C_ERROR_BUS_BUSY = -2
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void i2c_init         (i2c_t *obj, PinName sda, PinName scl);
 | 
			
		||||
void i2c_frequency    (i2c_t *obj, int hz);
 | 
			
		||||
int  i2c_start        (i2c_t *obj);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -221,12 +221,12 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
 | 
			
		||||
    if (i2c_start(obj)) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return 1;
 | 
			
		||||
        return I2C_ERROR_BUS_BUSY;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (i2c_do_write(obj, (address | 0x01))) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return 1;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // set rx mode
 | 
			
		||||
| 
						 | 
				
			
			@ -238,7 +238,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        uint8_t stop_ = (count == (length - 1)) ? 1 : 0;
 | 
			
		||||
        if (i2c_do_read(obj, ptr, stop_)) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return 1;
 | 
			
		||||
            return count;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -250,25 +250,25 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
    // last read
 | 
			
		||||
    data[count-1] = obj->i2c->D;
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		||||
    int i;
 | 
			
		||||
 | 
			
		||||
    if (i2c_start(obj)) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return 1;
 | 
			
		||||
        return I2C_ERROR_BUS_BUSY;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (i2c_do_write(obj, (address & 0xFE))) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return 1;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < length; i++) {
 | 
			
		||||
        if(i2c_do_write(obj, data[i])) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return 1;
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -276,7 +276,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
        i2c_stop(obj);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void i2c_reset(i2c_t *obj) {
 | 
			
		||||
| 
						 | 
				
			
			@ -363,7 +363,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
 | 
			
		|||
    for (count = 0; count < (length - 1); count++) {
 | 
			
		||||
        data[count] = obj->i2c->D;
 | 
			
		||||
        if(i2c_wait_end_rx_transfer(obj)) {
 | 
			
		||||
            return 0;
 | 
			
		||||
            return count;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -382,7 +382,7 @@ int i2c_slave_write(i2c_t *obj, const char *data, int length) {
 | 
			
		|||
    
 | 
			
		||||
    for (i = 0; i < length; i++) {
 | 
			
		||||
        if(i2c_do_write(obj, data[count++]) == 2) {
 | 
			
		||||
            return 0;
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -393,7 +393,7 @@ int i2c_slave_write(i2c_t *obj, const char *data, int length) {
 | 
			
		|||
    // otherwise the master cannot generate a stop bit
 | 
			
		||||
    obj->i2c->D;
 | 
			
		||||
    if(i2c_wait_end_rx_transfer(obj) == 2) {
 | 
			
		||||
        return 0;
 | 
			
		||||
        return count;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return count;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -196,13 +196,13 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
    
 | 
			
		||||
    if ((status != 0x10) && (status != 0x08)) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_BUS_BUSY;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    status = i2c_do_write(obj, (address | 0x01), 1);
 | 
			
		||||
    if (status != 0x40) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Read in all except last byte
 | 
			
		||||
| 
						 | 
				
			
			@ -211,7 +211,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        status = i2c_status(obj);
 | 
			
		||||
        if (status != 0x50) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return status;
 | 
			
		||||
            return count;
 | 
			
		||||
        }
 | 
			
		||||
        data[count] = (char) value;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -221,7 +221,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
    status = i2c_status(obj);
 | 
			
		||||
    if (status != 0x58) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return length - 1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    data[count] = (char) value;
 | 
			
		||||
| 
						 | 
				
			
			@ -231,7 +231,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        i2c_stop(obj);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		||||
| 
						 | 
				
			
			@ -241,20 +241,20 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
    
 | 
			
		||||
    if ((status != 0x10) && (status != 0x08)) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_BUS_BUSY;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    status = i2c_do_write(obj, (address & 0xFE), 1);
 | 
			
		||||
    if (status != 0x18) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    for (i=0; i<length; i++) {
 | 
			
		||||
        status = i2c_do_write(obj, data[i], 0);
 | 
			
		||||
        if(status != 0x28) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return status;
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -265,7 +265,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
        i2c_stop(obj);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void i2c_reset(i2c_t *obj) {
 | 
			
		||||
| 
						 | 
				
			
			@ -343,7 +343,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
 | 
			
		|||
    
 | 
			
		||||
    i2c_clear_SI(obj);
 | 
			
		||||
    
 | 
			
		||||
    return (count - 1);
 | 
			
		||||
    return count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int i2c_slave_write(i2c_t *obj, const char *data, int length) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -204,13 +204,13 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
    
 | 
			
		||||
    if ((status != 0x10) && (status != 0x08)) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_BUS_BUSY;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    status = i2c_do_write(obj, (address | 0x01), 1);
 | 
			
		||||
    if (status != 0x40) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // Read in all except last byte
 | 
			
		||||
| 
						 | 
				
			
			@ -219,7 +219,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        status = i2c_status(obj);
 | 
			
		||||
        if (status != 0x50) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return status;
 | 
			
		||||
            return count;
 | 
			
		||||
        }
 | 
			
		||||
        data[count] = (char) value;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -229,7 +229,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
    status = i2c_status(obj);
 | 
			
		||||
    if (status != 0x58) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return length - 1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    data[count] = (char) value;
 | 
			
		||||
| 
						 | 
				
			
			@ -239,7 +239,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        i2c_stop(obj);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		||||
| 
						 | 
				
			
			@ -249,20 +249,20 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
    
 | 
			
		||||
    if ((status != 0x10) && (status != 0x08)) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_BUS_BUSY;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    status = i2c_do_write(obj, (address & 0xFE), 1);
 | 
			
		||||
    if (status != 0x18) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    for (i=0; i<length; i++) {
 | 
			
		||||
        status = i2c_do_write(obj, data[i], 0);
 | 
			
		||||
        if(status != 0x28) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return status;
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -273,7 +273,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
        i2c_stop(obj);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void i2c_reset(i2c_t *obj) {
 | 
			
		||||
| 
						 | 
				
			
			@ -351,7 +351,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
 | 
			
		|||
    
 | 
			
		||||
    i2c_clear_SI(obj);
 | 
			
		||||
    
 | 
			
		||||
    return (count - 1);
 | 
			
		||||
    return count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int i2c_slave_write(i2c_t *obj, const char *data, int length) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -203,13 +203,13 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
    
 | 
			
		||||
    if ((status != 0x10) && (status != 0x08)) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_BUS_BUSY;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    status = i2c_do_write(obj, (address | 0x01), 1);
 | 
			
		||||
    if (status != 0x40) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // Read in all except last byte
 | 
			
		||||
| 
						 | 
				
			
			@ -218,7 +218,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        status = i2c_status(obj);
 | 
			
		||||
        if (status != 0x50) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return status;
 | 
			
		||||
            return count;
 | 
			
		||||
        }
 | 
			
		||||
        data[count] = (char) value;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -228,7 +228,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
    status = i2c_status(obj);
 | 
			
		||||
    if (status != 0x58) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return length - 1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    data[count] = (char) value;
 | 
			
		||||
| 
						 | 
				
			
			@ -238,7 +238,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        i2c_stop(obj);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		||||
| 
						 | 
				
			
			@ -248,20 +248,20 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
    
 | 
			
		||||
    if ((status != 0x10) && (status != 0x08)) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_BUS_BUSY;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    status = i2c_do_write(obj, (address & 0xFE), 1);
 | 
			
		||||
    if (status != 0x18) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    for (i=0; i<length; i++) {
 | 
			
		||||
        status = i2c_do_write(obj, data[i], 0);
 | 
			
		||||
        if (status != 0x28) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return status;
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -272,7 +272,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
        i2c_stop(obj);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void i2c_reset(i2c_t *obj) {
 | 
			
		||||
| 
						 | 
				
			
			@ -353,7 +353,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
 | 
			
		|||
    
 | 
			
		||||
    i2c_clear_SI(obj);
 | 
			
		||||
    
 | 
			
		||||
    return (count - 1);
 | 
			
		||||
    return count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int i2c_slave_write(i2c_t *obj, const char *data, int length) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -213,13 +213,13 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
    
 | 
			
		||||
    if ((status != 0x10) && (status != 0x08)) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_BUS_BUSY;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    status = i2c_do_write(obj, (address | 0x01), 1);
 | 
			
		||||
    if (status != 0x40) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // Read in all except last byte
 | 
			
		||||
| 
						 | 
				
			
			@ -228,7 +228,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        status = i2c_status(obj);
 | 
			
		||||
        if (status != 0x50) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return status;
 | 
			
		||||
            return count;
 | 
			
		||||
        }
 | 
			
		||||
        data[count] = (char) value;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -238,7 +238,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
    status = i2c_status(obj);
 | 
			
		||||
    if (status != 0x58) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return length - 1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    data[count] = (char) value;
 | 
			
		||||
| 
						 | 
				
			
			@ -248,7 +248,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        i2c_stop(obj);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		||||
| 
						 | 
				
			
			@ -258,20 +258,20 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
    
 | 
			
		||||
    if ((status != 0x10) && (status != 0x08)) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_BUS_BUSY;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    status = i2c_do_write(obj, (address & 0xFE), 1);
 | 
			
		||||
    if (status != 0x18) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    for (i=0; i<length; i++) {
 | 
			
		||||
        status = i2c_do_write(obj, data[i], 0);
 | 
			
		||||
        if (status != 0x28) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return status;
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -282,7 +282,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
        i2c_stop(obj);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void i2c_reset(i2c_t *obj) {
 | 
			
		||||
| 
						 | 
				
			
			@ -363,7 +363,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
 | 
			
		|||
    
 | 
			
		||||
    i2c_clear_SI(obj);
 | 
			
		||||
    
 | 
			
		||||
    return (count - 1);
 | 
			
		||||
    return count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int i2c_slave_write(i2c_t *obj, const char *data, int length) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -147,7 +147,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
    status = i2c_do_write(obj, (address | 0x01), 1);
 | 
			
		||||
    if (status != 0x01) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // Read in all except last byte
 | 
			
		||||
| 
						 | 
				
			
			@ -156,7 +156,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        status = i2c_status(obj);
 | 
			
		||||
        if (status != 0x00) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return status;
 | 
			
		||||
            return count;
 | 
			
		||||
        }
 | 
			
		||||
        data[count] = (char) value;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -166,7 +166,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
    status = i2c_status(obj);
 | 
			
		||||
    if (status != 0x01) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return length - 1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    data[count] = (char) value;
 | 
			
		||||
| 
						 | 
				
			
			@ -178,7 +178,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        repeated_start = 1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		||||
| 
						 | 
				
			
			@ -189,14 +189,14 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
    status = i2c_do_write(obj, (address & 0xFE), 1);
 | 
			
		||||
    if (status != 0x02) {
 | 
			
		||||
        i2c_stop(obj);
 | 
			
		||||
        return status;
 | 
			
		||||
        return I2C_ERROR_NO_SLAVE;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    for (i=0; i<length; i++) {
 | 
			
		||||
        status = i2c_do_write(obj, data[i], 0);
 | 
			
		||||
        if (status != 0x02) {
 | 
			
		||||
            i2c_stop(obj);
 | 
			
		||||
            return status;
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -207,7 +207,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
        repeated_start = 1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void i2c_reset(i2c_t *obj) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -251,7 +251,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
 | 
			
		|||
        i2c_stop(obj);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		||||
| 
						 | 
				
			
			@ -273,7 +273,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
 | 
			
		|||
        i2c_stop(obj);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
    return length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void i2c_reset(i2c_t *obj) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue