Quantcast
Channel: Forum - Recent Threads
Viewing all articles
Browse latest Browse all 1583

Operate GPIO in RZ/G2L Smarc Board using character device method how to map gpiochip0 witch actual pin number.

$
0
0

We are using RZ/G2l smarc board for our project.In that I had build the image using Yocto startup guide and booted the board. Also we have added user application which can able read and write the GPIO pins connected to board.

For GPIO application we are using character device method to control But In that I am opening using open("/dev/gpiochip0",O_RDWR); in that system call  i am using gpiochip0 to access gpio.
But my question is  How can i find this gpiochip0 maped with witch physical pins ? and to use particular pin i have to give offset so how to calculate the offset for that ?  

I am attaching  my source code for reference.

****************************************************************************************************************************************************************************************************

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/gpio.h>

void get_chip_info(void);
void get_line_info(void);
void request_output(void);
void set_values(int);


int fd;
struct gpiochip_info info_chip;
struct gpioline_info info_line;
struct gpiohandle_request req;
struct gpiohandle_data data;


int main(int argc, char **argv)
{

strcpy(addr,argv[1]);

get_chip_info();

get_line_info();

request_output();

while(1)
{
set_values(1);
sleep(1);
set_values(0);
sleep(1);
}

}

void get_chip_info(void)
{

int rv;

fd = open("/dev/gpiochip0",O_RDWR);
if (fd == -1)
{
printf("Failed to open \n");
exit(1);
}

rv = ioctl(fd,GPIO_GET_CHIPINFO_IOCTL,info_chip);
printf("chip Information\n");
printf("Name=%s ,label=%s, lines=%d\n",info_chip.name,info_chip.label,info_chip.lines);
}

void get_line_info(void)
{

int rv;

memset(&info_line,0,sizeof(info_line));
info_line.line_offset = 465;

rv = ioctl(fd,GPIO_GET_LINEINFO_IOCTL,&info_line);
printf("line Information\n");
printf("Name=%s ,label=%s, lineoffset=%d, flags=%d\n",info_line.name,info_line.consumer,info_line.line_offset,info_line.flags);
}

void request_output(void)
{

int rv;

req.flags |= GPIOHANDLE_REQUEST_OUTPUT;
req.lines = 1;
req.lineoffsets[0] = 465;
//req.lineoffsets[0] = 5;
req.default_values[0] = 0;
//req.default_values[1] = 0;

strcpy(req.consumer_label,"myname");

rv = ioctl(fd,GPIO_GET_LINEHANDLE_IOCTL,&req);
}

void set_values(int val)
{

int rv;

data.values[0] = val;
//data.values[1] = 1;

rv = ioctl(req.fd,GPIOHANDLE_SET_LINE_VALUES_IOCTL,&data);
}


Viewing all articles
Browse latest Browse all 1583

Trending Articles