Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4049

Advanced users • Re: Argon One Replacement Daemon

$
0
0
The Deamon will now do a dumb search for the correct device but check for gpiochip 0 - 10 and searching for the pinctrl in the label.

Code:

#include <stdio.h>#include <stdint.h>#include <unistd.h>#include <string.h>#include <fcntl.h>#include <sys/ioctl.h>#include <linux/gpio.h>#include <dirent.h>int find_pinctrl(void){  DIR *dir;  struct dirent *entry;  if ((dir = opendir("/dev")) == NULL) {    perror("opendir");    return -1;  }  while ((entry = readdir(dir)) != NULL) {    if (strncmp(entry->d_name, "gpiochip", 8) == 0) {      int fd;      char gpiochip_path[16]; // "/dev/gpiochip99\0" = 16      struct gpiochip_info info;      snprintf(gpiochip_path, sizeof(gpiochip_path) - 1, "/dev/%s", entry->d_name);      if ((fd = open(gpiochip_path, O_RDONLY)) < 0) {        perror("open");        continue;      }      if (ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, &info) == -1) {        perror("ioctl");        continue;      }      if (strncmp(info.label, "pinctrl-", 8) == 0) {        printf("pinctrl found on device %s [%s]\n", info.name, info.label);        closedir(dir);        return fd;      }      close(fd);    }  }  closedir(dir);  return -1;}
scandir() would work but meh due to the extra filter function and needing to free memory.
Mon Feb 19 21:41:16 2024 [ DEBUG ] FLAG Forground mode IS SET
Mon Feb 19 21:51:42 2024 [ CRITICAL ] Unable to locate pinctlr
Typos

Statistics: Posted by trejan — Thu Feb 22, 2024 2:57 pm



Viewing all articles
Browse latest Browse all 4049

Trending Articles