2 * QEMU single LED device
4 * Copyright (C) 2020 Philippe Mathieu-Daudé <f4bug@amsat.org>
6 * SPDX-License-Identifier: GPL-2.0-or-later
11 #include "qom/object.h"
12 #include "hw/qdev-core.h"
14 #define TYPE_LED "led"
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 */
38 DeviceState parent_obj
;
41 uint8_t intensity_percent
;
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
)
58 * led_set_intensity: Set the intensity of a LED device
60 * @intensity_percent: intensity as percentage in range 0 to 100.
62 void led_set_intensity(LEDState
*s
, unsigned intensity_percent
);
68 * Returns: The LED intensity as percentage in range 0 to 100.
70 unsigned led_get_intensity(LEDState
*s
);
73 * led_set_state: Set the state of a LED device
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
);
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
,
96 const char *description
);
98 #endif /* HW_MISC_LED_H */