GPIO edge event

group edge_event

Functions and data types for handling edge events.

An edge event object contains information about a single line edge event. It contains the event type, timestamp and the offset of the line on which the event occurred as well as two sequence numbers (global for all lines in the associated request and local for this line only).

Edge events are stored into an edge-event buffer object to improve performance and to limit the number of memory allocations when a large number of events are being read.

Enums

enum gpiod_edge_event_type

Event types.

Values:

enumerator GPIOD_EDGE_EVENT_RISING_EDGE

Rising edge event.

enumerator GPIOD_EDGE_EVENT_FALLING_EDGE

Falling edge event.

Functions

void gpiod_edge_event_free(struct gpiod_edge_event *event)

Free the edge event object.

Parameters:

event – Edge event object to free.

struct gpiod_edge_event *gpiod_edge_event_copy(struct gpiod_edge_event *event)

Copy the edge event object.

Parameters:

event – Edge event to copy.

Returns:

Copy of the edge event or NULL on error. The returned object must be freed by the caller using gpiod_edge_event_free.

enum gpiod_edge_event_type gpiod_edge_event_get_event_type(struct gpiod_edge_event *event)

Get the event type.

Parameters:

event – GPIO edge event.

Returns:

The event type (GPIOD_EDGE_EVENT_RISING_EDGE or GPIOD_EDGE_EVENT_FALLING_EDGE).

uint64_t gpiod_edge_event_get_timestamp_ns(struct gpiod_edge_event *event)

Get the timestamp of the event.

Note

The source clock for the timestamp depends on the event_clock setting for the line.

Parameters:

event – GPIO edge event.

Returns:

Timestamp in nanoseconds.

unsigned int gpiod_edge_event_get_line_offset(struct gpiod_edge_event *event)

Get the offset of the line which triggered the event.

Parameters:

event – GPIO edge event.

Returns:

Line offset.

unsigned long gpiod_edge_event_get_global_seqno(struct gpiod_edge_event *event)

Get the global sequence number of the event.

Parameters:

event – GPIO edge event.

Returns:

Sequence number of the event in the series of events for all lines in the associated line request.

unsigned long gpiod_edge_event_get_line_seqno(struct gpiod_edge_event *event)

Get the event sequence number specific to the line.

Parameters:

event – GPIO edge event.

Returns:

Sequence number of the event in the series of events only for this line within the lifetime of the associated line request.

struct gpiod_edge_event_buffer *gpiod_edge_event_buffer_new(size_t capacity)

Create a new edge event buffer.

Note

If capacity equals 0, it will be set to a default value of 64. If capacity is larger than 1024, it will be limited to 1024.

Note

The user space buffer is independent of the kernel buffer (gpiod_request_config_set_event_buffer_size). As the user space buffer is filled from the kernel buffer, there is no benefit making the user space buffer larger than the kernel buffer. The default kernel buffer size for each request is (16 * num_lines).

Parameters:

capacity – Number of events the buffer can store (min = 1, max = 1024).

Returns:

New edge event buffer or NULL on error.

size_t gpiod_edge_event_buffer_get_capacity(struct gpiod_edge_event_buffer *buffer)

Get the capacity (the max number of events that can be stored) of the event buffer.

Parameters:

buffer – Edge event buffer.

Returns:

The capacity of the buffer.

void gpiod_edge_event_buffer_free(struct gpiod_edge_event_buffer *buffer)

Free the edge event buffer and release all associated resources.

Parameters:

buffer – Edge event buffer to free.

struct gpiod_edge_event *gpiod_edge_event_buffer_get_event(struct gpiod_edge_event_buffer *buffer, unsigned long index)

Get an event stored in the buffer.

Warning

Thread-safety: Since events are tied to the buffer instance, different threads may not operate on the buffer and any associated events at the same time. Events can be copied using gpiod_edge_event_copy in order to create a standalone objects - which each may safely be used from a different thread concurrently.

Parameters:
  • buffer – Edge event buffer.

  • index – Index of the event in the buffer.

Returns:

Pointer to an event stored in the buffer. The lifetime of the event is tied to the buffer object. Users must not free the event returned by this function.

size_t gpiod_edge_event_buffer_get_num_events(struct gpiod_edge_event_buffer *buffer)

Get the number of events a buffer has stored.

Parameters:

buffer – Edge event buffer.

Returns:

Number of events stored in the buffer.