qemu-devel
[Top][All Lists]
Advanced

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

[PATCH 6/8] hw/avr/arduino: Add D13 LED


From: Heecheol Yang
Subject: [PATCH 6/8] hw/avr/arduino: Add D13 LED
Date: Mon, 12 Sep 2022 20:21:04 +0900

From: G S Niteesh Babu <niteesh.gs@gmail.com>

Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com>
Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
Message-Id: <20210311135539.10206-4-niteesh.gs@gmail.com>
[PMD: Added ArduinoMachineClass::d13_led_portb_bit]
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20210313165445.2113938-9-f4bug@amsat.org>
Signed-off-by: Heecheol Yang <heecheol.yang@outlook.com>
---
 hw/avr/Kconfig   |  1 +
 hw/avr/arduino.c | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/hw/avr/Kconfig b/hw/avr/Kconfig
index 16a57ced11..e0d4fc5537 100644
--- a/hw/avr/Kconfig
+++ b/hw/avr/Kconfig
@@ -8,3 +8,4 @@ config AVR_ATMEGA_MCU
 config ARDUINO
     select AVR_ATMEGA_MCU
     select UNIMP
+    select LED
diff --git a/hw/avr/arduino.c b/hw/avr/arduino.c
index 48ef478346..73563a35d0 100644
--- a/hw/avr/arduino.c
+++ b/hw/avr/arduino.c
@@ -12,6 +12,8 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "hw/boards.h"
+#include "hw/misc/led.h"
 #include "atmega.h"
 #include "boot.h"
 #include "qom/object.h"
@@ -21,6 +23,8 @@ struct ArduinoMachineState {
     MachineState parent_obj;
     /*< public >*/
     AtmegaMcuState mcu;
+
+    LEDState *onboard_led;
 };
 typedef struct ArduinoMachineState ArduinoMachineState;
 
@@ -30,6 +34,7 @@ struct ArduinoMachineClass {
     /*< public >*/
     const char *mcu_type;
     uint64_t xtal_hz;
+    unsigned d13_led_portb_bit; /* PORTB GPIO for D13 yellow LED */
 };
 typedef struct ArduinoMachineClass ArduinoMachineClass;
 
@@ -48,6 +53,16 @@ static void arduino_machine_init(MachineState *machine)
                              amc->xtal_hz, &error_abort);
     sysbus_realize(SYS_BUS_DEVICE(&ams->mcu), &error_abort);
 
+    /* Onboard led connected to digital header PIN 13 */
+    ams->onboard_led = led_create_simple(OBJECT(ams),
+                                         GPIO_POLARITY_ACTIVE_HIGH,
+                                         LED_COLOR_YELLOW,
+                                         "D13 LED");
+
+    qdev_connect_gpio_out(DEVICE(&ams->mcu.gpio[1]),
+                          amc->d13_led_portb_bit,
+                          qdev_get_gpio_in(DEVICE(ams->onboard_led), 0));
+
     if (machine->firmware) {
         if (!avr_load_firmware(&ams->mcu.cpu, machine,
                                &ams->mcu.flash, machine->firmware)) {
@@ -82,6 +97,7 @@ static void arduino_duemilanove_class_init(ObjectClass *oc, 
void *data)
     mc->alias       = "2009";
     amc->mcu_type   = TYPE_ATMEGA168_MCU;
     amc->xtal_hz    = 16 * 1000 * 1000;
+    amc->d13_led_portb_bit = 5;
 };
 
 static void arduino_uno_class_init(ObjectClass *oc, void *data)
@@ -97,6 +113,7 @@ static void arduino_uno_class_init(ObjectClass *oc, void 
*data)
     mc->alias       = "uno";
     amc->mcu_type   = TYPE_ATMEGA328_MCU;
     amc->xtal_hz    = 16 * 1000 * 1000;
+    amc->d13_led_portb_bit = 5;
 };
 
 static void arduino_mega_class_init(ObjectClass *oc, void *data)
@@ -112,6 +129,7 @@ static void arduino_mega_class_init(ObjectClass *oc, void 
*data)
     mc->alias       = "mega";
     amc->mcu_type   = TYPE_ATMEGA1280_MCU;
     amc->xtal_hz    = 16 * 1000 * 1000;
+    amc->d13_led_portb_bit = 7;
 };
 
 static void arduino_mega2560_class_init(ObjectClass *oc, void *data)
@@ -127,6 +145,7 @@ static void arduino_mega2560_class_init(ObjectClass *oc, 
void *data)
     mc->alias       = "mega2560";
     amc->mcu_type   = TYPE_ATMEGA2560_MCU;
     amc->xtal_hz    = 16 * 1000 * 1000; /* CSTCE16M0V53-R0 */
+    amc->d13_led_portb_bit = 7;
 };
 
 static const TypeInfo arduino_machine_types[] = {
-- 
2.34.1




reply via email to

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