summaryrefslogtreecommitdiff
path: root/FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_GCC/bsp/install/include/metal/led.h
blob: a430b84c2fc75959651d1ed9bf219e8c3bc5c728 (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
60
61
62
63
64
65
66
67
68
/* Copyright 2018 SiFive, Inc */
/* SPDX-License-Identifier: Apache-2.0 */

#ifndef METAL__LED_H
#define METAL__LED_H

/*!
 * @file led.h
 * @brief API for manipulating LEDs
 */

struct metal_led;

struct metal_led_vtable {
    int (*led_exist)(struct metal_led *led, char *label);
    void (*led_enable)(struct metal_led *led);
    void (*led_on)(struct metal_led *led);
    void (*led_off)(struct metal_led *led);
    void (*led_toggle)(struct metal_led *led);
};

/*!
 * @brief A handle for an LED
 */
struct metal_led {
    const struct metal_led_vtable *vtable;
};

/*!
 * @brief Get a handle for an LED
 * @param label The DeviceTree label for the desired LED
 * @return A handle to the LED, or NULL if none is found for the requested label
 */
struct metal_led* metal_led_get(char *label);

/*!
 * @brief Get a handle for a channel of an RGB LED
 * @param label The DeviceTree label for the desired LED
 * @param color The color for the LED in the DeviceTree
 * @return A handle to the LED, or NULL if none is found for the requested label and color
 */
struct metal_led* metal_led_get_rgb(char *label, char *color);

/*!
 * @brief Enable an LED
 * @param led The handle for the LED
 */
inline void metal_led_enable(struct metal_led *led) { led->vtable->led_enable(led); }

/*!
 * @brief Turn an LED on
 * @param led The handle for the LED
 */
inline void metal_led_on(struct metal_led *led) { led->vtable->led_on(led); }

/*!
 * @brief Turn an LED off
 * @param led The handle for the LED
 */
inline void metal_led_off(struct metal_led *led) { led->vtable->led_off(led); }

/*!
 * @brief Toggle the on/off state of an LED
 * @param led The handle for the LED
 */
inline void metal_led_toggle(struct metal_led *led) { led->vtable->led_toggle(led); }

#endif