[Armadeus-commitlog] armadeus branch, master, updated. release-3.3-352-g634a454
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2011-02-21 15:46:43
|
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 634a454c36fd16a4a3d2f016697fc8f7ed048ef7 (commit)
via ef1c781d21d84b267e245fa533dea4bc83ce9039 (commit)
via 4e30cc713952955e1ff49bb9b5064a4187fae23e (commit)
via 1550b94546abe3e756e42e7b6924c6d117f09c73 (commit)
via 165a6db56763840b3c6f339f983dbce57b053823 (commit)
via a368f490253739fdf3427a87fc118574a777ed20 (commit)
via 9c9879199fe6cde9e5c5b6b91996716924396793 (commit)
via 8ad5d5bcb61624c6457fa2ef247a829ea95e0d2c (commit)
via a6ee47b3814dcdb437f34d498c988b0d4507ead1 (commit)
from 6b83bc2d5d5ccbf47be5c1b169404497f53f3bbe (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 634a454c36fd16a4a3d2f016697fc8f7ed048ef7
Author: Fabien Marteau <fab...@ar...>
Date: Mon Feb 21 16:45:53 2011 +0100
[as_devices] Fix some bugs in dac C and Python class
commit ef1c781d21d84b267e245fa533dea4bc83ce9039
Author: Fabien Marteau <fab...@ar...>
Date: Mon Feb 21 16:21:41 2011 +0100
[as_devices] Adding Dac python class
commit 4e30cc713952955e1ff49bb9b5064a4187fae23e
Author: Fabien Marteau <fab...@ar...>
Date: Mon Feb 21 16:20:40 2011 +0100
[as_devices] suppressing some warnings
commit 1550b94546abe3e756e42e7b6924c6d117f09c73
Author: Fabien Marteau <fab...@ar...>
Date: Mon Feb 21 16:17:10 2011 +0100
[as_devices] fix api bug in as_dac wrapper
commit 165a6db56763840b3c6f339f983dbce57b053823
Author: Fabien Marteau <fab...@ar...>
Date: Mon Feb 21 16:12:41 2011 +0100
[as_devices] Change name of API for dac setting value
commit a368f490253739fdf3427a87fc118574a777ed20
Author: Fabien Marteau <fab...@ar...>
Date: Mon Feb 21 16:04:57 2011 +0100
[as_devices] Adding C wrapper for dac
commit 9c9879199fe6cde9e5c5b6b91996716924396793
Author: Fabien Marteau <fab...@ar...>
Date: Mon Feb 21 16:00:17 2011 +0100
[as_devices] Change license for python wrappers (to GNU Lesser General License)
commit 8ad5d5bcb61624c6457fa2ef247a829ea95e0d2c
Author: Fabien Marteau <fab...@ar...>
Date: Mon Feb 21 15:29:00 2011 +0100
[as_devices] Adding generic dac class
commit a6ee47b3814dcdb437f34d498c988b0d4507ead1
Author: Fabien Marteau <fab...@ar...>
Date: Mon Feb 21 15:27:25 2011 +0100
[as_devices] Adding as1531 chip class for adc
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/Makefile | 3 +-
target/packages/as_devices/c/as_as1531.c | 83 ++++++++++++++++
.../{python/src/AsAdc_wrap.h => c/as_as1531.h} | 28 ++++--
target/packages/as_devices/c/as_dac.c | 69 +++++++++++++
target/packages/as_devices/c/as_dac.h | 83 ++++++++++++++++
target/packages/as_devices/c/as_helpers.c | 1 -
target/packages/as_devices/c/as_max1027.c | 2 +-
target/packages/as_devices/c/as_max5821.c | 102 +++++++++++++++-----
target/packages/as_devices/c/as_max5821.h | 24 +++---
.../as_devices/python/AsDevices/Apf27Pwm.py | 4 +-
.../packages/as_devices/python/AsDevices/AsAdc.py | 8 +-
.../python/AsDevices/{AsAdc.py => AsDac.py} | 68 ++++++-------
.../packages/as_devices/python/AsDevices/AsGpio.py | 4 +-
.../as_devices/python/AsDevices/__init__.py | 7 +-
.../python/AsDevices/wrappers/__init__.py | 6 +-
target/packages/as_devices/python/Makefile | 1 +
.../python/src/{AsAdc_wrap.c => AsDac_wrap.c} | 52 +++++-----
.../python/src/{AsAdc_wrap.h => AsDac_wrap.h} | 8 +-
18 files changed, 423 insertions(+), 130 deletions(-)
create mode 100644 target/packages/as_devices/c/as_as1531.c
copy target/packages/as_devices/{python/src/AsAdc_wrap.h => c/as_as1531.h} (65%)
create mode 100644 target/packages/as_devices/c/as_dac.c
create mode 100644 target/packages/as_devices/c/as_dac.h
copy target/packages/as_devices/python/AsDevices/{AsAdc.py => AsDac.py} (54%)
copy target/packages/as_devices/python/src/{AsAdc_wrap.c => AsDac_wrap.c} (63%)
copy target/packages/as_devices/python/src/{AsAdc_wrap.h => AsDac_wrap.h} (81%)
diff --git a/target/packages/as_devices/c/Makefile b/target/packages/as_devices/c/Makefile
index 3d20edf..cba285c 100644
--- a/target/packages/as_devices/c/Makefile
+++ b/target/packages/as_devices/c/Makefile
@@ -17,7 +17,8 @@ OBJ += as_93lcxx.o
OBJ += as_spi.o
OBJ += as_as1531.o
OBJ += as_max1027.o
-#OBJ += as_max5821.o
+OBJ += as_max5821.o
+OBJ += as_dac.o
OBJ += as_helpers.o
OBJ += as_adc.o
diff --git a/target/packages/as_devices/c/as_as1531.c b/target/packages/as_devices/c/as_as1531.c
new file mode 100644
index 0000000..6924cb0
--- /dev/null
+++ b/target/packages/as_devices/c/as_as1531.c
@@ -0,0 +1,83 @@
+#include "as_as1531.h"
+#include "as_helpers.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h> /* for close() */
+
+#define AS_AS1531_MAX_VALUE 2500
+#define BUFF_SIZE (300)
+
+#undef ERROR
+#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+
+struct as_adc_device *as_adc_open_as1531(int aDeviceNum, int aVRef) {
+ struct as_adc_device *dev;
+ int ret;
+ int fname;
+ char buf[BUFF_SIZE];
+
+ snprintf(buf, BUFF_SIZE, "/sys/class/hwmon/hwmon%d/device/name", aDeviceNum);
+ fname = open(buf, O_RDONLY);
+ if (fname < 0) {
+ ERROR("Can't open file %s, is as1531 modprobed ?\n", buf);
+ return NULL;
+ }
+
+ ret = read(fname, buf, BUFF_SIZE);
+ if (ret <= 0) {
+ ERROR("Can't read name\n");
+ return NULL;
+ }
+
+ ret = strncmp(AS_AS1531_NAME, buf, strlen(AS_AS1531_NAME));
+ if (ret != 0) {
+ ERROR("Wrong driver name %s\n",buf);
+ return NULL;
+ }
+
+ close(fname);
+
+ dev = malloc(sizeof(struct as_adc_device));
+ if (dev == NULL) {
+ ERROR("Can't allocate memory for as_adc structure\n");
+ return NULL;
+ }
+
+ dev->device_type = "as1531";
+ dev->device_num = aDeviceNum;
+ dev->vref = aVRef;
+ return dev;
+}
+
+int32_t as_adc_get_value_in_millivolts_as1531(struct as_adc_device *aDev, int aChannel) {
+ int ret;
+ int finput;
+ int value;
+ char buf[BUFF_SIZE];
+
+ snprintf(buf, BUFF_SIZE,
+ "/sys/class/hwmon/hwmon%d/device/in%d_input",
+ aDev->device_num, aChannel);
+ finput = open(buf, O_RDONLY);
+ if (finput < 0) {
+ ERROR("Can't open file %s.\n", buf);
+ return -1;
+ }
+
+ ret = as_read_int(finput, &value);
+ if (ret < 0) {
+ ERROR("Can't read value on channel %d\n", aChannel);
+ return -1;
+ }
+ close(finput);
+
+ if (AS_AS1531_MAX_VALUE == aDev->vref) return value;
+
+ return (value*aDev->vref)/AS_AS1531_MAX_VALUE;
+}
+
+int32_t as_adc_close_as1531(struct as_adc_device *aDev) {
+ return 0;
+}
diff --git a/target/packages/as_devices/python/src/AsAdc_wrap.h b/target/packages/as_devices/c/as_as1531.h
similarity index 65%
copy from target/packages/as_devices/python/src/AsAdc_wrap.h
copy to target/packages/as_devices/c/as_as1531.h
index 7fa0b8f..507fdaf 100644
--- a/target/packages/as_devices/python/src/AsAdc_wrap.h
+++ b/target/packages/as_devices/c/as_as1531.h
@@ -1,5 +1,5 @@
/*
-** THE ARMadeus Systems
+** The ARMadeus Project
**
** Copyright (C) 2011 The armadeus systems team
** Fabien Marteau <fab...@ar...>
@@ -19,14 +19,22 @@
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <Python.h>
+#ifndef __ASAS1531_H__
+#define __ASAS1531_H__
-/* Init module */
-void initAsAdc_wrap();
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
-/*********************/
-/* Functions wrapped */
-/*********************/
-static PyObject * adc_open(PyObject *self, PyObject *args);
-static PyObject * getValueInMillivolts(PyObject *self, PyObject *args);
-static PyObject * adc_close(PyObject *self, PyObject *args);
+#include "as_adc.h"
+
+struct as_adc_device *as_adc_open_as1531(int aDeviceNum, int aVRef);
+
+int32_t as_adc_get_value_in_millivolts_as1531(struct as_adc_device *aDev, int aChannel);
+
+int32_t as_adc_close_as1531(struct as_adc_device *aDev);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __ASAS1531_H__ */
diff --git a/target/packages/as_devices/c/as_dac.c b/target/packages/as_devices/c/as_dac.c
new file mode 100644
index 0000000..e492b0d
--- /dev/null
+++ b/target/packages/as_devices/c/as_dac.c
@@ -0,0 +1,69 @@
+/*
+ * This software 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
+ *
+ *
+ * Copyright (C) 2011 Fabien Marteau <fab...@ar...>
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h> /* for close() */
+#include <string.h>
+
+#include "as_dac.h"
+#include "as_max5821.h"
+
+#undef ERROR
+#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+
+struct as_dac_device *as_dac_open(const char *aDacType, int aBusNumber,
+ int aAddress, int aVRef)
+{
+ if (strncmp(AS_MAX5821_TYPE, aDacType, strlen(AS_MAX5821_TYPE)) == 0)
+ return as_dac_open_max5821(aBusNumber, aAddress, aVRef);
+ /* TODO: mcp4912 */
+ ERROR("Undefined DAC type '%s'\n", aDacType);
+ return NULL;
+}
+
+int32_t as_dac_set_value_in_millivolts(struct as_dac_device *aDev,
+ int aChannel,
+ int aValue)
+{
+ if (strncmp(AS_MAX5821_TYPE, aDev->device_type, strlen(AS_MAX5821_TYPE)) == 0) {
+ if ((aChannel == 0) || (aChannel == 1))
+ return as_dac_set_value_max5821(aDev, aChannel + 'A', aValue);
+ else {
+ ERROR("Wrong channel number %d\n",aChannel);
+ return -1;
+ }
+ }
+
+ ERROR("Undefined DAC type '%s'\n", aDev->device_type);
+ return -1;
+}
+
+
+int32_t as_dac_close(struct as_dac_device *aDev)
+{
+ if (strncmp(AS_MAX5821_TYPE, aDev->device_type, strlen(AS_MAX5821_TYPE)) == 0)
+ as_dac_close_max5821(aDev);
+
+ free(aDev);
+ return 0;
+}
+
diff --git a/target/packages/as_devices/c/as_dac.h b/target/packages/as_devices/c/as_dac.h
new file mode 100644
index 0000000..6b569a3
--- /dev/null
+++ b/target/packages/as_devices/c/as_dac.h
@@ -0,0 +1,83 @@
+/*
+ * This software 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
+ *
+ *
+ * Copyright (C) 2011 Fabien Marteau <fab...@ar...>
+ *
+ */
+
+
+#ifndef AS_DAC_H_
+#define AS_DAC_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "as_dac.h"
+
+#define AS_MAX5821_TYPE "max5821"
+#define AS_MCP4912
+
+/**
+ * Store dac parameters
+ */
+struct as_dac_device {
+ int bus_number;
+ int chip_address;
+ int vref;
+ const char *device_type;
+ void *chip_param;
+};
+
+/** @brief Open dac
+ *
+ * @param aDacType type name of adc ("max5821" or "mcp4912")
+ * @param aBusNumber bus number used
+ * @param aAddress i2c address for i2c chip, and CS number for SPI chip
+ * @param aVRef voltage reference in milivolt
+ * @param aVDefault default voltage value at open
+ *
+ * @return as_dac_device structure pointer on success, NULL on error
+ */
+struct as_dac_device *as_dac_open(const char *aDacType, int aBusNumber,
+ int aAddress, int aVRef);
+
+
+/** @brief set a channel value.
+ *
+ * @param aDev structure pointer of dac device
+ * @param aChannel channel number (A:0, B:1,...)
+ * @param aValue channel value in milivolt
+ *
+ * @return negative value on error
+ */
+int32_t as_dac_set_value_in_millivolts(struct as_dac_device *aDev,
+ int aChannel,
+ int aValue);
+
+/** @brief close device
+ *
+ * @param aDev structure pointer of dac device
+ *
+ * @return negative value on error
+ */
+int32_t as_dac_close(struct as_dac_device *aDev);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* AS_DAC_H_ */
diff --git a/target/packages/as_devices/c/as_helpers.c b/target/packages/as_devices/c/as_helpers.c
index a3dc318..e2fa27c 100644
--- a/target/packages/as_devices/c/as_helpers.c
+++ b/target/packages/as_devices/c/as_helpers.c
@@ -62,7 +62,6 @@ int as_write_buffer(int fd, int value)
int as_write_buffer_string(int fd, char *string)
{
int ret;
- char buffer[SIZE_OF_BUFF];
int string_len;
string_len = strlen(string);
diff --git a/target/packages/as_devices/c/as_max1027.c b/target/packages/as_devices/c/as_max1027.c
index 0008abe..3887701 100644
--- a/target/packages/as_devices/c/as_max1027.c
+++ b/target/packages/as_devices/c/as_max1027.c
@@ -204,7 +204,7 @@ int32_t as_adc_get_value_in_millivolts_max1027(struct as_adc_device *aDev, int a
file = open(buffer, O_WRONLY);
if (file < 0) {
ERROR("Can't open conversion file\n");
- return NULL;
+ return -1;
}
ret = as_write_buffer(file, MAX1027_CONV |
MAX1027_CONV_CHSEL(aChannel) |
diff --git a/target/packages/as_devices/c/as_max5821.c b/target/packages/as_devices/c/as_max5821.c
index 168fbd6..33959b8 100644
--- a/target/packages/as_devices/c/as_max5821.c
+++ b/target/packages/as_devices/c/as_max5821.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include "as_dac.h"
#include "as_max5821.h"
#include "as_i2c.h"
@@ -44,39 +45,80 @@
/*-----------------------------------------------------------------------------*/
-struct as_max5821_device *as_max5821_open(int aI2cBus, int aI2cAddress)
+struct as_dac_device *as_dac_open_max5821(int aI2cBus, int aI2cAddress, int aVRef)
{
- struct as_max5821_device *dev;
+ struct as_max5821_device *max5821_dev;
+ struct as_dac_device *dev;
+ struct as_i2c_device *i2c_dev;
+ int ret;
- dev = (struct as_max5821_device *)malloc(sizeof(struct as_max5821_device));
- if (dev == NULL)
- {
- ERROR("can't allocate memory for device structure\n");
+ i2c_dev = as_i2c_open(aI2cBus);
+ if (i2c_dev == NULL) {
+ ERROR("Can't open i2c bus number %d\n", aI2cBus);
return NULL;
}
- dev->i2c_bus = as_i2c_open(aI2cBus);
- if (dev->i2c_bus < 0)
- {
- ERROR("Can't open i2c bus number %d\n",aI2cBus);
- free(dev);
- return NULL;
+ ret = as_i2c_set_slave_addr(i2c_dev, aI2cAddress);
+ if (ret < 0) {
+ ERROR("Can't set i2c address 0x%02x\n",aI2cAddress);
+ goto close_i2c_err;
+ }
+
+ dev = (struct as_dac_device *)malloc(sizeof(struct as_dac_device));
+ if (dev == NULL) {
+ ERROR("can't allocate memory for device structure\n");
+ goto close_i2c_err;
+ }
+ max5821_dev = (struct as_max5821_device *)malloc(sizeof(struct as_max5821_device));
+ if (max5821_dev == NULL) {
+ ERROR("can't allocate memory for device structure\n");
+ goto free_dev_err;
}
- dev->i2c_address = aI2cAddress;
+
+
+ max5821_dev->i2c_dev = i2c_dev;
+
+ dev->bus_number = aI2cBus;
+ dev->chip_address = aI2cAddress;
+ dev->device_type = AS_MAX5821_TYPE;
+ dev->vref = aVRef;
+ dev->chip_param = (void *)max5821_dev;
+
+ ret = as_dac_max5821_power(dev, 'A', MAX5821_POWER_UP);
+ if (ret < 0) {
+ ERROR("Can't power up MAX5821 channel A\n");
+ goto free_max5821_dev_err;
+ }
+ ret = as_dac_max5821_power(dev, 'B', MAX5821_POWER_UP);
+ if (ret < 0) {
+ ERROR("Can't power up MAX5821 channel B\n");
+ goto free_max5821_dev_err;
+ }
return dev;
+
+free_max5821_dev_err:
+ free(max5821_dev);
+free_dev_err:
+ free(dev);
+close_i2c_err:
+ as_i2c_close(i2c_dev);
+ return NULL;
}
/*-----------------------------------------------------------------------------*/
-int32_t as_max5821_power(struct as_max5821_device *aDev,
+int32_t as_dac_max5821_power(struct as_dac_device *aDev,
char aChannel,
AS_max5821_power_mode aMode)
{
+ struct as_max5821_device *max5821_dev;
int ret;
unsigned char buff[2];
+ max5821_dev = aDev->chip_param;
+
switch(aChannel)
{
case 'a':
@@ -88,13 +130,13 @@ int32_t as_max5821_power(struct as_max5821_device *aDev,
default: ERROR("Wrong channel name %c\n", aChannel);
return -1;
}
-
+
buff[0] = MAX5821_EXTENDED_COMMAND_MODE;
- ret = as_i2c_write(aDev->i2c_bus, aDev->i2c_address, buff, 2);
+ ret = as_i2c_write(max5821_dev->i2c_dev, buff, 2);
if (ret < 0) {
ERROR("can't write on i2c bus %d, address %d, value %x %x\n",
- aDev->i2c_bus,aDev->i2c_address,buff[0], buff[1]);
+ aDev->bus_number, aDev->chip_address,buff[0], buff[1]);
return -1;
}
@@ -103,13 +145,16 @@ int32_t as_max5821_power(struct as_max5821_device *aDev,
/*-----------------------------------------------------------------------------*/
-int32_t as_max5821_set_one_value(struct as_max5821_device *aDev,
+int32_t as_dac_set_value_max5821(struct as_dac_device *aDev,
char aChannel,
int aValue)
{
+ struct as_max5821_device *max5821_dev;
int ret;
unsigned char buff[2];
+ max5821_dev = aDev->chip_param;
+
switch(aChannel)
{
case 'a':
@@ -124,7 +169,7 @@ int32_t as_max5821_set_one_value(struct as_max5821_device *aDev,
buff[1] =(unsigned char)((aValue << 2) & 0x00FC);
- ret = as_i2c_write(aDev->i2c_bus, aDev->i2c_address, buff, 2);
+ ret = as_i2c_write(max5821_dev->i2c_dev, buff, 2);
if (ret < 0) {
ERROR("can't write on i2c bus\n");
return -1;
@@ -135,16 +180,19 @@ int32_t as_max5821_set_one_value(struct as_max5821_device *aDev,
/*-----------------------------------------------------------------------------*/
-int32_t as_max5821_set_both_value(struct as_max5821_device *aDev,
+int32_t as_max5821_set_both_value(struct as_dac_device *aDev,
int aValue)
{
+ struct as_max5821_device *max5821_dev;
int ret;
unsigned char buff[2];
+ max5821_dev = aDev->chip_param;
+
buff[0] = 0xC0 | ((unsigned char)((aValue >> 6)) & 0x0F);
buff[1] = (unsigned char)((aValue << 2) & 0x00FC);
-
- ret = as_i2c_write(aDev->i2c_bus, aDev->i2c_address, buff, 2);
+
+ ret = as_i2c_write(max5821_dev->i2c_dev, buff, 2);
if (ret < 0) {
ERROR("can't write on i2c bus\n");
return -1;
@@ -155,10 +203,14 @@ int32_t as_max5821_set_both_value(struct as_max5821_device *aDev,
/*-----------------------------------------------------------------------------*/
-int32_t as_max5821_close(struct as_max5821_device *aDev)
+int32_t as_dac_close_max5821(struct as_dac_device *aDev)
{
- as_i2c_close(aDev->i2c_bus);
- free(aDev);
+ struct as_max5821_device *max5821_dev;
+
+ max5821_dev = (struct as_max5821_device *)(aDev->chip_param);
+ as_i2c_close(max5821_dev->i2c_dev);
+ free(max5821_dev);
+ aDev->chip_param = NULL;
return 0;
}
diff --git a/target/packages/as_devices/c/as_max5821.h b/target/packages/as_devices/c/as_max5821.h
index 580d1bc..8c17d10 100644
--- a/target/packages/as_devices/c/as_max5821.h
+++ b/target/packages/as_devices/c/as_max5821.h
@@ -27,16 +27,13 @@ extern "C" {
#include "as_i2c.h"
-/**
- * Store max5821 parameters
- */
struct as_max5821_device {
- int i2c_bus;
- int i2c_address;
+ struct as_i2c_device *i2c_dev;
};
+
typedef enum {
- MAX5821_POWER_UP = 0,
+ MAX5821_POWER_UP = 0,
MAX5821_POWER_DOWN_MODE0,
MAX5821_POWER_DOWN_MODE1,
MAX5821_POWER_DOWN_MODE2
@@ -46,11 +43,14 @@ typedef enum {
*
* @param aI2cBus i2c bus number
* @param aI2cAddress i2c chip address
+ * @param aVRef reference voltage
+ * @param aVDefault voltage required when device opened
*
* @return as_max5821_device structure on success, NULL on error
*/
-struct as_max5821_device *as_max5821_open(int aI2cBus, int aI2cAddress);
-
+struct as_dac_device *as_dac_open_max5821(int aI2cBus,
+ int aI2cAddress,
+ int aVRef);
/** @brief Power a channel
*
* @param aDev pointer to device structure
@@ -59,7 +59,7 @@ struct as_max5821_device *as_max5821_open(int aI2cBus, int aI2cAddress);
*
* @return negative value on header.
*/
-int32_t as_max5821_power(struct as_max5821_device *aDev,
+int32_t as_dac_max5821_power(struct as_dac_device *aDev,
char aChannel,
AS_max5821_power_mode aMode);
@@ -71,7 +71,7 @@ int32_t as_max5821_power(struct as_max5821_device *aDev,
*
* @return negative value on error.
*/
-int32_t as_max5821_set_one_value(struct as_max5821_device *aDev,
+int32_t as_dac_set_value_max5821(struct as_dac_device *aDev,
char aChannel,
int aValue);
@@ -82,7 +82,7 @@ int32_t as_max5821_set_one_value(struct as_max5821_device *aDev,
*
* @return negative value on error
*/
-int32_t as_max5821_set_both_value(struct as_max5821_device *aDev,
+int32_t as_max5821_set_both_value(struct as_dac_device *aDev,
int aValue);
/** @brief Close max5821
@@ -91,7 +91,7 @@ int32_t as_max5821_set_both_value(struct as_max5821_device *aDev,
*
* @return negative value on error
*/
-int32_t as_max5821_close(struct as_max5821_device *aDev);
+int32_t as_dac_close_max5821(struct as_dac_device *aDev);
#ifdef __cplusplus
}
diff --git a/target/packages/as_devices/python/AsDevices/Apf27Pwm.py b/target/packages/as_devices/python/AsDevices/Apf27Pwm.py
index ac19491..ee34690 100644
--- a/target/packages/as_devices/python/AsDevices/Apf27Pwm.py
+++ b/target/packages/as_devices/python/AsDevices/Apf27Pwm.py
@@ -16,9 +16,9 @@
# 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.
+# GNU Lesser General Public License for more details.
#
-# You should have received a copy of the GNU General Public License
+# You should have received a copy of the GNU Lesser 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.
#
diff --git a/target/packages/as_devices/python/AsDevices/AsAdc.py b/target/packages/as_devices/python/AsDevices/AsAdc.py
index d46aa05..43bbb6c 100644
--- a/target/packages/as_devices/python/AsDevices/AsAdc.py
+++ b/target/packages/as_devices/python/AsDevices/AsAdc.py
@@ -9,16 +9,16 @@
# Copyright (2011) Armadeus Systems
#
# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
+# 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.
+# GNU Lesser General Public License for more details.
#
-# You should have received a copy of the GNU General Public License
+# You should have received a copy of the GNU Lesser 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.
#
@@ -30,7 +30,7 @@
#
#-----------------------------------------------------------------------------
-__doc__ = "This class drive ARMadeus board ADCs"
+__doc__ = "This class drive ARMadeus boards ADCs"
__version__ = "0.1"
__author__ = "Fabien Marteau <fab...@ar...>"
diff --git a/target/packages/as_devices/python/AsDevices/AsAdc.py b/target/packages/as_devices/python/AsDevices/AsDac.py
similarity index 54%
copy from target/packages/as_devices/python/AsDevices/AsAdc.py
copy to target/packages/as_devices/python/AsDevices/AsDac.py
index d46aa05..983345f 100644
--- a/target/packages/as_devices/python/AsDevices/AsAdc.py
+++ b/target/packages/as_devices/python/AsDevices/AsDac.py
@@ -1,96 +1,90 @@
#! /usr/bin/python
# -*- coding: utf-8 -*-
#-----------------------------------------------------------------------------
-# Name: AsAdc.py
-# Purpose:
+# Name: AsDac.py
+# Purpose:
# Author: Fabien Marteau <fab...@ar...>
-# Created: 04/02/2011
+# Created: 21/02/2011
#-----------------------------------------------------------------------------
# Copyright (2011) Armadeus Systems
#
# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
+# 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
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser 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.
#
-# created :Â 04/02/2011
-#-----------------------------------------------------------------------------
-# Revision list :
-#
-# Date By Changes
-#
#-----------------------------------------------------------------------------
-__doc__ = "This class drive ARMadeus board ADCs"
+__doc__ = "This class drive ARMadeus boards DACs"
__version__ = "0.1"
__author__ = "Fabien Marteau <fab...@ar...>"
-import wrappers.AsAdc_wrap as wrapper
+import wrappers.AsDac_wrap as wrapper
-class AsAdcError(Exception):
+class AsDacError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
-class AsAdc:
- """ Drive adc
+class AsDac:
+ """ Drive dac
"""
- # Dictionary of adc multiton classes
- __adc = {}
+ # Dictionary of dac multiton classes
+ __dac = {}
################################################################
class __impl:
""" implementation
"""
- def __init__(self, aAdcType, aDeviceNum, aVRef):
+ def __init__(self, aDacType, aBusNumber, aAddress, aVRef):
try:
- self.__device = wrapper.adc_open(aAdcType, aDeviceNum, aVRef)
+ self.__device = wrapper.dac_open(aDacType, aBusNumber, aAddress, aVRef)
except Exception, e:
- raise AsAdcError("Can't open adc port type "+str(aAdcType)+\
- " num "+str(aDeviceNum))
+ raise AsDacError("Can't open dac port type "+str(aDacType)+\
+ " num "+str(aBusNumber))
def __del__(self):
try:
- wrapper.adc_close(self.__device)
+ wrapper.dac_close(self.__device)
except Exception, e:
pass
- def getValueInMillivolts(self, aChannel):
+ def setValueInMillivolts(self, aChannel, aValue):
""" Get value in millivolts
"""
try:
- return wrapper.getValueInMillivolts(self.__device, aChannel)
+ return wrapper.dac_setValueInMillivolts(self.__device, aChannel, aValue)
except Exception, e:
- raise AsAdcError(str(e))
+ raise AsDacError(str(e))
################################################################
@classmethod
- def getInstance(cls, aAdcType, aDeviceNum, aVRef):
+ def getInstance(cls, aDacType, aBusNumber, aAddress, aVRef):
try:
- return AsAdc.__adc["%s:%d"%(aAdcType, aDeviceNum)]
+ return AsDac.__dac["%s:%d-0x%02x"%(aDacType, aBusNumber, aAddress)]
except KeyError:
- AsAdc.__adc["%s:%d"%(aAdcType, aDeviceNum)] =\
- cls.__impl(aAdcType, aDeviceNum, aVRef)
+ AsDac.__dac["%s:%d-0x%02x"%(aDacType, aBusNumber, aAddress)] =\
+ cls.__impl(aDacType, aBusNumber, aAddress, aVRef)
- return AsAdc.__adc["%s:%d"%(aAdcType, aDeviceNum)]
+ return AsDac.__dac["%s:%d-0x%02x"%(aDacType, aBusNumber, aAddress)]
def __init__(self):
- """ Initialize adc
+ """ Initialize dac
"""
raise Exception("This constructor is private, to instanciate object do:"+\
- "AsAdc.getInstance(adctype, deviceNum, vref)")
+ "AsDac.getInstance(dactype, busnumber, address, vref)")
if __name__ == "__main__":
import os
diff --git a/target/packages/as_devices/python/AsDevices/AsGpio.py b/target/packages/as_devices/python/AsDevices/AsGpio.py
index 1ac7eb9..9c9f357 100644
--- a/target/packages/as_devices/python/AsDevices/AsGpio.py
+++ b/target/packages/as_devices/python/AsDevices/AsGpio.py
@@ -16,9 +16,9 @@
# 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.
+# GNU Lesser General Public License for more details.
#
-# You should have received a copy of the GNU General Public License
+# You should have received a copy of the GNU Lesser 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.
#
diff --git a/target/packages/as_devices/python/AsDevices/__init__.py b/target/packages/as_devices/python/AsDevices/__init__.py
index 5d9150a..64208f5 100644
--- a/target/packages/as_devices/python/AsDevices/__init__.py
+++ b/target/packages/as_devices/python/AsDevices/__init__.py
@@ -9,16 +9,16 @@
# Copyright (2008) Armadeus Systems
#
# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
+# 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.
+# GNU Lesser General Public License for more details.
#
-# You should have received a copy of the GNU General Public License
+# You should have received a copy of the GNU Lesser 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.
#
@@ -37,3 +37,4 @@ __author__ = "Fabien Marteau <fab...@ar...>"
import wrappers
from AsGpio import *
from AsAdc import *
+from AsDac import *
diff --git a/target/packages/as_devices/python/AsDevices/wrappers/__init__.py b/target/packages/as_devices/python/AsDevices/wrappers/__init__.py
index a699242..47ab497 100644
--- a/target/packages/as_devices/python/AsDevices/wrappers/__init__.py
+++ b/target/packages/as_devices/python/AsDevices/wrappers/__init__.py
@@ -9,16 +9,16 @@
# Copyright (2008) Armadeus Systems
#
# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
+# 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.
+# GNU Lesser General Public License for more details.
#
-# You should have received a copy of the GNU General Public License
+# You should have received a copy of the GNU Lesser 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.
#
diff --git a/target/packages/as_devices/python/Makefile b/target/packages/as_devices/python/Makefile
index f2714b1..8368d4e 100644
--- a/target/packages/as_devices/python/Makefile
+++ b/target/packages/as_devices/python/Makefile
@@ -17,6 +17,7 @@ LIBNAME=AsDevices
WRAPPER_LIBS=AsGpio_wrap.so
WRAPPER_LIBS+= AsAdc_wrap.so
+WRAPPER_LIBS+= AsDac_wrap.so
WRAPPER_DIR=src
PYTHON_VERS=2.4
diff --git a/target/packages/as_devices/python/src/AsAdc_wrap.c b/target/packages/as_devices/python/src/AsDac_wrap.c
similarity index 63%
copy from target/packages/as_devices/python/src/AsAdc_wrap.c
copy to target/packages/as_devices/python/src/AsDac_wrap.c
index 6179052..7f76582 100644
--- a/target/packages/as_devices/python/src/AsAdc_wrap.c
+++ b/target/packages/as_devices/python/src/AsDac_wrap.c
@@ -18,50 +18,51 @@
** 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 "AsAdc_wrap.h"
-#include "as_adc.h"
-
+#include "AsDac_wrap.h"
+#include "as_dac.h"
/* Methods definitions */
-static PyMethodDef AsAdc_wrap_methods[] = {
- {"adc_open", adc_open, METH_VARARGS, "Initialize adc"},
- {"getValueInMillivolts", getValueInMillivolts, METH_VARARGS, "Get Channel value in millivolts"},
- {"adc_close", adc_close, METH_VARARGS, "Close adc"},
+static PyMethodDef AsDac_wrap_methods[] = {
+ {"dac_open", dac_open, METH_VARARGS, "Initialize dac"},
+ {"dac_setValueInMillivolts", dac_setValueInMillivolts, METH_VARARGS, "Set Channel value in millivolts"},
+ {"dac_close", dac_close, METH_VARARGS, "Close dac"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
/* Init module */
-void initAsAdc_wrap() /* called on first import */
+void initAsDac_wrap() /* called on first import */
{ /* name matter if called dynamically */
- (void) Py_InitModule("AsAdc_wrap", AsAdc_wrap_methods); /* mod name, table ptr */
+ (void) Py_InitModule("AsDac_wrap", AsDac_wrap_methods); /* mod name, table ptr */
}
/** @brief Initialize pin port access
* @return PyObject
*/
-static PyObject * adc_open(PyObject *self, PyObject *args)
+static PyObject * dac_open(PyObject *self, PyObject *args)
{
/* parameters */
- char *aAdcType;
- int aDeviceNum;
+ char *aDacType;
+ int aBusNumber;
+ int aAddress;
int aVref;
- struct as_adc_device *dev;
+ struct as_dac_device *dev;
PyObject *ret;
char buff[300];
/* Get arguments */
- if (!PyArg_ParseTuple(args, "sii", &aAdcType, &aDeviceNum, &aVref))
+ if (!PyArg_ParseTuple(args, "siii", &aDacType,
+ &aBusNumber, &aAddress, &aVref))
{
PyErr_SetString(PyExc_IOError,
"Wrong parameters.");
return NULL;
}
- dev = as_adc_open(aAdcType, aDeviceNum, aVref);
+ dev = as_dac_open(aDacType, aBusNumber, aAddress, aVref);
if (dev == NULL)
{
snprintf(buff, 300,
- "Initialization error for ADC type %s bus %d. Is kernel module loaded ?",
- aAdcType, aDeviceNum);
+ "Initialization error for DAC type %s bus %d. Is kernel module loaded ?",
+ aDacType, aBusNumber);
PyErr_SetString(PyExc_IOError,buff);
return NULL;
}
@@ -71,23 +72,24 @@ static PyObject * adc_open(PyObject *self, PyObject *args)
return ret;
}
-static PyObject * getValueInMillivolts(PyObject *self, PyObject *args)
+static PyObject * dac_setValueInMillivolts(PyObject *self, PyObject *args)
{
/* parameters */
- struct as_adc_device *aFdev;
+ struct as_dac_device *aDev;
int aChannel;
+ int aValue;
int ret;
/* Get arguments */
- if (!PyArg_ParseTuple(args, "li", (long *)&aFdev, &aChannel))
+ if (!PyArg_ParseTuple(args, "lii", (long *)&aDev, &aChannel, &aValue))
{
PyErr_SetString(PyExc_IOError,
"Wrong parameters.");
return NULL;
}
- ret = as_adc_get_value_in_millivolts(aFdev, aChannel);
+ ret = as_dac_set_value_in_millivolts(aDev, aChannel, aValue);
if (ret < 0)
{
PyErr_SetString(PyExc_IOError,
@@ -98,22 +100,22 @@ static PyObject * getValueInMillivolts(PyObject *self, PyObject *args)
return Py_BuildValue("i", ret);
}
-static PyObject * adc_close(PyObject *self, PyObject *args)
+static PyObject * dac_close(PyObject *self, PyObject *args)
{
/* parameters */
- struct as_adc_device *aFdev;
+ struct as_dac_device *aDev;
int ret;
/* Get arguments */
- if (!PyArg_ParseTuple(args, "l", (long *)&aFdev))
+ if (!PyArg_ParseTuple(args, "l", (long *)&aDev))
{
PyErr_SetString(PyExc_IOError,
"Wrong parameters.");
return NULL;
}
- ret = as_adc_close(aFdev);
+ ret = as_dac_close(aDev);
if (ret < 0)
{
PyErr_SetString(PyExc_IOError,
diff --git a/target/packages/as_devices/python/src/AsAdc_wrap.h b/target/packages/as_devices/python/src/AsDac_wrap.h
similarity index 81%
copy from target/packages/as_devices/python/src/AsAdc_wrap.h
copy to target/packages/as_devices/python/src/AsDac_wrap.h
index 7fa0b8f..6ba91a7 100644
--- a/target/packages/as_devices/python/src/AsAdc_wrap.h
+++ b/target/packages/as_devices/python/src/AsDac_wrap.h
@@ -22,11 +22,11 @@
#include <Python.h>
/* Init module */
-void initAsAdc_wrap();
+void initAsDac_wrap();
/*********************/
/* Functions wrapped */
/*********************/
-static PyObject * adc_open(PyObject *self, PyObject *args);
-static PyObject * getValueInMillivolts(PyObject *self, PyObject *args);
-static PyObject * adc_close(PyObject *self, PyObject *args);
+static PyObject * dac_open(PyObject *self, PyObject *args);
+static PyObject * dac_setValueInMillivolts(PyObject *self, PyObject *args);
+static PyObject * dac_close(PyObject *self, PyObject *args);
hooks/post-receive
--
armadeus
|