avoid using a global variable

pull/487/head
Yihui Xiong 2014-09-11 15:17:33 +08:00
parent 7d9048fccc
commit 274a34f472
2 changed files with 5 additions and 6 deletions

View File

@ -30,8 +30,6 @@ static const PinMap PinMap_I2C_SCL[] = {
{NC, NC, 0} {NC, NC, 0}
}; };
uint8_t addrSet = 0;
void i2c_interface_enable(i2c_t *obj) void i2c_interface_enable(i2c_t *obj)
{ {
obj->i2c->ENABLE = (TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos); obj->i2c->ENABLE = (TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos);
@ -97,7 +95,7 @@ int i2c_start(i2c_t *obj)
{ {
int status = 0; int status = 0;
i2c_reset(obj); i2c_reset(obj);
addrSet = 0; obj->address_set = 0;
return status; return status;
} }
@ -113,7 +111,7 @@ int i2c_stop(i2c_t *obj)
return 1; return 1;
} }
} }
addrSet = 0; obj->address_set = 0;
i2c_reset(obj); i2c_reset(obj);
return 0; return 0;
} }
@ -266,8 +264,8 @@ int i2c_byte_read(i2c_t *obj, int last)
int i2c_byte_write(i2c_t *obj, int data) int i2c_byte_write(i2c_t *obj, int data)
{ {
int status = 0; int status = 0;
if (!addrSet) { if (!obj->address_set) {
addrSet = 1; obj->address_set = 1;
obj->i2c->ADDRESS = (data >> 1); obj->i2c->ADDRESS = (data >> 1);
if (data & 1) { if (data & 1) {

View File

@ -53,6 +53,7 @@ struct i2c_s {
PinName sda; PinName sda;
PinName scl; PinName scl;
int freq; int freq;
uint8_t address_set;
}; };
struct analogin_s { struct analogin_s {