diff --git a/lib/libgpio/Makefile b/lib/libgpio/Makefile --- a/lib/libgpio/Makefile +++ b/lib/libgpio/Makefile @@ -27,6 +27,8 @@ gpio.3 gpio_pin_pulldown.3 \ gpio.3 gpio_pin_invin.3 \ gpio.3 gpio_pin_invout.3 \ - gpio.3 gpio_pin_pulsate.3 + gpio.3 gpio_pin_pulsate.3 \ + gpio.3 gpio_configure_events.3 \ + gpio.3 gpio_fileno.3 .include diff --git a/lib/libgpio/gpio.3 b/lib/libgpio/gpio.3 --- a/lib/libgpio/gpio.3 +++ b/lib/libgpio/gpio.3 @@ -79,6 +79,10 @@ .Fn gpio_pin_invout "gpio_handle_t handle" "gpio_pin_t pin" .Ft int .Fn gpio_pin_pulsate "gpio_handle_t handle" "gpio_pin_t pin" +.Ft int +.Fn gpio_configure_events "gpio_handle_t handle" "uint32_t report_type" "uint32_t fifo_size" +.Ft int +.Fn gpio_fileno "gpio_handle_t handle" .Sh DESCRIPTION The .Nm libgpio @@ -156,6 +160,42 @@ .Fn gpio_pin_pulsate are wrappers around .Fn gpio_pin_set_flags . +.Pp +The function +.Fn gpio_configure_events +configures the interrupt delivery type and FIFO size for buffered gpio interrupts. By default, delivery is of type +.Ft gpio_event_detail +with a default FIFO size of 2 * number of pins belonging to the +.Ft gpio_device_t +instance. The FIFO argument is only meaningful when the delivery is of type +.Ft gpio_event_detail . +The complete list of delivery types and their associated structures is defined in +.Pa /usr/include/sys/gpio.h . +This setting is tracked on a per device instance basis. The FIFO size cannot be reduced below the default value, nor can it be decreased after it has been increased. If any pin on the device +has already been configured, +.Fn gpio_configure_events +will fail and return EINVAL. +.Pp +The function +.Fn gpio_fileno +returns the file descriptor associated with the +.Ft gpio_handle_t +instance. +.Pp +File operations have the following semantics: +.Bl -tag -width ioctl +.It Xr read 2 +Read one or more gpio interrupts that have occured since the last successful +.Xr read 2 . +The results are placed into the output buffer of the type previously established via +.Fn gpio_configure_events . +If there are no pending interrupts, +.Xr read 2 +blocks until an interrupt occurs, unless O_NONBLOCK is set. +.It Xr poll 2 +When receiving notification via +.Xr poll 2 +or similar interfaces, the file descriptor becomes readable when one or more gpio interrupts are pending. .Sh EXAMPLES The following example shows how to configure pin 16 as output and then drive it high: diff --git a/lib/libgpio/gpio.c b/lib/libgpio/gpio.c --- a/lib/libgpio/gpio.c +++ b/lib/libgpio/gpio.c @@ -274,3 +274,22 @@ { return (gpio_pin_set_flag(handle, pin, GPIO_PIN_PULSATE)); } + +int +gpio_configure_events(gpio_handle_t handle, uint32_t report_type, uint32_t fifo_size) +{ + struct gpio_event_config gpevent_config; + + gpevent_config.gp_report_type = report_type; + gpevent_config.gp_fifo_size = fifo_size; + if (ioctl(handle, GPIOCONFIGEVENTS, &gpevent_config) < 0) + return (-1); + + return (0); +} + +int +gpio_fileno(gpio_handle_t handle) +{ + return (handle); +} diff --git a/lib/libgpio/libgpio.h b/lib/libgpio/libgpio.h --- a/lib/libgpio/libgpio.h +++ b/lib/libgpio/libgpio.h @@ -102,7 +102,21 @@ int gpio_pin_invin(gpio_handle_t, gpio_pin_t); int gpio_pin_invout(gpio_handle_t, gpio_pin_t); int gpio_pin_pulsate(gpio_handle_t, gpio_pin_t); +/* + * GPIO event reporting configuration + * + * Set the event reporting type, the default being gpio_event_detail, + * and fifo size of 2 * number of pins belonging to the gpioc device instance. + * FIFO size can only be changed when report_type is gpio_event_detail. + */ +int gpio_configure_events(gpio_handle_t, uint32_t, uint32_t); +/* + * Retrieve the file descriptor associated with gpio_handle_t, which can + * be used for gpio interrupts + */ +int gpio_fileno(gpio_handle_t); __END_DECLS #endif /* _LIBGPIO_H_ */ +