GPIO class
GPIO wrapper functions for Linux userspace character device gpio-cdev and sysfs GPIOs.
Character device GPIOs were introduced in Linux kernel version 4.8. If the toolchain used to compiled c-periphery contains Linux kernel headers older than 4.8 (i.e. linux/gpio.h is missing), then only legacy sysfs GPIOs will be supported.
c-periphery GPIO documentation.
Constructors
- GPIO(int line, GPIOdirection direction, [int chip = 0])
-
Opens the character device GPIO with the specified GPIO
line
anddirection
at the default character device GPIO with thechip
number. The default chip number is 0, with the path /dev/gpiochip0. - GPIO.advanced(int line, GPIOconfig config, [int chip = 0])
-
Opens the character device GPIO with the specified GPIO
line
and configurationconfig
at the default character device GPIO with thechip
number. The default chip numer is 0, with the path /dev/gpiochip0. Use GPIO.setBaseGPIOpath to change the default character device path. - GPIO.isolate(String json)
- Duplicates an existing GPIO from a JSON string. This special constructor is used to transfer an existing GPIO to an other isolate.
- GPIO.name(String name, GPIOdirection direction, [int chip = 0])
-
Opens the character device GPIO with the specified GPIO
name
anddirection
at the default character device GPIO with thechip
number. The default chip number is 0, with the path /dev/gpiochip0. Use GPIO.setBaseGPIOpath to change the default character device path. - GPIO.nameAdvanced(String name, GPIOconfig config, [int chip = 0])
-
Opens the character device GPIO with the specified GPIO
name
and the configurationconfig
at the default character device GPIO with thechip
number. The default chip numer is 0, with the path /dev/gpiochip0. Use GPIO.setBaseGPIOpath to change the default character device path. - GPIO.sysfs(int line, GPIOdirection direction)
-
Opens the sysfs GPIO with the specified
line
anddirection
.
Properties
- chip → int
-
GPIO chip number, e.g. 0 for /dev/gpiochip0
final
- direction → GPIOdirection
-
input/ouput GPIO direction
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- line → int
-
GPIO line number, is -1 if GPIO.name is used
final
- name → String
-
GPIO name, is empty if GPIO.line is used
final
- path → String
-
GPIO chip device path e.g. /dev/gpiochip0
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
) → void - Releases all internal native resources.
-
fromJson(
String json) → IsolateAPI -
getErrno(
) → int - Returns the libc errno of the last failure that occurred.
-
getGPIObias(
) → GPIObias - Returns the property bias of the GPIO.
-
getGPIOchipFD(
) → int - Returns the GPIO chip file descriptor of the GPIO handle. This method is intended for use with character device GPIOs and is unsupported by sysfs GPIOs.
-
getGPIOchipLabel(
) → String - Returns the label of the GPIO chip associated with the GPIO.
-
getGPIOchipName(
) → String - Returns the label of the GPIO chip associated with the GPIO.
-
getGPIOdirection(
) → GPIOdirection - Returns the property direction of the GPIO.
-
getGPIOdrive(
) → GPIOdrive - Returns the property drive of the GPIO.
-
getGPIOedge(
) → GPIOedge - Returns the property edge of the GPIO.
-
getGPIOfd(
) → int - Returns the native line file descriptor of the GPIO handle.
-
getGPIOinfo(
) → String - Returns a string representation of the native GPIO handle.
-
getGPIOinverted(
) → bool - Returns if the GPIO line is inverted,
-
getGPIOlabel(
) → String - Returns the line consumer label of the GPIO. This method is intended for use with character device GPIOs and always returns the empty string for sysfs GPIOs.
-
getGPIOname(
) → String - Returns the line name of the GPIO. This method is intended for use with character device GPIOs and always returns the empty string for sysfs GPIOs.
-
getHandle(
) → int - Returns the address of the internal handle.
-
getLine(
) → int - Returns the line of the GPIO handle was opened with.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
poll(
int timeoutMillis) → GPIOpolling - Polls a GPIO for the edge event configured with GPIO.setGPIOedge. For character device GPIOs, the edge event should be consumed with gpio_read_event(). For sysfs GPIOs, the edge event should be consumed with GPIO.read.
-
read(
) → bool - Reads the state of the GPIO line.
-
readEvent(
) → GPIOreadEvent - Reads the edge event that occurred with the GPIO. This method is intended for use with character device GPIOs and is unsupported by sysfs GPIOs.
-
setGPIObias(
GPIObias bias) → void -
Sets the
bias
of the GPIO. -
setGPIOdirection(
GPIOdirection direction) → void -
Sets the
direction
of the GPIO. -
setGPIOdrive(
GPIOdrive drive) → void -
Sets the
drive
of the GPIO. -
setGPIOedge(
GPIOedge edge) → void -
Sets the
edge
of the GPIO. -
setGPIOinverted(
bool inverted) → void - Inverts the GPIO line.
-
setHandle(
int handle) → void -
toJson(
) → String - Converts a GPIO to a JSON string. See constructor isolate for detials.
-
toString(
) → String -
A string representation of this object.
inherited
-
write(
bool value) → void -
Sets the state of the GPIO to
value
.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
getGPIOerrorCode(
int value) → GPIOerrorCode -
Converts the native error code
value
to GPIOerrorCode. -
pollMultiple(
List< GPIO> gpios, int timeoutMillis) → PollMultipleEvent -
Polls multiple GPIOs for an edge event configured with GPIO.setGPIOedge.
For character device GPIOs, the edge event should be consumed with GPIO.readEvent. For sysfs GPIOs,
the edge event should be consumed with GPIO.read.
timeoutMillis
can be positive for a timeout in milliseconds, zero for a non-blocking poll, or negative for a blocking poll. Returns a PollMultipleEvent() -
setBaseGPIOpath(
String chipBasePath) → void -
Sets an alternative
chipBasePath
, default value is '/dev/gpiochip'