Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache gpio chip detection when properly initialized #962

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions utility/RPi/interrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ void IrqChipCache::openDevice()
msg += "; ";
msg += strerror(errno);
throw IRQException(msg);
return;
}
}
chipInitialized = true;
}

void IrqChipCache::closeDevice()
Expand Down Expand Up @@ -89,6 +91,10 @@ int attachInterrupt(rf24_gpio_pin_t pin, int mode, void (*function)(void))
irqChipCache.openDevice();
}
catch (IRQException& exc) {
if (irqChipCache.chipInitialized) {
throw exc;
return 0;
}
irqChipCache.chip = "/dev/gpiochip0";
irqChipCache.openDevice();
}
Expand Down
1 change: 1 addition & 0 deletions utility/RPi/interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct IrqChipCache
{
const char* chip = RF24_LINUX_GPIO_CHIP;
int fd = -1;
bool chipInitialized = false;

/// Open the File Descriptor for the GPIO chip
void openDevice();
Expand Down
6 changes: 6 additions & 0 deletions utility/SPIDEV/gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ void GPIOChipCache::openDevice()
msg += "; ";
msg += strerror(errno);
throw GPIOException(msg);
return;
}
}
chipInitialized = true;
}

void GPIOChipCache::closeDevice()
Expand Down Expand Up @@ -77,6 +79,10 @@ void GPIO::open(rf24_gpio_pin_t port, int DDR)
gpioCache.openDevice();
}
catch (GPIOException& exc) {
if (gpioCache.chipInitialized) {
throw exc;
return;
}
gpioCache.chip = "/dev/gpiochip0";
gpioCache.openDevice();
}
Expand Down
1 change: 1 addition & 0 deletions utility/SPIDEV/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct GPIOChipCache
{
const char* chip = RF24_LINUX_GPIO_CHIP;
int fd = -1;
bool chipInitialized = false;

/// Open the File Descriptor for the GPIO chip
void openDevice();
Expand Down
4 changes: 4 additions & 0 deletions utility/SPIDEV/interrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ int attachInterrupt(rf24_gpio_pin_t pin, int mode, void (*function)(void))
irqChipCache.openDevice();
}
catch (GPIOException& exc) {
if (irqChipCache.chipInitialized) {
throw exc;
return 0;
}
irqChipCache.chip = "/dev/gpiochip0";
irqChipCache.openDevice();
}
Expand Down