hw/misc/led: Add yellow LED
[qemu/ar7.git] / include / hw / misc / led.h
blob29c087957080039f816e0d19b545e3252260da4d
1 /*
2 * QEMU single LED device
4 * Copyright (C) 2020 Philippe Mathieu-Daudé <f4bug@amsat.org>
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 #ifndef HW_MISC_LED_H
9 #define HW_MISC_LED_H
11 #include "qom/object.h"
12 #include "hw/qdev-core.h"
14 #define TYPE_LED "led"
16 /**
17 * LEDColor: Color of a LED
19 * This set is restricted to physically available LED colors.
21 * LED colors from 'Table 1. Product performance of LUXEON Rebel Color
22 * Line' of the 'DS68 LUXEON Rebel Color Line' datasheet available at:
23 * https://www.lumileds.com/products/color-leds/luxeon-rebel-color/
25 typedef enum { /* Coarse wavelength range */
26 LED_COLOR_VIOLET, /* 425 nm */
27 LED_COLOR_BLUE, /* 475 nm */
28 LED_COLOR_CYAN, /* 500 nm */
29 LED_COLOR_GREEN, /* 535 nm */
30 LED_COLOR_YELLOW, /* 567 nm */
31 LED_COLOR_AMBER, /* 590 nm */
32 LED_COLOR_ORANGE, /* 615 nm */
33 LED_COLOR_RED, /* 630 nm */
34 } LEDColor;
36 struct LEDState {
37 /* Private */
38 DeviceState parent_obj;
39 /* Public */
41 uint8_t intensity_percent;
42 qemu_irq irq;
44 /* Properties */
45 char *description;
46 char *color;
48 * Determines whether a GPIO is using a positive (active-high)
49 * logic (when used with GPIO, the intensity at reset is related
50 * to the GPIO polarity).
52 bool gpio_active_high;
54 typedef struct LEDState LEDState;
55 DECLARE_INSTANCE_CHECKER(LEDState, LED, TYPE_LED)
57 /**
58 * led_set_intensity: Set the intensity of a LED device
59 * @s: the LED object
60 * @intensity_percent: intensity as percentage in range 0 to 100.
62 void led_set_intensity(LEDState *s, unsigned intensity_percent);
64 /**
65 * led_get_intensity:
66 * @s: the LED object
68 * Returns: The LED intensity as percentage in range 0 to 100.
70 unsigned led_get_intensity(LEDState *s);
72 /**
73 * led_set_state: Set the state of a LED device
74 * @s: the LED object
75 * @is_emitting: boolean indicating whether the LED is emitting
77 * This utility is meant for LED connected to GPIO.
79 void led_set_state(LEDState *s, bool is_emitting);
81 /**
82 * led_create_simple: Create and realize a LED device
83 * @parentobj: the parent object
84 * @gpio_polarity: GPIO polarity
85 * @color: color of the LED
86 * @description: description of the LED (optional)
88 * Create the device state structure, initialize it, and
89 * drop the reference to it (the device is realized).
91 * Returns: The newly allocated and instantiated LED object.
93 LEDState *led_create_simple(Object *parentobj,
94 GpioPolarity gpio_polarity,
95 LEDColor color,
96 const char *description);
98 #endif /* HW_MISC_LED_H */