[Armadeus-commitlog] armadeus branch, master, updated. armadeus-5.3-298-ga072196
Brought to you by:
sszy
|
From: Julien B a. A. <ar...@us...> - 2014-06-23 18:18:28
|
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 a0721960e6e3f8b7f4d8ea0bf7070fad8c0721be (commit)
via 201e2d90fac01b25953b05c5f19d359ae87e76f3 (commit)
from f4b9141b825d14a45b870cea31dea8e29e4e9cb2 (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 a0721960e6e3f8b7f4d8ea0bf7070fad8c0721be
Author: Julien Boibessot <jul...@ar...>
Date: Mon Jun 23 20:17:26 2014 +0200
[ASDEVICES] Lindent some C files
commit 201e2d90fac01b25953b05c5f19d359ae87e76f3
Author: Julien Boibessot <jul...@ar...>
Date: Mon Jun 23 18:58:37 2014 +0200
[BUILDROOT] 2013.11: fixes Tk build
-----------------------------------------------------------------------
Summary of changes:
.../2013.11/011-armadeus-add-tk-package.patch | 3 +-
target/packages/as_devices/c/as_adc.c | 127 +-
target/packages/as_devices/c/as_adc.h | 49 +-
target/packages/as_devices/c/as_dac.c | 70 +-
target/packages/as_devices/c/as_dac.h | 65 +-
target/packages/as_devices/c/as_helpers.c | 126 +-
target/packages/as_devices/c/as_helpers.h | 9 +-
target/packages/as_devices/main.c | 118 +-
target/packages/as_devices/test_c.h | 2101 ++++++++++----------
9 files changed, 1359 insertions(+), 1309 deletions(-)
diff --git a/patches/buildroot/2013.11/011-armadeus-add-tk-package.patch b/patches/buildroot/2013.11/011-armadeus-add-tk-package.patch
index 3bb3ef5..e4bb262 100644
--- a/patches/buildroot/2013.11/011-armadeus-add-tk-package.patch
+++ b/patches/buildroot/2013.11/011-armadeus-add-tk-package.patch
@@ -39,7 +39,7 @@ Index: buildroot/package/tk/tk.mk
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ buildroot/package/tk/tk.mk 2014-06-16 21:20:26.187716126 +0200
-@@ -0,0 +1,29 @@
+@@ -0,0 +1,30 @@
+################################################################################
+#
+# tk
@@ -52,6 +52,7 @@ Index: buildroot/package/tk/tk.mk
+TK_SITE = http://downloads.sourceforge.net/project/tcl/Tcl/$(TK_VERSION)
+TK_LICENSE = tcl license
+TK_LICENSE_FILES = license.terms
++TK_SUBDIR = unix
+TK_INSTALL_STAGING = YES
+TK_DEPENDENCIES = tcl xlib_libX11
+
diff --git a/target/packages/as_devices/c/as_adc.c b/target/packages/as_devices/c/as_adc.c
index c8755bb..1218515 100644
--- a/target/packages/as_devices/c/as_adc.c
+++ b/target/packages/as_devices/c/as_adc.c
@@ -21,17 +21,11 @@
#include <stdlib.h>
#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h> /* for close() */
-#include <sys/select.h>
+#include <unistd.h> /* close() */
#include <string.h>
-#include <sys/ioctl.h>
-#include <linux/ppdev.h>
-
#include "as_helpers.h"
#include "as_adc.h"
-
#include "as_max1027.h"
#include "as_as1531.h"
#include "as_adc_iio.h"
@@ -40,72 +34,67 @@
#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";
+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) {
- 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);
- 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;
+ 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);
+ 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;
}
-int32_t as_adc_get_value_in_millivolts(struct as_adc_device *aDev,
- int aChannel) {
- if (aDev == NULL) {
- ERROR("Device is NULL\n");
- return -1;
- }
-
- if (aDev->device_type == AS_MAX1027_NAME)
- return as_adc_get_value_in_millivolts_max1027(aDev, aChannel);
- 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;
+int32_t as_adc_get_value_in_millivolts(struct as_adc_device * aDev,
+ int aChannel)
+{
+ if (aDev == NULL) {
+ ERROR("Device is NULL\n");
+ return -1;
+ }
+
+ if (aDev->device_type == AS_MAX1027_NAME)
+ return as_adc_get_value_in_millivolts_max1027(aDev, aChannel);
+ 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;
}
-int32_t as_adc_close(struct as_adc_device *aDev) {
- int ret;
-
- if (aDev == NULL) {
- ERROR("Device is NULL\n");
- return -1;
- }
-
- if (aDev->device_type == AS_MAX1027_NAME) {
- ret = as_adc_close_max1027(aDev);
- free(aDev);
- return ret;
- }
- 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;
+int32_t as_adc_close(struct as_adc_device * aDev)
+{
+ int ret;
+
+ if (aDev == NULL) {
+ ERROR("Device is NULL\n");
+ return -1;
+ }
+
+ if (aDev->device_type == AS_MAX1027_NAME) {
+ ret = as_adc_close_max1027(aDev);
+ free(aDev);
+ return ret;
+ }
+ 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 b3786da..6c58917 100644
--- a/target/packages/as_devices/c/as_adc.h
+++ b/target/packages/as_devices/c/as_adc.h
@@ -19,57 +19,58 @@
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef __ASADC_H__
-#define __ASADC_H__
+#ifndef __AS_ADC_H__
+#define __AS_ADC_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
-#endif /* __cplusplus */
+#endif /* __cplusplus */
extern const char AS_MAX1027_NAME[];
extern const char AS_AS1531_NAME[];
extern const char AS_IIO_NAME[];
-/**
- * Store adc parameters
+/** @brief Store ADC parameters
*/
struct as_adc_device {
- const char *device_type; /* Name of device type as1531 or max1027 */
- int device_num;
- int vref; /* reference tension in millivolts */
- void *chip_param; /* chip specific parameters */
+ const char *device_type; /*!< device type: "as1531" or "max1027" */
+ int device_num; /*!< device id on bus */
+ int vref; /*!< reference voltage in millivolts */
+ void *chip_param; /*!< private data for chip handler */
};
-/** @brief Initialize port access
+/** @brief Initialize ADC chip access
*
- * @param aDeviceNum device number
- * @param aAdcType ADC type 0:max1027 1:as1531
- * @param aVRef reference tension in millivolts
+ * @param device_num device number
+ * @param type ADC type: "max1027"/"as1531"/"iio"
+ * @param vref reference voltage in millivolts
*
* @return error if negative value
*/
-struct as_adc_device *as_adc_open(const char *aAdcType, int aDeviceNum, int aVRef);
+struct as_adc_device *as_adc_open(const char *type, int device_num,
+ int vref);
-/** @brief get value in millivolts
+/** @brief Get given ADC channel value in millivolts
*
- * @param aDev as_gpio_device pointer structure
+ * @param adc ADC handler
+ * @param channel channel to use
*
- * @return error if negative millivolts
+ * @return millivolts or error if negative
*/
-int32_t as_adc_get_value_in_millivolts(struct as_adc_device *aDev, int aChannel);
+int32_t as_adc_get_value_in_millivolts(struct as_adc_device *adc,
+ int channel);
-/** @brief Close device
+/** @brief Close given ADC access
*
- * @param Adev as_adc_device pointer structure
+ * @param adc ADC handler
*
* @return error if negative
*/
-int32_t as_adc_close(struct as_adc_device *aDev);
+int32_t as_adc_close(struct as_adc_device *adc);
#ifdef __cplusplus
}
-#endif /* __cplusplus */
-
-#endif /* __ASADC_H__ */
+#endif /* __cplusplus */
+#endif /* __AS_ADC_H__ */
diff --git a/target/packages/as_devices/c/as_dac.c b/target/packages/as_devices/c/as_dac.c
index ab36e3d..a9a71c2 100644
--- a/target/packages/as_devices/c/as_dac.c
+++ b/target/packages/as_devices/c/as_dac.c
@@ -21,7 +21,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
-#include <unistd.h> /* for close() */
+#include <unistd.h> /* close() */
#include <string.h>
#include "as_dac.h"
@@ -30,51 +30,45 @@
#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)
+struct as_dac_device *as_dac_open(const char *dac_type, int bus,
+ int address, int vref)
{
- 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;
+ if (strncmp(AS_MAX5821_TYPE, dac_type, strlen(AS_MAX5821_TYPE)) == 0)
+ return as_dac_open_max5821(bus, address, vref);
+ /* TODO: mcp4912 */
+ ERROR("Undefined DAC type '%s'\n", dac_type);
+ return NULL;
}
-int32_t as_dac_set_value_in_millivolts(struct as_dac_device *aDev,
- int aChannel,
- int aValue)
+int32_t as_dac_set_value_in_millivolts(struct as_dac_device * dac,
+ int channel, int value)
{
- if (aDev == NULL) {
- ERROR("Device is NULL\n");
- return -1;
- }
+ if (dac == NULL) {
+ ERROR("Device is NULL\n");
+ return -1;
+ }
- 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;
- }
- }
+ if (strncmp(AS_MAX5821_TYPE,
+ dac->device_type, strlen(AS_MAX5821_TYPE)) == 0) {
+ if ((channel == 0) || (channel == 1)) {
+ return as_dac_set_value_max5821(dac,
+ channel + 'A', value);
+ } else {
+ ERROR("Wrong channel number %d\n", channel);
+ return -1;
+ }
+ }
- ERROR("Undefined DAC type '%s'\n", aDev->device_type);
- return -1;
+ ERROR("Undefined DAC type '%s'\n", dac->device_type);
+ return -1;
}
-
-int32_t as_dac_close(struct as_dac_device *aDev)
+int32_t as_dac_close(struct as_dac_device * dac)
{
- if (strncmp(AS_MAX5821_TYPE,
- aDev->device_type,
- strlen(AS_MAX5821_TYPE)) == 0)
- as_dac_close_max5821(aDev);
+ if (strncmp(AS_MAX5821_TYPE,
+ dac->device_type, strlen(AS_MAX5821_TYPE)) == 0)
+ as_dac_close_max5821(dac);
- free(aDev);
- return 0;
+ free(dac);
+ return 0;
}
-
diff --git a/target/packages/as_devices/c/as_dac.h b/target/packages/as_devices/c/as_dac.h
index 8ace82b..140b968 100644
--- a/target/packages/as_devices/c/as_dac.h
+++ b/target/packages/as_devices/c/as_dac.h
@@ -14,71 +14,64 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
- * Copyright (C) 2011 Fabien Marteau <fab...@ar...>
+ * Copyright (C) 2011-2014 The Armadeus Project & Armadeus Systems teams
+ * Author: Fabien Marteau <fab...@ar...>
*
*/
-
-#ifndef AS_DAC_H_
-#define AS_DAC_H_
+#ifndef __AS_DAC_H__
+#define __AS_DAC_H__
#ifdef __cplusplus
extern "C" {
#endif
-#include "as_dac.h"
-#include <stdint.h>
-
#define AS_MAX5821_TYPE "max5821"
#define AS_MCP4912
-/**
- * Store dac parameters
+/** @brief Store DAC parameters
+ *
*/
struct as_dac_device {
- int bus_number;
- int chip_address;
- int vref;
- const char *device_type;
- void *chip_param;
+ int bus_number; /*!< bus number */
+ int chip_address; /*!< chip address on bus */
+ int vref; /*!< reference voltage */
+ const char *device_type; /*!< device type: "max5821" or "mcp4912" */
+ void *chip_param; /*!< private data for chip handler */
};
-/** @brief Open dac
+/** @brief Initialize DAC chip access
*
- * @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
+ * @param dac_type type of DAC ("max5821" or "mcp4912")
+ * @param bus bus number used (I2C/SPI)
+ * @param address I2C address for I2C chip, and CS number for SPI chip
+ * @param vref voltage reference in milivolt
*
* @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);
+struct as_dac_device *as_dac_open(const char *dac_type, int bus,
+ int address, int vref);
-
-/** @brief set a channel value.
+/** @brief Set a DAC channel to given value
*
- * @param aDev structure pointer of dac device
- * @param aChannel channel number (A:0, B:1,...)
- * @param aValue channel value in milivolt
+ * @param dac handler of the DAC device
+ * @param channel channel number (A:0, B:1,...)
+ * @param value 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);
+int32_t as_dac_set_value_in_millivolts(struct as_dac_device *dac,
+ int channel, int value);
-/** @brief close device
+/** @brief Close DAC device access
*
- * @param aDev structure pointer of dac device
+ * @param dac handler of DAC device
*
* @return negative value on error
*/
-int32_t as_dac_close(struct as_dac_device *aDev);
+int32_t as_dac_close(struct as_dac_device *dac);
#ifdef __cplusplus
}
-#endif /* __cplusplus */
-
-#endif /* AS_DAC_H_ */
+#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 068a64a..fe4d902 100644
--- a/target/packages/as_devices/c/as_helpers.c
+++ b/target/packages/as_devices/c/as_helpers.c
@@ -1,8 +1,8 @@
/*
** AsDevices - Helpers functions for other modules
**
-** Copyright (C) 2009-2010 The armadeus systems team
-** Fabien Marteau <fab...@ar...>
+** Copyright (C) 2009-2014 The Armadeus Project & Armadeus Systems teams
+** Author: 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
@@ -19,11 +19,10 @@
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <string.h>
#include <stdio.h>
#include <stdlib.h>
-#include <fcntl.h> /* for open() */
-#include <unistd.h> /* for write() */
+#include <unistd.h> /* write()/lseek()/read() */
+#include <string.h>
/* #define DEBUG */
#include "as_helpers.h"
@@ -33,85 +32,84 @@
#undef ERROR
#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
-
int as_write_buffer(int fd, int value)
{
- int ret;
- char buffer[16];
- int buffer_len;
+ int ret;
+ char buffer[16];
+ int buffer_len;
- ret = snprintf(buffer, 16, "%d\n", value);
- if (ret < 0)
- return ret;
+ ret = snprintf(buffer, 16, "%d\n", value);
+ if (ret < 0)
+ return ret;
- buffer_len = strlen(buffer);
- ret = write(fd, buffer, buffer_len);
+ buffer_len = strlen(buffer);
+ ret = write(fd, buffer, buffer_len);
//XXX if (ret < 0) {
//XXX ERROR("Can't write file, buffer lenght %d $>%s<$\n", buffer_len, buffer);
//XXX return ret;
//XXX }
- ret = lseek(fd, 0, SEEK_SET);
- if (ret < 0) {
- ERROR("lseek error\n");
- return ret;
- }
+ ret = lseek(fd, 0, SEEK_SET);
+ if (ret < 0) {
+ ERROR("lseek error\n");
+ return ret;
+ }
- return buffer_len;
+ return buffer_len;
}
int as_write_buffer_string(int fd, char *string)
{
- int ret;
- int string_len;
-
- string_len = strlen(string);
- ret = write(fd, string, string_len);
- if (ret < 0) {
- ERROR("Can't write file ");
- return ret;
- }
- ret = lseek(fd, 0, SEEK_SET);
- if (ret < 0) {
- ERROR("lseek error ");
- return ret;
- }
-
- return string_len;
+ int ret;
+ int string_len;
+
+ string_len = strlen(string);
+ ret = write(fd, string, string_len);
+ if (ret < 0) {
+ ERROR("Can't write file ");
+ return ret;
+ }
+ ret = lseek(fd, 0, SEEK_SET);
+ if (ret < 0) {
+ ERROR("lseek error ");
+ return ret;
+ }
+
+ return string_len;
}
int as_read_buffer(int fd, char *buf, int size)
{
- int ret, err;
-
- ret = read(fd, buf, size);
- if (ret < 0) {
- ERROR("Can't read file ");
- return ret;
- }
- err = lseek(fd, 0, SEEK_SET);
- if (err < 0) {
- ERROR("lseek error ");
- return err;
- }
-
- return ret;
+ int ret, err;
+
+ ret = read(fd, buf, size);
+ if (ret < 0) {
+ ERROR("Can't read file ");
+ return ret;
+ }
+ err = lseek(fd, 0, SEEK_SET);
+ if (err < 0) {
+ ERROR("lseek error ");
+ return err;
+ }
+
+ return ret;
}
int as_read_int(int fd, int *value_res)
{
- const int SIZEOFBUFF = 20;
- ssize_t ret;
- char buf[SIZEOFBUFF];
- 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;
-
- return 0;
+ const int SIZEOFBUFF = 20;
+ ssize_t ret;
+ char buf[SIZEOFBUFF];
+ 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;
+
+ return 0;
}
int as_helpers_get_platform(void)
@@ -138,7 +136,7 @@ int as_helpers_get_platform(void)
char *as_helpers_get_root()
{
- char * root;
+ char *root;
root = getenv("AS_DEVICES_ROOT");
if (root)
diff --git a/target/packages/as_devices/c/as_helpers.h b/target/packages/as_devices/c/as_helpers.h
index c558db3..3e8bd64 100644
--- a/target/packages/as_devices/c/as_helpers.h
+++ b/target/packages/as_devices/c/as_helpers.h
@@ -1,8 +1,8 @@
/*
** AsDevices - Helpers functions for other modules
**
-** Copyright (C) 2009-2010 The armadeus systems team
-** Fabien Marteau <fab...@ar...>
+** Copyright (C) 2009-2014 The Armadeus Project & Armadeus Systems teams
+** Author: 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
@@ -26,9 +26,9 @@
#include <stdlib.h>
#ifdef DEBUG
-# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
-# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
+#define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__ */
#endif
/** @brief Write an int value as string in a /sys/ or /proc interface
@@ -91,4 +91,3 @@ enum {
};
#endif /* __ASHELPERS_H__ */
-
diff --git a/target/packages/as_devices/main.c b/target/packages/as_devices/main.c
index e1c5053..ec88275 100644
--- a/target/packages/as_devices/main.c
+++ b/target/packages/as_devices/main.c
@@ -20,63 +20,73 @@
*/
#ifdef __cplusplus
-# include "test_cpp.h"
+#include "test_cpp.h"
#else
-# include "test_c.h"
+#include "test_c.h"
#endif
-int main(int argc, char ** argv)
+int main(int argc, char **argv)
{
- char buffer[20];
- buffer[0] = '0';
+ char buffer[20];
+ buffer[0] = '0';
- while(buffer[0] != 'q')
- {
- system("clear");
- printf("*******************************************************\n");
- printf("* Testing program for as_devices library *\n");
- printf("*******************************************************\n");
- printf("Choose a test ('q' to quit):\n");
- printf(" 1) pwm\n");
- printf(" 2) i2c\n");
- printf(" 3) spi\n");
- printf(" 4) 93LCxx eeprom\n");
- printf(" 5) gpio\n");
- printf(" 6) max1027\n");
- printf(" 7) max5821\n");
- printf(" 8) as1531\n");
- printf(" 9) backlight\n");
- printf(" a) i2c eeprom\n");
- printf(" b) tcs3472\n");
- printf("> ");
- scanf("%s",buffer);
-
- switch(buffer[0])
- {
- case '1' : test_pwm();
- break;
- case '2' : test_i2c();
- break;
- case '3' : test_spi();
- break;
- case '4' : test_93LC();
- break;
- case '5' : test_gpio();
- break;
- case '6' : test_max1027();
- break;
- case '7' : test_max5821();
- break;
- case '8' : test_as1531();
- break;
- case '9' : test_backlight();
- break;
- case 'a': test_i2c_eeprom();
- break;
- case 'b': test_tcs3472();
- break;
- default : break;
- }
- }
- return 0;
+ while (buffer[0] != 'q') {
+ system("clear");
+ printf("**********************************************\n");
+ printf("* Testing program for as_devices library *\n");
+ printf("**********************************************\n");
+ printf("Choose a test ('q' to quit):\n");
+ printf(" 1) pwm\n");
+ printf(" 2) i2c\n");
+ printf(" 3) spi\n");
+ printf(" 4) 93LCxx eeprom\n");
+ printf(" 5) gpio\n");
+ printf(" 6) max1027\n");
+ printf(" 7) max5821\n");
+ printf(" 8) as1531\n");
+ printf(" 9) backlight\n");
+ printf(" a) i2c eeprom\n");
+ printf(" b) tcs3472\n");
+ printf("> ");
+ scanf("%s", buffer);
+
+ switch (buffer[0]) {
+ case '1':
+ test_pwm();
+ break;
+ case '2':
+ test_i2c();
+ break;
+ case '3':
+ test_spi();
+ break;
+ case '4':
+ test_93LC();
+ break;
+ case '5':
+ test_gpio();
+ break;
+ case '6':
+ test_max1027();
+ break;
+ case '7':
+ test_max5821();
+ break;
+ case '8':
+ test_as1531();
+ break;
+ case '9':
+ test_backlight();
+ break;
+ case 'a':
+ test_i2c_eeprom();
+ break;
+ case 'b':
+ test_tcs3472();
+ break;
+ default:
+ break;
+ }
+ }
+ return 0;
}
diff --git a/target/packages/as_devices/test_c.h b/target/packages/as_devices/test_c.h
index e294806..02ef5af 100644
--- a/target/packages/as_devices/test_c.h
+++ b/target/packages/as_devices/test_c.h
@@ -21,7 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h> /* sleep */
+#include <unistd.h> /* sleep */
#include <math.h>
#include "as_pwm.h"
@@ -43,1086 +43,1151 @@
void press_enter_to_continue(void)
{
- printf("\nPress enter to continue\n");
- while( getc(stdin) != '\n');
- while( getc(stdin) != '\n');
+ printf("\nPress enter to continue\n");
+ while (getc(stdin) != '\n') ;
+ while (getc(stdin) != '\n') ;
}
/* pwm test */
void test_pwm(void)
{
- int ret;
- char buffer[20];
- char buffer2[20];
- int value;
- struct as_pwm_device *pwm_dev;
-
- pwm_dev = as_pwm_open(PWM_NUM);
- if (pwm_dev == NULL) {
- printf("can't init pwm0\n");
- press_enter_to_continue();
- return;
- }
- while (buffer[0] != 'q') {
- system("clear");
- printf("*********************************\n");
- printf("* Testing pwm menu *\n");
- printf("*********************************\n");
- printf("Choose ('q' to quit):\n");
- printf(" 1) set Frequency\n");
- printf(" 2) get Frequency\n");
- printf(" 3) set Period\n");
- printf(" 4) get Period\n");
- printf(" 5) set Duty\n");
- printf(" 6) get Duty\n");
- printf(" 7) activate/desactivate\n");
- printf(" 8) get state\n");
- printf("> ");
- scanf("%s", buffer);
-
- switch (buffer[0])
- {
- case '1' : printf("Give frequency :");
- scanf("%d",&value);
- as_pwm_set_frequency(pwm_dev,value);
- press_enter_to_continue();
- break;
- case '2' : printf("Current pwm frequency is %d\n",
- as_pwm_get_frequency(pwm_dev));
- press_enter_to_continue();
- break;
- case '3' : printf("Give period :");
- scanf("%d", &value);
- as_pwm_set_period(pwm_dev, value);
- press_enter_to_continue();
- break;
- case '4' : printf("Current period is %d\n",
- as_pwm_get_period(pwm_dev));
- press_enter_to_continue();
- break;
- case '5' : printf("Give Duty :");
- scanf("%d", &value);
- as_pwm_set_duty(pwm_dev, value);
- press_enter_to_continue();
- break;
- case '6' : printf("Current Duty is %d\n",
- as_pwm_get_duty(pwm_dev));
- press_enter_to_continue();
- break;
- case '7' : printf("Activate 'a' or Desactivate 'd' ?");
- scanf("%s", buffer2);
- if (buffer2[0] == 'a') {
- as_pwm_set_state(pwm_dev, 1);
- printf("Pwm activated\n");
- press_enter_to_continue();
- } else if (buffer2[0] == 'd') {
- as_pwm_set_state(pwm_dev, 0);
- printf("Pwm desactivated\n");
- press_enter_to_continue();
- } else {
- printf("Option %c unknown\n",buffer[0]);
- press_enter_to_continue();
- }
- break;
- case '8' : if (as_pwm_get_state(pwm_dev)) {
- printf("pwm is active\n");
- press_enter_to_continue();
- } else {
- printf("pwm is inactive\n");
- press_enter_to_continue();
- }
- break;
- default : break;
- }
- }
- ret = as_pwm_close(pwm_dev);
- if (ret < 0) {
- printf("can't close pwm0\n");
- return;
- }
+ int ret;
+ char buffer[20];
+ char buffer2[20];
+ int value;
+ struct as_pwm_device *pwm_dev;
+
+ pwm_dev = as_pwm_open(PWM_NUM);
+ if (pwm_dev == NULL) {
+ printf("can't init pwm0\n");
+ press_enter_to_continue();
+ return;
+ }
+ while (buffer[0] != 'q') {
+ system("clear");
+ printf("*********************************\n");
+ printf("* Testing pwm menu *\n");
+ printf("*********************************\n");
+ printf("Choose ('q' to quit):\n");
+ printf(" 1) set Frequency\n");
+ printf(" 2) get Frequency\n");
+ printf(" 3) set Period\n");
+ printf(" 4) get Period\n");
+ printf(" 5) set Duty\n");
+ printf(" 6) get Duty\n");
+ printf(" 7) activate/desactivate\n");
+ printf(" 8) get state\n");
+ printf("> ");
+ scanf("%s", buffer);
+
+ switch (buffer[0]) {
+ case '1':
+ printf("Give frequency :");
+ scanf("%d", &value);
+ as_pwm_set_frequency(pwm_dev, value);
+ press_enter_to_continue();
+ break;
+ case '2':
+ printf("Current pwm frequency is %d\n",
+ as_pwm_get_frequency(pwm_dev));
+ press_enter_to_continue();
+ break;
+ case '3':
+ printf("Give period :");
+ scanf("%d", &value);
+ as_pwm_set_period(pwm_dev, value);
+ press_enter_to_continue();
+ break;
+ case '4':
+ printf("Current period is %d\n",
+ as_pwm_get_period(pwm_dev));
+ press_enter_to_continue();
+ break;
+ case '5':
+ printf("Give Duty :");
+ scanf("%d", &value);
+ as_pwm_set_duty(pwm_dev, value);
+ press_enter_to_continue();
+ break;
+ case '6':
+ printf("Current Duty is %d\n",
+ as_pwm_get_duty(pwm_dev));
+ press_enter_to_continue();
+ break;
+ case '7':
+ printf("Activate 'a' or Desactivate 'd' ?");
+ scanf("%s", buffer2);
+ if (buffer2[0] == 'a') {
+ as_pwm_set_state(pwm_dev, 1);
+ printf("Pwm activated\n");
+ press_enter_to_continue();
+ } else if (buffer2[0] == 'd') {
+ as_pwm_set_state(pwm_dev, 0);
+ printf("Pwm desactivated\n");
+ press_enter_to_continue();
+ } else {
+ printf("Option %c unknown\n", buffer[0]);
+ press_enter_to_continue();
+ }
+ break;
+ case '8':
+ if (as_pwm_get_state(pwm_dev)) {
+ printf("pwm is active\n");
+ press_enter_to_continue();
+ } else {
+ printf("pwm is inactive\n");
+ press_enter_to_continue();
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ ret = as_pwm_close(pwm_dev);
+ if (ret < 0) {
+ printf("can't close pwm0\n");
+ return;
+ }
}
/* i2c bus test */
void test_i2c(void)
{
- char buffer[20];
- int value;
- int initialized = 0;
-
- struct as_i2c_device *i2c_bus = 0;
- int i2c_id = 0;
-
- while (buffer[0] != 'q') {
- system("clear");
- printf("*********************************\n");
- printf("* Testing i2c menu *\n");
- printf("*********************************\n");
- printf("Choose ('q' to quit):\n");
- if (initialized == 0) {
- printf(" 1) Open i2c bus \n");
- printf(" 2) Change bus number (%d)\n",i2c_id);
- } else {
- printf(" 1) Close i2c bus \n");
- }
- printf("> ");
- scanf("%s",buffer);
-
- if (initialized == 0)
- {
- switch(buffer[0])
- {
- case '1' : printf("Open i2c bus\n");
- i2c_bus = as_i2c_open( i2c_id);
- if (i2c_bus < 0)
- {
- printf("Error can't open i2c bus\n");
- } else {
- printf("Bus %d opened\n", i2c_id);
- initialized = 1;
- }
- press_enter_to_continue();
- break;
- case '2' : printf("Give bus number (max %d): ", sizeof(_STR(AS_I2C_DEV_COUNT))-1);
- scanf("%d",&value);
- if ((value >= sizeof(_STR(AS_I2C_DEV_COUNT))) || (value < 0))
- {
- printf(" Wrong value\n");
- } else {
- i2c_id = value;
- }
- press_enter_to_continue();
- default : break;
- }
- } else {
- switch(buffer[0])
- {
- case '1' : printf("Close i2c bus\n");
- value = as_i2c_close(i2c_bus);
- if (value < 0)
- {
- printf(" Error, can't close i2c bus num %d\n", i2c_id);
- } else {
- initialized = 0;
- }
- press_enter_to_continue();
- break;
- default : break;
- }
- }
- }
+ char buffer[20];
+ int value;
+ int initialized = 0;
+
+ struct as_i2c_device *i2c_bus = 0;
+ int i2c_id = 0;
+
+ while (buffer[0] != 'q') {
+ system("clear");
+ printf("*********************************\n");
+ printf("* Testing i2c menu *\n");
+ printf("*********************************\n");
+ printf("Choose ('q' to quit):\n");
+ if (initialized == 0) {
+ printf(" 1) Open i2c bus \n");
+ printf(" 2) Change bus number (%d)\n", i2c_id);
+ } else {
+ printf(" 1) Close i2c bus \n");
+ }
+ printf("> ");
+ scanf("%s", buffer);
+
+ if (initialized == 0) {
+ switch (buffer[0]) {
+ case '1':
+ printf("Open i2c bus\n");
+ i2c_bus = as_i2c_open(i2c_id);
+ if (i2c_bus < 0) {
+ printf("Error can't open i2c bus\n");
+ } else {
+ printf("Bus %d opened\n", i2c_id);
+ initialized = 1;
+ }
+ press_enter_to_continue();
+ break;
+ case '2':
+ printf("Give bus number (max %d): ",
+ sizeof(_STR(AS_I2C_DEV_COUNT)) - 1);
+ scanf("%d", &value);
+ if ((value >= sizeof(_STR(AS_I2C_DEV_COUNT)))
+ || (value < 0)) {
+ printf(" Wrong value\n");
+ } else {
+ i2c_id = value;
+ }
+ press_enter_to_continue();
+ default:
+ break;
+ }
+ } else {
+ switch (buffer[0]) {
+ case '1':
+ printf("Close i2c bus\n");
+ value = as_i2c_close(i2c_bus);
+ if (value < 0) {
+ printf
+ (" Error, can't close i2c bus num %d\n",
+ i2c_id);
+ } else {
+ initialized = 0;
+ }
+ press_enter_to_continue();
+ break;
+ default:
+ break;
+ }
+ }
+ }
}
/* spi bus test */
void test_spi(void)
{
- printf("TODO\n");
- press_enter_to_continue();
+ printf("TODO\n");
+ press_enter_to_continue();
}
-
/* 93LCxx eepromm test */
int address_size(int aType, int aWordSize)
{
- return (((aType-46)/10) + 6 + 2 - (aWordSize/8));
+ return (((aType - 46) / 10) + 6 + 2 - (aWordSize / 8));
}
int max_address(int aType, int aWordSize)
{
- return (pow(2,address_size(aType, aWordSize))-1);
+ return (pow(2, address_size(aType, aWordSize)) - 1);
}
void test_93LC()
{
- char buffer[50];
- int i;
-
- int type = 46;
- char spidevpath[50];
- struct as_93lcxx_device *dev;
- /* defaults values */
- int frequency = 1000000;
- uint8_t word_size = 8;
- int value, value2;
- int initialized=0;
- snprintf(spidevpath, 50, "%s", "/dev/spidev2.0");
-
- while(buffer[0] != 'q')
- {
- system("clear");
- printf("*********************************\n");
- printf("* Testing 93LCxx menu *\n");
- printf("*********************************\n");
- printf("Choose ('q' to quit):\n");
- if (initialized == 0)
- {
- printf(" 1) Change word size (%d)\n", word_size);
- printf(" 2) Change bus frequency (%d)\n", frequency);
- printf(" 3) Change eeprom type (%d)\n", type);
- printf(" 4) Change spidev path (%s)\n", spidevpath);
- printf(" 5) Initialize eeprom\n");
- } else {
- printf(" 1) Close eeprom\n");
- printf(" 2) Read specific address\n");
- printf(" 3) Erase specific address\n");
- printf(" 4) Write specific address\n");
- printf(" 5) Write all\n");
- printf(" 6) Read all\n");
- printf(" 7) Erase all\n");
- printf(" 8) Unlock write\n");
- printf(" 9) lock write\n");
- }
-
- printf("> ");
- scanf("%s",buffer);
-
- if (initialized == 0)
- {
- switch(buffer[0])
- {
- case '1' : printf("Give new word size (8 or 16) : ");
- scanf("%d", &value);
- if ( (value != 8) && (value != 16) )
- {
- printf("Wrong value\n");
- press_enter_to_continue();
- } else {
- word_size = value;
- }
- break;
- case '2' : printf("Give bus frequency : ");
- scanf("%d", &value);
- frequency = value;
- printf("Frequency changed to %dHz\n",frequency);
- break;
- case '3' : printf("Give new type of eeprom (46, 56 or 66) : ");
- scanf("%d", &value);
- if ( (value != 46) && (value != 56) && (value != 66) )
- {
- printf("Wrong value\n");
- press_enter_to_continue();
- } else {
- type = value;
- }
- break;
- case '4' : printf("Give new path for spidev : \n");
- scanf("%s", spidevpath);
- printf("New path is %s\n",spidevpath);
- break;
- case '5' : dev = as_93lcxx_open((unsigned char *)spidevpath,
- type,
- frequency,
- word_size);
- if (dev == NULL)
- {
- printf("Error, can't initialize eeprom. Have you modprobed spidev ?\n");
- } else {
- initialized = 1;
- }
- press_enter_to_continue();
- break;
- default : break;
- }
- } else {
- switch(buffer[0])
- {
- case '1' : as_93lcxx_close(dev);
- printf("eeprom closed\n");
- initialized = 0;
- press_enter_to_continue();
- break;
- case '2' : printf(" Read specific address\n");
- printf("Give address in hexadecimal (max 0x%03X):",
- max_address(type, word_size));
- scanf("%x",&value);
- if (value > max_address(type, word_size))
- {
- printf(" Error, address wrong\n");
- } else {
- value2 = as_93lcxx_read(dev, value);
- if (value2 < 0)
- {
- printf("Error, can't read value\n");
- } else {
- printf(" Read %02x at %02X", value2, value );
- }
- }
- press_enter_to_continue();
- break;
- case '3' : printf("Erase specific address\n");
- printf("Give address in hexadecimal (max 0x%03X):",
- max_address(type, word_size));
- scanf("%x",&value);
- if (value > max_address(type, word_size))
- {
- printf(" Error, address wrong\n");
- } else {
- value2 = as_93lcxx_erase(dev, value);
- if (value2 < 0)
- {
- printf("Error, can't erase value\n");
- } else {
- printf("Value erased\n");
- }
- }
- press_enter_to_continue();
- break;
- case '4' : printf("Write specific address\n");
- printf("Give address in hexadecimal (max 0x%03X):",
- max_address(type, word_size));
- scanf("%x",&value);
- if (value > max_address(type, word_size))
- {
- printf(" Error, address wrong\n");
- press_enter_to_continue();
- break;
- }
- printf("Give value in hexadecimal :");
- scanf("%x",&value2);
- value2 = as_93lcxx_write(dev, value, value2);
- if (value2 < 0)
- {
- printf("Error, can't write value\n");
- }
- press_enter_to_continue();
- break;
- case '5' : printf(" Write all\n");
- printf("Give value in hexadecimal:");
- scanf("%x",&value);
- value2 = as_93lcxx_write_all(dev, value);
- if (value2 < 0)
- {
- printf("Error, can't write value\n");
- }
- press_enter_to_continue();
- break;
- case '6' : printf(" Read all\n");
- for(i = 0; i <= max_address(type, word_size); i++)
- {
- if (word_size == 8)
- {
- printf("%03X -> %02X\n",
- i,as_93lcxx_read(dev, i));
- } else{
- printf("%03X -> %04X\n",
- i,as_93lcxx_read(dev, i));
- }
- }
- press_enter_to_continue();
- break;
- case '7' : printf(" Erase all\n");
- value = as_93lcxx_erase_all(dev);
- if (value < 0)
- printf(" Error in erasing eeprom\n");
- press_enter_to_continue();
- break;
- case '8' : printf("Unlock write\n");
- if (as_93lcxx_ewen(dev) < 0)
- printf("Error can't unlock write\n");
- press_enter_to_continue();
- break;
- case '9' : printf("lock write\n");
- if (as_93lcxx_ewds(dev) < 0)
- printf("Error can't lock write\n");
- press_enter_to_continue();
- break;
- default : break;
- }
- }
- }
+ char buffer[50];
+ int i;
+
+ int type = 46;
+ char spidevpath[50];
+ struct as_93lcxx_device *dev;
+ /* defaults values */
+ int frequency = 1000000;
+ uint8_t word_size = 8;
+ int value, value2;
+ int initialized = 0;
+ snprintf(spidevpath, 50, "%s", "/dev/spidev2.0");
+
+ while (buffer[0] != 'q') {
+ system("clear");
+ printf("*********************************\n");
+ printf("* Testing 93LCxx menu *\n");
+ printf("*********************************\n");
+ printf("Choose ('q' to quit):\n");
+ if (initialized == 0) {
+ printf(" 1) Change word size (%d)\n", word_size);
+ printf(" 2) Change bus frequency (%d)\n", frequency);
+ printf(" 3) Change eeprom type (%d)\n", type);
+ printf(" 4) Change spidev path (%s)\n", spidevpath);
+ printf(" 5) Initialize eeprom\n");
+ } else {
+ printf(" 1) Close eeprom\n");
+ printf(" 2) Read specific address\n");
+ printf(" 3) Erase specific address\n");
+ printf(" 4) Write specific address\n");
+ printf(" 5) Write all\n");
+ printf(" 6) Read all\n");
+ printf(" 7) Erase all\n");
+ printf(" 8) Unlock write\n");
+ printf(" 9) lock write\n");
+ }
+
+ printf("> ");
+ scanf("%s", buffer);
+
+ if (initialized == 0) {
+ switch (buffer[0]) {
+ case '1':
+ printf("Give new word size (8 or 16) : ");
+ scanf("%d", &value);
+ if ((value != 8) && (value != 16)) {
+ printf("Wrong value\n");
+ press_enter_to_continue();
+ } else {
+ word_size = value;
+ }
+ break;
+ case '2':
+ printf("Give bus frequency : ");
+ scanf("%d", &value);
+ frequency = value;
+ printf("Frequency changed to %dHz\n",
+ frequency);
+ break;
+ case '3':
+ printf
+ ("Give new type of eeprom (46, 56 or 66) : ");
+ scanf("%d", &value);
+ if ((value != 46) && (value != 56)
+ && (value != 66)) {
+ printf("Wrong value\n");
+ press_enter_to_continue();
+ } else {
+ type = value;
+ }
+ break;
+ case '4':
+ printf("Give new path for spidev : \n");
+ scanf("%s", spidevpath);
+ printf("New path is %s\n", spidevpath);
+ break;
+ case '5':
+ dev =
+ as_93lcxx_open((unsigned char *)spidevpath,
+ type, frequency, word_size);
+ if (dev == NULL) {
+ printf
+ ("Error, can't initialize eeprom. Have you modprobed spidev ?\n");
+ } else {
+ initialized = 1;
+ }
+ press_enter_to_continue();
+ break;
+ default:
+ break;
+ }
+ } else {
+ switch (buffer[0]) {
+ case '1':
+ as_93lcxx_close(dev);
+ printf("eeprom closed\n");
+ initialized = 0;
+ press_enter_to_continue();
+ break;
+ case '2':
+ printf(" Read specific address\n");
+ printf
+ ("Give address in hexadecimal (max 0x%03X):",
+ max_address(type, word_size));
+ scanf("%x", &value);
+ if (value > max_address(type, word_size)) {
+ printf(" Error, address wrong\n");
+ } else {
+ value2 = as_93lcxx_read(dev, value);
+ if (value2 < 0) {
+ printf
+ ("Error, can't read value\n");
+ } else {
+ printf(" Read %02x at %02X",
+ value2, value);
+ }
+ }
+ press_enter_to_continue();
+ break;
+ case '3':
+ printf("Erase specific address\n");
+ printf
+ ("Give address in hexadecimal (max 0x%03X):",
+ max_address(type, word_size));
+ scanf("%x", &value);
+ if (value > max_address(type, word_size)) {
+ printf(" Error, address wrong\n");
+ } else {
+ value2 = as_93lcxx_erase(dev, value);
+ if (value2 < 0) {
+ printf
+ ("Error, can't erase value\n");
+ } else {
+ printf("Value erased\n");
+ }
+ }
+ press_enter_to_continue();
+ break;
+ case '4':
+ printf("Write specific address\n");
+ printf
+ ("Give address in hexadecimal (max 0x%03X):",
+ max_address(type, word_size));
+ scanf("%x", &value);
+ if (value > max_address(type, word_size)) {
+ printf(" Error, address wrong\n");
+ press_enter_to_continue();
+ break;
+ }
+ printf("Give value in hexadecimal :");
+ scanf("%x", &value2);
+ value2 = as_93lcxx_write(dev, value, value2);
+ if (value2 < 0) {
+ printf("Error, can't write value\n");
+ }
+ press_enter_to_continue();
+ break;
+ case '5':
+ printf(" Write all\n");
+ printf("Give value in hexadecimal:");
+ scanf("%x", &value);
+ value2 = as_93lcxx_write_all(dev, value);
+ if (value2 < 0) {
+ printf("Error, can't write value\n");
+ }
+ press_enter_to_continue();
+ break;
+ case '6':
+ printf(" Read all\n");
+ for (i = 0; i <= max_address(type, word_size);
+ i++) {
+ if (word_size == 8) {
+ printf("%03X -> %02X\n",
+ i, as_93lcxx_read(dev,
+ i));
+ } else {
+ printf("%03X -> %04X\n",
+ i, as_93lcxx_read(dev,
+ i));
+ }
+ }
+ press_enter_to_continue();
+ break;
+ case '7':
+ printf(" Erase all\n");
+ value = as_93lcxx_erase_all(dev);
+ if (value < 0)
+ printf(" Error in erasing eeprom\n");
+ press_enter_to_continue();
+ break;
+ case '8':
+ printf("Unlock write\n");
+ if (as_93lcxx_ewen(dev) < 0)
+ printf("Error can't unlock write\n");
+ press_enter_to_continue();
+ break;
+ case '9':
+ printf("lock write\n");
+ if (as_93lcxx_ewds(dev) < 0)
+ printf("Error can't lock write\n");
+ press_enter_to_continue();
+ break;
+ default:
+ break;
+ }
+ }
+ }
}
void test_gpio()
{
- char buffer[50];
- struct as_gpio_device *gpio_dev;
- int32_t ret;
- int32_t value;
- int pin_num = 173; /* default: PF13 */
- int pin_value = 1, platform;
-
- platform = as_helpers_get_platform();
- switch (platform) {
- case APF9328:
- pin_num = 0x007;
- break;
- case APF27:
- pin_num = 173;
- break;
- case APF51:
- pin_num = 3;
- break;
- default:
- break;
- }
-
- gpio_dev = as_gpio_open(pin_num);
- if (gpio_dev == NULL) {
- printf("Error can't open gpio %d\nHave you got gpiolib ?\n", pin_num);
- press_enter_to_continue();
- return ;
- }
-
- pin_value = as_gpio_get_pin_value(gpio_dev);
- if (pin_value < 0) {
- printf("Error, can't get pin value\n");
- return;
- }
-
- while(buffer[0] != 'q')
- {
- system("clear");
- printf("**************************\n");
- printf(" Testing GPIO Port%d \n", pin_num);
- printf("**************************\n");
- printf("Choose ('q' to quit):\n");
- printf(" 1) Change gpio (%d)\n", as_gpio_get_pin_num(gpio_dev));
- printf(" 2) Change direction (%s)\n", as_gpio_get_pin_direction(gpio_dev));
- printf(" 3) Change value (%d)\n", as_gpio_get_pin_value(gpio_dev));
- printf(" 4) Read pin value\n");
- printf(" 5) Set irq/event mode (%s)\n", as_gpio_get_irq_mode(gpio_dev));
- printf(" a) Wait an event\n");
-
- printf("> ");
- scanf("%s",buffer);
-
- switch (buffer[0])
- {
- case '1' : printf("Give pin number : ");
- scanf("%d", &pin_num);
-
- gpio_dev = as_gpio_open(pin_num);
- if (gpio_dev == NULL)
- {
- printf("Error, can't open %d\n", pin_num);
- press_enter_to_continue();
- break;
- }
- printf("Ok %d is open\n", pin_num);
- press_enter_to_continue();
- break;
- case '2' : printf("Give direction (in/out) : ");
- scanf("%s", buffer);
- ret = as_gpio_set_pin_direction(gpio_dev, buffer);
- if (ret < 0)
- {
- printf("Error, can't change direction\n");
- press_enter_to_continue();
- break;
- }
- printf("Ok direction changed\n");
- press_enter_to_continue();
- break;
- case '3' : printf("Give value : ");
- scanf("%d", &value);
- ret = as_gpio_set_pin_value(gpio_dev, value);
- if (ret < 0)
- {
- printf("Error, can't change pin value\n");
- press_enter_to_continue();
- break;
- }
- printf("Ok value changed\n");
- press_enter_to_continue();
- break;
- case '4' : printf("Get value \n");
- pin_value = as_gpio_get_pin_value(gpio_dev);
- if (pin_value < 0) {
- printf("Error, can't get pin value\n");
- press_enter_to_continue();
- break;
- }
- printf("Value is %d\n", pin_value);
- press_enter_to_continue();
- break;
- case '5':
+ char buffer[50];
+ struct as_gpio_device *gpio_dev;
+ int32_t ret;
+ int32_t value;
+ int pin_num = 173; /* default: PF13 */
+ int pin_value = 1, platform;
+
+ platform = as_helpers_get_platform();
+ switch (platform) {
+ case APF9328:
+ pin_num = 0x007;
+ break;
+ case APF27:
+ pin_num = 173;
+ break;
+ case APF51:
+ pin_num = 3;
+ break;
+ default:
+ break;
+ }
+
+ gpio_dev = as_gpio_open(pin_num);
+ if (gpio_dev == NULL) {
+ printf("Error can't open gpio %d\nHave you got gpiolib ?\n",
+ pin_num);
+ press_enter_to_continue();
+ return;
+ }
+
+ pin_value = as_gpio_get_pin_value(gpio_dev);
+ if (pin_value < 0) {
+ printf("Error, can't get pin value\n");
+ return;
+ }
+
+ while (buffer[0] != 'q') {
+ system("clear");
+ printf("**************************\n");
+ printf(" Testing GPIO Port%d \n", pin_num);
+ printf("**************************\n");
+ printf("Choose ('q' to quit):\n");
+ printf(" 1) Change gpio (%d)\n", as_gpio_get_pin_num(gpio_dev));
+ printf(" 2) Change direction (%s)\n",
+ as_gpio_get_pin_direction(gpio_dev));
+ printf(" 3) Change value (%d)\n",
+ as_gpio_get_pin_value(gpio_dev));
+ printf(" 4) Read pin value\n");
+ printf(" 5) Set irq/event mode (%s)\n",
+ as_gpio_get_irq_mode(gpio_dev));
+ printf(" a) Wait an event\n");
+
+ printf("> ");
+ scanf("%s", buffer);
+
+ switch (buffer[0]) {
+ case '1':
+ printf("Give pin number : ");
+ scanf("%d", &pin_num);
+
+ gpio_dev = as_gpio_open(pin_num);
+ if (gpio_dev == NULL) {
+ printf("Error, can't open %d\n", pin_num);
+ press_enter_to_continue();
+ break;
+ }
+ printf("Ok %d is open\n", pin_num);
+ press_enter_to_continue();
+ break;
+ case '2':
+ printf("Give direction (in/out) : ");
+ scanf("%s", buffer);
+ ret = as_gpio_set_pin_direction(gpio_dev, buffer);
+ if (ret < 0) {
+ printf("Error, can't change direction\n");
+ press_enter_to_continue();
+ break;
+ }
+ printf("Ok direction changed\n");
+ press_enter_to_continue();
+ break;
+ case '3':
+ printf("Give value : ");
+ scanf("%d", &value);
+ ret = as_gpio_set_pin_value(gpio_dev, value);
+ if (ret < 0) {
+ printf("Error, can't change pin value\n");
+ press_enter_to_continue();
+ break;
+ }
+ printf("Ok value changed\n");
+ press_enter_to_continue();
+ break;
+ case '4':
+ printf("Get value \n");
+ pin_value = as_gpio_get_pin_value(gpio_dev);
+ if (pin_value < 0) {
+ printf("Error, can't get pin value\n");
+ press_enter_to_continue();
+ break;
+ }
+ printf("Value is %d\n", pin_value);
+ press_enter_to_continue();
+ break;
+ case '5':
printf("rising / falling / both / none\n");
- printf("Please choose a mode : ");
- scanf("%s", buffer);
- ret = as_gpio_set_irq_mode(gpio_dev, buffer);
- if (ret < 0)
- {
- printf("Error, can't change irq value\n");
- press_enter_to_continue();
- break;
- }
- printf("Ok value changed\n");
- press_enter_to_continue();
- break;
- case 'a' : printf("Blocking read (10 sec timeout)\n");
- ret = as_gpio_wait_event(gpio_dev, 10000);
- if (ret < 0)
- {
- printf("Error, can't read value\n");
- press_enter_to_continue();
- break;
- }
- printf("Value read %d\n",ret);
- press_enter_to_continue();
- break;
- default : break;
- }
- }
- ret = as_gpio_close(gpio_dev);
- if(ret < 0)
- {
- printf("Error, can't close gpio\n");
- press_enter_to_continue();
- }
+ printf("Please choose a mode : ");
+ scanf("%s", buffer);
+ ret = as_gpio_set_irq_mode(gpio_dev, buffer);
+ if (ret < 0) {
+ printf("Error, can't change irq value\n");
+ press_enter_to_continue();
+ break;
+ }
+ printf("Ok value changed\n");
+ press_enter_to_continue();
+ break;
+ case 'a':
+ printf("Blocking read (10 sec timeout)\n");
+ ret = as_gpio_wait_event(gpio_dev, 10000);
+ if (ret < 0) {
+ printf("Error, can't read value\n");
+ press_enter_to_continue();
+ break;
+ }
+ printf("Value read %d\n", ret);
+ press_enter_to_continue();
+ break;
+ default:
+ break;
+ }
+ }
+ ret = as_gpio_close(gpio_dev);
+ if (ret < 0) {
+ printf("Error, can't close gpio\n");
+ press_enter_to_continue();
+ }
}
#define NUM_OF_CHANNEL (8)
void test_max1027()
{
- char buffer[50];
- int ret;
- int value;
- float fValue;
- struct as_adc_device *max1027_dev;
- int channel=0;
- float vRef = 2500;
- int devNumber = 0;
- int initialized = 0;
-
- while(buffer[0] != 'q')
- {
- system("clear");
- printf("**************************\n");
- printf(" Testing max1027 *\n");
- printf("**************************\n");
- printf("Choose ('q' to quit):\n");
-
- if (initialized == 0)
- {
- printf(" 1) Open Max 1027 device\n");
- printf(" 2) Change device number (%i)\n", devNumber);
- }
- else
- {
- printf(" 1) Close Max 1027 device\n");
- printf(" 2) Change Vref (%fmV)\n",vRef);
- printf(" 3) Select channel (%i)\n", channel);
- printf(" 4) Read channel value\n");
- }
+ char buffer[50];
+ int ret;
+ int value;
+ float fValue;
+ struct as_adc_device *max1027_dev;
+ int channel = 0;
+ float vRef = 2500;
+ int devNumber = 0;
+ int initialized = 0;
+
+ while (buffer[0] != 'q') {
+ system("clear");
+ printf("**************************\n");
+ printf(" Testing max1027 *\n");
+ printf("**************************\n");
+ printf("Choose ('q' to quit):\n");
+
+ if (initialized == 0) {
+ printf(" 1) Open Max 1027 device\n");
+ printf(" 2) Change device number (%i)\n", devNumber);
+ } else {
+ printf(" 1) Close Max 1027 device\n");
+ printf(" 2) Change Vref (%fmV)\n", vRef);
+ printf(" 3) Select channel (%i)\n", channel);
+ printf(" 4) Read channel value\n");
+ }
+
+ printf("> ");
+ scanf("%s", buffer);
+
+ if (initialized == 0) {
+ switch (buffer[0]) {
+ case '1':
+ printf("Open MAX1027 device\n");
+ max1027_dev =
+ as_adc_open(AS_MA...
[truncated message content] |