Изучаем проект direwolf, родительский репозиторий, Я попытался написать свою собственную функцию чтения:
Код: Выделить всё
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;
}
В таблице данных хорошо объясняется, как записать GPIO с использованием HID (хотя это не совсем та же команда, что и GitHub проекты), но мне действительно неясно, как читать. Я был бы признателен за любые идеи или проекты, использующие эту функцию.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -interface