[Armadeus-commitlog] armadeus branch, master, updated. release-3.2-417-g982adb8
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2010-06-09 06:57:33
|
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 982adb8874d8c9ecfdc332cea3f303166b8b4a6d (commit)
via d610361b8dea6456eb5a2918f24e7dd57d37bd45 (commit)
via 1b7699ace49a01efaa6107e5d9b84e2f43a02f09 (commit)
via 10f29f40e7ae42e99127a29b4ea78e3b1f518a7d (commit)
from 0aec528c8888f3c4d08844ec329e22e2492bc157 (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 982adb8874d8c9ecfdc332cea3f303166b8b4a6d
Merge: d610361b8dea6456eb5a2918f24e7dd57d37bd45 0aec528c8888f3c4d08844ec329e22e2492bc157
Author: Fabien Marteau <fab...@ar...>
Date: Wed Jun 9 08:56:20 2010 +0200
merge
commit d610361b8dea6456eb5a2918f24e7dd57d37bd45
Author: Fabien Marteau <fab...@ar...>
Date: Tue Jun 8 19:25:46 2010 +0200
[linux] Add pin management full capability on gpio driver module
commit 1b7699ace49a01efaa6107e5d9b84e2f43a02f09
Author: Fabien Marteau <fab...@ar...>
Date: Tue Jun 8 19:20:39 2010 +0200
[as_devices] Modify as_gpio to manage gpio pin independantly
commit 10f29f40e7ae42e99127a29b4ea78e3b1f518a7d
Author: Fabien Marteau <fab...@ar...>
Date: Fri Jun 4 15:03:26 2010 +0200
[as_devices] deleting a debug message
-----------------------------------------------------------------------
Summary of changes:
target/linux/modules/gpio/core.c | 433 +++++++++++++++++++---------
target/linux/modules/gpio/core.h | 13 +-
target/packages/as_devices/c/as_gpio.c | 304 ++++++--------------
target/packages/as_devices/c/as_gpio.h | 59 +++--
target/packages/as_devices/python/Makefile | 2 +-
target/packages/as_devices/test_c.h | 96 ++-----
6 files changed, 444 insertions(+), 463 deletions(-)
diff --git a/target/linux/modules/gpio/core.c b/target/linux/modules/gpio/core.c
index 418789e..bb5ab83 100755
--- a/target/linux/modules/gpio/core.c
+++ b/target/linux/modules/gpio/core.c
@@ -1,9 +1,10 @@
/*
* Armadeus i.MXL/27 GPIO management driver
*
- * Copyright (C) 2006-2010 Julien Boibessot <jul...@ar...>
- * Nicolas Colombain <nic...@ar...>
- * Armadeus Project / Armadeus Systems
+ * Copyright (C) 2006-2008 Julien Boibessot <jul...@ar...>
+ * Nicolas Colombain <nic...@ar...>
+ * Fabien Marteau <fab...@ar...>
+ * Armadeus Project / Armadeus Systems
*
* Inspired by a lot of other GPIO management systems...
*
@@ -14,7 +15,7 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
@@ -29,10 +30,10 @@
#include <linux/proc_fs.h>
#include <asm/io.h>
#include <asm/uaccess.h>
-#include <linux/interrupt.h> /* request_irq */
-#include <linux/irq.h> /* set_irq_type */
-#include <asm/gpio.h> /* imx_gpio_... */
-#include <linux/cdev.h> /* struct cdev */
+#include <linux/interrupt.h> /* request_irq */
+#include <linux/irq.h> /* set_irq_type */
+#include <asm/gpio.h> /* imx_gpio_... */
+#include <linux/cdev.h> /* struct cdev */
#include <mach/hardware.h>
#include <asm/mach/map.h>
#include <linux/poll.h>
@@ -46,31 +47,31 @@
#include "core.h" /* for ioctl defs */
-#define DRIVER_NAME "Armadeus GPIOs driver"
+#define DRIVER_NAME "Armadeus GPIOs driver"
#define DRIVER_VERSION "2.4"
/* By default, we use dynamic allocation of major numbers -> MAJOR = 0 */
#define GPIO_MAJOR 0
-#define GPIO_PROC_DIRNAME "driver/gpio"
+#define GPIO_PROC_DIRNAME "driver/gpio"
#define GPIO_PROC_FILE 1
-#define SETTINGS_PROC_FILE (1 << 3)
-#define SETTINGS_IRQ_PROC_FILE (1 << 4)
-#define SETTINGS_PULLUP_PROC_FILE (1 << 5)
-#define SETTINGS_MODE_PROC_FILE (1 << 6)
+#define SETTINGS_PROC_FILE (1 << 3)
+#define SETTINGS_IRQ_PROC_FILE (1 << 4)
+#define SETTINGS_PULLUP_PROC_FILE (1 << 5)
+#define SETTINGS_MODE_PROC_FILE (1 << 6)
#define MAX_NUMBER_OF_PINS 32
-#define PORT_A 0
-#define PORT_B 1
-#define PORT_C 2
-#define PORT_D 3
+#define PORT_A (0)
+#define PORT_B (1)
+#define PORT_C (2)
+#define PORT_D (3)
#ifdef CONFIG_ARCH_IMX
-#define NB_PORTS 4
+#define NB_PORTS (4)
#endif
#ifdef CONFIG_ARCH_MX2
-#define PORT_E 4
-#define PORT_F 5
-#define NB_PORTS 6
+#define PORT_E (4)
+#define PORT_F (5)
+#define NB_PORTS (6)
#endif
#define MAX_MINOR (255) /* Linux limitation */
@@ -242,15 +243,30 @@ static unsigned char get_irq_from_pin(int num_pin, int num_port)
shad = shadows_irq_h[num_port];
num_pin -= (portSize/2);
}
+ return (shad >> (2*num_pin))&0x03;
+}
+
+static void set_irq_for_pin(int pin_num, int port_num, int value)
+{
+ int portSize = number_of_pins[port_num];
+ int return_value;
- return shad >> (/*portSize-2-*/(2*num_pin))& 3;
+ if (pin_num < (portSize/2)) {
+ return_value = shadows_irq_l[port_num]&(~(0x03<<(pin_num*2)));
+ shadows_irq_l[port_num] |= (value&0x03) << (pin_num*2);
+ } else {
+ return_value =
+ shadows_irq_h[port_num]&(~(0x03 << (2*(pin_num - MAX_NUMBER_OF_PINS))));
+ shadows_irq_h[port_num] |= (value&0x03) << (2*(pin_num - MAX_NUMBER_OF_PINS));
+ }
}
+
/*
* Low level functions
*/
/* These masks are for restricting user access to configuration of some
- criticals GPIO pins used by Armadeus and not configurable */
+ * criticals GPIO pins used by Armadeus and not configurable */
#ifdef CONFIG_ARCH_IMX
static unsigned long PORT_MASK[]= { 0x0003FFFE, 0xF00FFF00, 0x0003E1F8, 0xFFFFFFFF };
#else
@@ -331,7 +347,7 @@ static void initialize_all_ports(void)
static void write_on_port(unsigned int aPort, unsigned int aValue)
{
- __raw_writel(aValue, VA_GPIO_BASE + MXC_DR(aPort));
+ __raw_writel(aValue & 0xFFFFFFFF, VA_GPIO_BASE + MXC_DR(aPort));
}
static unsigned int read_from_port(unsigned int aPort)
@@ -373,18 +389,18 @@ static unsigned int get_port_mode(unsigned int aPort)
int i;
int ocr1, ocr2, gius, value = 0;
- ocr1 = __raw_readl(VA_GPIO_BASE + MXC_OCR1(aPort));
- ocr2 = __raw_readl(VA_GPIO_BASE + MXC_OCR2(aPort));
+ ocr1 = __raw_readl(VA_GPIO_BASE + MXC_OCR1(aPort));
+ ocr2 = __raw_readl(VA_GPIO_BASE + MXC_OCR2(aPort));
gius = __raw_readl(VA_GPIO_BASE + MXC_GIUS(aPort));
/* pin is a GPIO if OCR == 3 AND GIUS == 1 */
for (i=0; i < number_of_pins[aPort]; i++) {
if (i < 16) {
- if (((ocr1>>(i*2)) & 3) == 3)
- value = value | (1<<i);
- } else {
- if (((ocr2>>((i-16)*2)) & 3) == 3)
+ if (((ocr1>>(i*2)) & 3) == 3)
+ value = value | (1<<i);
+ } else {
+ if (((ocr2>>((i-16)*2)) & 3) == 3)
value = value | (1<<i);
- }
+ }
}
value = value & gius;
@@ -560,7 +576,7 @@ static int armadeus_gpio_dev_open(struct inode *inode, struct file *file)
gpio = kzalloc(sizeof(struct gpio_item), GFP_KERNEL);
if (!gpio)
- goto err_request;
+ goto err_kzalloc;
file->private_data = gpio;
spin_lock_init(&gpio->lock);
@@ -577,7 +593,7 @@ static int armadeus_gpio_dev_open(struct inode *inode, struct file *file)
case FULL_PORTF_MINOR:
#endif
gpio->nb_pins = 32;
- gpio->changed = 1;
+ gpio->changed = 0;
gpio->port = FULL_MINOR_TO_PORT(minor);
pr_debug("Reserving full %s\n", port_name[gpio->port]);
goto success;
@@ -586,11 +602,11 @@ static int armadeus_gpio_dev_open(struct inode *inode, struct file *file)
/* Pin by pin access */
gpio->nb_pins = 1;
- gpio->changed = 1;
+ gpio->changed = 0;
if ((ret = gpio_request(minor, "gpio-dev"))) {
printk("GPIO %i is already in use\n", minor);
- goto err_request;
+ goto err_gpio_request;
}
gpio->port = minor >> GPIO_PORT_SHIFT;
@@ -614,7 +630,8 @@ static int armadeus_gpio_dev_open(struct inode *inode, struct file *file)
goto err_irq;
switch (gpio->irq_value) {
case (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING):
- ;
+ set_irq_type(irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING);
+ break ;
case IRQF_TRIGGER_RISING:
set_irq_type(irq, IRQF_TRIGGER_RISING);
break;
@@ -631,11 +648,13 @@ success:
gpio->initialized = 1;
return 0;
+ free_irq(irq, gpio);
err_irq:
printk("%s error while requesting irq %d\n", __FUNCTION__, irq);
- free_irq(irq, gpio);
-err_request:
+ gpio_free(minor);
+err_gpio_request:
kfree(gpio);
+err_kzalloc:
/* what about spinlock & wait_queue ?? */
return ret;
}
@@ -662,21 +681,25 @@ static int armadeus_gpio_dev_release(struct inode *inode, struct file *file)
/* Handling of IOCTL calls */
int armadeus_gpio_dev_ioctl(struct inode *inode, struct file *filp,
- unsigned int cmd, unsigned long arg)
+ unsigned int cmd, unsigned long arg)
{
int err = 0, ret = 0, value = 0;
+ unsigned int return_value;
+ unsigned int port_num, pin_num;
unsigned int minor;
+ unsigned int irq;
+ struct gpio_item *gpio = filp->private_data;
pr_debug(DRIVER_NAME " ## IOCTL received: (0x%x) ##\n", cmd);
/* Extract the type and number bitfields, and don't decode wrong cmds:
- return ENOTTY (inappropriate ioctl) before access_ok() */
+ * return ENOTTY (inappropriate ioctl) before access_ok() */
if (_IOC_TYPE(cmd) != PP_IOCTL)
return -ENOTTY;
/* The direction is a bitmask, and VERIFY_WRITE catches R/W transfers.
- `Type' is user-oriented, while access_ok is kernel-oriented,
- so the concept of "read" and "write" is reversed */
+ * `Type' is user-oriented, while access_ok is kernel-oriented,
+ * so the concept of "read" and "write" is reversed */
if (_IOC_DIR(cmd) & _IOC_READ)
err = !access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd));
else if (_IOC_DIR(cmd) & _IOC_WRITE)
@@ -696,106 +719,234 @@ int armadeus_gpio_dev_ioctl(struct inode *inode, struct file *filp,
#else
if (minor < FULL_PORTD_MINOR) {
#endif
- printk("IOCTLs are only available on 'full port' minors !\n");
- ret = -EFAULT;
- goto out;
- }
+ port_num= (unsigned int)(minor/MAX_NUMBER_OF_PINS);
+ pin_num = (unsigned int)(minor%MAX_NUMBER_OF_PINS);
- switch (cmd) {
+ /* ioctl for /dev/gpio/PXx */
+ switch(cmd)
+ {
case GPIORDDIRECTION:
- value = get_port_dir(MAX_MINOR - minor);
- ret = __put_user(value, (unsigned int *)arg);
- break;
+ value = get_port_dir(port_num);
+ return_value = (((value & (1<<pin_num))!=0)?1:0);
+ ret = __put_user(return_value, (unsigned int *)arg);
+ break;
case GPIOWRDIRECTION:
- ret = __get_user(value, (unsigned int *)arg);
- if (ret == 0) {
- set_port_dir(MAX_MINOR - minor, value);
- }
- break;
+ ret = __get_user(value, (unsigned int *)arg);
+ return_value = get_port_dir(port_num);
+ if (value != 0)
+ set_port_dir(port_num, return_value | (1<<pin_num));
+ else
+ set_port_dir(port_num, return_value & (~(1<<pin_num)));
+ break;
case GPIORDDATA:
- value = read_from_port(MAX_MINOR - minor);
- ret = __put_user(value, (unsigned int *)arg);
- break;
+ value = read_from_port(port_num);
+ return_value = (((value & (1<<pin_num))!=0)?1:0);
+ ret = __put_user(return_value, (unsigned int *)arg);
+ break;
case GPIOWRDATA:
- ret = __get_user(value, (unsigned int *)arg);
- if (ret == 0) {
- write_on_port(MAX_MINOR - minor, value);
- }
- break;
+ ret = __get_user(value, (unsigned int *)arg);
+ return_value = __raw_readl(VA_GPIO_BASE + MXC_DR(port_num));
+ if (value != 0)
+ {
+ write_on_port(port_num, return_value | (1<<pin_num));
+ }
+ else
+ {
+ write_on_port(port_num, return_value & (~(1<<pin_num)));
+ }
+ break;
case GPIORDMODE:
- value = get_port_mode(MAX_MINOR - minor);
- ret = __put_user(value, (unsigned int *)arg);
- break;
+ value = get_port_mode(port_num);
+ return_value = (((value & (1<<pin_num))!=0)?1:0);
+ ret = __put_user(return_value, (unsigned int *)arg);
+ break;
case GPIOWRMODE:
- ret = __get_user(value, (unsigned int *)arg);
- if (ret == 0) {
- set_port_mode(MAX_MINOR - minor, value);
- }
- break;
-
- case GPIORDIRQMODE_H:
- value = shadows_irq_h[MAX_MINOR - minor];
- ret = __put_user(value, (unsigned int *)arg);
- break;
-
- case GPIORDIRQMODE_L:
- value = shadows_irq_l[MAX_MINOR - minor];
- ret = __put_user(value, (unsigned int *)arg);
- break;
-
- case GPIOWRIRQMODE_H:
- ret = __get_user(value, (unsigned int *)arg);
- if (ret == 0) {
- shadows_irq_h[MAX_MINOR - minor] = value;
- }
- break;
+ ret = __get_user(value, (unsigned int *)arg);
+ return_value = get_port_mode(port_num);
+ if (value != 0)
+ set_port_mode(port_num, return_value | (1<<pin_num));
+ else
+ set_port_mode(port_num, return_value & (~(1<<pin_num)));
+ break;
- case GPIOWRIRQMODE_L:
- ret = __get_user(value, (unsigned int *)arg);
- if (ret == 0) {
- shadows_irq_l[MAX_MINOR - minor] = value;
- }
- break;
+ case GPIORDIRQMODE:
+ ret = __put_user(get_irq_from_pin(pin_num, port_num), (unsigned int *)arg);
+ break;
+ case GPIOWRIRQMODE:
+ ret = __get_user(value, (unsigned int *)arg);
+ value &= 0x03;
+ if (ret == 0) {
+ set_irq_for_pin(pin_num, port_num, value);
+ }
+ irq = IRQ_GPIOA(minor); /* irq number are continuous */
+ if (value != IRQF_TRIGGER_NONE) {
+ if (gpio->irq_value == IRQF_TRIGGER_NONE)
+ {
+ ret = request_irq(irq, armadeus_gpio_interrupt, 0, "gpio", gpio);
+ if (ret)
+ {
+ printk(KERN_ERR "GPIO TODO: manage request_irq error\n");
+ }
+ }
+ gpio->irq_value = value;
+ switch (gpio->irq_value) {
+ case (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING):
+ set_irq_type(irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING);
+ break ;
+ case IRQF_TRIGGER_RISING:
+ set_irq_type(irq, IRQF_TRIGGER_RISING);
+ break;
+ case IRQF_TRIGGER_FALLING:
+ set_irq_type(irq, IRQF_TRIGGER_FALLING);
+ break;
+ case IRQF_TRIGGER_NONE:
+ break;
+ }
+ } else {
+ if (gpio->irq_value != IRQF_TRIGGER_NONE){
+ free_irq(irq, gpio);
+ }
+ gpio->irq_value = IRQF_TRIGGER_NONE;
+ }
+ break;
case GPIORDPULLUP:
- value = get_port_pull_up(MAX_MINOR - minor);
- ret = __put_user(value, (unsigned int *)arg);
- break;
+ value = get_port_pull_up(port_num);
+ return_value = (((value & (1<<pin_num))!=0)?1:0);
+ ret = __put_user(return_value, (unsigned int *)arg);
+ break;
case GPIOWRPULLUP:
- ret = __get_user(value, (unsigned int *)arg);
- if (ret == 0) {
- set_port_pullup(MAX_MINOR - minor, value);
- }
- break;
+ ret = __get_user(value, (unsigned int *)arg);
+ return_value = get_port_pull_up(port_num);
+ if (value != 0)
+ set_port_pullup(port_num, return_value | (1<<pin_num));
+ else
+ set_port_pullup(port_num, return_value & (~(1<<pin_num)));
+ break;
case GPIORDISR:
- value = get_port_isr(MAX_MINOR - minor);
- ret = __put_user(value, (unsigned int *)arg);
- break;
+ value = get_port_isr(port_num);
+ return_value = (((value & (1<<pin_num))!=0)?1:0);
+ ret = __put_user(return_value, (unsigned int *)arg);
+ break;
case GPIOWRISR:
- ret = __get_user(value, (unsigned int *)arg);
- if (ret == 0) {
- set_port_isr(MAX_MINOR - minor, value);
- }
- break;
+ ret = __get_user(value, (unsigned int *)arg);
+ return_value = get_port_isr(port_num);
+ if (value != 0)
+ set_port_isr(port_num, return_value | (1<<pin_num));
+ else
+ set_port_isr(port_num, return_value & (~(1<<pin_num)));
+
+ break;
default:
- printk("IOCTL not supported\n");
- ret = -ENOTTY;
- break;
- }
-out:
- /* Release exclusive access */
- up(&gpio_sema);
+ printk("IOCTL not supported\n");
+ ret = -ENOTTY;
+ break;
+ }
+ } else switch (cmd) {
- return ret;
+ case GPIORDDIRECTION:
+ value = get_port_dir(MAX_MINOR - minor);
+ ret = __put_user(value, (unsigned int *)arg);
+ break;
+
+ case GPIOWRDIRECTION:
+ ret = __get_user(value, (unsigned int *)arg);
+ if (ret == 0) {
+ set_port_dir(MAX_MINOR - minor, value);
+ }
+ break;
+
+ case GPIORDDATA:
+ value = read_from_port(MAX_MINOR - minor);
+ ret = __put_user(value, (unsigned int *)arg);
+ break;
+
+ case GPIOWRDATA:
+ ret = __get_user(value, (unsigned int *)arg);
+ if (ret == 0) {
+ write_on_port(MAX_MINOR - minor, value);
+ }
+ break;
+
+ case GPIORDMODE:
+ value = get_port_mode(MAX_MINOR - minor);
+ ret = __put_user(value, (unsigned int *)arg);
+ break;
+
+ case GPIOWRMODE:
+ ret = __get_user(value, (unsigned int *)arg);
+ if (ret == 0) {
+ set_port_mode(MAX_MINOR - minor, value);
+ }
+ break;
+
+ case GPIORDIRQMODE_H:
+ value= shadows_irq_h[MAX_MINOR - minor];
+ ret = __put_user(value, (unsigned int *)arg);
+ break;
+
+ case GPIORDIRQMODE_L:
+ value = shadows_irq_l[MAX_MINOR - minor];
+ ret = __put_user(value, (unsigned int *)arg);
+ break;
+
+ case GPIOWRIRQMODE_H:
+ ret = __get_user(value, (unsigned int *)arg);
+ if (ret == 0) {
+ shadows_irq_h[MAX_MINOR - minor] = value;
+ }
+ break;
+
+ case GPIOWRIRQMODE_L:
+ ret = __get_user(value, (unsigned int *)arg);
+ if (ret == 0) {
+ shadows_irq_l[MAX_MINOR - minor] = value;
+ }
+ break;
+
+ case GPIORDPULLUP:
+ value = get_port_pull_up(MAX_MINOR - minor);
+ ret = __put_user(value, (unsigned int *)arg);
+ break;
+
+ case GPIOWRPULLUP:
+ ret = __get_user(value, (unsigned int *)arg);
+ if (ret == 0) {
+ set_port_pullup(MAX_MINOR - minor, value);
+ }
+ break;
+
+ case GPIORDISR:
+ value = get_port_isr(MAX_MINOR - minor);
+ ret = __put_user(value, (unsigned int *)arg);
+ break;
+
+ case GPIOWRISR:
+ ret = __get_user(value, (unsigned int *)arg);
+ if (ret == 0) {
+ set_port_isr(MAX_MINOR - minor, value);
+ }
+ break;
+
+ default:
+ printk("IOCTL not supported\n");
+ ret = -ENOTTY;
+ break;
+ }
+
+ /* Release exclusive access */
+ up(&gpio_sema);
+
+ return ret;
}
static int armadeus_gpio_dev_fasync(int fd, struct file* filp, int on)
@@ -813,7 +964,8 @@ static unsigned int armadeus_gpio_dev_poll(struct file *filp, poll_table *wait)
spin_lock_irq(&gpio->lock);
poll_wait(filp, &gpio->change_wq, wait);
- if (gpio->changed) {
+ if (gpio->changed)
+ {
mask |= (POLLIN | POLLRDNORM);
}
@@ -823,18 +975,17 @@ static unsigned int armadeus_gpio_dev_poll(struct file *filp, poll_table *wait)
}
static struct file_operations gpio_fops = {
- .owner = THIS_MODULE,
- .llseek = no_llseek,
- .write = armadeus_gpio_dev_write,
- .read = armadeus_gpio_dev_read,
- .open = armadeus_gpio_dev_open,
- .release = armadeus_gpio_dev_release,
- .ioctl = armadeus_gpio_dev_ioctl,
- .fasync = armadeus_gpio_dev_fasync,
- .poll = armadeus_gpio_dev_poll,
+ .owner = THIS_MODULE,
+ .llseek = no_llseek,
+ .write = armadeus_gpio_dev_write,
+ .read = armadeus_gpio_dev_read,
+ .open = armadeus_gpio_dev_open,
+ .release = armadeus_gpio_dev_release,
+ .ioctl = armadeus_gpio_dev_ioctl,
+ .fasync = armadeus_gpio_dev_fasync,
+ .poll = armadeus_gpio_dev_poll,
};
-
/*
* PROC file functions
*/
@@ -852,10 +1003,10 @@ static int armadeus_gpio_proc_read(char *buffer, char **start, off_t offset,
}
/* We give all of our information in one go, so if the user asks us if we
- have more information the answer should always be no. This is important
- because the standard read function from the library would continue to
- issue the read system call until the kernel replies that it has no more
- information, or until its buffer is filled
+ * have more information the answer should always be no. This is important
+ * because the standard read function from the library would continue to
+ * issue the read system call until the kernel replies that it has no more
+ * information, or until its buffer is filled
*/
if (offset > 0 || buffer_length < (number_of_pins[port_ID]+2))
return 0;
@@ -914,7 +1065,7 @@ static char new_gpio_state[MAX_NUMBER_OF_PINS*2];
static int armadeus_gpio_proc_write(__attribute__ ((unused)) struct file *file, const char *buf, unsigned long count, __attribute__ ((unused)) void* data)
{
int len;
- unsigned int gpio_state=0, gpio_state2=0;
+ unsigned int gpio_state=0, gpio_state2=0;
unsigned int port_ID = 0;
struct gpio_settings *settings = (struct gpio_settings *) data;
@@ -950,7 +1101,7 @@ static int armadeus_gpio_proc_write(__attribute__ ((unused)) struct file *file,
if (settings->type != INTERRUPT) {
gpio_state = fromString(new_gpio_state, number_of_pins[port_ID], 1);
} else {
- gpio_state = fromString(new_gpio_state, number_of_pins[port_ID]/2, 2);
+ gpio_state = fromString(new_gpio_state, number_of_pins[port_ID]/2, 2);
gpio_state2 = fromString(new_gpio_state+(number_of_pins[port_ID]/2), (number_of_pins[port_ID]/2), 2);
}
@@ -1016,9 +1167,9 @@ static int initialize_proc_entry( struct proc_config_entry *config )
printk(KERN_ERR DRIVER_NAME ": Couldn't register %s. Terminating.\n", config[i].name);
return -ENOMEM;
}
- config[i].entry->read_proc = armadeus_gpio_proc_read;
- config[i].entry->write_proc = armadeus_gpio_proc_write;
- config[i].entry->data = kmalloc(sizeof(struct gpio_settings), GFP_KERNEL);
+ config[i].entry->read_proc = armadeus_gpio_proc_read;
+ config[i].entry->write_proc = armadeus_gpio_proc_write;
+ config[i].entry->data = kmalloc(sizeof(struct gpio_settings), GFP_KERNEL);
((struct gpio_settings*) config[i].entry->data)->port = i;
((struct gpio_settings*) config[i].entry->data)->type = config[i].type;
}
@@ -1143,7 +1294,7 @@ static void print_port_params(int port, int nb, int* params)
{
int i;
- printk(" %s Parameters (%i): ", port_name[port], nb);
+ printk(" %s Parameters (%i): ", port_name[port], nb);
for (i = 0; i < NB_CONFIG_REGS; i++) {
printk(" 0x%x", params[i]);
}
@@ -1242,7 +1393,7 @@ EXPORT_SYMBOL(gpioGetPortDir);
module_init(armadeus_gpio_init);
module_exit(armadeus_gpio_cleanup);
-MODULE_AUTHOR("Julien Boibessot / Nicolas Colombain");
+MODULE_AUTHOR("Julien Boibessot / Nicolas Colombain / Fabien Marteau");
MODULE_DESCRIPTION("Armadeus GPIOs driver");
MODULE_LICENSE("GPL");
diff --git a/target/linux/modules/gpio/core.h b/target/linux/modules/gpio/core.h
index d452f46..cac9bbb 100755
--- a/target/linux/modules/gpio/core.h
+++ b/target/linux/modules/gpio/core.h
@@ -26,7 +26,6 @@
#ifndef __CORE_GPIO_H__
#define __CORE_GPIO_H__
-
/* IOCTL */
/* direction: 1 output, 0 input */
#define GPIORDDIRECTION _IOR(PP_IOCTL, 0xF0, int)
@@ -40,15 +39,19 @@
#define GPIORDPULLUP _IOR(PP_IOCTL, 0xF6, int)
#define GPIOWRPULLUP _IOW(PP_IOCTL, 0xF7, int)
+
+#define GPIORDIRQMODE_H _IOR(PP_IOCTL, 0xF8, int) /* only for /dev/gpio/gpioX */
+#define GPIORDIRQMODE_L _IOR(PP_IOCTL, 0xF9, int) /* */
+#define GPIOWRIRQMODE_H _IOW(PP_IOCTL, 0xFA, int) /* */
+#define GPIOWRIRQMODE_L _IOW(PP_IOCTL, 0xFB, int) /* */
/* 2bits per pin for IRQ mode: 0 none, 1 rising, 2 falling, 3 both */
-#define GPIORDIRQMODE_H _IOR(PP_IOCTL, 0xF8, int)
-#define GPIORDIRQMODE_L _IOR(PP_IOCTL, 0xF9, int)
-#define GPIOWRIRQMODE_H _IOW(PP_IOCTL, 0xFA, int)
-#define GPIOWRIRQMODE_L _IOW(PP_IOCTL, 0xFB, int)
#define GPIORDISR _IOR(PP_IOCTL, 0xFC, int)
#define GPIOWRISR _IOW(PP_IOCTL, 0xFD, int)
+#define GPIORDIRQMODE _IOR(PP_IOCTL, 0xFE, int) /* only for /dev/gpio/PXx */
+#define GPIOWRIRQMODE _IOW(PP_IOCTL, 0xFF, int) /* */
+
/* Pretend we're PPDEV for IOCTL */
#include <linux/ppdev.h>
diff --git a/target/packages/as_devices/c/as_gpio.c b/target/packages/as_devices/c/as_gpio.c
index eef3f1e..8d6741d 100644
--- a/target/packages/as_devices/c/as_gpio.c
+++ b/target/packages/as_devices/c/as_gpio.c
@@ -49,7 +49,9 @@
#define GPIORDISR _IOR(PP_IOCTL, 0xFC, int)
#define GPIOWRISR _IOW(PP_IOCTL, 0xFD, int)
-#define GPIO_BASE_PORT ("/dev/gpio/port")
+#define GPIORDIRQMODE _IOR(PP_IOCTL, 0xFE, int)
+#define GPIOWRIRQMODE _IOW(PP_IOCTL, 0xFF, int)
+
#define GPIO_BASE_PIN ("/dev/gpio/P")
#define BUFF_SIZE (300)
@@ -71,118 +73,107 @@
/*------------------------------------------------------------------------------*/
-struct as_gpio_device *as_gpio_open(char aPortChar)
+struct as_gpio_device *as_gpio_open(char aPortChar, int aPinNum)
{
struct as_gpio_device *dev;
char gpio_file_path[50];
int ret=0;
- int i;
+ int file;
+ int value;
if (((aPortChar-'A') > (NUMBER_OF_PORTS-1)) || ((aPortChar-'A') < 0))
{
ERROR("No port named %c\n",aPortChar);
- return NULL;
+ goto letter_error;
}
/* make gpio port string path */
- ret = snprintf(gpio_file_path,50, "%s%c",
- GPIO_BASE_PORT, aPortChar);
+ ret = snprintf(gpio_file_path,50, "%s%c%d",
+ GPIO_BASE_PIN, aPortChar, aPinNum);
if (ret < 0) {
- ERROR("Can't forge gpio port path\n");
- return NULL;
+ ERROR("Can't forge gpio pin port path\n");
+ goto path_error;
}
/* opening gpio port */
- ret = open(gpio_file_path, O_RDWR);
- if (ret < 0) {
- ERROR("Can't open file port\n");
- return NULL;
+ file = open(gpio_file_path, O_RDWR);
+ if (file < 0) {
+ ERROR("Can't open file pin port\n");
+ goto open_file_error;
}
dev = (struct as_gpio_device *)malloc(sizeof(struct as_gpio_device));
if (dev == NULL)
{
ERROR("Can't allocate memory for gpio device structure\n");
- return NULL;
+ goto malloc_error;
}
dev->port_letter = aPortChar;
- dev->fdev = ret;
- for(i=0; i < PORT_SIZE; i++)
+ dev->fpin = file;
+ dev->pin_num = aPinNum;
+
+ value = 1;
+ ret = ioctl(dev->fpin, GPIOWRMODE, &value); /* set pin on gpio mode */
+ if (ret < 0)
{
- dev->fpin[i] = -1;
- dev->irq_mode[i] = GPIO_IRQ_MODE_NOINT;
+ ERROR("can't set pin in gpio mode.\n");
+ goto mode_error;
}
return dev;
+
+mode_error:
+ free(dev);
+malloc_error:
+ close(file);
+open_file_error:
+path_error:
+letter_error:
+ return NULL;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_set_pin_direction(struct as_gpio_device *aDev,
- int aPinNum,
- int aDirection)
+int32_t as_gpio_set_pin_direction(struct as_gpio_device *aDev, int aDirection)
{
int ret=0;
int portval;
- /* Set PIN as GPIO; read/modify/write */
- ret = ioctl(aDev->fdev, GPIORDMODE, &portval);
- if (ret < 0) {
- ERROR("Can't set gpio read mode\n");
- return ret;
- }
+ portval = (aDirection != 0)?1:0;
- portval |= (1 << aPinNum);
-
- ret = ioctl(aDev->fdev, GPIOWRMODE, &portval);
+ ret = ioctl(aDev->fpin, GPIOWRDIRECTION, &portval);
if (ret < 0) {
- ERROR("Can't set gpio write mode\n");
+ ERROR("Can't set gpio direction\n");
return ret;
}
+ return 0;
+}
- /* set direction */
- ret = ioctl(aDev->fdev, GPIORDDIRECTION, &portval);
- if (ret < 0) {
- ERROR("Can't get gpio direction\n");
- return ret;
- }
+/*------------------------------------------------------------------------------*/
- if (aDirection == 0) {
- portval &= ~(1 << aPinNum);
- } else {
- portval |= (1 << aPinNum);
- }
+int32_t as_gpio_get_pin_direction(struct as_gpio_device *aDev)
+{
+ int ret=0;
+ int portval;
- ret = ioctl(aDev->fdev, GPIOWRDIRECTION, &portval);
+ ret = ioctl(aDev->fpin, GPIORDDIRECTION, &portval);
if (ret < 0) {
ERROR("Can't get gpio direction\n");
return ret;
}
- return 0;
+ return ((portval !=0)?1:0);
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_set_pin_value(struct as_gpio_device *aDev,
- int aPinNum,
- int aValue)
+int32_t as_gpio_set_pin_value(struct as_gpio_device *aDev, int aValue)
{
int ret=0;
int portval;
- ret = ioctl(aDev->fdev, GPIORDDATA, &portval);
- if (ret < 0) {
- ERROR("Can't read gpio data\n");
- return ret;
- }
-
- if (aValue == 0) {
- portval &= ~(1 << aPinNum);
- } else {
- portval |= (1 << aPinNum);
- }
- ret = ioctl(aDev->fdev, GPIOWRDATA, &portval);
+ portval = (aValue != 0)?1:0;
+ ret = ioctl(aDev->fpin, GPIOWRDATA, &portval);
if (ret < 0) {
ERROR("Can't write gpio data\n");
return ret;
@@ -193,19 +184,18 @@ int32_t as_gpio_set_pin_value(struct as_gpio_device *aDev,
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev,
- int aPinNum)
+int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev)
{
int ret=0;
int portval;
-
- ret = ioctl(aDev->fdev, GPIORDDATA, &portval);
+
+ ret = ioctl(aDev->fpin, GPIORDDATA, &portval);
if (ret < 0) {
ERROR("Can't read gpio data\n");
return ret;
}
- if ((portval & (1<<aPinNum)) != 0) {
+ if (portval != 0) {
return 1;
} else {
return 0;
@@ -215,7 +205,6 @@ 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 aPinNum,
int aDelay_s,
int aDelay_us)
{
@@ -227,35 +216,23 @@ int32_t as_gpio_blocking_get_pin_value(struct as_gpio_device *aDev,
int retval;
- if (aPinNum >= PORT_SIZE )
- {
- ERROR("Pin num %d upper than port size (%d)\n", aPinNum, PORT_SIZE);
- return -1;
- }
- if (aPinNum < 0 )
- {
- ERROR("Wrong pin number %d\n",aPinNum);
- return -1;
- }
-
- if (aDev->fpin[aPinNum] == -1)
+ if (as_gpio_get_irq_mode(aDev) == GPIO_IRQ_MODE_NOINT)
{
ERROR("irq must be configured before\n");
return -1;
}
FD_ZERO(&rfds);
- FD_SET(aDev->fpin[aPinNum], &rfds);
+ FD_SET(aDev->fpin, &rfds);
tv.tv_sec = aDelay_s;
tv.tv_usec = aDelay_us;
/* flush the file */
- retval = select(aDev->fpin[aPinNum]+1, &rfds, NULL, NULL, &tv);
+ retval = select(aDev->fpin+1, &rfds, NULL, NULL, &tv);
if (retval > 0)
{
- printf("DEBUG: read value\n");
- ret = read(aDev->fpin[aPinNum], &value, 1);
+ ret = read(aDev->fpin, &value, 1);
if (ret < 0)
{
ERROR("Can't read pin value\n");
@@ -269,24 +246,22 @@ int32_t as_gpio_blocking_get_pin_value(struct as_gpio_device *aDev,
} else {
return -1;
}
-
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_get_pullup_value(struct as_gpio_device *aDev,
- int aPinNum)
+int32_t as_gpio_get_pullup_value(struct as_gpio_device *aDev)
{
int ret=0;
int portval;
- ret = ioctl(aDev->fdev, GPIORDPULLUP, &portval);
+ ret = ioctl(aDev->fpin, GPIORDPULLUP, &portval);
if (ret < 0) {
ERROR("can't get pullup value\n");
return ret;
}
- if ((portval & (1<<aPinNum)) != 0) {
+ if (portval != 0) {
return 1;
} else {
return 0;
@@ -296,25 +271,14 @@ int32_t as_gpio_get_pullup_value(struct as_gpio_device *aDev,
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_set_pullup_value(struct as_gpio_device *aDev,
- int aPinNum,
- int aValue)
+int32_t as_gpio_set_pullup_value(struct as_gpio_device *aDev, int aValue)
{
int ret=0;
int portval;
- ret = ioctl(aDev->fdev, GPIORDPULLUP, &portval);
- if (ret < 0) {
- ERROR("Can't get pullup value\n");
- return ret;
- }
+ portval = (aValue != 0)?1:0;
- if (aValue == 0) {
- portval &= ~(1 << aPinNum);
- } else {
- portval |= (1 << aPinNum);
- }
- ret = ioctl(aDev->fdev, GPIOWRPULLUP, &portval);
+ ret = ioctl(aDev->fpin, GPIOWRPULLUP, &portval);
if (ret < 0) {
ERROR("Can't set pullup value\n");
return ret;
@@ -325,49 +289,23 @@ int32_t as_gpio_set_pullup_value(struct as_gpio_device *aDev,
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_get_irq_mode(struct as_gpio_device *aDev,
- int aPinNum)
+int32_t as_gpio_get_irq_mode(struct as_gpio_device *aDev)
{
int ret=0;
int portval;
- /* check pin num */
- if (aPinNum >= PORT_SIZE)
- {
- ERROR("Pin num %d upper than port size (%d)\n", aPinNum, PORT_SIZE);
- return -1;
+ ret = ioctl(aDev->fpin, GPIORDIRQMODE, &portval);
+ if (ret < 0) {
+ ERROR("Can't read irq mode\n");
+ return ret;
}
- if (aPinNum < PORT_SIZE/2)
- {
-
- ret = ioctl(aDev->fdev, GPIORDIRQMODE_L, &portval);
- if (ret < 0) {
- ERROR("Can't read irq mode L\n");
- return ret;
- }
-
- portval &= (3 << (aPinNum * 2));
- return portval >> (aPinNum * 2);
-
- } else {
-
- ret = ioctl(aDev->fdev, GPIORDIRQMODE_H, &portval);
- if (ret < 0) {
- ERROR("Can't read irq mode H\n");
- return ret;
- }
-
- portval &= (3 << ((aPinNum - (PORT_SIZE/2)) * 2));
- return portval >> ((aPinNum - (PORT_SIZE/2)) * 2);
- }
+ return portval;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
- int aPinNum,
- int aMode)
+int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev, int aMode)
{
int ret=0;
int portval;
@@ -377,100 +315,26 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
struct timeval tv;
int retval;
+ portval = aMode;
- /* check mode value */
- if (aMode > 3)
- {
- ERROR("Wrong mode value %d\n",aMode);
- return -1;
- }
-
- /* check pin num */
- if (aPinNum >= PORT_SIZE)
- {
- ERROR("Pin num %d upper than port size (%d)\n", aPinNum, PORT_SIZE);
- return -2;
- }
-
- /* close fpin file */
- if (aDev->fpin[aPinNum] != -1)
- {
- close(aDev->fpin[aPinNum]);
- aDev->fpin[aPinNum] = -1;
- }
-
- if (aPinNum < PORT_SIZE/2)
- {
- ret = ioctl(aDev->fdev, GPIORDIRQMODE_L, &portval);
- if (ret < 0) {
- ERROR("Can't read irq mode L\n");
- return ret;
- }
-
- portval &= ~(3 << (aPinNum * 2));
- portval |= (aMode << (aPinNum * 2));
-
- ret = ioctl(aDev->fdev, GPIOWRIRQMODE_L, &portval);
- if (ret < 0) {
- ERROR("Can't write irq mode L\n");
- return ret;
- }
-
- } else {
-
- ret = ioctl(aDev->fdev, GPIORDIRQMODE_H, &portval);
- if (ret < 0) {
- ERROR("Can't read irq mode H\n");
- return ret;
- }
-
- portval &= ~(3 << ((aPinNum - (PORT_SIZE/2)) * 2));
- portval |= (aMode << ((aPinNum - (PORT_SIZE/2)) * 2));
-
- ret = ioctl(aDev->fdev, GPIOWRIRQMODE_H, &portval);
- if (ret < 0) {
- ERROR("Can't write irq mode H\n");
- return ret;
- }
- }
-
- if ((aMode != GPIO_IRQ_MODE_NOINT) && (aDev->fpin[aPinNum] == -1))
- {
- /* open fpin file */
- ret = snprintf(buffer, BUFF_SIZE, "%s%c%d",
- GPIO_BASE_PIN, aDev->port_letter, aPinNum);
- if (ret < 0)
- {
- ERROR("Can't forge fpin path\n");
- return ret;
- }
-
- ret = open(buffer, O_RDONLY);
- if (ret < 0)
- {
- ERROR("Can't open %s\n",buffer);
- return ret;
- }
- aDev->fpin[aPinNum] = ret;
-
+ ret = ioctl(aDev->fpin, GPIOWRIRQMODE, &portval);
+ if (ret < 0) {
+ ERROR("Can't write irq mode L\n");
+ return ret;
}
-
FD_ZERO(&rfds);
- FD_SET(aDev->fpin[aPinNum], &rfds);
+ FD_SET(aDev->fpin, &rfds);
tv.tv_sec = 0;
- tv.tv_usec = 1;
-
+ tv.tv_usec = 10;
/* flush the file */
- retval = select(aDev->fpin[aPinNum]+1, &rfds, NULL, NULL, &tv);
- if (retval)
+ retval = select(aDev->fpin, &rfds, NULL, NULL, &tv);
+ if (retval > 0)
{
- read(aDev->fpin[aPinNum], buffer, BUFF_SIZE);
+ read(aDev->fpin, buffer, BUFF_SIZE);
}
-
- aDev->irq_mode[aPinNum] = aMode;
return 0;
}
@@ -478,13 +342,7 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
int32_t as_gpio_close(struct as_gpio_device *aDev)
{
- int i;
- close(aDev->fdev);
- for (i=0; i < PORT_SIZE; i++)
- {
- if (aDev->fpin[i] != -1)
- close(aDev->fpin[i]);
- }
+ close(aDev->fpin);
free(aDev);
return 0;
}
diff --git a/target/packages/as_devices/c/as_gpio.h b/target/packages/as_devices/c/as_gpio.h
index d644511..af94b46 100644
--- a/target/packages/as_devices/c/as_gpio.h
+++ b/target/packages/as_devices/c/as_gpio.h
@@ -35,71 +35,72 @@ extern "C" {
#define PORT_SIZE (32)
-//TODO: test irq
+//TODO: Change structure to use pin instead of port.
/**
* Store gpio parameters
*/
struct as_gpio_device {
unsigned char port_letter;
- int fdev; /* port file */
- int fpin[PORT_SIZE]; /* pin file for blocking read */
- int irq_mode[PORT_SIZE];
+ int pin_num;
+ int fpin; /* pin file */
+ int irq_mode;
};
/** @brief Initialize port access
*
* @param aPortChar character port in UPPER case
+ * @param aPinNum int pin number
*
* @return error if negative value
*/
-struct as_gpio_device *as_gpio_open(char aPortChar);
+struct as_gpio_device *as_gpio_open(char aPortChar, int aPinNum);
/** @brief Set pin direction
*
* @param aDev as_gpio_device pointer structure
- * @param aPinNum pin number
* @param aDirection direction 0:input 1:output
*
* @return error if negative value
*/
int32_t as_gpio_set_pin_direction(struct as_gpio_device *aDev,
- int aPinNum,
int aDirection);
+/** @brief Get pin direction
+ *
+ * @param aDev as_gpio_device pointer structure
+ *
+ * @return error if negative value
+ */
+int32_t as_gpio_get_pin_direction(struct as_gpio_device *aDev);
+
/** @brief Set pin value
*
* @param aDev as_gpio_device pointer structure
- * @param aPinNum pin number
* @param aValue value of pin (1 or 0)
*
* @return error if negative
*/
int32_t as_gpio_set_pin_value(struct as_gpio_device *aDev,
- int aPinNum,
int aValue);
/** @brief Get pin value
*
* @param aDev as_gpio_device pointer structure
- * @param aPinNum pin number
*
* @return pin value if positive or null, error if negative
*/
-int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev,
- int aPinNum);
+int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev);
/** @brief Get pin value, blocking until interrupt occur
*
* @param aDev as_gpio_device pointer structure
- * @param aPinNum pin number
* @param aDelay_s waiting delay in seconds
* @param aDelay_us waiting delay in useconds (plus delay in seconds)
*
* @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 aPinNum,
int aDelay_s,
int aDelay_us);
@@ -110,42 +111,54 @@ int32_t as_gpio_blocking_get_pin_value(struct as_gpio_device *aDev,
*
* @return pin pull up value if positive or null, error if negative
*/
-int32_t as_gpio_get_pullup_value(struct as_gpio_device *aDev,
- int aPinNum);
+int32_t as_gpio_get_pullup_value(struct as_gpio_device *aDev);
/** @brief Set pin pull-up value
*
* @param aDev as_gpio_device pointer structure
- * @param aPinNum pin number
* @param aValue value of pin (1 or 0)
*
* @return error if negative
*/
int32_t as_gpio_set_pullup_value(struct as_gpio_device *aDev,
- int aPinNum,
int aValue);
/** @brief Set pin irq mode
*
* @param aDev as_gpio_device pointer structure
- * @param aPinNum pin number
* @param aMode irq mode
*
* @return error if negative
*/
int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
- int aPinNum,
int aMode);
/** @brief Get pin irq mode value
*
* @param aDev as_gpio_device pointer structure
- * @param aPinNum pin number
*
* @return pin mode value if positive or null, error if negative
*/
-int32_t as_gpio_get_irq_mode(struct as_gpio_device *aDev,
- int aPinNum);
+int32_t as_gpio_get_irq_mode(struct as_gpio_device *aDev);
+
+/** @brief Get pin number value
+ *
+ * @param aDev as_gpio_device pointer structure
+ *
+ * @return pin mode value if positive or null, error if negative
+ */
+int32_t as_gpio_get_pin_num(struct as_gpio_device *aDev)
+{ return aDev->pin_num;}
+
+/** @brief Get port letter
+ *
+ * @param aDev as_gpio_device pointer structure
+ *
+ * @return pin mode value if positive or null, error if negative
+ */
+int32_t as_gpio_get_port_letter(struct as_gpio_device *aDev)
+{ return aDev->port_letter;}
+
/** @brief Close port access
*
diff --git a/target/packages/as_devices/python/Makefile b/target/packages/as_devices/python/Makefile
index 232dcb8..2b5e0ba 100644
--- a/target/packages/as_devices/python/Makefile
+++ b/target/packages/as_devices/python/Makefile
@@ -21,7 +21,7 @@ AS_LIB=../c/libas_devices.so
LIBNAME=AsDevices
-WRAPPER_LIBS=AsGpio_wrap.so
+#WRAPPER_LIBS=AsGpio_wrap.so
WRAPPER_DIR=src
PYTHON_VERS=2.4
diff --git a/target/packages/as_devices/test_c.h b/target/packages/as_devices/test_c.h
index 04fa50c..e22d4c7 100644
--- a/target/packages/as_devices/test_c.h
+++ b/target/packages/as_devices/test_c.h
@@ -434,7 +434,6 @@ void test_gpio()
char buffer[50];
struct as_gpio_device *gpio_dev;
int32_t ret;
- char c_value;
int32_t value;
char port_letter = 'F';
int pin_num = 13;
@@ -442,15 +441,14 @@ void test_gpio()
int port_value = 1;
int pullup=1;
- gpio_dev = as_gpio_open(port_letter);
+ gpio_dev = as_gpio_open(port_letter, pin_num);
if (gpio_dev == NULL)
{
printf("Error can't open gpio %c\nHave you run loadgpio.sh ?\n", port_letter);
pressEnterToContinue();
return ;
}
- ret = as_gpio_get_pin_value(gpio_dev,
- pin_num);
+ ret = as_gpio_get_pin_value(gpio_dev);
if (ret < 0)
{
printf("Error, can't get pin value\n");
@@ -463,18 +461,17 @@ void test_gpio()
{
system("clear");
printf("**************************\n");
- printf(" Testing GPIO P%c%d \n", port_letter, pin_num);
+ printf(" Testing GPIO P%c%d \n", as_gpio_get_port_letter(gpio_dev),
+ as_gpio_get_pin_num(gpio_dev));
printf("**************************\n");
printf("Choose ('q' to quit):\n");
- printf(" 1) Change port letter (%c)\n", port_letter);
- printf(" 2) Change port num (%d)\n", pin_num);
- printf(" 3) Change direction (%d)\n", port_direction);
- printf(" 4) Change value (%d)\n", port_value);
+ printf(" 1) Change gpio (P%c%d)\n", as_gpio_get_port_letter(gpio_dev),
+ as_gpio_get_pin_num(gpio_dev));
+ printf(" 3) Change direction (%d)\n", as_gpio_get_pin_direction(gpio_dev));
+ printf(" 4) Change value (%d)\n", as_gpio_get_pin_value(gpio_dev));
printf(" 5) Read pin value\n");
- printf(" 6) Change Pull-Up (%d)\n", pullup);
- printf(" 7) Read Pull-Up\n");
- printf(" 8) Set irq mode\n");
- printf(" 9) get irq mode\n");
+ printf(" 6) Change Pull-Up (%d)\n", as_gpio_get_pullup_value(gpio_dev));
+ printf(" 8) Set irq mode (%d)\n", as_gpio_get_irq_mode(gpio_dev));
printf(" a) blocking read\n");
printf("> ");
@@ -489,35 +486,29 @@ void test_gpio()
ret = as_gpio_close(gpio_dev);
if(ret < 0)
{
- printf("Error, can't close Port%c\n", port_letter);
+ printf("Error, can't close gpio\n");
pressEnterToContinue();
break;
}
}
- gpio_dev = as_gpio_open(buffer[0]);
+ port_letter = buffer[0];
+
+ printf("Give pin number : ");
+ scanf("%d", &pin_num);
+
+ gpio_dev = as_gpio_open(port_letter,pin_num);
if(gpio_dev == NULL)
{
- printf("Error, can't open Port%c\n", c_value);
+ printf("Error, can't open P%c%d\n", port_letter, pin_num);
pressEnterToContinue();
break;
}
- port_letter = buffer[0];
- printf("Ok Port %c is set\n", port_letter);
- pressEnterToContinue();
- break;
- case '2' : printf("Give pin number : ");
- scanf("%d", &value);
- if ((value < 0) || (value > 31))
- printf("Error, wrong value\n");
- else
- pin_num = value;
+ printf("Ok P%c%d is open\n", port_letter, pin_num);
pressEnterToContinue();
break;
case '3' : printf("Give direction (0:in, 1:out) : ");
scanf("%d", &value);
- ret = as_gpio_set_pin_direction(gpio_dev,
- pin_num,
- value);
+ ret = as_gpio_set_pin_direction(gpio_dev, value);
if(ret < 0)
{
printf("Error, can't change direction\n");
@@ -530,37 +521,31 @@ void test_gpio()
break;
case '4' : printf("Give value : ");
scanf("%d", &value);
- ret = as_gpio_set_pin_value(gpio_dev,
- pin_num,
- value);
+ ret = as_gpio_set_pin_value(gpio_dev, value);
if(ret < 0)
{
printf("Error, can't change pin value\n");
pressEnterToContinue();
break;
}
- port_value = value;
printf("Ok value changed\n");
pressEnterToContinue();
break;
case '5' : printf("Get value \n");
- ret = as_gpio_get_pin_value(gpio_dev,
- pin_num);
+ ret = as_gpio_get_pin_value(gpio_dev);
if (ret < 0)
{
printf("Error, can't get pin value\n");
pressEnterToContinue();
break;
}
- printf("Value is %d\n",ret);
+ printf("Value is %d\n", ret);
port_value = ret;
pressEnterToContinue();
break;
case '6' : printf("Give value : ");
scanf("%d", &value);
- ret = as_gpio_set_pullup_value(gpio_dev,
- pin_num,
- value);
+ ret = as_gpio_set_pullup_value(gpio_dev, value);
if(ret < 0)
{
printf("Error, can't change pull up value\n");
@@ -571,19 +556,6 @@ void test_gpio()
printf("Ok value changed\n");
pressEnterToContinue();
break;
- case '7' : printf("Get value \n");
- ret = as_gpio_get_pullup_value(gpio_dev,
- pin_num);
- if (ret < 0)
- {
- printf("Error, can't get pull up value\n");
- pressEnterToContinue();
- break;
- }
- printf("Value is %d\n",ret);
- pullup = ret;
- pressEnterToContinue();
- break;
case '8' : printf("1) GPIO_IRQ_MODE_NOINT \n");
printf("2) GPIO_IRQ_MODE_RISING \n");
printf("3) GPIO_IRQ_MODE_FALLING\n");
@@ -594,9 +566,7 @@ void test_gpio()
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,
- pin_num,
- value);
+ ret = as_gpio_set_irq_mode(gpio_dev, value);
if(ret < 0)
{
printf("Error, can't change irq value\n");
@@ -606,22 +576,8 @@ void test_gpio()
printf("Ok value changed\n");
pressEnterToContinue();
break;
- case '9' : printf("Get value \n");
- ret = as_gpio_get_irq_mode(gpio_dev, pin_num);
- if (ret < 0)
- {
- printf("Error, can't get pull up value\n");
- pressEnterToContinue();
- break;
- }
- if (ret==GPIO_IRQ_MODE_NOINT )printf("GPIO_IRQ_MODE_NOINT \n");
- if (ret==GPIO_IRQ_MODE_RISING )printf("GPIO_IRQ_MODE_RISING \n");
- if (ret==GPIO_IRQ_MODE_FALLING)printf("GPIO_IRQ_MODE_FALLING\n");
- if (ret==GPIO_IRQ_MODE_BOTH )printf("GPIO_IRQ_MODE_BOTH \n");
- pressEnterToContinue();
- break;
case 'a' : printf("Blocking read \n");
- ret = as_gpio_blocking_get_pin_value(gpio_dev, pin_num, 10, 0);
+ ret = as_gpio_blocking_get_pin_value(gpio_dev, 10, 0);
if (ret < 0)
{
printf("Error, can't read value\n");
hooks/post-receive
--
armadeus
|