white space diffs.

pull/637/head
Rohit Grover 2014-11-03 08:56:31 +00:00
parent fa0a82d695
commit fd3b27b327
1 changed files with 32 additions and 32 deletions

View File

@ -79,12 +79,12 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
if ((obj->i2c == I2C_2)&& !i2c2_inited) { if ((obj->i2c == I2C_2)&& !i2c2_inited) {
i2c2_inited = 1; i2c2_inited = 1;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
// Configure I2C pins // Configure I2C pins
pinmap_pinout(scl, PinMap_I2C_SCL); pinmap_pinout(scl, PinMap_I2C_SCL);
pin_mode(scl, OpenDrain); pin_mode(scl, OpenDrain);
pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(sda, PinMap_I2C_SDA);
pin_mode(sda, OpenDrain); pin_mode(sda, OpenDrain);
} }
// Reset to clear pending flags if any // Reset to clear pending flags if any
i2c_reset(obj); i2c_reset(obj);
@ -94,16 +94,16 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
} }
void i2c_frequency(i2c_t *obj, int hz) { void i2c_frequency(i2c_t *obj, int hz) {
int timeout; int timeout;
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2C_InitTypeDef I2C_InitStructure; I2C_InitTypeDef I2C_InitStructure;
if ((hz != 0) && (hz <= 400000)) { if ((hz != 0) && (hz <= 400000)) {
// wait before init // wait before init
timeout = LONG_TIMEOUT; timeout = LONG_TIMEOUT;
while((I2C_GetFlagStatus(i2c, I2C_FLAG_BUSY)) && (timeout-- != 0)); while ((I2C_GetFlagStatus(i2c, I2C_FLAG_BUSY)) && (timeout-- != 0)) {
}
I2C_DeInit(i2c); I2C_DeInit(i2c);
@ -122,7 +122,7 @@ void i2c_frequency(i2c_t *obj, int hz) {
inline int i2c_start(i2c_t *obj) { inline int i2c_start(i2c_t *obj) {
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout; int timeout;
I2C_ClearFlag(i2c, I2C_FLAG_AF); // Clear Acknowledge failure flag I2C_ClearFlag(i2c, I2C_FLAG_AF); // Clear Acknowledge failure flag
@ -151,9 +151,9 @@ inline int i2c_stop(i2c_t *obj) {
int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) { int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout; int timeout;
int count; int count;
int value; int value;
i2c_start(obj); i2c_start(obj);
@ -171,7 +171,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
// Read all bytes except last one // Read all bytes except last one
for (count = 0; count < (length - 1); count++) { for (count = 0; count < (length - 1); count++) {
value = i2c_byte_read(obj, 0); value = i2c_byte_read(obj, 0);
data[count] = (char)value; data[count] = (char)value;
} }
@ -182,7 +182,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
} }
// Read the last byte // Read the last byte
value = i2c_byte_read(obj, 1); value = i2c_byte_read(obj, 1);
data[count] = (char)value; data[count] = (char)value;
return length; return length;
@ -190,8 +190,8 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout; int timeout;
int count; int count;
i2c_start(obj); i2c_start(obj);
@ -224,8 +224,8 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
int i2c_byte_read(i2c_t *obj, int last) { int i2c_byte_read(i2c_t *obj, int last) {
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint8_t data; uint8_t data;
int timeout; int timeout;
if (last) { if (last) {
// Don't acknowledge the last byte // Don't acknowledge the last byte
@ -251,14 +251,14 @@ 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) {
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout; int timeout;
I2C_SendData(i2c, (uint8_t)data); I2C_SendData(i2c, (uint8_t)data);
// Wait until the byte is transmitted // Wait until the byte is transmitted
timeout = FLAG_TIMEOUT; timeout = FLAG_TIMEOUT;
while ((I2C_GetFlagStatus(i2c, I2C_FLAG_TXE) == RESET) && while ((I2C_GetFlagStatus(i2c, I2C_FLAG_TXE) == RESET) &&
(I2C_GetFlagStatus(i2c, I2C_FLAG_BTF) == RESET)) { (I2C_GetFlagStatus(i2c, I2C_FLAG_BTF) == RESET)) {
timeout--; timeout--;
if (timeout == 0) { if (timeout == 0) {
return 0; return 0;
@ -270,11 +270,12 @@ int i2c_byte_write(i2c_t *obj, int data) {
void i2c_reset(i2c_t *obj) { void i2c_reset(i2c_t *obj) {
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout; int timeout;
// wait before reset // wait before reset
timeout = LONG_TIMEOUT; timeout = LONG_TIMEOUT;
while((I2C_GetFlagStatus(i2c, I2C_FLAG_BUSY)) && (timeout-- != 0)); while ((I2C_GetFlagStatus(i2c, I2C_FLAG_BUSY)) && (timeout-- != 0)) {
}
if (obj->i2c == I2C_1) { if (obj->i2c == I2C_1) {
RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE); RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
@ -290,7 +291,7 @@ void i2c_reset(i2c_t *obj) {
void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) { void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) {
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint16_t tmpreg; uint16_t tmpreg;
// Get the old register value // Get the old register value
tmpreg = i2c->OAR1; tmpreg = i2c->OAR1;
@ -313,8 +314,8 @@ void i2c_slave_mode(i2c_t *obj, int enable_slave) {
#define WriteAddressed 3 // the master is writing to this slave (slave = receiver) #define WriteAddressed 3 // the master is writing to this slave (slave = receiver)
int i2c_slave_receive(i2c_t *obj) { int i2c_slave_receive(i2c_t *obj) {
int retValue = NoData; int retValue = NoData;
uint32_t event; uint32_t event;
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
event = I2C_GetLastEvent(i2c); event = I2C_GetLastEvent(i2c);
@ -376,7 +377,6 @@ int i2c_slave_write(i2c_t *obj, const char *data, int length) {
return count; return count;
} }
#endif // DEVICE_I2CSLAVE #endif // DEVICE_I2CSLAVE
#endif // DEVICE_I2C #endif // DEVICE_I2C