HAL_Linux: add export gpio during direction set if not exported during initialisation

This commit is contained in:
bugobliterator 2014-05-24 10:57:39 +05:30 committed by Andrew Tridgell
parent a7ead42f52
commit 85d10e2ce3

View File

@ -60,14 +60,27 @@ void LinuxGPIO::init()
void LinuxGPIO::pinMode(uint8_t pin, uint8_t output)
{
int fd;
int fd,len;
char buf[64];
snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/direction", pin);
fd = ::open(buf, O_WRONLY);
if (fd < 0) {
perror("LinuxGPIO::direction");
fd = open(SYSFS_GPIO_DIR "/export", O_WRONLY); //try exporting GPIO pin
if (fd < 0) {
perror("LinuxGPIO::direction");
}
len = snprintf(buf, sizeof(buf), "%d", pin);
::write(fd, buf, len);
close(fd);
snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/direction", pin); //retry writing direction
fd = ::open(buf, O_WRONLY);
if (fd < 0) {
perror("LinuxGPIO::direction"); //report faillure
}
}
if (output == GPIO_OUTPUT)