I am trying to read from MIO 50 button of Zybo Z7-20 in linux , I have changed the voltage from 1.8V to 3.3V in VIVADO and used the .XSA file and generated linux image in petalinux and I have used the following code to read from MIO 50.
Even if I don't press the MIO 50 button , I am still getting result as button pressed.
int fd; //file handler.
struct gpiohandle_request button;
struct gpiohandle_data data;
/*Open the gpiochip0 file which is mapped to the gpio physical layer*/
fd = open("/dev/gpiochip0", O_RDWR); //opening the file in read-write mode.
if(fd < 0)
{
perror("File not present\n");
return -1;
}
Question
SuryaPrakash
I am trying to read from MIO 50 button of Zybo Z7-20 in linux , I have changed the voltage from 1.8V to 3.3V in VIVADO and used the .XSA file and generated linux image in petalinux and I have used the following code to read from MIO 50.
Even if I don't press the MIO 50 button , I am still getting result as button pressed.
int fd; //file handler.
struct gpiohandle_request button;
struct gpiohandle_data data;
/*Open the gpiochip0 file which is mapped to the gpio physical layer*/
fd = open("/dev/gpiochip0", O_RDWR); //opening the file in read-write mode.
if(fd < 0)
{
perror("File not present\n");
return -1;
}
/*Set button (MIO-50) as input*/
button.flags = GPIOHANDLE_REQUEST_INPUT;
strcpy(button.consumer_label , "BUTTON");
memset(button.default_values , 0 , sizeof(button.default_values));
button.lines = 1;
button.lineoffsets[0] = PS_SWITCH;
/*Make request to make MIO50 as input*/
if(ioctl(fd , GPIO_GET_LINEHANDLE_IOCTL,&button) < 0)
{
perror("GPIO input request failed\n");
close(fd);
close(led.fd);
return -1;
}
//Intialize the data.values array to 0.
memset(data.values , 0 , sizeof(data.values));
if(ioctl(button.fd , GPIOHANDLE_GET_LINE_VALUES_IOCTL , &data) < 0)
{
perror("Getting value from GPIO input pin failed\n");
close(fd);
close(led.fd);
close(button.fd);
return -1;
}
if(data.values[0] == 1)
{
printf("\nBUTTON PRESS DETECTED\n");
}
else
{
printf("\nBUTTON PRESS NOT DETECTED\n");
}
close(fd);
close(button.fd);
return 0;
Link to comment
Share on other sites
0 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now