pub enum GpioError {
InvalidPin(u8),
UnknownMode(u8),
UnknownSoC,
PermissionDenied,
InstanceExists,
NotInitialized,
Io(Error),
ThreadPanic,
}
Expand description
Errors that can occur when accessing the GPIO peripheral.
Variants
InvalidPin(u8)
Invalid GPIO pin number.
The GPIO pin number is not available on this Raspberry Pi model.
UnknownMode(u8)
Unknown GPIO pin mode.
The GPIO pin is set to an unknown mode.
UnknownSoC
Unknown SoC.
It wasn’t possible to automatically identify the Raspberry Pi’s SoC.
PermissionDenied
Permission denied when opening /dev/gpiomem
and/or /dev/mem
for read/write access.
Make sure the user has read and write access to /dev/gpiomem
.
Common causes are either incorrect file permissions on /dev/gpiomem
, or
the user isn’t a member of the gpio
group. If /dev/gpiomem
is missing, upgrade to a more
recent version of Raspbian.
/dev/mem
is a fallback when /dev/gpiomem
can’t be accessed. Getting read and write
access to /dev/mem
is typically accomplished by executing the program as a
privileged user through sudo
. A better solution that doesn’t require sudo
would be
to upgrade to a version of Raspbian that implements /dev/gpiomem
.
InstanceExists
An instance of Gpio
already exists.
Multiple instances of Gpio
can cause race conditions or pin configuration issues when
several threads write to the same register simultaneously. While other applications
can’t be prevented from writing to the GPIO registers at the same time, limiting Gpio
to a single instance will at least make the Rust interface less error-prone.
You can share a Gpio
instance with other threads using channels, or cloning an
Arc<Mutex<Gpio>>
. Although discouraged, you could also share it globally
wrapped in a Mutex
using the lazy_static
crate.
NotInitialized
Gpio
isn’t initialized.
You should normally only see this error when you call a method after
running cleanup
.
Io(Error)
IO error.
ThreadPanic
Interrupt polling thread panicked.