[Armadeus-commitlog] armadeus branch, master, updated. release-3.3-339-ge286942
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2011-02-18 17:39:14
|
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 e286942d6a1f5ab26ef7cab9f6ed331a11253421 (commit)
via 8c6b69bbc3a98ef648103c3f8c4ba2ec01ea25f1 (commit)
via 69fc8638b9d20e837a1750f52127c5e74001e07d (commit)
via c33b4201d49245363521260789d8716cf1339718 (commit)
from d716aadd2589cfdb196cf52c2d08f09d11018097 (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 e286942d6a1f5ab26ef7cab9f6ed331a11253421
Merge: 8c6b69bbc3a98ef648103c3f8c4ba2ec01ea25f1 d716aadd2589cfdb196cf52c2d08f09d11018097
Author: Fabien Marteau <fab...@ar...>
Date: Fri Feb 18 18:38:49 2011 +0100
Merge branch 'master' of ssh://armadeus.git.sourceforge.net/gitroot/armadeus/armadeus
commit 8c6b69bbc3a98ef648103c3f8c4ba2ec01ea25f1
Author: Fabien Marteau <fab...@ar...>
Date: Fri Feb 18 18:38:23 2011 +0100
[as_devices] Return error if read fail
commit 69fc8638b9d20e837a1750f52127c5e74001e07d
Author: Fabien Marteau <fab...@ar...>
Date: Fri Feb 18 18:37:56 2011 +0100
[as_devices] Adding generic as_adc class, with specific calls to as1531 and max1027 chip
commit c33b4201d49245363521260789d8716cf1339718
Author: Fabien Marteau <fab...@ar...>
Date: Fri Feb 18 18:33:26 2011 +0100
[as_devices] Adding python dependency for wrapper
-----------------------------------------------------------------------
Summary of changes:
.../package/armadeus/as_devices/as_devices.mk | 4 +-
target/packages/as_devices/c/Makefile | 3 +-
target/packages/as_devices/c/as_adc.c | 116 +----
target/packages/as_devices/c/as_adc.h | 11 +-
target/packages/as_devices/c/as_helpers.c | 1 +
target/packages/as_devices/c/as_max1027.c | 480 +++++++-------------
target/packages/as_devices/c/as_max1027.h | 67 +---
.../packages/as_devices/python/AsDevices/AsAdc.py | 6 +-
target/packages/as_devices/python/src/AsAdc_wrap.c | 9 +-
9 files changed, 219 insertions(+), 478 deletions(-)
diff --git a/buildroot/package/armadeus/as_devices/as_devices.mk b/buildroot/package/armadeus/as_devices/as_devices.mk
index 678068e..5cc203b 100644
--- a/buildroot/package/armadeus/as_devices/as_devices.mk
+++ b/buildroot/package/armadeus/as_devices/as_devices.mk
@@ -64,11 +64,11 @@ endif
ifeq ($(strip $(BR2_PACKAGE_AS_DEVICES_PYTHON)),y)
-$(TARGET_DIR)/$(AS_DEVICES_PYTHON_TARGET_BINARY): $(AS_DEVICES_DIR)/python/AsDevices/wrappers/$(AS_DEVICES_PYTHON_BINARY)
+$(TARGET_DIR)/$(AS_DEVICES_PYTHON_TARGET_BINARY): python $(AS_DEVICES_DIR)/python/AsDevices/wrappers/$(AS_DEVICES_PYTHON_BINARY)
cp -rf $(AS_DEVICES_DIR)/python/AsDevices $(TARGET_DIR)/$(AS_DEVICES_PYTHON_TARGET_DIR)
$(STRIPCMD) $(STRIP_STRIP_UNNEEDED) $(TARGET_DIR)/$(AS_DEVICES_PYTHON_TARGET_BINARY)/wrappers/*.so
-$(AS_DEVICES_DIR)/python/AsDevices/wrappers/$(AS_DEVICES_PYTHON_BINARY): $(AS_DEVICES_DIR)/python/Makefile
+$(AS_DEVICES_DIR)/python/AsDevices/wrappers/$(AS_DEVICES_PYTHON_BINARY): python $(AS_DEVICES_DIR)/python/Makefile
$(TARGET_CONFIGURE_OPTS) $(MAKE) CC="$(TARGET_CC)" CXX="$(TARGET_CXX)" -C $(AS_DEVICES_DIR)/python
endif
diff --git a/target/packages/as_devices/c/Makefile b/target/packages/as_devices/c/Makefile
index ba754b7..3d20edf 100644
--- a/target/packages/as_devices/c/Makefile
+++ b/target/packages/as_devices/c/Makefile
@@ -15,7 +15,8 @@ OBJ += as_gpio.o
endif
OBJ += as_93lcxx.o
OBJ += as_spi.o
-#OBJ += as_max1027.o
+OBJ += as_as1531.o
+OBJ += as_max1027.o
#OBJ += as_max5821.o
OBJ += as_helpers.o
OBJ += as_adc.o
diff --git a/target/packages/as_devices/c/as_adc.c b/target/packages/as_devices/c/as_adc.c
index 91bcf89..eb702f4 100644
--- a/target/packages/as_devices/c/as_adc.c
+++ b/target/packages/as_devices/c/as_adc.c
@@ -32,111 +32,47 @@
#include "as_helpers.h"
#include "as_adc.h"
-#define BUFF_SIZE (300)
-
-#define AS_MAX1027_NAME "max1027"
-
-#define AS_AS1531_NAME "as1531"
-#define AS_AS1531_MAX_VALUE 2500
+#include "as_max1027.h"
+#include "as_as1531.h"
#undef ERROR
#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
-/*------------------------------------------------------------------------------*/
-
-struct as_adc_device *as_adc_open_max1027(int aDeviceNum, int aVRef) {
- ERROR("Max1027 not yet supported by as_adc class\n");
- return NULL;
-}
-
-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;
- }
+struct as_adc_device *as_adc_open(const char *aAdcType, int aDeviceNum, int aVRef) {
+ if (strncmp(AS_MAX1027_NAME, aAdcType, strlen(AS_MAX1027_NAME)) == 0)
+ return as_adc_open_max1027(aDeviceNum, aVRef);
+ if (strncmp(AS_AS1531_NAME, aAdcType, strlen(AS_AS1531_NAME)) == 0)
+ return as_adc_open_as1531(aDeviceNum, aVRef);
- dev->device_type = AS_AS1531_TYPE;
- dev->device_num = aDeviceNum;
- dev->vref = aVRef;
- return dev;
+ ERROR("Undefined ADC type '%s'\n",aAdcType);
+ return NULL;
}
-struct as_adc_device *as_adc_open(int aAdcType, int aDeviceNum, int aVRef) {
+int32_t as_adc_get_value_in_millivolts(struct as_adc_device *aDev, int aChannel) {
+ if (strncmp(AS_MAX1027_NAME, aDev->device_type, strlen(AS_MAX1027_NAME)) == 0)
+ return as_adc_get_value_in_millivolts_max1027(aDev, aChannel);
- switch(aAdcType) {
- case AS_MAX1027_TYPE: return as_adc_open_max1027(aDeviceNum, aVRef);
- case AS_AS1531_TYPE : return as_adc_open_as1531(aDeviceNum, aVRef);
- default : ERROR("Undefined ADC type %d\n",aAdcType);
- return NULL;
- }
-}
+ if (strncmp(AS_AS1531_NAME, aDev->device_type, strlen(AS_AS1531_NAME)) == 0)
+ return as_adc_get_value_in_millivolts_as1531(aDev, aChannel);
-int32_t as_adc_get_value_in_millivolts_max1027(struct as_adc_device *aDev, int aChannel) {
- ERROR("max1027 not supported yet\n");
+ ERROR("Undefined ADC type '%s'\n", aDev->device_type);
return -1;
}
-int32_t as_adc_get_value_in_millivolts_as1531(struct as_adc_device *aDev, int aChannel) {
+int32_t as_adc_close(struct as_adc_device *aDev) {
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;
+ if (strncmp(AS_MAX1027_NAME, aDev->device_type, strlen(AS_MAX1027_NAME)) == 0) {
+ ret = as_adc_close(aDev);
+ free(aDev);
+ return ret;
}
-
- ret = as_read_int(finput, &value);
- if (ret < 0) {
- ERROR("Can't read value on channel %d\n", aChannel);
- return -1;
+ if (strncmp(AS_AS1531_NAME, aDev->device_type, strlen(AS_AS1531_NAME)) == 0) {
+ ret = as_adc_close_max1027(aDev);
+ free(aDev);
+ return ret;
}
- close(finput);
- if (AS_AS1531_MAX_VALUE == aDev->vref) return value;
-
- return (value*aDev->vref)/AS_AS1531_MAX_VALUE;
-}
-
-int32_t as_adc_get_value_in_millivolts(struct as_adc_device *aDev, int aChannel) {
- switch(aDev->device_type) {
- case AS_MAX1027_TYPE: return as_adc_get_value_in_millivolts_max1027(aDev, aChannel);
- case AS_AS1531_TYPE : return as_adc_get_value_in_millivolts_as1531(aDev, aChannel);
- default : ERROR("Undefined ADC type %d\n", aDev->device_type);
- return -1;
- }
-}
-
-int32_t as_adc_close(struct as_adc_device *aDev) {
- return 0;
+ ERROR("Undefined ADC type '%s'\n", aDev->device_type);
+ return -1;
}
diff --git a/target/packages/as_devices/c/as_adc.h b/target/packages/as_devices/c/as_adc.h
index dd04e87..5c9b678 100644
--- a/target/packages/as_devices/c/as_adc.h
+++ b/target/packages/as_devices/c/as_adc.h
@@ -28,16 +28,17 @@
extern "C" {
#endif /* __cplusplus */
-#define AS_MAX1027_TYPE 0
-#define AS_AS1531_TYPE 1
+#define AS_MAX1027_NAME "max1027"
+#define AS_AS1531_NAME "as1531"
/**
* Store adc parameters
*/
struct as_adc_device {
- int device_type;
+ const char *device_type; /* Name of device type as1531 or max1027 */
int device_num;
- int vref; /* reference tension in millivolts */
+ int vref; /* reference tension in millivolts */
+ void *chip_param; /* chip specific parameters */
};
/** @brief Initialize port access
@@ -48,7 +49,7 @@ struct as_adc_device {
*
* @return error if negative value
*/
-struct as_adc_device *as_adc_open(int aDeviceNum, int aAdcType, int aVRef);
+struct as_adc_device *as_adc_open(const char *aAdcType, int aDeviceNum, int aVRef);
/** @brief get value in millivolts
*
diff --git a/target/packages/as_devices/c/as_helpers.c b/target/packages/as_devices/c/as_helpers.c
index 7fb6e7d..a3dc318 100644
--- a/target/packages/as_devices/c/as_helpers.c
+++ b/target/packages/as_devices/c/as_helpers.c
@@ -106,6 +106,7 @@ int as_read_int(int fd, int *value_res)
int value;
ret = as_read_buffer(fd, buf, SIZEOFBUFF);
+ if (ret < 0) return ret;
buf[ret-1] = '\0';
value = strtol(buf, NULL, 10);
*value_res = value;
diff --git a/target/packages/as_devices/c/as_max1027.c b/target/packages/as_devices/c/as_max1027.c
index 52b0752..0008abe 100644
--- a/target/packages/as_devices/c/as_max1027.c
+++ b/target/packages/as_devices/c/as_max1027.c
@@ -32,6 +32,7 @@
typedef unsigned char u8;
#include "as_max1027.h"
+#include "as_helpers.h"
/* Redundant with <linux/spi/max1027.h>, but... */
/* 00 : Scans channels 0 through N.
@@ -42,384 +43,239 @@ typedef unsigned char u8;
#define SCAN_MODE_01 1
#define SCAN_MODE_10 2
#define SCAN_MODE_11 3
-#define MAX1027_CONV 0x80
-#define MAX1027_CONV_TEMP 0x01
-#define MAX1027_SETUP 0x40
-#define MAX1027_AVG 0x20
+#define MAX1027_SETUP (0x40)
+#define MAX1027_SETUP_CLKSEL(x) ((x&0x03)<<4)
+#define MAX1027_SETUP_REFSEL(x) ((x&0x03)<<2)
+#define MAX1027_SETUP_DIFFSEL(x) (x&0x03)
+#define MAX1027_CONV (0x80)
+#define MAX1027_CONV_CHSEL(x) ((x&0x0f)<<3)
+#define MAX1027_CONV_SCAN(x) ((x&0x03)<<1)
+#define MAX1027_CONV_TEMP 0x01
+#define GET_SCAN_MODE(conv) ( (conv & 0x06) >> 1 )
+#define MAX1027_AVG (0x20)
+#define MAX1027_AVG_AVGON(x) ((x&0x01)<<4)
+#define MAX1027_AVG_NAVG(x) ((x&0x03)<<2)
+#define MAX1027_AVG_NSCAN(x) (x&0x03)
#define BUFFER_SIZE (70)
-#define PATH_SIZE (50)
-#define SYS_PATH "/sys/bus/spi/devices/spi%d.0/"
+#define SYS_PATH "/sys/class/hwmon/hwmon%d/device/"
#define TEMP_NAME "temp1_input"
#define SLOW_INPUT_NAME "in%d_input"
-#define FAST_INPUT_PATH "/dev/max1027/AIN%d"
-//#define DEBUG
-#ifdef DEBUG
-# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
-#else
-# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
-#endif
+#undef ERROR
+#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
-/** @brief Function used to write in /sys file
- *
- * @param aFile_handler /sys file handler
- * @param aValue int value to write
- *
- * @return negative value on error
- */
-int32_t as_max1027_write_buffer(int aFile_handler, int aValue)
-{
+int32_t as_max1027_set_averaging(struct as_max1027_device *aDev, uint8_t aNbConv){
+ uint8_t avg_register = 0;
+ char buffer[BUFFER_SIZE];
+ int file;
int ret;
- char buffer[50];
- int buffer_len;
- ret = snprintf(buffer, 50, "%d", aValue);
- if (ret < 0)
- return -1;
- buffer_len = strlen(buffer);
- ret = write(aFile_handler, buffer, buffer_len);
- if (ret < 0)
+ switch (aNbConv)
{
- ERROR("Can't write file ");
- return -1;
+ case 1: avg_register = MAX1027_AVG_NAVG(0) | MAX1027_AVG_AVGON(0);
+ aDev->scan_mode = SCAN_MODE_11; /* no scan */
+ break;
+ case 4: avg_register = MAX1027_AVG_NAVG(0) | MAX1027_AVG_AVGON(1);
+ aDev->scan_mode = SCAN_MODE_10; /* scan */
+ break;
+ case 8: avg_register = MAX1027_AVG_NAVG(1) | MAX1027_AVG_AVGON(1);
+ aDev->scan_mode = SCAN_MODE_10; /* scan */
+ break;
+ case 16: avg_register = MAX1027_AVG_NAVG(2) | MAX1027_AVG_AVGON(1);
+ aDev->scan_mode = SCAN_MODE_10; /* scan */
+ break;
+ case 32: avg_register = MAX1027_AVG_NAVG(3) | MAX1027_AVG_AVGON(1);
+ aDev->scan_mode = SCAN_MODE_10; /* scan */
+ break;
+ default:
+ ERROR("%s: unsupported setting\n", __func__);
+ return -1;
}
- ret = lseek(aFile_handler, 0, SEEK_SET);
- if (ret < 0)
- {
- ERROR("lseek error ");
+
+ /* select averaging */
+ snprintf(buffer, BUFFER_SIZE, "%s%s", aDev->path, "averaging");
+ file = open(buffer, O_WRONLY);
+ if (file < 0) {
+ ERROR("Can't open averaging file\n");
return -1;
}
-
- return buffer_len;
-}
-
-/** @brief function used to read int value in /sys file
- *
- * @param aFile_handler /sys file handler
- * @param aValueRead pointer to int value read
- *
- * @return negative value on error,
- */
-int32_t as_max1027_read_buffer(int aFile_handler, int *aValueRead)
-{
- const int SIZEOFBUFF = 20;
- ssize_t ret;
- char valueRead[SIZEOFBUFF];
- int value;
-
- ret = read(aFile_handler, valueRead, SIZEOFBUFF);
+ avg_register |= MAX1027_AVG | MAX1027_AVG_NSCAN(2);
+ ret = as_write_buffer(file, avg_register);
if (ret < 0)
{
- ERROR("Error, reading buffer file\n");
+ ERROR("Error, setting averaging\n");
return -1;
}
- valueRead[ret-1] = '\0';
+ close(file);
- ret = lseek(aFile_handler, 0, SEEK_SET);
- if (ret < 0)
- return -1;
- value = strtol(valueRead, NULL, 10);
- *aValueRead = value;
- return 0;
+ return aNbConv;
}
-struct as_max1027_device *as_max1027_open(int aSpiNum,
- AS_max1027_mode aMode)
-{
+
+struct as_adc_device *as_adc_open_max1027(int aDeviceNum, int aVRef) {
+ struct as_adc_device *adc_dev;
struct as_max1027_device *dev;
- int i;
- int fConversion, fSetup, fAveraging;
- int fTemperature;
- int fLowSpeed[NUMBER_OF_CHANNELS];
- int fHighSpeed[NUMBER_OF_CHANNELS];
- char path[PATH_SIZE];
+ int file;
char buffer[BUFFER_SIZE];
- char slow_input_name[20];
int ret;
- /** XXX */
- if (aMode == AS_MAX1027_FAST)
- {
- printf("Error, fast mode not supported yet\n");
- return NULL;
- }
+ dev = (struct as_max1027_device *)malloc(sizeof(struct as_max1027_device));
- ret = snprintf(path, PATH_SIZE, SYS_PATH, aSpiNum);
+ ret = snprintf(dev->path, PATH_SIZE, SYS_PATH, aDeviceNum);
if (ret<0)
{
ERROR("Error in path writing\n");
- return NULL;
+ goto err;
}
- /* Open file handler register */
- /* conversion */
- ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, "conversion");
- if (ret<0)
- {
- ERROR("Error in path writing\n");
- return NULL;
+ /* Check driver name */
+ snprintf(buffer, BUFFER_SIZE, "%s%s", dev->path, "modalias");
+ file = open(buffer, O_RDONLY);
+ if (file < 0) {
+ ERROR("Error, can't open modalias file.\n");
+ goto err;
}
- fConversion = open(buffer, O_RDWR);
- if (fConversion < 0)
- {
- ERROR("Error, can't open conversion file. Is max1027 modprobed ?\n");
- return NULL;
+
+ ret = read(file, buffer, BUFFER_SIZE);
+ if (ret <= 0) {
+ ERROR("Can't read name\n");
+ goto err;
}
- /* setup */
- ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, "setup");
- if (ret<0)
- {
- ERROR("Error in path writing\n");
- return NULL;
+
+ ret = strncmp(AS_MAX1027_NAME, buffer, strlen(AS_MAX1027_NAME));
+ if (ret != 0) {
+ ERROR("Wrong driver name %s\n", buffer);
+ goto err;
}
- fSetup = open(buffer, O_RDWR);
- if (fSetup < 0)
- {
+ close(file);
+
+ snprintf(buffer, BUFFER_SIZE, "%s%s", dev->path, "setup");
+ file = open(buffer, O_WRONLY);
+ if (file < 0) {
ERROR("Error, can't open setup file.\n");
- return NULL;
+ goto err;
}
- ret = as_max1027_write_buffer(fSetup,
- MAX1027_SETUP |
- MAX1027_SETUP_CLKSEL(0) |
- MAX1027_SETUP_REFSEL(0) |
- MAX1027_SETUP_DIFFSEL(0));
- if (ret < 0)
- {
+ ret = as_write_buffer(file, MAX1027_SETUP |
+ MAX1027_SETUP_CLKSEL(0) |
+ MAX1027_SETUP_REFSEL(0) |
+ MAX1027_SETUP_DIFFSEL(0));
+ if (ret < 0) {
ERROR("Error, can't set default setup parameters\n");
- return NULL;
- }
- /* averaging */
- ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, "averaging");
- if (ret<0) {
- ERROR("Error in path writing\n");
- return NULL;
- }
-
- fAveraging = open(buffer, O_RDWR);
- if (fAveraging < 0)
- {
- ERROR("Error, can't open averaging file.\n");
- return NULL;
+ goto err;
}
+ close(file);
- /* temperature */
- if (aMode == AS_MAX1027_SLOW)
- {
- ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, "temp1_input");
- if (ret<0)
- {
- ERROR("Error in path writing\n");
- return NULL;
- }
- fTemperature = open(buffer, O_RDONLY);
- if (fTemperature < 0)
- {
- ERROR("Error, can't open temperature file.\n");
- return NULL;
- }
- } else {
- fTemperature = -1;
- }
+ adc_dev = (struct as_adc_device *)malloc(sizeof(struct as_adc_device));
- /* Open each channels (0 to 6)*/
- for(i=0 ; i<NUMBER_OF_CHANNELS ; i++){
- fLowSpeed[i] = -1;
- fHighSpeed[i] = -1;
- if (aMode == AS_MAX1027_SLOW)
- {
- ret = snprintf(slow_input_name, 20, SLOW_INPUT_NAME, i);
- if (ret < 0)
- {
- ERROR("Error in path writing\n");
- return NULL;
- }
-
- ret = snprintf(buffer, BUFFER_SIZE, "%s%s", path, slow_input_name);
- if (ret < 0)
- {
- ERROR("Error in path writing\n");
- return NULL;
- }
-
- fLowSpeed[i] = open(buffer, O_RDONLY);
- if (fLowSpeed[i] < 0)
- {
- ERROR("Error, can't open %s\n", buffer);
- return NULL;
- }
- }
- else if ((aMode == AS_MAX1027_FAST))
- {
- ret = snprintf(buffer, BUFFER_SIZE, FAST_INPUT_PATH, i);
- if (ret < 0)
- {
- ERROR("Error in path writing\n");
- return NULL;
- }
-
- fHighSpeed[i] = open(buffer, O_RDONLY);
- if (fHighSpeed[i] < 0)
- {
- ERROR("Error, can't open %s\nIs loadmax.sh launched ?\n", buffer);
- return NULL;
- }
-
- }
- }
+ dev->mode = AS_MAX1027_FAST ;
+ dev->scan_mode = SCAN_MODE_11;
- dev = (struct as_max1027_device *)malloc(sizeof(struct as_max1027_device));
+ adc_dev->chip_param = (void *)dev;
+ adc_dev->device_type = "max1027";
+ adc_dev->device_num = aDeviceNum;
+ adc_dev->vref = 2500; /* Voltage reference is always 2.5V */
- dev->mode = aMode;
- dev->scan_mode = SCAN_MODE_11;
- dev->fConversion = fConversion;
- dev->fSetup = fSetup;
- dev->fAveraging = fAveraging;
- for(i=0 ; i<NUMBER_OF_CHANNELS ; i++)
- {
- dev->fLowSpeed[i] = fLowSpeed[i];
- dev->fHighSpeed[i] = fHighSpeed[i];
- }
- dev->fTemperature = fTemperature;
+ as_max1027_set_averaging(dev, 4);
+ return adc_dev;
- return dev;
+err:
+ free(dev);
+ return NULL;
}
-int32_t as_max1027_read_temperature_mC(struct as_max1027_device *aDev,
- int *aTemperature)
-{
+int32_t as_adc_get_value_in_millivolts_max1027(struct as_adc_device *aDev, int aChannel) {
int32_t ret;
+ int32_t value;
+ int file;
+ char buffer[BUFFER_SIZE];
+ struct as_max1027_device *dev;
- /* temperature is read only on slow mode */
- if (aDev->mode != AS_MAX1027_SLOW)
+ dev = (struct as_max1027_device *)aDev->chip_param;
+
+ if ((aChannel >= NUMBER_OF_CHANNELS) || (aChannel < 0)) {
+ ERROR("Wrong num channel\n");
return -1;
+ }
/* launch conversion */
- ret = as_max1027_write_buffer(aDev->fConversion,
- MAX1027_CONV |
- MAX1027_CONV_CHSEL(0) |
- MAX1027_CONV_SCAN(aDev->scan_mode) |
- MAX1027_CONV_TEMP);
- if (ret < 0)
- {
+ snprintf(buffer, BUFFER_SIZE, "%s%s", dev->path, "conversion");
+ file = open(buffer, O_WRONLY);
+ if (file < 0) {
+ ERROR("Can't open conversion file\n");
+ return NULL;
+ }
+ ret = as_write_buffer(file, MAX1027_CONV |
+ MAX1027_CONV_CHSEL(aChannel) |
+ MAX1027_CONV_SCAN(dev->scan_mode));
+ if (ret < 0) {
ERROR("Error launching conversion\n");
return -1;
}
+ close(file);
/* read value */
- ret = as_max1027_read_buffer(aDev->fTemperature, aTemperature);
- if (ret < 0)
- {
- ERROR("Error, reading fTemperature\n");
+ snprintf(buffer, BUFFER_SIZE, "%sin%d_input", dev->path, aChannel);
+ file = open(buffer, O_RDONLY);
+ if (file < 0) {
+ ERROR("Can't open in%d_input file\n", aChannel);
return -1;
}
-
- return 0;
-}
-
-int32_t as_max1027_set_averaging(struct as_max1027_device *aDev, uint8_t aNbConv){
- uint8_t avg_register = 0;
- int ret;
-
- switch (aNbConv)
- {
- case 1: avg_register = MAX1027_AVG_NAVG(0) | MAX1027_AVG_AVGON(0);
- aDev->scan_mode = SCAN_MODE_11; /* no scan */
- break;
- case 4: avg_register = MAX1027_AVG_NAVG(0) | MAX1027_AVG_AVGON(1);
- aDev->scan_mode = SCAN_MODE_10; /* scan */
- break;
- case 8: avg_register = MAX1027_AVG_NAVG(1) | MAX1027_AVG_AVGON(1);
- aDev->scan_mode = SCAN_MODE_10; /* scan */
- break;
- case 16: avg_register = MAX1027_AVG_NAVG(2) | MAX1027_AVG_AVGON(1);
- aDev->scan_mode = SCAN_MODE_10; /* scan */
- break;
- case 32: avg_register = MAX1027_AVG_NAVG(3) | MAX1027_AVG_AVGON(1);
- aDev->scan_mode = SCAN_MODE_10; /* scan */
- break;
- default:
- ERROR("%s: unsupported setting\n", __func__);
- return -1;
- }
-
- /* select averaging */
- avg_register |= MAX1027_AVG | MAX1027_AVG_NSCAN(2);
- ret = as_max1027_write_buffer(aDev->fAveraging, avg_register);
- if (ret < 0)
- {
- ERROR("Error, setting averaging\n");
+ ret = as_read_int(file, &value);
+ if (ret < 0) {
+ ERROR("Can't read input file\n");
return -1;
}
+ close(file);
- return aNbConv;
+ return value;
}
-int32_t as_max1027_get_value_milliVolt(struct as_max1027_device *aDev,
- int aChannelNum, int *aValue)
-{
- int32_t ret;
-
- if ((aChannelNum >= NUMBER_OF_CHANNELS) || (aChannelNum < 0))
- {
- ERROR("Wrong num channel\n");
- return -1;
- }
-
- if (aDev->mode == AS_MAX1027_SLOW)
- {
- /* launch conversion */
- ret = as_max1027_write_buffer(aDev->fConversion,
- MAX1027_CONV |
- MAX1027_CONV_CHSEL(aChannelNum) |
- MAX1027_CONV_SCAN(aDev->scan_mode));
- if (ret < 0)
- {
- ERROR("Error launching conversion\n");
- return -1;
- }
-
- /* read value */
- ret = as_max1027_read_buffer(aDev->fLowSpeed[aChannelNum], aValue);
- if (ret < 0)
- {
- ERROR("Error, reading fLowSpeed[%d]\n", aChannelNum);
- return -1;
- }
- }
- else if (aDev->mode == AS_MAX1027_FAST)
- {
- ERROR("TODO: fast mode channel reading\n");
- return -1;
- }
- else
- {
- ERROR("Unknown mode\n");
- return -1;
- }
+int32_t as_adc_close_max1027(struct as_adc_device *aDev) {
+ struct as_max1027_device *dev =
+ (struct as_max1027_device *)aDev->chip_param;
+ free(dev);
return 0;
}
-int32_t as_max1027_close(struct as_max1027_device *aDev)
-{
- int i;
- if (aDev->fConversion > 0) close(aDev->fConversion);
- if (aDev->fSetup > 0) close(aDev->fSetup);
- if (aDev->fAveraging > 0) close(aDev->fAveraging);
+/**************************/
+/* old Not used functions */
+/**************************/
+
+//int32_t as_max1027_read_temperature_mC(struct as_max1027_device *aDev,
+// int *aTemperature)
+//{
+// int32_t ret;
+//
+// /* temperature is read only on slow mode */
+// if (aDev->mode != AS_MAX1027_SLOW)
+// return -1;
+//
+// /* launch conversion */
+// ret = as_write_buffer(aDev->fConversion,
+// MAX1027_CONV |
+// MAX1027_CONV_CHSEL(0) |
+// MAX1027_CONV_SCAN(aDev->scan_mode) |
+// MAX1027_CONV_TEMP);
+// if (ret < 0)
+// {
+// ERROR("Error launching conversion\n");
+// return -1;
+// }
+//
+// /* read value */
+// ret = as_read_int(aDev->fTemperature, aTemperature);
+// if (ret < 0)
+// {
+// ERROR("Error, reading fTemperature\n");
+// return -1;
+// }
+//
+// return 0;
+//}
- if (aDev->fTemperature > 0) close(aDev->fTemperature);
- for (i=0 ; i<NUMBER_OF_CHANNELS; i++)
- {
- if (aDev->fLowSpeed[i] > 0) close(aDev->fLowSpeed[i]);
- if (aDev->fHighSpeed[i] > 0) close(aDev->fHighSpeed[i]);
- }
-
- free(aDev);
-
- return 0;
-}
diff --git a/target/packages/as_devices/c/as_max1027.h b/target/packages/as_devices/c/as_max1027.h
index c094831..edd071f 100644
--- a/target/packages/as_devices/c/as_max1027.h
+++ b/target/packages/as_devices/c/as_max1027.h
@@ -25,78 +25,25 @@
extern "C" {
#endif
+#include "as_adc.h"
#define NUMBER_OF_CHANNELS (7)
+#define PATH_SIZE (50)
typedef enum {
AS_MAX1027_FAST,
AS_MAX1027_SLOW
} AS_max1027_mode;
-/**
- * Store max1027 parameters
- */
struct as_max1027_device {
AS_max1027_mode mode;
uint8_t scan_mode;
- uint8_t fConversion; /**< File handler for conversion register */
- uint8_t fSetup; /**< File handler for setup register */
- uint8_t fAveraging; /**< File handler for averaging register */
- uint8_t fLowSpeed[NUMBER_OF_CHANNELS]; /**< Files handlers for lowspeed */
- uint8_t fHighSpeed[NUMBER_OF_CHANNELS]; /**< Files handlers for high speed */
- uint8_t fTemperature; /**< File handler for temperature */
-
+ char path[PATH_SIZE];
};
-/** @brief Open max1027
- *
- * @param aSpiNum spi bus number used
- * @param aMode enum to set mode (fast or slow)
- *
- * @return as_max1027_device structure pointer, NULL if error
- */
-struct as_max1027_device *as_max1027_open(int aSpiNum,
- AS_max1027_mode aMode);
-
-/** @brief set averaging measurement
- *
- * @param as_max1027_device structure pointer.
- * @param aNbConv number of conversions to do for the averaging (4, 8, 16, 32). Set to 1 for disabling averaging.
- *
- * @return negative value on error and aNbConv on success
- */
-int32_t as_max1027_set_averaging(struct as_max1027_device *aDev, uint8_t aNbConv);
-
-/** @brief read temperature in milidegree â°C
- *
- * @param as_max1027_device structure pointer.
- * @param aTemperature pointer for temperature result.
- *
- * @return negative value on error
- *
- * @note Only slow mode can read temperature value.
- */
-int32_t as_max1027_read_temperature_mC(struct as_max1027_device *aDev,
- int *aTemperature);
-
-/** @brief read milivoltage value
- *
- * @param as_max1027_device structure pointer.
- * @param aChannelNum channel number to read.
- * @param *aValue pointer to returned value.
- *
- * @return negative value on error
- */
-int32_t as_max1027_get_value_milliVolt(struct as_max1027_device *aDev,
- int aChannelNum,
- int *aValue);
-
-/** @brief Close max1027
- *
- * @param aDev structure device pointer
- *
- * @return negative value on error
- */
-int32_t as_max1027_close(struct as_max1027_device *aDev);
+struct as_adc_device *as_adc_open_max1027(int aDeviceNum, int aVRef);
+int32_t as_adc_get_value_in_millivolts_max1027(struct as_adc_device *aDev,
+ int aChannel);
+int32_t as_adc_close_max1027(struct as_adc_device *aDev);
#ifdef __cplusplus
}
diff --git a/target/packages/as_devices/python/AsDevices/AsAdc.py b/target/packages/as_devices/python/AsDevices/AsAdc.py
index ff1f876..d46aa05 100644
--- a/target/packages/as_devices/python/AsDevices/AsAdc.py
+++ b/target/packages/as_devices/python/AsDevices/AsAdc.py
@@ -79,12 +79,12 @@ class AsAdc:
@classmethod
def getInstance(cls, aAdcType, aDeviceNum, aVRef):
try:
- return AsAdc.__adc["%d:%d"%(aAdcType, aDeviceNum)]
+ return AsAdc.__adc["%s:%d"%(aAdcType, aDeviceNum)]
except KeyError:
- AsAdc.__adc["%d:%d"%(aAdcType, aDeviceNum)] =\
+ AsAdc.__adc["%s:%d"%(aAdcType, aDeviceNum)] =\
cls.__impl(aAdcType, aDeviceNum, aVRef)
- return AsAdc.__adc["%d:%d"%(aAdcType, aDeviceNum)]
+ return AsAdc.__adc["%s:%d"%(aAdcType, aDeviceNum)]
def __init__(self):
""" Initialize adc
diff --git a/target/packages/as_devices/python/src/AsAdc_wrap.c b/target/packages/as_devices/python/src/AsAdc_wrap.c
index e841f62..6179052 100644
--- a/target/packages/as_devices/python/src/AsAdc_wrap.c
+++ b/target/packages/as_devices/python/src/AsAdc_wrap.c
@@ -42,26 +42,25 @@ void initAsAdc_wrap() /* called on first import */
static PyObject * adc_open(PyObject *self, PyObject *args)
{
/* parameters */
+ char *aAdcType;
int aDeviceNum;
- int aAdcType;
int aVref;
struct as_adc_device *dev;
PyObject *ret;
char buff[300];
/* Get arguments */
- if (!PyArg_ParseTuple(args, "iii", &aDeviceNum, &aAdcType, &aVref))
+ if (!PyArg_ParseTuple(args, "sii", &aAdcType, &aDeviceNum, &aVref))
{
PyErr_SetString(PyExc_IOError,
"Wrong parameters.");
return NULL;
}
-
- dev = as_adc_open(aDeviceNum, aAdcType, aVref);
+ dev = as_adc_open(aAdcType, aDeviceNum, aVref);
if (dev == NULL)
{
snprintf(buff, 300,
- "Initialization error for ADC type %d bus %d. Is kernel module loaded ?",
+ "Initialization error for ADC type %s bus %d. Is kernel module loaded ?",
aAdcType, aDeviceNum);
PyErr_SetString(PyExc_IOError,buff);
return NULL;
hooks/post-receive
--
armadeus
|