[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
- Re: [PATCH 04/11] hw/gpio/avr_gpio: Add migration VMstate, (continued)
- [PATCH 05/11] hw/gpio/avr_gpio: Add 'id' field in AVRGPIOState, Philippe Mathieu-Daudé, 2021/03/13
- [PATCH 06/11] hw/gpio/avr_gpio: Simplify avr_gpio_write_port using extract32(), Philippe Mathieu-Daudé, 2021/03/13
- [PATCH 07/11] hw/gpio/avr_gpio: Add tracing for reads and writes, Philippe Mathieu-Daudé, 2021/03/13
- [PATCH 08/11] hw/avr/arduino: Add D13 LED, Philippe Mathieu-Daudé, 2021/03/13
- [PATCH 09/11] hw/avr/arduino: Replace magic number by gpio_port_index() call,
Philippe Mathieu-Daudé <=
- [PATCH 10/11] target/avr: Fix some comment spelling errors, Philippe Mathieu-Daudé, 2021/03/13
- [PATCH 11/11] target/avr: Fix interrupt execution, Philippe Mathieu-Daudé, 2021/03/13
- Re: [PATCH 00/11] AVR patch queue for QEMU 6.0, Michael Rolnik, 2021/03/13
- Re: [PATCH 00/11] AVR patch queue for QEMU 6.0, Philippe Mathieu-Daudé, 2021/03/14