[Armadeus-commitlog] armadeus branch, master, updated. armadeus-4.1-456-g4e43b7c
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2012-07-20 16:38:58
|
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 4e43b7cf48559691e1412c0e094305118bbcd46d (commit)
via b0c7dd692fff679f3729f83b593db3ea8a0ee044 (commit)
via 690cb8b6632a555b16c66574183820198d43d998 (commit)
from 9cb4659fed106a037ceac6731736460bcc1300f6 (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 4e43b7cf48559691e1412c0e094305118bbcd46d
Author: Fabien Marteau <fab...@ar...>
Date: Fri Jul 20 18:37:38 2012 +0200
[package][as_devices] adding python spi wrapper
commit b0c7dd692fff679f3729f83b593db3ea8a0ee044
Author: Fabien Marteau <fab...@ar...>
Date: Fri Jul 20 18:36:45 2012 +0200
[package][as_devices] fix bug in AsI2c class
commit 690cb8b6632a555b16c66574183820198d43d998
Author: Fabien Marteau <fab...@ar...>
Date: Fri Jul 20 16:44:47 2012 +0200
[as_devices] __def__() -> __del__()
-----------------------------------------------------------------------
Summary of changes:
.../packages/as_devices/python/AsDevices/AsI2c.py | 4 +-
.../packages/as_devices/python/AsDevices/AsSpi.py | 149 +++++++++
.../as_devices/python/AsDevices/__init__.py | 1 +
target/packages/as_devices/python/Makefile | 1 +
target/packages/as_devices/python/src/AsSpi_wrap.c | 348 ++++++++++++++++++++
.../python/src/{AsI2c_wrap.h => AsSpi_wrap.h} | 27 +-
6 files changed, 514 insertions(+), 16 deletions(-)
create mode 100644 target/packages/as_devices/python/AsDevices/AsSpi.py
create mode 100644 target/packages/as_devices/python/src/AsSpi_wrap.c
copy target/packages/as_devices/python/src/{AsI2c_wrap.h => AsSpi_wrap.h} (54%)
diff --git a/target/packages/as_devices/python/AsDevices/AsI2c.py b/target/packages/as_devices/python/AsDevices/AsI2c.py
index 9106417..809e31f 100644
--- a/target/packages/as_devices/python/AsDevices/AsI2c.py
+++ b/target/packages/as_devices/python/AsDevices/AsI2c.py
@@ -47,9 +47,9 @@ class AsI2c:
raise AsI2cError("Can't open i2c bus number "+str(aBusNumber)+\
": "+str(e))
- def __def__(self):
+ def __del__(self):
try:
- wrappers.i2c_close(self.__device)
+ wrapper.i2c_close(self.__device)
except Exception, e:
pass
diff --git a/target/packages/as_devices/python/AsDevices/AsSpi.py b/target/packages/as_devices/python/AsDevices/AsSpi.py
new file mode 100644
index 0000000..16eb69b
--- /dev/null
+++ b/target/packages/as_devices/python/AsDevices/AsSpi.py
@@ -0,0 +1,149 @@
+#! /usr/bin/python
+# -*- coding: utf-8 -*-
+#-----------------------------------------------------------------------------
+# Name: AsSpi.py
+# Purpose:
+# Author: Fabien Marteau <fab...@ar...>
+# Created: 20/07/2012
+#-----------------------------------------------------------------------------
+# Copyright (2012) Armadeus Systems
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+#-----------------------------------------------------------------------------
+
+__doc__ = "This class drive ARMadeus Board SPI"
+__version__ = "0.1"
+__author__ = "Fabien Marteau <fab...@ar...>"
+
+import wrappers.AsSpi_wrap as wrapper
+
+class AsSpiError(Exception):
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
+
+class AsSpi:
+ """
+ """
+
+ def __init__(self, aSpidevName):
+ try:
+ self.__device = wrapper.spi_open(aSpidevName)
+ except Exception, e:
+ raise AsSpiError(str(e))
+
+ def __del__(self):
+ try:
+ wrapper.spi_close(self.__device)
+ except Exception, e:
+ pass
+
+ def setLsb(self, aLsb):
+ """ Set lsb
+ """
+ try:
+ return wrapper.spi_set_lsb(self.__device, aLsb)
+ except Exception, e:
+ raise AsSpiError(str(e))
+
+ def getLsb(self):
+ """ Get lsb
+ """
+ try:
+ return wrapper.spi_get_lsb(self.__device)
+ except Exception, e:
+ raise AsSpiError(str(e))
+
+ def setMode(self, aMode):
+ """ Set mode
+ """
+ try:
+ return wrapper.spi_set_mode(self.__device, aMode)
+ except Exception, e:
+ raise AsSpiError(str(e))
+
+ def getMode(self):
+ """ Set mode
+ """
+ try:
+ return wrapper.spi_get_mode(self.__device)
+ except Exception, e:
+ raise AsSpiError(str(e))
+
+ def setSpeed(self, aSpeed):
+ """ Set speed
+ """
+ try:
+ return wrapper.spi_set_speed(self.__device, aSpeed)
+ except Exception, e:
+ raise AsSpiError(str(e))
+
+ def getSpeed(self):
+ """ get speed
+ """
+ try:
+ return wrapper.spi_get_speed(self.__device)
+ except Exception, e:
+ raise AsSpiError(str(e))
+
+ def getBitsPerWord(self):
+ """ Get bits per word
+ """
+ try:
+ return wrapper.spi_get_bits_per_word(self.__device)
+ except Exception, e:
+ raise AsSpiError(str(e))
+
+ def setBitsPerWord(self, aBits):
+ """ Set bits per word
+ """
+ try:
+ return wrapper.spi_set_bits_per_word(self.__device, aBits)
+ except Exception, e:
+ raise AsSpiError(str(e))
+
+ def msg(self, aSpeed, aLen, aMsg):
+ """ send/rcv message
+ aSpeed : spi speed
+ aLen : number of bits to send
+ aMsg : list of bytes to send (max 8)
+ """
+ if aLen <= 0:
+ raise AsSpiError("aLen must be upper than 0")
+ if aLen > 64:
+ raise AsSpiError("aLen can't be upper than 64")
+
+ if type(aMsg) != type([]):
+ raise AsSpiError("aMsg argument must be a list")
+ if len(aMsg) <= 0:
+ raise AsSpiError("aMsg list must have at least one value")
+ if len(aMsg) > 8:
+ raise AsSpiError("aMsg list can have 8 values maximum")
+
+ if aLen%8 == 0:
+ list_len = aLen/8
+ else:
+ list_len = (aLen/8) + 1
+
+ msg = aMsg + [0 for i in range(8 - list_len)]
+
+ try:
+ return wrapper.spi_msg(self.__device, aSpeed, aLen,
+ msg[7], msg[6], msg[5], msg[4], msg[3], msg[2], msg[1], msg[0])
+ except Exception, e:
+ raise AsSpiError(str(e))
+
diff --git a/target/packages/as_devices/python/AsDevices/__init__.py b/target/packages/as_devices/python/AsDevices/__init__.py
index 2b9eaf1..4c96c87 100644
--- a/target/packages/as_devices/python/AsDevices/__init__.py
+++ b/target/packages/as_devices/python/AsDevices/__init__.py
@@ -39,3 +39,4 @@ from AsGpio import *
from AsAdc import *
from AsDac import *
from AsI2c import *
+from AsSpi import *
diff --git a/target/packages/as_devices/python/Makefile b/target/packages/as_devices/python/Makefile
index b3fa2a3..7a6a3bd 100644
--- a/target/packages/as_devices/python/Makefile
+++ b/target/packages/as_devices/python/Makefile
@@ -19,6 +19,7 @@ WRAPPER_LIBS=AsGpio_wrap.so
WRAPPER_LIBS+= AsAdc_wrap.so
WRAPPER_LIBS+= AsDac_wrap.so
WRAPPER_LIBS+= AsI2c_wrap.so
+WRAPPER_LIBS+= AsSpi_wrap.so
WRAPPER_DIR=src
PYTHON_VERS=2.7
diff --git a/target/packages/as_devices/python/src/AsSpi_wrap.c b/target/packages/as_devices/python/src/AsSpi_wrap.c
new file mode 100644
index 0000000..6cac628
--- /dev/null
+++ b/target/packages/as_devices/python/src/AsSpi_wrap.c
@@ -0,0 +1,348 @@
+/*
+** The ARMadeus Project
+**
+** Copyright (C) 2012 The armadeus systems team
+** Fabien Marteau <fab...@ar...>
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+*/
+
+#include "AsSpi_wrap.h"
+#include "as_spi.h"
+
+/* Methods definitions */
+static PyMethodDef AsSpi_wrap_methods[] = {
+ {"spi_open" , spi_open , METH_VARARGS, "as_spi function wrapped"},
+ {"spi_close" , spi_close , METH_VARARGS, "as_spi function wrapped"},
+ {"spi_set_lsb" , spi_set_lsb , METH_VARARGS, "as_spi function wrapped"},
+ {"spi_get_lsb" , spi_get_lsb , METH_VARARGS, "as_spi function wrapped"},
+ {"spi_set_mode" , spi_set_mode , METH_VARARGS, "as_spi function wrapped"},
+ {"spi_get_mode" , spi_get_mode , METH_VARARGS, "as_spi function wrapped"},
+ {"spi_set_speed" , spi_set_speed , METH_VARARGS, "as_spi function wrapped"},
+ {"spi_get_speed" , spi_get_speed , METH_VARARGS, "as_spi function wrapped"},
+ {"spi_get_bits_per_word" , spi_get_bits_per_word, METH_VARARGS, "as_spi function wrapped"},
+ {"spi_set_bits_per_word" , spi_set_bits_per_word, METH_VARARGS, "as_spi function wrapped"},
+ {"spi_msg" , spi_msg , METH_VARARGS, "as_spi function wrapped"},
+ {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
+/* Init Module */
+void initAsSpi_wrap() /* called on first import */
+{ /* name matter if called dynamically */
+ (void) Py_InitModule("AsSpi_wrap", AsSpi_wrap_methods); /* mod name, table ptr */
+}
+
+static PyObject * spi_open(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ unsigned char *aSpidevName;
+
+ int dev;
+
+ PyObject *ret;
+ char buff[300];
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "s", &aSpidevName))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+ dev = as_spi_open(aSpidevName);
+ if (dev < 0 )
+ {
+ snprintf(buff, 300,
+ "Can't open spidev %s", aSpidevName);
+ PyErr_SetString(PyExc_IOError,buff);
+ return NULL;
+ }
+
+ ret = Py_BuildValue("l", (long)dev);
+ return ret;
+}
+
+static PyObject * spi_close(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ long aDev;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "l", (long *)&aDev))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ as_spi_close((int)aDev);
+
+ return Py_BuildValue("i", 0);
+}
+
+static PyObject * spi_set_lsb(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ long aDev;
+ int aLsb;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "li", (long *)&aDev, &aLsb))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_spi_set_lsb((int)aDev, aLsb);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't set lsb");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * spi_get_lsb(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ long aDev;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "l", (long *)&aDev))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_spi_get_lsb((int)aDev);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get lsb");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+
+}
+
+static PyObject * spi_set_mode(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ long aDev;
+ int aMode;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "li", (long *)&aDev, &aMode))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_spi_set_mode((int)aDev, aMode);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't set mode");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * spi_get_mode(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ long aDev;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "l", (long *)&aDev))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_spi_get_mode((int)aDev);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get lsb");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * spi_set_speed(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ long aDev;
+ int aSpeed;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "li", (long *)&aDev, &aSpeed))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_spi_set_speed((int)aDev, aSpeed);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't set speed");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * spi_get_speed(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ long aDev;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "l", (long *)&aDev))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_spi_get_speed((int)aDev);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get speed");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * spi_get_bits_per_word(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ long aDev;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "l", (long *)&aDev))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_spi_get_bits_per_word((int)aDev);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get bit per word");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * spi_set_bits_per_word(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ long aDev;
+ int aBits;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "li", (long *)&aDev, &aBits))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_spi_set_bits_per_word((int)aDev, aBits);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't set speed");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * spi_msg(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ long aDev;
+ int aSpeed;
+ int aLen;
+ char msg[8];
+
+ long long ret, value;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "liibbbbbbbb", (long *)&aDev, &aSpeed, &aLen,
+ &msg[0], &msg[1], &msg[2], &msg[3],
+ &msg[4], &msg[5], &msg[6], &msg[7]))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ value = 0;
+ value += (long long)msg[0] << (7-0)*8;
+ value += (long long)msg[1] << (7-1)*8;
+ value += (long long)msg[2] << (7-2)*8;
+ value += (long long)msg[3] << (7-3)*8;
+ value += (long long)msg[4] << (7-4)*8;
+ value += (long long)msg[5] << (7-5)*8;
+ value += (long long)msg[6] << (7-6)*8;
+ value += (long long)msg[7] << (7-7)*8;
+
+ ret = as_spi_msg((int)aDev, value, aLen, aSpeed);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't make message");
+ return NULL;
+ }
+
+ return Py_BuildValue("bbbbbbbb",msg[0], msg[1], msg[2], msg[3],
+ msg[4], msg[5], msg[6], msg[7]);
+}
diff --git a/target/packages/as_devices/python/src/AsI2c_wrap.h b/target/packages/as_devices/python/src/AsSpi_wrap.h
similarity index 54%
copy from target/packages/as_devices/python/src/AsI2c_wrap.h
copy to target/packages/as_devices/python/src/AsSpi_wrap.h
index 61b8147..6f5ff54 100644
--- a/target/packages/as_devices/python/src/AsI2c_wrap.h
+++ b/target/packages/as_devices/python/src/AsSpi_wrap.h
@@ -1,7 +1,7 @@
/*
** THE ARMadeus Systems
**
-** Copyright (C) 2011 The armadeus systems team
+** Copyright (C) 2012 The armadeus systems team
** Fabien Marteau <fab...@ar...>
**
** This library is free software; you can redistribute it and/or
@@ -19,28 +19,27 @@
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
#include <Python.h>
/* Init module */
-void initAsI2c_wrap();
+void initAsSpi_wrap();
/*********************/
/* Functions wrapped */
/*********************/
-static PyObject * i2c_open(PyObject *self, PyObject *args);
-static PyObject * i2c_close(PyObject *self, PyObject *args);
-static PyObject * i2c_set_slave_addr(PyObject *self, PyObject *args);
-static PyObject * i2c_get_slave_addr(PyObject *self, PyObject *args);
+static PyObject * spi_open(PyObject *self, PyObject *args);
+static PyObject * spi_close(PyObject *self, PyObject *args);
-static PyObject * i2c_read(PyObject *self, PyObject *args);
-static PyObject * i2c_write(PyObject *self, PyObject *args);
+static PyObject * spi_set_lsb(PyObject *self, PyObject *args);
+static PyObject * spi_get_lsb(PyObject *self, PyObject *args);
-static PyObject * i2c_read_reg(PyObject *self, PyObject *args);
-static PyObject * i2c_write_reg(PyObject *self, PyObject *args);
+static PyObject * spi_set_mode(PyObject *self, PyObject *args);
+static PyObject * spi_get_mode(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 * spi_set_speed(PyObject *self, PyObject *args);
+static PyObject * spi_get_speed(PyObject *self, PyObject *args);
-static PyObject * i2c_read_msg(PyObject *self, PyObject *args);
+static PyObject * spi_get_bits_per_word(PyObject *self, PyObject *args);
+static PyObject * spi_set_bits_per_word(PyObject *self, PyObject *args);
+static PyObject * spi_msg(PyObject *self, PyObject *args);
hooks/post-receive
--
armadeus
|