[Armadeus-commitlog] armadeus branch, master, updated. armadeus-5.2-204-g8f31f7e
Brought to you by:
sszy
|
From: SebR <se...@us...> - 2013-03-13 13:44:42
|
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 8f31f7e2dcd81631c0467f0b1c5b9ce0c22c8c91 (commit)
from 94cfc443553a9cd96949b2ce097991e17bab5e36 (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 8f31f7e2dcd81631c0467f0b1c5b9ce0c22c8c91
Author: seb <seb...@ar...>
Date: Wed Mar 13 14:43:39 2013 +0100
[as_devices] add iio bus for adc + backlight not limited to imx-bl
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/Makefile | 1 +
target/packages/as_devices/c/as_adc.c | 33 +++--
target/packages/as_devices/c/as_adc.h | 5 +-
target/packages/as_devices/c/as_adc_iio.c | 142 ++++++++++++++++++++
.../as_devices/c/{as_max1027.h => as_adc_iio.h} | 29 +---
target/packages/as_devices/c/as_as1531.c | 2 +-
target/packages/as_devices/c/as_backlight.c | 24 +++-
target/packages/as_devices/c/as_backlight.h | 16 ++-
target/packages/as_devices/c/as_max1027.c | 2 +-
target/packages/as_devices/cpp/as_backlight.cpp | 7 +-
target/packages/as_devices/cpp/as_backlight.hpp | 3 +-
11 files changed, 214 insertions(+), 50 deletions(-)
create mode 100644 target/packages/as_devices/c/as_adc_iio.c
copy target/packages/as_devices/c/{as_max1027.h => as_adc_iio.h} (57%)
diff --git a/target/packages/as_devices/c/Makefile b/target/packages/as_devices/c/Makefile
index 41bc090..b4cd6c0 100644
--- a/target/packages/as_devices/c/Makefile
+++ b/target/packages/as_devices/c/Makefile
@@ -17,6 +17,7 @@ endif
OBJ += as_dac.o
OBJ += as_adc.o
+OBJ += as_adc_iio.o
OBJ += as_93lcxx.o
OBJ += as_spi.o
OBJ += as_as1531.o
diff --git a/target/packages/as_devices/c/as_adc.c b/target/packages/as_devices/c/as_adc.c
index 2ca2be4..c8755bb 100644
--- a/target/packages/as_devices/c/as_adc.c
+++ b/target/packages/as_devices/c/as_adc.c
@@ -34,10 +34,15 @@
#include "as_max1027.h"
#include "as_as1531.h"
+#include "as_adc_iio.h"
#undef ERROR
#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+const char AS_MAX1027_NAME[] = "max1027";
+const char AS_AS1531_NAME[] = "as1531";
+const char AS_IIO_NAME[] = "iio";
+
struct as_adc_device *as_adc_open(const char *aAdcType,
int aDeviceNum,
int aVRef) {
@@ -49,6 +54,10 @@ struct as_adc_device *as_adc_open(const char *aAdcType,
aAdcType,
strlen(AS_AS1531_NAME)) == 0)
return as_adc_open_as1531(aDeviceNum, aVRef);
+ if (strncmp(AS_IIO_NAME,
+ aAdcType,
+ strlen(AS_IIO_NAME)) == 0)
+ return as_adc_open_iio(aDeviceNum, aVRef);
ERROR("Undefined ADC type '%s'\n",aAdcType);
return NULL;
@@ -61,15 +70,12 @@ int32_t as_adc_get_value_in_millivolts(struct as_adc_device *aDev,
return -1;
}
- if (strncmp(AS_MAX1027_NAME,
- aDev->device_type,
- strlen(AS_MAX1027_NAME)) == 0)
+ if (aDev->device_type == AS_MAX1027_NAME)
return as_adc_get_value_in_millivolts_max1027(aDev, aChannel);
-
- if (strncmp(AS_AS1531_NAME,
- aDev->device_type,
- strlen(AS_AS1531_NAME)) == 0)
+ if (aDev->device_type == AS_AS1531_NAME)
return as_adc_get_value_in_millivolts_as1531(aDev, aChannel);
+ if (aDev->device_type == AS_IIO_NAME)
+ return as_adc_get_value_in_millivolts_iio(aDev, aChannel);
ERROR("Undefined ADC type '%s'\n", aDev->device_type);
return -1;
@@ -83,20 +89,21 @@ int32_t as_adc_close(struct as_adc_device *aDev) {
return -1;
}
- if (strncmp(AS_MAX1027_NAME,
- aDev->device_type,
- strlen(AS_MAX1027_NAME)) == 0) {
+ if (aDev->device_type == AS_MAX1027_NAME) {
ret = as_adc_close_max1027(aDev);
free(aDev);
return ret;
}
- if (strncmp(AS_AS1531_NAME,
- aDev->device_type,
- strlen(AS_AS1531_NAME)) == 0) {
+ if (aDev->device_type == AS_AS1531_NAME) {
ret = as_adc_close_as1531(aDev);
free(aDev);
return ret;
}
+ if (aDev->device_type == AS_IIO_NAME) {
+ ret = as_adc_close_iio(aDev);
+ free(aDev);
+ return ret;
+ }
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 5c9b678..b3786da 100644
--- a/target/packages/as_devices/c/as_adc.h
+++ b/target/packages/as_devices/c/as_adc.h
@@ -28,8 +28,9 @@
extern "C" {
#endif /* __cplusplus */
-#define AS_MAX1027_NAME "max1027"
-#define AS_AS1531_NAME "as1531"
+extern const char AS_MAX1027_NAME[];
+extern const char AS_AS1531_NAME[];
+extern const char AS_IIO_NAME[];
/**
* Store adc parameters
diff --git a/target/packages/as_devices/c/as_adc_iio.c b/target/packages/as_devices/c/as_adc_iio.c
new file mode 100644
index 0000000..78966b3
--- /dev/null
+++ b/target/packages/as_devices/c/as_adc_iio.c
@@ -0,0 +1,142 @@
+/*
+ * 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) 2013 Sébastien Royen <seb...@ar...>
+ *
+ *
+ * TODO:
+ * - use type in /sys/bus/iio/devices/iio:device:X/scan_elements to format result
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include "as_adc_iio.h"
+#include "as_helpers.h"
+
+#undef ERROR
+#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+
+#define IIO_DEVICE_MAX_CHANNELS 32
+
+struct as_adc_iio_device {
+ int channelDesc[IIO_DEVICE_MAX_CHANNELS];
+};
+
+static int open_channels(struct as_adc_iio_device *aDev, int aDeviceNum)
+{
+ char buffer[128];
+ int i;
+ int count;
+
+ count = 0;
+ for (i=0; i<IIO_DEVICE_MAX_CHANNELS; i++) {
+ snprintf(buffer, sizeof(buffer),
+ "/sys/bus/iio/devices/iio:device%d/in_voltage%d_raw",
+ aDeviceNum, i);
+ aDev->channelDesc[i] = open(buffer, O_RDONLY);
+ if (aDev->channelDesc[i] >= 0) {
+ count++;
+ }
+ }
+ return count;
+}
+
+static void close_channels(struct as_adc_iio_device *aDev)
+{
+ int i;
+
+ for (i=0; i<IIO_DEVICE_MAX_CHANNELS; i++) {
+ if (aDev->channelDesc[i] >= 0) {
+ close(aDev->channelDesc[i]);
+ }
+ }
+}
+
+struct as_adc_device *as_adc_open_iio(int aDeviceNum, int aVRef)
+{
+ struct as_adc_device *adc_dev;
+ struct as_adc_iio_device *dev;
+
+ dev = (struct as_adc_iio_device *)malloc(sizeof(struct as_adc_iio_device));
+ if (dev == NULL) {
+ ERROR("Error during memory allocation\n");
+ return NULL;
+ }
+
+ if (open_channels(dev, aDeviceNum) == 0) {
+ ERROR("No in voltage channel found\n");
+ goto err;
+ }
+
+ adc_dev = (struct as_adc_device *)malloc(sizeof(struct as_adc_device));
+ if (dev == NULL) {
+ close_channels(dev);
+ ERROR("Error during memory allocation\n");
+ goto err;
+ }
+
+ adc_dev->chip_param = (void*)dev;
+ adc_dev->device_type = AS_IIO_NAME;
+ adc_dev->device_num = aDeviceNum;
+ adc_dev->vref = aVRef; /* NOT USED */
+
+ return adc_dev;
+
+err:
+ free(dev);
+ return NULL;
+}
+
+int32_t as_adc_get_value_in_millivolts_iio(struct as_adc_device *aDev, int aChannel) {
+ struct as_adc_iio_device *dev;
+ int32_t value;
+ int32_t ret;
+
+ dev = (struct as_adc_iio_device *)aDev->chip_param;
+
+ if ((aChannel >= IIO_DEVICE_MAX_CHANNELS) || (aChannel < 0)) {
+ ERROR("Wrong num channel\n");
+ return -1;
+ }
+
+ if (dev->channelDesc[aChannel] != -1) {
+ ret = as_read_int(dev->channelDesc[aChannel], &value);
+ if (ret < 0) {
+ ERROR("Can't read input file\n");
+ return -1;
+ }
+ }
+
+ return value;
+}
+
+int32_t as_adc_close_iio(struct as_adc_device *aDev) {
+ struct as_adc_iio_device *dev =
+ (struct as_adc_iio_device *)aDev->chip_param;
+
+ close_channels(dev);
+ free(dev);
+ return 0;
+}
+
diff --git a/target/packages/as_devices/c/as_max1027.h b/target/packages/as_devices/c/as_adc_iio.h
similarity index 57%
copy from target/packages/as_devices/c/as_max1027.h
copy to target/packages/as_devices/c/as_adc_iio.h
index edd071f..e15fc64 100644
--- a/target/packages/as_devices/c/as_max1027.h
+++ b/target/packages/as_devices/c/as_adc_iio.h
@@ -14,40 +14,27 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
- * Copyright (C) 2010 Fabien Marteau <fab...@ar...>
+ * Copyright (C) 2013 Sébastien Royen <seb...@ar...>
*
*/
-#ifndef AS_MAX1027_H_
-#define AS_MAX1027_H_
+#ifndef AS_ADC_IMX28_LRADC_H_
+#define AS_ADC_IMX28_LRADC_H_
#ifdef __cplusplus
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;
-
-struct as_max1027_device {
- AS_max1027_mode mode;
- uint8_t scan_mode;
- char path[PATH_SIZE];
-};
-
-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);
+struct as_adc_device *as_adc_open_iio(int aDeviceNum, int aVRef);
+int32_t as_adc_get_value_in_millivolts_iio(struct as_adc_device *aDev,
+ int aChannel);
+int32_t as_adc_close_iio(struct as_adc_device *aDev);
#ifdef __cplusplus
}
#endif /* __cplusplus */
-#endif /* AS_MAX1027_H_ */
+#endif /* AS_ADC_IMX28_LRADC_H_ */
diff --git a/target/packages/as_devices/c/as_as1531.c b/target/packages/as_devices/c/as_as1531.c
index 6924cb0..0a74262 100644
--- a/target/packages/as_devices/c/as_as1531.c
+++ b/target/packages/as_devices/c/as_as1531.c
@@ -45,7 +45,7 @@ struct as_adc_device *as_adc_open_as1531(int aDeviceNum, int aVRef) {
return NULL;
}
- dev->device_type = "as1531";
+ dev->device_type = AS_AS1531_NAME;
dev->device_num = aDeviceNum;
dev->vref = aVRef;
return dev;
diff --git a/target/packages/as_devices/c/as_backlight.c b/target/packages/as_devices/c/as_backlight.c
index 2fd7fad..0e3a4fe 100644
--- a/target/packages/as_devices/c/as_backlight.c
+++ b/target/packages/as_devices/c/as_backlight.c
@@ -2,7 +2,7 @@
** THE ARMadeus Systems
**
** Copyright (C) 2012 The armadeus systems team
-** Jérémie Scheer <jer...@ar...>
+** J�r�mie Scheer <jer...@ar...>
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
@@ -30,7 +30,8 @@
#include "as_backlight.h"
-#define BACKLIGHT_SYS_PATH "/sys/class/backlight/imx-bl"
+#define BACKLIGHT_SYS_PATH "/sys/class/backlight"
+#define BACKLIGHT_DEFAULT "imx-bl"
#define ACTUAL_BRIGHTNESS_PATH "actual_brightness"
#define MAX_BRIGHTNESS_PATH "max_brightness"
#define BRIGHTNESS_PATH "brightness"
@@ -39,11 +40,15 @@
/*------------------------------------------------------------------------------*/
-struct as_backlight_device *as_backlight_open()
+struct as_backlight_device *as_backlight_open2(char *aBacklightName)
{
char buffer[SIZE_OF_BUFF];
struct as_backlight_device *dev;
+ if (aBacklightName == NULL) {
+ aBacklightName = BACKLIGHT_DEFAULT;
+ }
+
dev = (struct as_backlight_device *)malloc(sizeof(struct as_backlight_device));
if (dev == NULL) {
ERROR("Can't allocate memory for backlight device structure\n");
@@ -51,17 +56,17 @@ struct as_backlight_device *as_backlight_open()
}
/* open backlight management files */
- snprintf(buffer, SIZE_OF_BUFF, "%s/%s", BACKLIGHT_SYS_PATH, ACTUAL_BRIGHTNESS_PATH);
+ snprintf(buffer, SIZE_OF_BUFF, "%s/%s/%s", BACKLIGHT_SYS_PATH, aBacklightName, ACTUAL_BRIGHTNESS_PATH);
if ((dev->fileActualBrightness = open(buffer, O_RDWR)) < 0) {
ERROR("Can't open actual brightness file");
return NULL;
}
- snprintf(buffer, SIZE_OF_BUFF, "%s/%s", BACKLIGHT_SYS_PATH, MAX_BRIGHTNESS_PATH);
+ snprintf(buffer, SIZE_OF_BUFF, "%s/%s/%s", BACKLIGHT_SYS_PATH, aBacklightName, MAX_BRIGHTNESS_PATH);
if ((dev->fileMaxBrightness = open(buffer, O_RDWR)) < 0) {
ERROR("Can't open max brightness file");
return NULL;
}
- snprintf(buffer, SIZE_OF_BUFF, "%s/%s", BACKLIGHT_SYS_PATH, BRIGHTNESS_PATH);
+ snprintf(buffer, SIZE_OF_BUFF, "%s/%s/%s", BACKLIGHT_SYS_PATH, aBacklightName, BRIGHTNESS_PATH);
if((dev->fileBrightness = open(buffer, O_RDWR)) < 0) {
ERROR("Can't open brightness file");
return NULL;
@@ -70,6 +75,11 @@ struct as_backlight_device *as_backlight_open()
return dev;
}
+struct as_backlight_device *as_backlight_open()
+{
+ return as_backlight_open2(NULL);
+}
+
/*------------------------------------------------------------------------------*/
int32_t as_backlight_get_actual_brightness(struct as_backlight_device *aDev)
@@ -152,5 +162,7 @@ int32_t as_backlight_close(struct as_backlight_device *aDev)
return ret;
}
+ free(aDev);
+
return ret;
}
diff --git a/target/packages/as_devices/c/as_backlight.h b/target/packages/as_devices/c/as_backlight.h
index 424fea5..06b70be 100644
--- a/target/packages/as_devices/c/as_backlight.h
+++ b/target/packages/as_devices/c/as_backlight.h
@@ -2,7 +2,7 @@
** THE ARMadeus Systems
**
** Copyright (C) 2012 The armadeus systems team
-** Jérémie Scheer <jer...@ar...>
+** J�r�mie Scheer <jer...@ar...>
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
@@ -29,15 +29,23 @@ extern "C" {
#include <stdint.h>
struct as_backlight_device {
- int fileActualBrightness;
- int fileMaxBrightness;
- int fileBrightness;
+ int fileActualBrightness;
+ int fileMaxBrightness;
+ int fileBrightness;
};
/** @brief Open Backlight device
*
+ * @param aBacklightName name of backlight to use (imx-bl if NULL)
+ *
* @return pointer to device structure, NULL if error
*/
+struct as_backlight_device *as_backlight_open2(char *aBacklightName);
+
+/** @brief Open Backlight device
+ *
+ * @return result of as_backlight_open2(NULL)
+ */
struct as_backlight_device *as_backlight_open();
/** @brief Get actual brightness
diff --git a/target/packages/as_devices/c/as_max1027.c b/target/packages/as_devices/c/as_max1027.c
index 3887701..207edfa 100644
--- a/target/packages/as_devices/c/as_max1027.c
+++ b/target/packages/as_devices/c/as_max1027.c
@@ -173,7 +173,7 @@ struct as_adc_device *as_adc_open_max1027(int aDeviceNum, int aVRef) {
dev->scan_mode = SCAN_MODE_11;
adc_dev->chip_param = (void *)dev;
- adc_dev->device_type = "max1027";
+ adc_dev->device_type = AS_MAX1027_NAME;
adc_dev->device_num = aDeviceNum;
adc_dev->vref = 2500; /* Voltage reference is always 2.5V */
diff --git a/target/packages/as_devices/cpp/as_backlight.cpp b/target/packages/as_devices/cpp/as_backlight.cpp
index 451bafa..dc5e9bf 100644
--- a/target/packages/as_devices/cpp/as_backlight.cpp
+++ b/target/packages/as_devices/cpp/as_backlight.cpp
@@ -2,7 +2,7 @@
** THE ARMadeus Systems
**
** Copyright (C) 2012 The armadeus systems team
-** Jérémie Scheer <jer...@ar...>
+** J�r�mie Scheer <jer...@ar...>
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
@@ -23,6 +23,11 @@
#include "as_backlight.hpp"
#include <iostream>
+AsBacklight::AsBacklight(char *aBacklightName)
+{
+ mDev = as_backlight_open2(aBacklightName);
+}
+
AsBacklight::AsBacklight()
{
mDev = as_backlight_open();
diff --git a/target/packages/as_devices/cpp/as_backlight.hpp b/target/packages/as_devices/cpp/as_backlight.hpp
index b30904b..79a4e43 100644
--- a/target/packages/as_devices/cpp/as_backlight.hpp
+++ b/target/packages/as_devices/cpp/as_backlight.hpp
@@ -2,7 +2,7 @@
** THE ARMadeus Systems
**
** Copyright (C) 2012 The armadeus systems team
-** Jérémie Scheer <jer...@ar...>
+** J�r�mie Scheer <jer...@ar...>
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
@@ -35,6 +35,7 @@ public:
* Constructor
*/
AsBacklight();
+ AsBacklight(char *aBacklightName);
virtual ~AsBacklight();
/** @brief Get actual brightness
hooks/post-receive
--
armadeus
|