diff mbox series

[3/3] avr/arduino: Add D13 LED

Message ID 20210311135539.10206-4-niteesh.gs@gmail.com
State New
Headers show
Series AVR GPIO Emulation and Arduino D13 LED | expand

Commit Message

Niteesh G. S. March 11, 2021, 1:55 p.m. UTC
Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com>
---
 hw/avr/Kconfig   |  1 +
 hw/avr/arduino.c | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

Comments

Philippe Mathieu-Daudé March 13, 2021, 3:10 p.m. UTC | #1
On 3/11/21 2:55 PM, G S Niteesh Babu wrote:
> Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com>
> ---
>  hw/avr/Kconfig   |  1 +
>  hw/avr/arduino.c | 15 +++++++++++++++
>  2 files changed, 16 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 3c8388490d..5cdba3201c 100644
> --- a/hw/avr/arduino.c
> +++ b/hw/avr/arduino.c
> @@ -13,6 +13,7 @@
>  #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"
> @@ -22,6 +23,8 @@ struct ArduinoMachineState {
>      MachineState parent_obj;
>      /*< public >*/
>      AtmegaMcuState mcu;
> +
> +    LEDState *onboard_led;
>  };
>  typedef struct ArduinoMachineState ArduinoMachineState;
>  
> @@ -49,6 +52,18 @@ static void arduino_machine_init(MachineState *machine)
>                               amc->xtal_hz, &error_abort);
>      sysbus_realize(SYS_BUS_DEVICE(&ams->mcu), &error_abort);
>  
> +    ams->onboard_led = led_create_simple(OBJECT(ams),
> +                                         GPIO_POLARITY_ACTIVE_HIGH,
> +                                         LED_COLOR_BLUE,
> +                                         "D13 LED");
> +
> +    /* TODO: Add macro or function to map pins to ports */
> +    /* The onboard led is connected to PIN 13 in all boards currently supported

Yes,

> +     * in QEMU. And PIN 13 is mapped to PORT B BIT 5.

No. Only on the Duemilanove / UNO. On both Mega it is bit 7.

> +     */
> +    qdev_connect_gpio_out(DEVICE(&ams->mcu.gpio[1]), 5,
> +                          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)) {
>
diff mbox series

Patch

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 3c8388490d..5cdba3201c 100644
--- a/hw/avr/arduino.c
+++ b/hw/avr/arduino.c
@@ -13,6 +13,7 @@ 
 #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"
@@ -22,6 +23,8 @@  struct ArduinoMachineState {
     MachineState parent_obj;
     /*< public >*/
     AtmegaMcuState mcu;
+
+    LEDState *onboard_led;
 };
 typedef struct ArduinoMachineState ArduinoMachineState;
 
@@ -49,6 +52,18 @@  static void arduino_machine_init(MachineState *machine)
                              amc->xtal_hz, &error_abort);
     sysbus_realize(SYS_BUS_DEVICE(&ams->mcu), &error_abort);
 
+    ams->onboard_led = led_create_simple(OBJECT(ams),
+                                         GPIO_POLARITY_ACTIVE_HIGH,
+                                         LED_COLOR_BLUE,
+                                         "D13 LED");
+
+    /* TODO: Add macro or function to map pins to ports */
+    /* The onboard led is connected to PIN 13 in all boards currently supported
+     * in QEMU. And PIN 13 is mapped to PORT B BIT 5.
+     */
+    qdev_connect_gpio_out(DEVICE(&ams->mcu.gpio[1]), 5,
+                          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)) {