button.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright 2018 SiFive, Inc */
  2. /* SPDX-License-Identifier: Apache-2.0 */
  3. #ifndef METAL__BUTTON_H
  4. #define METAL__BUTTON_H
  5. /*!
  6. * @file button.h
  7. * API for interfacing with physical buttons
  8. */
  9. #include <metal/interrupt.h>
  10. struct metal_button;
  11. struct metal_button_vtable {
  12. int (*button_exist)(struct metal_button *button, char *label);
  13. struct metal_interrupt* (*interrupt_controller)(struct metal_button *button);
  14. int (*get_interrupt_id)(struct metal_button *button);
  15. };
  16. /*!
  17. * @brief A button device handle
  18. *
  19. * A `struct metal_button` is an implementation-defined object which represents
  20. * a button on a development board.
  21. */
  22. struct metal_button {
  23. const struct metal_button_vtable *vtable;
  24. };
  25. /*!
  26. * @brief Get a reference to a button
  27. *
  28. * @param label The DeviceTree label for the button
  29. * @return A handle for the button
  30. */
  31. struct metal_button* metal_button_get(char *label);
  32. /*!
  33. * @brief Get the interrupt controller for a button
  34. *
  35. * @param button The handle for the button
  36. * @return A pointer to the interrupt controller responsible for handling
  37. * button interrupts.
  38. */
  39. __inline__ struct metal_interrupt*
  40. metal_button_interrupt_controller(struct metal_button *button) { return button->vtable->interrupt_controller(button); }
  41. /*!
  42. * @brief Get the interrupt id for a button
  43. *
  44. * @param button The handle for the button
  45. * @return The interrupt id corresponding to a button.
  46. */
  47. __inline__ int metal_button_get_interrupt_id(struct metal_button *button) { return button->vtable->get_interrupt_id(button); }
  48. #endif