summaryrefslogtreecommitdiff
path: root/FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1-RevB_FreedomStudio/freedom-metal/metal/button.h
blob: 3ae1c143ebacf043cddfb42b0c8fb63f4fb5efad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Copyright 2018 SiFive, Inc */
/* SPDX-License-Identifier: Apache-2.0 */

#ifndef METAL__BUTTON_H
#define METAL__BUTTON_H

/*!
 * @file button.h
 * API for interfacing with physical buttons
 */

#include <metal/interrupt.h>

struct metal_button;

struct metal_button_vtable {
    int (*button_exist)(struct metal_button *button, char *label);
    struct metal_interrupt* (*interrupt_controller)(struct metal_button *button);
    int (*get_interrupt_id)(struct metal_button *button);
};

/*!
 * @brief A button device handle
 *
 * A `struct metal_button` is an implementation-defined object which represents
 * a button on a development board.
 */
struct metal_button {
    const struct metal_button_vtable *vtable;
};

/*!
 * @brief Get a reference to a button
 *
 * @param label The DeviceTree label for the button
 * @return A handle for the button
 */
struct metal_button* metal_button_get(char *label);


/*!
 * @brief Get the interrupt controller for a button
 *
 * @param button The handle for the button
 * @return A pointer to the interrupt controller responsible for handling
 * button interrupts.
 */
__inline__ struct metal_interrupt*
    metal_button_interrupt_controller(struct metal_button *button) { return button->vtable->interrupt_controller(button); }

/*!
 * @brief Get the interrupt id for a button
 *
 * @param button The handle for the button
 * @return The interrupt id corresponding to a button.
 */
__inline__ int metal_button_get_interrupt_id(struct metal_button *button) { return button->vtable->get_interrupt_id(button); }

#endif