qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 09/11] hw/avr/arduino: Replace magic number by gpio_port_index()


From: Philippe Mathieu-Daudé
Subject: [PATCH 09/11] hw/avr/arduino: Replace magic number by gpio_port_index() call
Date: Sat, 13 Mar 2021 17:54:43 +0100

The '1' magic value means 'Port B'. Introduce and use the
gpio_port_index() helper to explicit the port name.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/avr/arduino.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/avr/arduino.c b/hw/avr/arduino.c
index 73563a35d0d..87124d17f18 100644
--- a/hw/avr/arduino.c
+++ b/hw/avr/arduino.c
@@ -43,6 +43,12 @@ typedef struct ArduinoMachineClass ArduinoMachineClass;
 DECLARE_OBJ_CHECKERS(ArduinoMachineState, ArduinoMachineClass,
                      ARDUINO_MACHINE, TYPE_ARDUINO_MACHINE)
 
+static unsigned gpio_port_index(char c)
+{
+    assert(c >= 'A' && c < 'A' + GPIO_MAX);
+    return c - 'A';
+}
+
 static void arduino_machine_init(MachineState *machine)
 {
     ArduinoMachineClass *amc = ARDUINO_MACHINE_GET_CLASS(machine);
@@ -59,7 +65,7 @@ static void arduino_machine_init(MachineState *machine)
                                          LED_COLOR_YELLOW,
                                          "D13 LED");
 
-    qdev_connect_gpio_out(DEVICE(&ams->mcu.gpio[1]),
+    qdev_connect_gpio_out(DEVICE(&ams->mcu.gpio[gpio_port_index('B')]),
                           amc->d13_led_portb_bit,
                           qdev_get_gpio_in(DEVICE(ams->onboard_led), 0));
 
-- 
2.26.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]