-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathesp32_gpio.c
96 lines (79 loc) · 2.25 KB
/
esp32_gpio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* ESP32 GPIO emulation
*
* Copyright (c) 2019 Espressif Systems (Shanghai) Co. Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 or
* (at your option) any later version.
*/
#include "qemu/osdep.h"
#include "qemu/log.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
#include "hw/hw.h"
#include "hw/sysbus.h"
#include "hw/registerfields.h"
#include "hw/irq.h"
#include "hw/qdev-properties.h"
#include "hw/gpio/esp32_gpio.h"
static uint64_t esp32_gpio_read(void *opaque, hwaddr addr, unsigned int size)
{
Esp32GpioState *s = ESP32_GPIO(opaque);
uint64_t r = 0;
switch (addr) {
case A_GPIO_STRAP:
r = s->strap_mode;
break;
default:
break;
}
return r;
}
static void esp32_gpio_write(void *opaque, hwaddr addr,
uint64_t value, unsigned int size)
{
}
static const MemoryRegionOps uart_ops = {
.read = esp32_gpio_read,
.write = esp32_gpio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
};
static void esp32_gpio_reset(DeviceState *dev)
{
}
static void esp32_gpio_realize(DeviceState *dev, Error **errp)
{
}
static void esp32_gpio_init(Object *obj)
{
Esp32GpioState *s = ESP32_GPIO(obj);
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
memory_region_init_io(&s->iomem, obj, &uart_ops, s,
TYPE_ESP32_GPIO, 0x1000);
sysbus_init_mmio(sbd, &s->iomem);
sysbus_init_irq(sbd, &s->irq);
}
static Property esp32_gpio_properties[] = {
DEFINE_PROP_UINT32("strap_mode", Esp32GpioState, strap_mode, ESP32_STRAP_MODE_FLASH_BOOT),
DEFINE_PROP_END_OF_LIST(),
};
static void esp32_gpio_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
dc->reset = esp32_gpio_reset;
dc->realize = esp32_gpio_realize;
device_class_set_props(dc, esp32_gpio_properties);
}
static const TypeInfo esp32_gpio_info = {
.name = TYPE_ESP32_GPIO,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(Esp32GpioState),
.instance_init = esp32_gpio_init,
.class_init = esp32_gpio_class_init
};
static void esp32_gpio_register_types(void)
{
type_register_static(&esp32_gpio_info);
}
type_init(esp32_gpio_register_types)