[Armadeus-commitlog] armadeus branch, master, updated. release-3.4-150-g231931d
Brought to you by:
sszy
|
From: Julien B a. A. <ar...@us...> - 2011-05-25 10:11:18
|
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 231931d9f012ed086fc20df212e995c1993809c1 (commit)
via 5db82673a4a2113655d1477b330398dc0ea3543b (commit)
via ee426f2e6e843c052bf748d7f92c6782a7ac6e4e (commit)
via 70b6cfb8557236fa0b3c6aab83aa87d5267a8da2 (commit)
from 7cb4f61d238e7614b990f1a24c434b50b46201e0 (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 231931d9f012ed086fc20df212e995c1993809c1
Author: Julien Boibessot <jul...@ar...>
Date: Wed May 25 12:08:25 2011 +0200
[AS_DEVICES] Cleanup as_gpio and add possibility to wait for events/irq on GPIO (edge configurable)
commit 5db82673a4a2113655d1477b330398dc0ea3543b
Author: Julien Boibessot <jul...@ar...>
Date: Wed May 25 12:06:53 2011 +0200
[AS_DEVICES] Makes Python wrapper compiles standalone
commit ee426f2e6e843c052bf748d7f92c6782a7ac6e4e
Author: Julien Boibessot <jul...@ar...>
Date: Wed May 25 12:03:20 2011 +0200
[AS_DEVICES] Cleanup
commit 70b6cfb8557236fa0b3c6aab83aa87d5267a8da2
Author: Julien Boibessot <jul...@ar...>
Date: Wed May 25 11:54:03 2011 +0200
[AS_DEVICES] Add possibility to get APF model (in C)
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/as_gpio.c | 185 ++++++++++++--------
target/packages/as_devices/c/as_gpio.h | 36 ++--
target/packages/as_devices/c/as_helpers.c | 22 +++
target/packages/as_devices/c/as_helpers.h | 13 ++
target/packages/as_devices/c/as_i2c.c | 1 -
target/packages/as_devices/cpp/as_gpio.cpp | 30 ++--
target/packages/as_devices/cpp/as_gpio.hpp | 12 +-
target/packages/as_devices/main.c | 16 +-
target/packages/as_devices/python/Makefile | 3 +-
.../packages/as_devices/python/src/AsGpio_wrap.c | 38 ++--
target/packages/as_devices/test_c.h | 76 +++++----
target/packages/as_devices/test_cpp.h | 36 ++---
12 files changed, 271 insertions(+), 197 deletions(-)
diff --git a/target/packages/as_devices/c/as_gpio.c b/target/packages/as_devices/c/as_gpio.c
index 24e161d..eb3333b 100644
--- a/target/packages/as_devices/c/as_gpio.c
+++ b/target/packages/as_devices/c/as_gpio.c
@@ -1,7 +1,7 @@
/*
- ** The ARMadeus Project
+ ** C wrapper for GPIOs usage.
**
- ** Copyright (C) 2009, 2010, 2011 The armadeus systems team
+ ** Copyright (C) 2009, 2010, 2011 The Armadeus Project - ARMadeus Systems
** Fabien Marteau <fab...@ar...>
**
** This library is free software; you can redistribute it and/or
@@ -24,14 +24,15 @@
#include <fcntl.h>
#include <unistd.h> /* for close() */
#include <sys/select.h>
+#include <poll.h>
+#include <errno.h>
#include <sys/ioctl.h>
-#include <linux/ppdev.h>
#include "as_helpers.h"
#include "as_gpio.h"
-#define BUFF_SIZE (300)
+#define BUFF_SIZE 300
#undef ERROR
#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
@@ -96,69 +97,53 @@ struct as_gpio_device *as_gpio_open(char aPortChar, int aPinNum)
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_set_pin_direction(struct as_gpio_device *aDev, int aDirection)
+int32_t as_gpio_set_pin_direction(struct as_gpio_device *gpio_dev, char *direction)
{
- char buf[BUFF_SIZE];
- int pin_file;
- int retval;
+ char buf[BUFF_SIZE];
+ int gpio_fd;
+ int ret = 0;
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/direction", aDev->port_num);
- pin_file = open(buf, O_WRONLY);
- if (pin_file < 0) {
- ERROR("Can't open gpio%d direction\n", aDev->port_num);
- return -1;
- }
+ snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/direction", gpio_dev->port_num);
+ gpio_fd = open(buf, O_WRONLY);
+ if (gpio_fd < 0) {
+ ERROR("Can't open gpio%d direction\n", gpio_dev->port_num);
+ return -EINVAL;
+ }
- if (aDirection == 0) {
- retval = as_write_buffer_string(pin_file, "in");
- if (retval < 0) {
- ERROR("Error writting direction\n");
- close(pin_file);
- return -1;
- }
- } else {
- retval = as_write_buffer_string(pin_file, "out");
- if (retval < 0) {
- ERROR("Error writting direction\n");
- close(pin_file);
- return -1;
- }
- }
- close(pin_file);
+ ret = as_write_buffer_string(gpio_fd, direction);
+ if (ret < 0)
+ ERROR("Error writing direction\n");
+
+ close(gpio_fd);
- return aDirection;
+ return ret;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_get_pin_direction(struct as_gpio_device *aDev)
+const char* as_gpio_get_pin_direction(struct as_gpio_device *gpio_dev)
{
- char buf[BUFF_SIZE];
- int pin_file;
- int retval;
-
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/direction", aDev->port_num);
- pin_file = open(buf, O_RDONLY);
- if (pin_file < 0) {
- ERROR("Can't open gpio%d direction\n", aDev->port_num);
- return -1;
- }
- retval = as_read_buffer(pin_file, buf, 4);
- if (retval < 0) {
- ERROR("Can't read gpio%d direction file\n", aDev->port_num);
- close(pin_file);
- return -1;
- }
- close(pin_file);
-
- if ((buf[0] == 'i') && (buf[1] == 'n'))
- return 0;
- else if ((buf[0] == 'o') && (buf[1] == 'u') && (buf[2] == 't'))
- return 1;
- else {
- ERROR("Wrong value >%s< read in direction file\n", buf);
- return -1;
- }
+ char buf[BUFF_SIZE];
+ static char direction[4];
+ FILE *gpio_file;
+ int ret = 0;
+ static const char none[] = "??";
+
+ snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction",
+ gpio_dev->port_num);
+ gpio_file = fopen(buf, "r");
+ if (!gpio_file) {
+ ERROR("Can't open gpio%d direction\n", gpio_dev->port_num);
+ return none;
+ }
+ ret = fscanf(gpio_file, "%s", direction);
+ fclose(gpio_file);
+ if (ret < 0) {
+ ERROR("Can't get gpio%d direction\n", gpio_dev->port_num);
+ return none;
+ }
+
+ return direction;
}
/*------------------------------------------------------------------------------*/
@@ -199,7 +184,7 @@ int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev)
snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/value", aDev->port_num);
pin_file = open(buf, O_RDONLY);
if (pin_file < 0) {
- ERROR("Can't open gpio%d direction\n", aDev->port_num);
+ ERROR("Can't open gpio%d value\n", aDev->port_num);
return -1;
}
@@ -216,28 +201,85 @@ int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev)
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_blocking_get_pin_value(struct as_gpio_device *aDev,
- int aDelay_s,
- int aDelay_us)
+int32_t as_gpio_wait_event(struct as_gpio_device *gpio_dev, int delay_ms)
{
- printf("as_gpio_blocking_get_pin_value:TODO\n");
- return -1;
+ char gpio_sys_name[BUFF_SIZE];
+ int gpio_fd;
+ struct pollfd poll_set[1];
+ int ret;
+ char tmp[16];
+
+ snprintf(gpio_sys_name, BUFF_SIZE, "/sys/class/gpio/gpio%d/value",
+ gpio_dev->port_num);
+ gpio_fd = open(gpio_sys_name, O_RDONLY);
+ if (gpio_fd < 0) {
+ ERROR("Can't open gpio%d value\n", gpio_dev->port_num);
+ return -EINVAL;
+ }
+
+ /* flush pending event */
+ read(gpio_fd, tmp, sizeof(tmp));
+
+ poll_set[0].fd = gpio_fd;
+ poll_set[0].events = POLLPRI;
+ poll_set[0].revents = 0;
+ ret = poll(poll_set, 1, delay_ms);
+ if (ret > 0) {
+ printf("event received\n");
+ read(gpio_fd, tmp, sizeof(tmp));
+ }
+
+ return 0;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_get_irq_mode(struct as_gpio_device *aDev)
+const char* as_gpio_get_irq_mode(struct as_gpio_device *gpio_dev)
{
- printf("as_gpio_get_irq_mode:TODO\n");
- return -1;
+ char buf[BUFF_SIZE];
+ static char mode[8];
+ FILE *gpio_file;
+ int ret = 0;
+ static const char unknown[] = "??";
+
+ snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/edge", gpio_dev->port_num);
+ gpio_file = fopen(buf, "r");
+ if (!gpio_file) {
+ ERROR("Can't open gpio%d edge\n", gpio_dev->port_num);
+ return unknown;
+ }
+ ret = fscanf(gpio_file, "%s", mode);
+ fclose(gpio_file);
+ if (ret < 0) {
+ ERROR("Can't get gpio%d edge\n", gpio_dev->port_num);
+ return unknown;
+ }
+
+ return mode;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev, int aMode)
+int32_t as_gpio_set_irq_mode(struct as_gpio_device *gpio_dev, char *mode)
{
- printf("as_gpio_set_irq_mode:TODO\n");
- return -1;
+ char buf[BUFF_SIZE];
+ int gpio_fd;
+ int ret = 0;
+
+ snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/edge", gpio_dev->port_num);
+ gpio_fd = open(buf, O_WRONLY);
+ if (gpio_fd < 0) {
+ ERROR("Can't open gpio%d edge\n", gpio_dev->port_num);
+ return -EINVAL;
+ }
+
+ ret = as_write_buffer_string(gpio_fd, mode);
+ if (ret < 0)
+ ERROR("Error writing mode\n");
+
+ close(gpio_fd);
+
+ return ret;
}
/*------------------------------------------------------------------------------*/
@@ -249,7 +291,7 @@ int32_t as_gpio_get_pin_num(struct as_gpio_device *aDev)
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_get_port_letter(struct as_gpio_device *aDev)
+char as_gpio_get_port_letter(struct as_gpio_device *aDev)
{
return aDev->port_letter;
}
@@ -261,4 +303,3 @@ int32_t as_gpio_close(struct as_gpio_device *aDev)
return 0;
}
-
diff --git a/target/packages/as_devices/c/as_gpio.h b/target/packages/as_devices/c/as_gpio.h
index 8ba1246..b2b241f 100644
--- a/target/packages/as_devices/c/as_gpio.h
+++ b/target/packages/as_devices/c/as_gpio.h
@@ -57,21 +57,21 @@ struct as_gpio_device *as_gpio_open(char aPortChar, int aPinNum);
/** @brief Set pin direction
*
- * @param aDev as_gpio_device pointer structure
- * @param aDirection direction 0:input 1:output
+ * @param gpio_dev as_gpio_device pointer structure
+ * @param direction "in"/"out"
*
* @return error if negative value
*/
-int32_t as_gpio_set_pin_direction(struct as_gpio_device *aDev,
- int aDirection);
+int32_t as_gpio_set_pin_direction(struct as_gpio_device *gpio_dev,
+ char *direction);
/** @brief Get pin direction
*
- * @param aDev as_gpio_device pointer structure
+ * @param gpio_dev as_gpio_device pointer structure
*
* @return error if negative value
*/
-int32_t as_gpio_get_pin_direction(struct as_gpio_device *aDev);
+const char* as_gpio_get_pin_direction(struct as_gpio_device *gpio_dev);
/** @brief Set pin value
*
@@ -91,35 +91,31 @@ int32_t as_gpio_set_pin_value(struct as_gpio_device *aDev,
*/
int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev);
-/** @brief Get pin value, blocking until interrupt occur
+/** @brief Block until an event occur on that pin and return value
*
* @param aDev as_gpio_device pointer structure
- * @param aDelay_s waiting delay in seconds
- * @param aDelay_us waiting delay in useconds (plus delay in seconds)
+ * @param aDelay_ms timeout in milliseconds
*
* @return pin value if positive or null, read error if -1, timeout if -10
*/
-int32_t as_gpio_blocking_get_pin_value(struct as_gpio_device *aDev,
- int aDelay_s,
- int aDelay_us);
+int32_t as_gpio_wait_event(struct as_gpio_device *aDev, int aDelay_ms);
/** @brief Set pin irq mode
*
- * @param aDev as_gpio_device pointer structure
- * @param aMode irq mode
+ * @param gpio_dev as_gpio_device pointer structure
+ * @param mode irq mode (rising/falling/both/none)
*
* @return error if negative
*/
-int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
- int aMode);
+int32_t as_gpio_set_irq_mode(struct as_gpio_device *gpio_dev, char *mode);
/** @brief Get pin irq mode value
*
- * @param aDev as_gpio_device pointer structure
+ * @param gpio_dev as_gpio_device pointer structure
*
- * @return pin mode value if positive or null, error if negative
+ * @return pin triggering mode: (rising/falling/both/none)
*/
-int32_t as_gpio_get_irq_mode(struct as_gpio_device *aDev);
+const char* as_gpio_get_irq_mode(struct as_gpio_device *gpio_dev);
/** @brief Get pin number value
*
@@ -135,7 +131,7 @@ int32_t as_gpio_get_pin_num(struct as_gpio_device *aDev);
*
* @return port letter, error if negative
*/
-int32_t as_gpio_get_port_letter(struct as_gpio_device *aDev);
+char as_gpio_get_port_letter(struct as_gpio_device *aDev);
/** @brief Close port access
*
diff --git a/target/packages/as_devices/c/as_helpers.c b/target/packages/as_devices/c/as_helpers.c
index e2fa27c..7fe7d6d 100644
--- a/target/packages/as_devices/c/as_helpers.c
+++ b/target/packages/as_devices/c/as_helpers.c
@@ -113,3 +113,25 @@ int as_read_int(int fd, int *value_res)
return 0;
}
+int as_helpers_get_platform(void)
+{
+ FILE *plat_file;
+ char name[8];
+ int ret;
+
+ plat_file = fopen("/etc/machine", "r");
+ if (!plat_file)
+ return APF_UNKNOWN;
+
+ ret = fscanf(plat_file, "%s", name);
+ fclose(plat_file);
+
+ if (!strcmp(name, "APF9328"))
+ return APF9328;
+ if (!strcmp(name, "APF27"))
+ return APF27;
+ if (!strcmp(name, "APF51"))
+ return APF51;
+
+ return APF_UNKNOWN;
+}
diff --git a/target/packages/as_devices/c/as_helpers.h b/target/packages/as_devices/c/as_helpers.h
index 6e6bf6e..535dba2 100644
--- a/target/packages/as_devices/c/as_helpers.h
+++ b/target/packages/as_devices/c/as_helpers.h
@@ -68,5 +68,18 @@ int as_read_buffer(int fd, char *buf, int size);
*/
int as_read_int(int fd, int *value_res);
+/** @brief return APF platform type
+ *
+ * @return APF_UNKNOWN/APF9328/APF27/APF51
+ */
+int as_helpers_get_platform(void);
+
+enum {
+ APF_UNKNOWN,
+ APF9328,
+ APF27,
+ APF51,
+};
+
#endif /* __ASHELPERS_H__ */
diff --git a/target/packages/as_devices/c/as_i2c.c b/target/packages/as_devices/c/as_i2c.c
index 3c607c2..9434f6f 100644
--- a/target/packages/as_devices/c/as_i2c.c
+++ b/target/packages/as_devices/c/as_i2c.c
@@ -221,7 +221,6 @@ int32_t as_i2c_read_msg(struct as_i2c_device *aDev,
uint8_t *aWData, uint8_t aWriteSize,
uint8_t *aRData, size_t aReadSize)
{
- int i;
/* write reg */
struct i2c_msg msg = { aDev->slave_addr, 0, aWriteSize, aWData };
struct i2c_rdwr_ioctl_data rdwr = { &msg, 1 };
diff --git a/target/packages/as_devices/cpp/as_gpio.cpp b/target/packages/as_devices/cpp/as_gpio.cpp
index e08d883..e3b5580 100644
--- a/target/packages/as_devices/cpp/as_gpio.cpp
+++ b/target/packages/as_devices/cpp/as_gpio.cpp
@@ -57,7 +57,7 @@ AsGpio::~AsGpio()
*
* @return error if negative value
*/
-long AsGpio::setPinDirection(int aDirection)
+long AsGpio::setPinDirection(char *aDirection)
{
if (mDev != NULL)
{
@@ -74,7 +74,7 @@ long AsGpio::setPinDirection(int aDirection)
*
* @return pin direction if positive or null, error if negative
*/
-long AsGpio::getPinDirection() const
+const char* AsGpio::getPinDirection() const
{
if (mDev != NULL)
{
@@ -83,7 +83,7 @@ long AsGpio::getPinDirection() const
else
{
std::cerr<<"AsGpio device structure not allocated"<<std::endl;
- return -1;
+ return NULL;
}
}
@@ -123,18 +123,17 @@ long AsGpio::getPinValue() const
}
}
-/** @brief Get pin value, blocking until interrupt occur
+/** @brief Get pin value, blocking until an interrupt/event occurs
*
- * @param aDelay_s waiting delay in seconds
- * @param aDelay_us waiting delay in useconds (plus delay in seconds)
+ * @param aDelay_ms waiting delay in milliseconds
*
* @return pin value if positive or null, read error if -1, timeout if -10
*/
-long AsGpio::blockingGetPinValue(int aDelay_s, int aDelay_us) const
+long AsGpio::waitEvent(int aDelay_ms) const
{
if (mDev != NULL)
{
- return as_gpio_blocking_get_pin_value(mDev, aDelay_s, aDelay_us);
+ return as_gpio_wait_event(mDev, aDelay_ms);
}
else
{
@@ -149,7 +148,7 @@ long AsGpio::blockingGetPinValue(int aDelay_s, int aDelay_us) const
*
* @return error if negative
*/
-long AsGpio::setIrqMode(int aMode)
+long AsGpio::setIrqMode(char* aMode)
{
if (mDev != NULL)
{
@@ -164,9 +163,9 @@ long AsGpio::setIrqMode(int aMode)
/** @brief Get pin irq mode value
*
- * @return pin mode value if positive or null, error if negative
+ * @return none/rising/falling/both
*/
-long AsGpio::getIrqMode() const
+const char* AsGpio::getIrqMode() const
{
if (mDev != NULL)
{
@@ -175,7 +174,7 @@ long AsGpio::getIrqMode() const
else
{
std::cerr<<"AsGpio device structure not allocated"<<std::endl;
- return -1;
+ return '?';
}
}
@@ -198,9 +197,9 @@ long AsGpio::getPinNum() const
/** @brief Get port letter
*
- * @return port letter, error if negative
+ * @return port letter
*/
-long AsGpio::getPortLetter() const
+char AsGpio::getPortLetter() const
{
if (mDev != NULL)
{
@@ -209,6 +208,7 @@ long AsGpio::getPortLetter() const
else
{
std::cerr<<"AsGpio device structure not allocated"<<std::endl;
- return -1;
+ return '?';
}
}
+
diff --git a/target/packages/as_devices/cpp/as_gpio.hpp b/target/packages/as_devices/cpp/as_gpio.hpp
index 017957f..cdd2966 100644
--- a/target/packages/as_devices/cpp/as_gpio.hpp
+++ b/target/packages/as_devices/cpp/as_gpio.hpp
@@ -31,19 +31,19 @@ public:
AsGpio(char aPortChar, int aPinNum);
virtual ~AsGpio();
- long setPinDirection(int aDirection);
- long getPinDirection() const;
+ long setPinDirection(char* aDirection);
+ const char* getPinDirection() const;
long setPinValue(int aValue);
long getPinValue() const;
- long blockingGetPinValue(int aDelay_s, int aDelay_us) const;
+ long waitEvent(int aDelay_ms) const;
- long setIrqMode(int aMode);
- long getIrqMode() const;
+ long setIrqMode(char* aMode);
+ const char* getIrqMode() const;
long getPinNum() const;
- long getPortLetter() const;
+ char getPortLetter() const;
protected:
mutable struct as_gpio_device *mDev;
diff --git a/target/packages/as_devices/main.c b/target/packages/as_devices/main.c
index fc46ea9..fb778fd 100644
--- a/target/packages/as_devices/main.c
+++ b/target/packages/as_devices/main.c
@@ -37,14 +37,14 @@ int main(int argc, char ** argv)
printf("* Testing program for as_devices library *\n");
printf("*******************************************************\n");
printf("Choose a test ('q' to quit):\n");
- printf(" 1) Testing pwm\n");
- printf(" 2) Testing i2c\n");
- printf(" 3) Testing spi\n");
- printf(" 4) Testing 93LCxx eprom\n");
- printf(" 5) Testing gpio\n");
- printf(" 6) Testing max1027\n");
- printf(" 7) Testing max5821\n");
- printf(" 8) Testing as1531\n");
+ printf(" 1) pwm\n");
+ printf(" 2) i2c\n");
+ printf(" 3) spi\n");
+ printf(" 4) 93LCxx eprom\n");
+ printf(" 5) gpio\n");
+ printf(" 6) max1027\n");
+ printf(" 7) max5821\n");
+ printf(" 8) as1531\n");
printf("> ");
scanf("%s",buffer);
diff --git a/target/packages/as_devices/python/Makefile b/target/packages/as_devices/python/Makefile
index 375b6e2..a3c22b5 100644
--- a/target/packages/as_devices/python/Makefile
+++ b/target/packages/as_devices/python/Makefile
@@ -23,8 +23,9 @@ WRAPPER_DIR=src
PYTHON_VERS=2.4
PYTHON_SUBVERS=5
+STAGING_DIR=$(ARMADEUS_STAGING_DIR)
PYINC=$(STAGING_DIR)/usr/include/python2.4/
-PYLIB=../../../../buildroot/project_build_armv5te/apf27/root/usr/lib/python$(PYTHON_VERS)
+PYLIB=$(ARMADEUS_TARGET_DIR)/usr/lib/python$(PYTHON_VERS)
.PHONY: all
diff --git a/target/packages/as_devices/python/src/AsGpio_wrap.c b/target/packages/as_devices/python/src/AsGpio_wrap.c
index 8073c99..9f6472a 100644
--- a/target/packages/as_devices/python/src/AsGpio_wrap.c
+++ b/target/packages/as_devices/python/src/AsGpio_wrap.c
@@ -84,7 +84,7 @@ static PyObject * gpio_open(PyObject *self, PyObject *args)
/** @brief Set pin direction
*
* @param aFdev as_gpio_device structure pointer
- * @param aDirection direction 0:input 1:output
+ * @param aDirection direction "in" / "out"
*
* @return error if negative value
*/
@@ -92,12 +92,12 @@ static PyObject * setPinDirection(PyObject *self, PyObject *args)
{
/* parameters */
struct as_gpio_device *aFdev;
- int aDirection;
+ char* aDirection;
int ret;
/* Get arguments */
- if (!PyArg_ParseTuple(args, "li",
+ if (!PyArg_ParseTuple(args, "ls",
(long *)&aFdev,
&aDirection))
{
@@ -122,7 +122,7 @@ static PyObject * getPinDirection(PyObject *self, PyObject *args)
/* parameters */
struct as_gpio_device *aFdev;
- int ret;
+ const char* dir;
/* Get arguments */
if (!PyArg_ParseTuple(args, "l", (long *)&aFdev))
@@ -132,15 +132,15 @@ static PyObject * getPinDirection(PyObject *self, PyObject *args)
return NULL;
}
- ret = as_gpio_get_pin_direction(aFdev);
- if (ret < 0)
+ dir = as_gpio_get_pin_direction(aFdev);
+ if (strcmp(dir, "??"))
{
PyErr_SetString(PyExc_IOError,
"Can't get pin direction");
return NULL;
}
- return Py_BuildValue("i", ret);
+ return Py_BuildValue("s", dir);
}
/** @brief Set pin value
@@ -223,23 +223,21 @@ static PyObject * blockingGetPinValue(PyObject *self, PyObject *args)
{
/* parameters */
struct as_gpio_device *aFdev;
- int aDelay_s;
- int aDelay_us;
+ int aDelay_ms;
int ret;
/* Get arguments */
- if (!PyArg_ParseTuple(args, "lii",
+ if (!PyArg_ParseTuple(args, "li",
(long *)&aFdev,
- &aDelay_s,
- &aDelay_us))
+ &aDelay_ms))
{
PyErr_SetString(PyExc_IOError,
"Wrong parameters.");
return NULL;
}
- ret = as_gpio_blocking_get_pin_value(aFdev, aDelay_s, aDelay_us);
+ ret = as_gpio_wait_event(aFdev, aDelay_ms);
if (ret == -10)
{
PyErr_SetString(PyExc_IOError, "TIMEOUT");
@@ -266,12 +264,12 @@ static PyObject * setIrqMode(PyObject *self, PyObject *args)
{
/* parameters */
struct as_gpio_device *aFdev;
- int aMode;
+ char *aMode;
int ret;
/* Get arguments */
- if (!PyArg_ParseTuple(args, "li", (long *)&aFdev, &aMode))
+ if (!PyArg_ParseTuple(args, "ls", (long *)&aFdev, &aMode))
{
PyErr_SetString(PyExc_IOError,
"Wrong parameters.");
@@ -293,14 +291,14 @@ static PyObject * setIrqMode(PyObject *self, PyObject *args)
*
* @param aFDev as_gpio_device pointer structure
*
- * @return pin mode value if positive or null, error if negative
+ * @return pin mode ("falling"/"rising"/"both"/"none")
*/
static PyObject * getIrqMode(PyObject *self, PyObject *args)
{
/* parameters */
struct as_gpio_device *aFdev;
- int ret;
+ const char *mode;
/* Get arguments */
if (!PyArg_ParseTuple(args, "l", (long *)&aFdev))
@@ -310,15 +308,15 @@ static PyObject * getIrqMode(PyObject *self, PyObject *args)
return NULL;
}
- ret = as_gpio_get_irq_mode(aFdev);
- if (ret < 0)
+ mode = as_gpio_get_irq_mode(aFdev);
+ if (strcmp(mode, "??"))
{
PyErr_SetString(PyExc_IOError,
"Can't get pin value");
return NULL;
}
- return Py_BuildValue("i", ret);
+ return Py_BuildValue("s", mode);
}
/** @brief Get pin number value
diff --git a/target/packages/as_devices/test_c.h b/target/packages/as_devices/test_c.h
index 5adf7ff..9a1def3 100644
--- a/target/packages/as_devices/test_c.h
+++ b/target/packages/as_devices/test_c.h
@@ -1,7 +1,6 @@
/*
- ** THE ARMadeus Systems
**
- ** Copyright (C) 2009 The armadeus systems team
+ ** Copyright (C) 2009-2011 The Armadeus Project - ARMadeus Systems
** Fabien Marteau <fab...@ar...>
**
** This library is free software; you can redistribute it and/or
@@ -16,7 +15,7 @@
**
** 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
+ **** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
@@ -31,6 +30,7 @@
#include "as_max5821.h"
#include "as_adc.h"
#include "as_dac.h"
+#include "as_helpers.h"
#define PWM_NUM 0
@@ -442,7 +442,25 @@ void test_gpio()
int pin_num = 13;
int port_direction = 0;
int port_value = 1;
-
+ int platform;
+
+ platform = as_helpers_get_platform();
+ switch (platform) {
+ case APF9328:
+ port_letter = 'X';
+ pin_num = 0x007;
+ break;
+ case APF27:
+ port_letter = 'F';
+ pin_num = 13;
+ break;
+ case APF51:
+ port_letter = 'A';
+ pin_num = 3;
+ break;
+ default:
+ break;
+ }
gpio_dev = as_gpio_open(port_letter, pin_num);
if (gpio_dev == NULL)
{
@@ -463,22 +481,21 @@ void test_gpio()
{
system("clear");
printf("**************************\n");
- printf(" Testing GPIO P%c%d \n", as_gpio_get_port_letter(gpio_dev),
- as_gpio_get_pin_num(gpio_dev));
+ printf(" Testing GPIO Port%c%d \n", port_letter, pin_num);
printf("**************************\n");
printf("Choose ('q' to quit):\n");
printf(" 1) Change gpio (P%c%d)\n", as_gpio_get_port_letter(gpio_dev),
as_gpio_get_pin_num(gpio_dev));
- printf(" 2) Change direction (%d)\n", as_gpio_get_pin_direction(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 mode (%d)\n", as_gpio_get_irq_mode(gpio_dev));
- printf(" a) blocking read\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])
+ switch (buffer[0])
{
case '1' : printf("Give letter of port in upper case : ");
scanf("%s", buffer);
@@ -498,7 +515,7 @@ void test_gpio()
scanf("%d", &pin_num);
gpio_dev = as_gpio_open(port_letter,pin_num);
- if(gpio_dev == NULL)
+ if (gpio_dev == NULL)
{
printf("Error, can't open P%c%d\n", port_letter, pin_num);
pressEnterToContinue();
@@ -507,10 +524,10 @@ void test_gpio()
printf("Ok P%c%d is open\n", port_letter, pin_num);
pressEnterToContinue();
break;
- case '2' : printf("Give direction (0:in, 1:out) : ");
- scanf("%d", &value);
- ret = as_gpio_set_pin_direction(gpio_dev, value);
- if(ret < 0)
+ 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");
pressEnterToContinue();
@@ -523,7 +540,7 @@ void test_gpio()
case '3' : printf("Give value : ");
scanf("%d", &value);
ret = as_gpio_set_pin_value(gpio_dev, value);
- if(ret < 0)
+ if (ret < 0)
{
printf("Error, can't change pin value\n");
pressEnterToContinue();
@@ -544,18 +561,12 @@ void test_gpio()
port_value = ret;
pressEnterToContinue();
break;
- case '5' : printf("1) GPIO_IRQ_MODE_NOINT \n");
- printf("2) GPIO_IRQ_MODE_RISING \n");
- printf("3) GPIO_IRQ_MODE_FALLING\n");
- printf("4) GPIO_IRQ_MODE_BOTH \n");
- printf("Give value : ");
- scanf("%d", &value);
- if (value == 1)value = GPIO_IRQ_MODE_NOINT ;
- if (value == 2)value = GPIO_IRQ_MODE_RISING ;
- if (value == 3)value = GPIO_IRQ_MODE_FALLING;
- if (value == 4)value = GPIO_IRQ_MODE_BOTH ;
- ret = as_gpio_set_irq_mode(gpio_dev, value);
- if(ret < 0)
+ 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");
pressEnterToContinue();
@@ -564,8 +575,8 @@ void test_gpio()
printf("Ok value changed\n");
pressEnterToContinue();
break;
- case 'a' : printf("Blocking read \n");
- ret = as_gpio_blocking_get_pin_value(gpio_dev, 10, 0);
+ 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");
@@ -628,7 +639,7 @@ void test_max1027()
{
switch(buffer[0])
{
- case '1' : printf("Open Max 1027 device\n");
+ case '1' : printf("Open MAX1027 device\n");
max1027_dev = as_adc_open(AS_MAX1027_NAME, devNumber, vRef);
if (max1027_dev < 0)
{
@@ -656,7 +667,7 @@ void test_max1027()
{
switch(buffer[0])
{
- case '1' : printf("Close Max 1027 device\n");
+ case '1' : printf("Close MAX1027 device\n");
ret = as_adc_close(max1027_dev);
if (ret < 0)
{
@@ -824,4 +835,3 @@ void test_as1531(void)
pressEnterToContinue();
}
-
diff --git a/target/packages/as_devices/test_cpp.h b/target/packages/as_devices/test_cpp.h
index 3d49a44..f39944e 100644
--- a/target/packages/as_devices/test_cpp.h
+++ b/target/packages/as_devices/test_cpp.h
@@ -146,14 +146,14 @@ void test_gpio()
{
system("clear");
printf("**************************\n");
- printf(" Testing GPIO P%c%d \n", gpio_dev->getPortLetter(), gpio_dev->getPinNum());
+ printf(" Testing GPIO Port%c%d \n", gpio_dev->getPortLetter(), gpio_dev->getPinNum());
printf("**************************\n");
printf("Choose ('q' to quit):\n");
printf(" 1) Change gpio (P%c%d)\n", gpio_dev->getPortLetter(), gpio_dev->getPinNum());
- printf(" 2) Change direction (%d)\n", gpio_dev->getPinDirection());
+ printf(" 2) Change direction (%s)\n", gpio_dev->getPinDirection());
printf(" 3) Change value (%d)\n", gpio_dev->getPinValue());
printf(" 4) Read pin value\n");
- printf(" 5) Set irq mode (%d)\n", gpio_dev->getIrqMode());
+ printf(" 5) Set irq mode (%s)\n", gpio_dev->getIrqMode());
printf(" a) blocking read\n");
printf("> ");
@@ -182,10 +182,10 @@ void test_gpio()
printf("Ok P%c%d is open\n", port_letter, pin_num);
pressEnterToContinue();
break;
- case '2' : printf("Give direction (0:in, 1:out) : ");
- scanf("%d", &value);
- ret = gpio_dev->setPinDirection(value);
- if(ret < 0)
+ case '2' : printf("Give direction (in / out) : ");
+ scanf("%s", buffer);
+ ret = gpio_dev->setPinDirection(buffer);
+ if (ret < 0)
{
printf("Error, can't change direction\n");
pressEnterToContinue();
@@ -219,18 +219,12 @@ void test_gpio()
port_value = ret;
pressEnterToContinue();
break;
- case '5' : printf("1) GPIO_IRQ_MODE_NOINT \n");
- printf("2) GPIO_IRQ_MODE_RISING \n");
- printf("3) GPIO_IRQ_MODE_FALLING\n");
- printf("4) GPIO_IRQ_MODE_BOTH \n");
- printf("Give value : ");
- scanf("%d", &value);
- if (value == 1)value = GPIO_IRQ_MODE_NOINT ;
- if (value == 2)value = GPIO_IRQ_MODE_RISING ;
- if (value == 3)value = GPIO_IRQ_MODE_FALLING;
- if (value == 4)value = GPIO_IRQ_MODE_BOTH ;
- ret = gpio_dev->setIrqMode(value);
- if(ret < 0)
+ case '5' :
+ printf("rising / falling / both / none\n");
+ printf("Please choose a mode : ");
+ scanf("%s", buffer);
+ ret = gpio_dev->setIrqMode(buffer);
+ if (ret < 0)
{
printf("Error, can't change irq value\n");
pressEnterToContinue();
@@ -239,8 +233,8 @@ void test_gpio()
printf("Ok value changed\n");
pressEnterToContinue();
break;
- case 'a' : printf("Blocking read \n");
- ret = gpio_dev->blockingGetPinValue(10, 0);
+ case 'a' : printf("Blocking read (10 sec timeout)\n");
+ ret = gpio_dev->waitEvent(10000);
if (ret < 0)
{
printf("Error, can't read value\n");
hooks/post-receive
--
armadeus
|