1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
4 #ifndef METAL__BUTTON_H
5 #define METAL__BUTTON_H
9 * API for interfacing with physical buttons
12 #include <metal/interrupt.h>
16 struct metal_button_vtable {
17 int (*button_exist)(struct metal_button *button, char *label);
18 struct metal_interrupt* (*interrupt_controller)(struct metal_button *button);
19 int (*get_interrupt_id)(struct metal_button *button);
23 * @brief A button device handle
25 * A `struct metal_button` is an implementation-defined object which represents
26 * a button on a development board.
29 const struct metal_button_vtable *vtable;
33 * @brief Get a reference to a button
35 * @param label The DeviceTree label for the button
36 * @return A handle for the button
38 struct metal_button* metal_button_get(char *label);
42 * @brief Get the interrupt controller for a button
44 * @param button The handle for the button
45 * @return A pointer to the interrupt controller responsible for handling
48 inline struct metal_interrupt*
49 metal_button_interrupt_controller(struct metal_button *button) { return button->vtable->interrupt_controller(button); }
52 * @brief Get the interrupt id for a button
54 * @param button The handle for the button
55 * @return The interrupt id corresponding to a button.
57 inline int metal_button_get_interrupt_id(struct metal_button *button) { return button->vtable->get_interrupt_id(button); }