I2C changes for upstream NuttX per trasaction freq control

This commit is contained in:
David Sidrane
2016-12-12 14:31:39 -10:00
committed by Lorenz Meier
parent 0177e250f4
commit dcc2d1c3d1
7 changed files with 59 additions and 54 deletions
+16 -10
View File
@@ -44,6 +44,10 @@
namespace device
{
/*
* N.B. By defaulting the value of _bus_clocks to non Zero
* All calls to init() will NOT set the buss frequency
*/
unsigned int I2C::_bus_clocks[3] = { 100000, 100000, 100000 };
@@ -128,12 +132,6 @@ I2C::init()
goto out;
}
// set the bus frequency on the first access if it has
// not been set yet
if (_bus_clocks[bus_index] == 0) {
_bus_clocks[bus_index] = _frequency;
}
// set frequency for this instance once to the bus speed
// the bus speed is the maximum supported by all devices on the bus,
// as we have to prioritize performance over compatibility.
@@ -143,7 +141,12 @@ I2C::init()
// This is necessary as automatically lowering the bus speed
// for maximum compatibility could induce timing issues on
// critical sensors the adopter might be unaware of.
I2C_SETFREQUENCY(_dev, _bus_clocks[bus_index]);
// set the bus frequency on the first access if it has
// not been set yet
if (_bus_clocks[bus_index] == 0) {
_bus_clocks[bus_index] = _frequency;
}
// call the probe function to check whether the device is present
ret = probe();
@@ -196,6 +199,7 @@ I2C::transfer(const uint8_t *send, unsigned send_len, uint8_t *recv, unsigned re
msgs = 0;
if (send_len > 0) {
msgv[msgs].frequency = _bus_clocks[_bus - 1];
msgv[msgs].addr = _address;
msgv[msgs].flags = 0;
msgv[msgs].buffer = const_cast<uint8_t *>(send);
@@ -204,6 +208,7 @@ I2C::transfer(const uint8_t *send, unsigned send_len, uint8_t *recv, unsigned re
}
if (recv_len > 0) {
msgv[msgs].frequency = _bus_clocks[_bus - 1];;
msgv[msgs].addr = _address;
msgv[msgs].flags = I2C_M_READ;
msgv[msgs].buffer = recv;
@@ -224,7 +229,7 @@ I2C::transfer(const uint8_t *send, unsigned send_len, uint8_t *recv, unsigned re
/* if we have already retried once, or we are going to give up, then reset the bus */
if ((retry_count >= 1) || (retry_count >= _retries)) {
up_i2creset(_dev);
I2C_RESET(_dev);
}
} while (retry_count++ < _retries);
@@ -239,8 +244,9 @@ I2C::transfer(i2c_msg_s *msgv, unsigned msgs)
int ret;
unsigned retry_count = 0;
/* force the device address into the message vector */
/* force the device address and Frequency into the message vector */
for (unsigned i = 0; i < msgs; i++) {
msgv[i].frequency = _bus_clocks[_bus - 1];
msgv[i].addr = _address;
}
@@ -255,7 +261,7 @@ I2C::transfer(i2c_msg_s *msgv, unsigned msgs)
/* if we have already retried once, or we are going to give up, then reset the bus */
if ((retry_count >= 1) || (retry_count >= _retries)) {
up_i2creset(_dev);
I2C_RESET(_dev);
}
} while (retry_count++ < _retries);
+1 -1
View File
@@ -59,7 +59,7 @@
#include <unistd.h>
#include <nuttx/arch.h>
#include <nuttx/i2c.h>
#include <nuttx/i2c/i2c_master.h>
#include <board_config.h>