[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 7/8] hw/avr/arduino: Replace magic number by gpio_port_index() ca
From: |
Heecheol Yang |
Subject: |
[PATCH 7/8] hw/avr/arduino: Replace magic number by gpio_port_index() call |
Date: |
Mon, 12 Sep 2022 20:21:05 +0900 |
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
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>
Message-Id: <20210313165445.2113938-10-f4bug@amsat.org>
Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
Signed-off-by: Heecheol Yang <heecheol.yang@outlook.com>
---
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 73563a35d0..87124d17f1 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.34.1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH 7/8] hw/avr/arduino: Replace magic number by gpio_port_index() call,
Heecheol Yang <=