led.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright 2018 SiFive, Inc */
  2. /* SPDX-License-Identifier: Apache-2.0 */
  3. #ifndef METAL__LED_H
  4. #define METAL__LED_H
  5. /*!
  6. * @file led.h
  7. * @brief API for manipulating LEDs
  8. */
  9. struct metal_led;
  10. struct metal_led_vtable {
  11. int (*led_exist)(struct metal_led *led, char *label);
  12. void (*led_enable)(struct metal_led *led);
  13. void (*led_on)(struct metal_led *led);
  14. void (*led_off)(struct metal_led *led);
  15. void (*led_toggle)(struct metal_led *led);
  16. };
  17. /*!
  18. * @brief A handle for an LED
  19. */
  20. struct metal_led {
  21. const struct metal_led_vtable *vtable;
  22. };
  23. /*!
  24. * @brief Get a handle for an LED
  25. * @param label The DeviceTree label for the desired LED
  26. * @return A handle to the LED, or NULL if none is found for the requested label
  27. */
  28. struct metal_led* metal_led_get(char *label);
  29. /*!
  30. * @brief Get a handle for a channel of an RGB LED
  31. * @param label The DeviceTree label for the desired LED
  32. * @param color The color for the LED in the DeviceTree
  33. * @return A handle to the LED, or NULL if none is found for the requested label and color
  34. */
  35. struct metal_led* metal_led_get_rgb(char *label, char *color);
  36. /*!
  37. * @brief Enable an LED
  38. * @param led The handle for the LED
  39. */
  40. __inline__ void metal_led_enable(struct metal_led *led) { led->vtable->led_enable(led); }
  41. /*!
  42. * @brief Turn an LED on
  43. * @param led The handle for the LED
  44. */
  45. __inline__ void metal_led_on(struct metal_led *led) { led->vtable->led_on(led); }
  46. /*!
  47. * @brief Turn an LED off
  48. * @param led The handle for the LED
  49. */
  50. __inline__ void metal_led_off(struct metal_led *led) { led->vtable->led_off(led); }
  51. /*!
  52. * @brief Toggle the on/off state of an LED
  53. * @param led The handle for the LED
  54. */
  55. __inline__ void metal_led_toggle(struct metal_led *led) { led->vtable->led_toggle(led); }
  56. #endif