Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

pio button

Altera_Forum
Honored Contributor II
1,327 Views

Hi, 

 

I try to use pio button. 

Typing cat /dev/button I can see that the button drivers are working. 

 

How can I use the functions in altera_pio_button.c to make my own uClinux app? 

 

thanks 

stepa
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
427 Views

I think the following code works... it's been awhile since I looked at it. I think there may have been an issue with shutting down the app properly but it should give you some good ideas as to how to proceed. 

 

#include <stdio.h># include <unistd.h># include <fcntl.h># include <stdlib.h> /* open /dev/button device for blocked reading * whenever button is pressed, *   display number of times button was pressed since startup */ int main (int argc, char* argv) {  int fd;  char path = "/dev/button";    int numclicks = 0;  char buf;    fd = open (path, O_RDONLY);    if (fd < 0) {    /* error occurred */    perror ("open");    exit (EXIT_FAILURE);  } else {    printf ("opened %s\n", path);  }    /* file is now open for reading... do your stuff... */  while (read (fd, buf, 1) != 0) {    if (buf == &#39;1&#39;) {      numclicks += 1;    }    printf ("The button has been pushed %d times.\n", numclicks);  }    if (close (fd) < 0) {    perror ("close");    exit (EXIT_FAILURE);  } else {    printf ("closed %s\n", path);  }    exit (EXIT_SUCCESS); }
0 Kudos
Altera_Forum
Honored Contributor II
427 Views

Thank you Ken

0 Kudos
Reply