Erkundung des Direwolf-Projekts, des übergeordneten Repos, Ich habe versucht, meine eigene Lesefunktion zu schreiben:
Code: Select all
static int cm108_read_gpio(char *name, int iomask) {
int fd;
unsigned char io[5] = {0};
int n;
// Open the device
fd = open(name, O_RDWR);
if (fd == -1) {
printf("Could not open %s for read/write, errno=%d\n", name, errno);
if (errno == EACCES) {
printf("Ensure the device has proper permissions (e.g., group 'audio').\n");
}
return -1;
}
// Prepare the command to request GPIO state
io[0] = 0x0; // Report ID, always 0 for CM108
io[1] = 0x1; // Command to read GPIO (as per datasheet)
io[2] = 0x0; // Reserved
io[3] = 0x0; // Reserved
io[4] = 0x0; // Reserved
// Send the command to the device
n = write(fd, io, sizeof(io));
if (n != sizeof(io)) {
printf("Failed to send GPIO read command to %s, errno=%d\n", name, errno);
close(fd);
return -1;
}
// Read the response from the device
n = read(fd, io, sizeof(io));
if (n != sizeof(io)) {
printf("Failed to read GPIO state from %s, errno=%d\n", name, errno);
close(fd);
return -1;
}
// Close the device
close(fd);
// Extract the GPIO state for the requested iomask
int gpio_state = io[2] & iomask; // Extract the relevant bit(s) for the requested GPIO(s)
return gpio_state;
}
Das Datenblatt erklärt gut, wie man GPIO mit HID schreibt, auch wenn es nicht genau derselbe Befehl wie der GitHub ist Projekte), aber ich finde es beim Lesen wirklich unklar. Ich würde mich über jeden Einblick oder jedes Projekt freuen, das diese Funktion nutzt.