[Armadeus-commitlog] armadeus branch, master, updated. release-3.3-370-gae635dd
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2011-02-24 18:30:17
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via ae635dda43b89f49e4737c8bd0c3cd351a4ffc7f (commit)
via e4d2036c89f17c81d6ccf2f7a7a260dba5721d02 (commit)
from 6b496a5cea9b63aaf9c47073921d637e92d22735 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ae635dda43b89f49e4737c8bd0c3cd351a4ffc7f
Merge: e4d2036c89f17c81d6ccf2f7a7a260dba5721d02 6b496a5cea9b63aaf9c47073921d637e92d22735
Author: Fabien Marteau <fab...@ar...>
Date: Thu Feb 24 19:29:35 2011 +0100
Merge branch 'master' of ssh://armadeus.git.sourceforge.net/gitroot/armadeus/armadeus
commit e4d2036c89f17c81d6ccf2f7a7a260dba5721d02
Author: Fabien Marteau <fab...@ar...>
Date: Thu Feb 24 19:28:36 2011 +0100
[as_devices]Adding i2c_read_msg function
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/as_i2c.c | 34 ++++++++++++++++++-
target/packages/as_devices/c/as_i2c.h | 7 ++++
.../packages/as_devices/python/AsDevices/AsI2c.py | 17 ++++++++++
target/packages/as_devices/python/src/AsI2c_wrap.c | 32 ++++++++++++++++++
target/packages/as_devices/python/src/AsI2c_wrap.h | 2 +
5 files changed, 90 insertions(+), 2 deletions(-)
diff --git a/target/packages/as_devices/c/as_i2c.c b/target/packages/as_devices/c/as_i2c.c
index 2fa54c6..698c249 100644
--- a/target/packages/as_devices/c/as_i2c.c
+++ b/target/packages/as_devices/c/as_i2c.c
@@ -171,16 +171,46 @@ int32_t as_i2c_write_reg(struct as_i2c_device *aDev,
return as_i2c_write(aDev, buf, sizeof(buf));
}
+int32_t as_i2c_read_msg(struct as_i2c_device *aDev,
+ uint8_t *aWData, uint8_t aWriteSize,
+ uint8_t *aRData, size_t aReadSize)
+{
+ /* write reg */
+ struct i2c_msg msg = { aDev->slave_addr, 0, aWriteSize, &aReadSize };
+ struct i2c_rdwr_ioctl_data rdwr = { &msg, 1 };
+
+ if (aDev->slave_addr == 0) {
+ ERROR("Slave address must be set before\n");
+ return -1;
+ }
+
+ if (ioctl(aDev->fi2c, I2C_RDWR, &rdwr) < 0) {
+ ERROR("Can't write on i2c\n");
+ return -1;
+ }
+ /* read data */
+ msg.flags = I2C_M_RD;
+ msg.len = aReadSize;
+ msg.buf = aRData;
+
+ if (ioctl(aDev->fi2c, I2C_RDWR, &rdwr) < 0) {
+ ERROR("Can't read on i2c\n");
+ return -2;
+ }
+
+ return 0;
+}
+
int32_t as_i2c_read_reg_byte(struct as_i2c_device *aDev, uint8_t aReg)
{
uint8_t val;
- int ret = as_i2c_read_reg(aDev, aReg, &val, 1);
+ int ret;
if (aDev->slave_addr == 0) {
ERROR("Slave address must be set before\n");
return -1;
}
-
+ ret = as_i2c_read_reg(aDev, aReg, &val, 1);
if (ret < 0)
return ret;
diff --git a/target/packages/as_devices/c/as_i2c.h b/target/packages/as_devices/c/as_i2c.h
index bab3a95..07fd78b 100644
--- a/target/packages/as_devices/c/as_i2c.h
+++ b/target/packages/as_devices/c/as_i2c.h
@@ -74,6 +74,13 @@ int32_t as_i2c_read_reg(struct as_i2c_device *aDev,
int32_t as_i2c_write_reg(struct as_i2c_device *aDev,
uint8_t aReg, const uint8_t *aData, size_t n);
+/** @brief forge a read message like this:
+ * S Addr[W] wdata0 [A] wdata1 [A] ... RS Addr R [rdata0] A [rdata1] A ... P
+ */
+int32_t as_i2c_read_msg(struct as_i2c_device *aDev,
+ uint8_t *aWData, uint8_t aWriteSize,
+ uint8_t *aRData, size_t aReadSize);
+
/** @brief Read a byte from the given register.
*/
int32_t as_i2c_read_reg_byte(struct as_i2c_device *aDev, uint8_t aReg);
diff --git a/target/packages/as_devices/python/AsDevices/AsI2c.py b/target/packages/as_devices/python/AsDevices/AsI2c.py
index 2963b2e..9106417 100644
--- a/target/packages/as_devices/python/AsDevices/AsI2c.py
+++ b/target/packages/as_devices/python/AsDevices/AsI2c.py
@@ -130,4 +130,21 @@ class AsI2c:
return wrapper.i2c_write_reg_byte(self.__device, aReg, aValue)
except Exception, e:
raise AsI2cError(str(e))
+ def readMsg(self, aWrList, aReadSize):
+ """ Write message wrote in aWrList, and read
+ aReadSize of byte after a repeated start
+ """
+ aWString = ''
+ for character in aWrList:
+ aWString += chr(character)
+ try:
+ Rstring = wrapper.i2c_read_msg(self.__device, aWString, aReadSize)
+ except Exception, e:
+ raise AsI2cError(str(e))
+ rList = []
+ for character in Rstring:
+ rList.append(ord(character))
+ return rList
+
+
diff --git a/target/packages/as_devices/python/src/AsI2c_wrap.c b/target/packages/as_devices/python/src/AsI2c_wrap.c
index b25184f..dadb15c 100644
--- a/target/packages/as_devices/python/src/AsI2c_wrap.c
+++ b/target/packages/as_devices/python/src/AsI2c_wrap.c
@@ -35,6 +35,7 @@ static PyMethodDef AsI2c_wrap_methods[] = {
{"i2c_write_reg" , i2c_write_reg , METH_VARARGS, "as_i2c function wrapped"},
{"i2c_read_reg_byte" , i2c_read_reg_byte , METH_VARARGS, "as_i2c function wrapped"},
{"i2c_write_reg_byte", i2c_write_reg_byte, METH_VARARGS, "as_i2c function wrapped"},
+ {"i2c_read_msg" , i2c_read_msg , METH_VARARGS, "as_i2c function wrapped"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
@@ -282,6 +283,37 @@ static PyObject * i2c_read_reg_byte(PyObject *self, PyObject *args)
return Py_BuildValue("i", ret);
}
+static PyObject * i2c_read_msg(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ struct as_i2c_device *aDev;
+ uint8_t *aWData;
+ int aWriteSize;
+ uint8_t RData[MAX_DATA_SIZE];
+ int aReadSize;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "ls#i", (long *)&aDev,
+ (unsigned char *)&aWData, &aWriteSize,
+ &aReadSize)) {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_i2c_read_msg(aDev, aWData, aWriteSize, RData, aReadSize);
+ if (ret < 0) {
+ PyErr_SetString(PyExc_IOError,
+ "Can't forge read message");
+ return NULL;
+ }
+
+ return Py_BuildValue("s#", (unsigned char *)RData, aReadSize);
+}
+
+
static PyObject * i2c_write_reg_byte(PyObject *self, PyObject *args)
{
/* parameters */
diff --git a/target/packages/as_devices/python/src/AsI2c_wrap.h b/target/packages/as_devices/python/src/AsI2c_wrap.h
index b4f0b47..61b8147 100644
--- a/target/packages/as_devices/python/src/AsI2c_wrap.h
+++ b/target/packages/as_devices/python/src/AsI2c_wrap.h
@@ -42,3 +42,5 @@ static PyObject * i2c_write_reg(PyObject *self, PyObject *args);
static PyObject * i2c_read_reg_byte(PyObject *self, PyObject *args);
static PyObject * i2c_write_reg_byte(PyObject *self, PyObject *args);
+
+static PyObject * i2c_read_msg(PyObject *self, PyObject *args);
hooks/post-receive
--
armadeus
|