Update AVR I2C functions
This commit is contained in:
parent
5d10775877
commit
6672befb31
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#define TIMEOUT (F_CPU/1000)
|
#define TIMEOUT (F_CPU/1000)
|
||||||
|
|
||||||
int i2c_start(uint8_t addr, bool read) {
|
int i2c_start(struct I2C * i2c, uint8_t addr, bool read) {
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
|
|
||||||
// reset TWI control register
|
// reset TWI control register
|
||||||
@ -38,12 +38,12 @@ int i2c_start(uint8_t addr, bool read) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_stop(void) {
|
void i2c_stop(struct I2C * i2c) {
|
||||||
// transmit STOP condition
|
// transmit STOP condition
|
||||||
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
|
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
int i2c_write(uint8_t * data, int length) {
|
int i2c_write(struct I2C * i2c, uint8_t * data, int length) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
// load data into data register
|
// load data into data register
|
||||||
@ -62,7 +62,7 @@ int i2c_write(uint8_t * data, int length) {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i2c_read(uint8_t * data, int length) {
|
int i2c_read(struct I2C * i2c, uint8_t * data, int length) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
if ((i + 1) < length) {
|
if ((i + 1) < length) {
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
#include <common/i2c.h>
|
#include <common/i2c.h>
|
||||||
|
|
||||||
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
|
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
|
||||||
return i2c_get(address, command, (uint8_t *)data, 2);
|
return i2c_get(NULL, address, command, (uint8_t *)data, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int smbus_write(uint8_t address, uint8_t command, uint16_t data) {
|
int smbus_write(uint8_t address, uint8_t command, uint16_t data) {
|
||||||
return i2c_set(address, command, (uint8_t *)&data, 2);
|
return i2c_set(NULL, address, command, (uint8_t *)&data, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void battery_debug(void) {
|
void battery_debug(void) {
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
#include <common/i2c.h>
|
#include <common/i2c.h>
|
||||||
|
|
||||||
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
|
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
|
||||||
return i2c_get(address, command, (uint8_t *)data, 2);
|
return i2c_get(NULL, address, command, (uint8_t *)data, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int smbus_write(uint8_t address, uint8_t command, uint16_t data) {
|
int smbus_write(uint8_t address, uint8_t command, uint16_t data) {
|
||||||
return i2c_set(address, command, (uint8_t *)&data, 2);
|
return i2c_set(NULL, address, command, (uint8_t *)&data, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void battery_debug(void) {
|
void battery_debug(void) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user