1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
4 #ifndef METAL__SWITCH_H
5 #define METAL__SWITCH_H
9 * @brief API for reading toggle switches
12 #include <metal/interrupt.h>
16 struct metal_switch_vtable {
17 int (*switch_exist)(struct metal_switch *sw, char *label);
18 struct metal_interrupt* (*interrupt_controller)(struct metal_switch *sw);
19 int (*get_interrupt_id)(struct metal_switch *sw);
23 * @brief A handle for a switch
26 const struct metal_switch_vtable *vtable;
30 * @brief Get a handle for a switch
31 * @param label The DeviceTree label for the desired switch
32 * @return A handle to the switch, or NULL if none is found for the requested label
34 struct metal_switch* metal_switch_get(char *label);
37 * @brief Get the interrupt controller for a switch
38 * @param sw The handle for the switch
39 * @return The interrupt controller handle
41 inline struct metal_interrupt*
42 metal_switch_interrupt_controller(struct metal_switch *sw) { return sw->vtable->interrupt_controller(sw); }
45 * @brief Get the interrupt id for a switch
46 * @param sw The handle for the switch
47 * @return The interrupt ID for the switch
49 inline int metal_switch_get_interrupt_id(struct metal_switch *sw) { return sw->vtable->get_interrupt_id(sw); }