From: Cyril B. <cyr...@gm...> - 2005-07-19 15:04:39
|
Hello all, We would like to know how to modify the GPIOs functions from a program in= =20 C/C++. If you have some sample code or you know a web page which explain it, it's= =20 welcome.=20 Thanks, Cyril |
From: Jim W. <jwa...@qu...> - 2005-07-19 15:36:38
|
Hi, I had made up a quick little program to read some GPIOs from C without using the /proc interface by copying some of the code out of the proc_gpio driver. Here's a quick snippet (may not compile because I snagged it from my source file and clipped out the unrelated stuff, but it gives you the general idea). To change the pin functions, you would need to modify the GAFR registers. // The address of the GPIO level registers #define GPLR0 0x40E00000 #define GPLR1 0x40E00004 // the memory mapping size #define MAP_SIZE 16 #define MAP_MASK 15 int main () { void * map, * regaddr1, * regaddr2; u32 val1, val2; fd_gp = open ("/dev/mem", O_RDWR | O_SYNC); if (0 > fd_gp) { perror ("opening mem file error"); exit (-1); } map = mmap (0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd_gp, GPLR0 & ~ MAP_MASK ); if ((void *) -1 == map) { perror ("mapping mem file error"); exit (-2); } regaddr1 = map + (GPLR0 & MAP_MASK); regaddr2 = map + (GPLR1 & MAP_MASK); // loop to read GPIO pins 28-32 > while (1) > { > val1 = * (u32 *) regaddr1; > val2 = * (u32 *) regaddr2; > > pinstate[1] = ! (1 << 28 && (val1 & 1 << 28)); > pinstate[2] = ! (1 << 29 && (val1 & 1 << 29)); > pinstate[3] = ! (1 << 30 && (val1 & 1 << 30)); > pinstate[4] = ! (1 << 31 && (val1 & 1 << 31)); > pinstate[5] = ! (1 && (val2 & 1)); > for (i = 0; i < NUMPINS; i++) > { > if (pinstate[i] != oldpinstate[i]) > { > pinchange = 1; > } > } // some other code to process the changes } } Cyril Bazin wrote: > Hello all, > > We would like to know how to modify the GPIOs functions from a program > in C/C++. > If you have some sample code or you know a web page which explain it, > it's welcome. > > Thanks, > > Cyril |
From: Pooya K. <poo...@gm...> - 2005-07-19 15:41:39
|
Hi, I believe the best way is to use PXA registers but as far as I know that need to be done as a kernel driver. What I did was to load proc_gpio and then write and read from /proc/gpio/GPIO*. Probably it is the worst way to do it but I don't know of any easier one. I also commented out a line in build_arm/linux-2.6.11gum/drivers/gpio/proc_gpio.c which was printing every change in GPIO lines and reuploaded the proc_gpio.ko file to gumstix. It is the line starting with: printk(KERN_INFO "Set (... Some sample codes: // open char gpioPath[256]; sprintf(gpioPath,"/proc/gpio/GPIO%d",pin); if ((fd =3D open(gpioPath, O_RDWR | O_FSYNC, 0)) < 0) { printf("Error opening %d proc file: %s\n", pin, strerror(errno)); return -1; } // setDirection sprintf(s,"GPIO %s\n",(dir=3D=3D1)?"out":"in"); if (pwrite(fd, s, strlen(s), 0) < 0) { printf("Error writing GPIO register %d\n",pin); return ; } =20 // write sprintf(s,"%s\n",(val=3D=3D1)?"set":"clear"); if (pwrite(fd, s, strlen(s), 0) < 0) { printf("Error writing GPIO register %d\n",pin); return ; } =20 // read if ((buflen =3D pread(fd, buf, sizeof(buf)-1, 0)) <=3D 0) { printf("Error reading GPIO register %d\n",pin); return 0; } buf[buflen]=3D0; if (strstr(buf,"clear\n")!=3DNULL) { return 0; } else if (strstr(buf,"set\n")!=3DNULL) { return 1; } printf("Error Reading!\n"); return -1; I got the idea from codes of stargate board but when I tried making a UISP for gumstix using them it didn't ever worked. Maybe it is because using this method you can not read or write fast enough. I will investigate that as soon as I can fix the erased u-boot ;) --Pooya Karimian=20 -http://www.pooyak.com/ -Autonomy Lab -School of Computing Science -Simon Fraser University On 7/19/05, Cyril Bazin <cyr...@gm...> wrote: > Hello all, > =20 > We would like to know how to modify the GPIOs functions from a program i= n > C/C++. > If you have some sample code or you know a web page which explain it, it= 's > welcome.=20 > =20 > Thanks, > =20 > Cyril > |
From: Cyril B. <cyr...@gm...> - 2005-07-20 07:31:25
|
Thanks for your examples,=20 Actually, we use the GPIO?? files in /proc/gpio to interact with the GPIO.= =20 Jim, I will note your technique, I didn't think about writing in=20 "/dev/mem"... I hoped a solution using directly an library to interact with the GPIOs. Something like: ------------------------------------------- #include <interface_for_gpio_interaction.h> ... modify_gpio(48, GPIO_FUNCTION_AF1_OUT); ... ------------------------------------------- Maybe, I code too much in Python... ;-) Cyril |
From: Craig H. <cr...@gu...> - 2005-07-20 19:20:21
|
On Jul 20, 2005, at 12:31 AM, Cyril Bazin wrote: > Thanks for your examples, > > Actually, we use the GPIO?? files in /proc/gpio to interact with > the GPIO. > Jim, I will note your technique, I didn't think about writing in "/ > dev/mem"... > > I hoped a solution using directly an library to interact with the > GPIOs. > > Something like: > ------------------------------------------- > #include <interface_for_gpio_interaction.h> > > ... > > modify_gpio(48, GPIO_FUNCTION_AF1_OUT); > > ... > ------------------------------------------- > > > Maybe, I code too much in Python... ;-) If you write that library on top of /dev/mem and then you want to contribute it, I'd be happy to add it to the buildroot for others :) C |
From: Jim W. <jwa...@qu...> - 2005-07-22 13:37:04
|
Hi Cyril, That's a good idea! I think that would be an excellent addition to the library of cool stuff that the gumstix can do. I'm a little bit overcomitted right now, but I'll keep this in mind when I go back and test-rewrite-finalize the code that I have that uses this. Thanks, Jim Walters Cyril Bazin wrote: > Thanks for your examples, > > Actually, we use the GPIO?? files in /proc/gpio to interact with the > GPIO. > Jim, I will note your technique, I didn't think about writing in > "/dev/mem"... > > I hoped a solution using directly an library to interact with the GPIOs. > > Something like: > ------------------------------------------- > #include <interface_for_gpio_interaction.h> > > ... > > modify_gpio(48, GPIO_FUNCTION_AF1_OUT); > > ... > ------------------------------------------- > > > Maybe, I code too much in Python... ;-) > > Cyril > |
From: Craig H. <cr...@gu...> - 2005-07-20 19:19:26
|
Cyril, The easiest way is probably to copy the code for the pxaregs tool (which uses /dev/kmem to read/write registers), and write to the GPIO registers directly. For an example of how to twiddle the right bits in the GPIO registers, check the proc_gpio driver in the kernel tree. C On Jul 19, 2005, at 8:04 AM, Cyril Bazin wrote: > Hello all, > > We would like to know how to modify the GPIOs functions from a > program in C/C++. > If you have some sample code or you know a web page which explain > it, it's welcome. > > Thanks, > > Cyril |
From: Seth C. <se...@ca...> - 2005-07-20 19:26:52
|
I posted this question earlier but don't think there was a response. Is there software access to the 10 GPIO pins with interrupt signals exposed on the audiostix header? Thanks, Seth -----Original Message----- From: gum...@li... [mailto:gum...@li...]On Behalf Of Craig Hughes Sent: Wednesday, July 20, 2005 1:19 PM To: gum...@li... Subject: Re: [Gumstix-users] How to modify the GPIOs from a C++ program? Cyril, The easiest way is probably to copy the code for the pxaregs tool (which uses /dev/kmem to read/write registers), and write to the GPIO registers directly. For an example of how to twiddle the right bits in the GPIO registers, check the proc_gpio driver in the kernel tree. C |
From: Craig H. <cr...@gu...> - 2005-07-20 20:36:11
|
I don't think so. You'd have to add something to the pxa-ac97 driver to access the ucb1400-specific registers which control those GPIOs. C On Jul 20, 2005, at 12:30 PM, Seth Cameron wrote: > > I posted this question earlier but don't think there was a > response. Is > there software access to the 10 GPIO pins with interrupt signals > exposed on > the audiostix header? > > Thanks, Seth > > -----Original Message----- > From: gum...@li... > [mailto:gum...@li...]On Behalf Of Craig > Hughes > Sent: Wednesday, July 20, 2005 1:19 PM > To: gum...@li... > Subject: Re: [Gumstix-users] How to modify the GPIOs from a C++ > program? > > Cyril, > > The easiest way is probably to copy the code for the pxaregs tool > (which uses /dev/kmem to read/write registers), and write to the GPIO > registers directly. For an example of how to twiddle the right bits > in the GPIO registers, check the proc_gpio driver in the kernel tree. > > C > > > > > > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > from IBM. Find simple to follow Roadmaps, straightforward articles, > informative Webcasts and more! Get everything you need to get up to > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > _______________________________________________ > gumstix-users mailing list > gum...@li... > https://lists.sourceforge.net/lists/listinfo/gumstix-users > |