From: Philippe Mathieu-Daudé <f4...@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é <f4...@amsat.org> Message-Id: <20210313165445.2113938-10-f4...@amsat.org> Reviewed-by: Michael Rolnik <mrol...@gmail.com> Signed-off-by: Heecheol Yang <heecheol.y...@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