MCPcopy Create free account
hub / github.com/WiringPi/WiringPi / OpenAndCheckGpioChip

Function OpenAndCheckGpioChip

wiringPi/wiringPi.c:1730–1770  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1728
1729
1730int OpenAndCheckGpioChip(int GPIONo, const char* label, const unsigned int lines) {
1731 char szGPIOChip[30];
1732
1733 sprintf(szGPIOChip, "/dev/gpiochip%d", GPIONo);
1734 int Fd = open(szGPIOChip, O_RDWR);
1735 if (Fd < 0) {
1736 fprintf(stderr, "wiringPi: ERROR: %s open ret=%d\n", szGPIOChip, Fd);
1737 return Fd;
1738 } else {
1739 if (wiringPiDebug) {
1740 printf("wiringPi: Open chip %s succeded, fd=%d\n", szGPIOChip, Fd) ;
1741 }
1742 struct gpiochip_info chipinfo;
1743 ZeroMemory(&chipinfo, sizeof(chipinfo));
1744 int ret = ioctl(Fd, GPIO_GET_CHIPINFO_IOCTL, &chipinfo);
1745 if (0==ret) {
1746 if (wiringPiDebug) {
1747 printf("%s: name=%s, label=%s, lines=%u\n", szGPIOChip, chipinfo.name, chipinfo.label, chipinfo.lines) ;
1748 }
1749 int chipOK = 1;
1750 if (label[0]!='\0' && NULL==strstr(chipinfo.label, label)) {
1751 chipOK = 0;
1752 }
1753 if (lines>0 && chipinfo.lines!=lines) {
1754 chipOK = 0;
1755 }
1756 if (chipOK) {
1757 if (wiringPiDebug) {
1758 printf("%s: valid, fd=%d\n", szGPIOChip, Fd);
1759 }
1760 } else {
1761 if (wiringPiDebug) {
1762 printf("%s: invalid, search for '%s' with %u lines!\n", szGPIOChip, label, lines) ;
1763 }
1764 close(Fd);
1765 return -1; // invalid chip
1766 }
1767 }
1768 }
1769 return Fd;
1770}
1771
1772int wiringPiGpioDeviceGetFd() {
1773 if (chipFd<0) {

Callers 1

wiringPiGpioDeviceGetFdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected