diff mbox series

[v3,3/7] hw/misc/led: Emit a trace event when LED intensity has changed

Message ID 20200620230719.32139-4-f4bug@amsat.org
State New
Headers show
Series [v3,1/7] hw/misc: Add a LED device | expand

Commit Message

Philippe Mathieu-Daudé June 20, 2020, 11:07 p.m. UTC
Track the LED intensity, and emit a trace event when it changes.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/misc/led.h | 1 +
 hw/misc/led.c         | 5 +++++
 hw/misc/trace-events  | 1 +
 3 files changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/include/hw/misc/led.h b/include/hw/misc/led.h
index 883006bb8f..df5b32a2db 100644
--- a/include/hw/misc/led.h
+++ b/include/hw/misc/led.h
@@ -35,6 +35,7 @@  typedef struct LEDState {
     DeviceState parent_obj;
     /* Public */
 
+    uint16_t current_intensity;
     qemu_irq irq;
 
     /* Properties */
diff --git a/hw/misc/led.c b/hw/misc/led.c
index 8503dde777..37d9f1f3d2 100644
--- a/hw/misc/led.c
+++ b/hw/misc/led.c
@@ -32,6 +32,11 @@  void led_set_intensity(LEDState *s, uint16_t new_intensity)
 {
     trace_led_set_intensity(s->description ? s->description : "n/a",
                             s->color, new_intensity);
+    if (new_intensity != s->current_intensity) {
+        trace_led_change_intensity(s->description ? s->description : "n/a",
+                                   s->color,
+                                   s->current_intensity, new_intensity);
+    }
     s->current_intensity = new_intensity;
 }
 
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
index f58853d367..57d39bf9b9 100644
--- a/hw/misc/trace-events
+++ b/hw/misc/trace-events
@@ -209,6 +209,7 @@  grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6
 
 # led.c
 led_set_intensity(const char *color, const char *desc, uint16_t intensity) "LED desc:'%s' color:%s intensity: 0x%04"PRIx16
+led_change_intensity(const char *color, const char *desc, uint16_t old_intensity, uint16_t new_intensity) "LED desc:'%s' color:%s intensity 0x%04"PRIx16" -> 0x%04"PRIx16""
 
 # pca9552.c
 pca9552_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]"