1 /* 2 * QEMU single LED device 3 * 4 * Copyright (C) 2020 Philippe Mathieu-Daudé <f4bug@amsat.org> 5 * 6 * SPDX-License-Identifier: GPL-2.0-or-later 7 */ 8 #ifndef HW_MISC_LED_H 9 #define HW_MISC_LED_H 10 11 #include "qom/object.h" 12 #include "hw/qdev-core.h" 13 14 #define TYPE_LED "led" 15 16 /** 17 * LEDColor: Color of a LED 18 * 19 * This set is restricted to physically available LED colors. 20 * 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/ 24 */ 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_AMBER, /* 590 nm */ 31 LED_COLOR_ORANGE, /* 615 nm */ 32 LED_COLOR_RED, /* 630 nm */ 33 } LEDColor; 34 35 struct LEDState { 36 /* Private */ 37 DeviceState parent_obj; 38 /* Public */ 39 40 uint8_t intensity_percent; 41 qemu_irq irq; 42 43 /* Properties */ 44 char *description; 45 char *color; 46 /* 47 * Determines whether a GPIO is using a positive (active-high) 48 * logic (when used with GPIO, the intensity at reset is related 49 * to the GPIO polarity). 50 */ 51 bool gpio_active_high; 52 }; 53 typedef struct LEDState LEDState; 54 DECLARE_INSTANCE_CHECKER(LEDState, LED, TYPE_LED) 55 56 /** 57 * led_set_intensity: Set the intensity of a LED device 58 * @s: the LED object 59 * @intensity_percent: intensity as percentage in range 0 to 100. 60 */ 61 void led_set_intensity(LEDState *s, unsigned intensity_percent); 62 63 /** 64 * led_get_intensity: 65 * @s: the LED object 66 * 67 * Returns: The LED intensity as percentage in range 0 to 100. 68 */ 69 unsigned led_get_intensity(LEDState *s); 70 71 /** 72 * led_set_state: Set the state of a LED device 73 * @s: the LED object 74 * @is_emitting: boolean indicating whether the LED is emitting 75 * 76 * This utility is meant for LED connected to GPIO. 77 */ 78 void led_set_state(LEDState *s, bool is_emitting); 79 80 /** 81 * led_create_simple: Create and realize a LED device 82 * @parentobj: the parent object 83 * @gpio_polarity: GPIO polarity 84 * @color: color of the LED 85 * @description: description of the LED (optional) 86 * 87 * Create the device state structure, initialize it, and 88 * drop the reference to it (the device is realized). 89 * 90 * Returns: The newly allocated and instantiated LED object. 91 */ 92 LEDState *led_create_simple(Object *parentobj, 93 GpioPolarity gpio_polarity, 94 LEDColor color, 95 const char *description); 96 97 #endif /* HW_MISC_LED_H */ 98