[RFC PREVIEW 2/4] hw: gpio: Move the pcf8574 struct to header

7 views
Skip to first unread message

chenmiao

unread,
Oct 23, 2025, 1:22:17 PMOct 23
to chao...@openatom.club, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com
To better implement the Rust PCF8574 bindings, move its struct definition to
the header file.

Signed-off-by: chenmiao <chen...@openatom.club>
---
hw/gpio/pcf8574.c | 32 --------------------------------
include/hw/gpio/pcf8574.h | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/hw/gpio/pcf8574.c b/hw/gpio/pcf8574.c
index 274b44b..670fc00 100644
--- a/hw/gpio/pcf8574.c
+++ b/hw/gpio/pcf8574.c
@@ -15,38 +15,6 @@
#include "qemu/module.h"
#include "qom/object.h"

-/*
- * PCF8574 and compatible chips incorporate quasi-bidirectional
- * IO. Electrically it means that device sustain pull-up to line
- * unless IO port is configured as output _and_ driven low.
- *
- * IO access is implemented as simple I2C single-byte read
- * or write operation. So, to configure line to input user write 1
- * to corresponding bit. To configure line to output and drive it low
- * user write 0 to corresponding bit.
- *
- * In essence, user can think of quasi-bidirectional IO as
- * open-drain line, except presence of builtin rising edge acceleration
- * embedded in PCF8574 IC
- *
- * PCF8574 has interrupt request line, which is being pulled down when
- * port line state differs from last read. Port read operation clears
- * state and INT line returns to high state via pullup.
- */
-
-OBJECT_DECLARE_SIMPLE_TYPE(PCF8574State, PCF8574)
-
-#define PORTS_COUNT (8)
-
-struct PCF8574State {
- I2CSlave parent_obj;
- uint8_t lastrq; /* Last requested state. If changed - assert irq */
- uint8_t input; /* external electrical line state */
- uint8_t output; /* Pull-up (1) or drive low (0) on bit */
- qemu_irq handler[PORTS_COUNT];
- qemu_irq intrq; /* External irq request */
-};
-
static void pcf8574_reset(DeviceState *dev)
{
PCF8574State *s = PCF8574(dev);
diff --git a/include/hw/gpio/pcf8574.h b/include/hw/gpio/pcf8574.h
index 3291d7d..fe1ce89 100644
--- a/include/hw/gpio/pcf8574.h
+++ b/include/hw/gpio/pcf8574.h
@@ -10,6 +10,42 @@
#ifndef _HW_GPIO_PCF8574
#define _HW_GPIO_PCF8574

+#include "qemu/osdep.h"
+#include "hw/i2c/i2c.h"
+#include "qom/object.h"
+
#define TYPE_PCF8574 "pcf8574"

+/*
+ * PCF8574 and compatible chips incorporate quasi-bidirectional
+ * IO. Electrically it means that device sustain pull-up to line
+ * unless IO port is configured as output _and_ driven low.
+ *
+ * IO access is implemented as simple I2C single-byte read
+ * or write operation. So, to configure line to input user write 1
+ * to corresponding bit. To configure line to output and drive it low
+ * user write 0 to corresponding bit.
+ *
+ * In essence, user can think of quasi-bidirectional IO as
+ * open-drain line, except presence of builtin rising edge acceleration
+ * embedded in PCF8574 IC
+ *
+ * PCF8574 has interrupt request line, which is being pulled down when
+ * port line state differs from last read. Port read operation clears
+ * state and INT line returns to high state via pullup.
+ */
+
+OBJECT_DECLARE_SIMPLE_TYPE(PCF8574State, PCF8574)
+
+#define PORTS_COUNT (8)
+
+struct PCF8574State {
+ I2CSlave parent_obj;
+ uint8_t lastrq; /* Last requested state. If changed - assert irq */
+ uint8_t input; /* external electrical line state */
+ uint8_t output; /* Pull-up (1) or drive low (0) on bit */
+ qemu_irq handler[PORTS_COUNT];
+ qemu_irq intrq; /* External irq request */
+};
+
#endif /* _HW_GPIO_PCF8574 */
--
2.43.0

chenmiao

unread,
Oct 23, 2025, 9:41:20 PMOct 23
to chao...@openatom.club, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com

Chao Liu

unread,
Oct 23, 2025, 10:58:25 PMOct 23
to chenmiao, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com
On 10/24/2025 9:41 AM, chenmiao wrote:
> To better implement the Rust PCF8574 bindings, move its struct definition to
> the header file.
>

Reviewed-by: Chao Liu <chao...@openatom.club>

chenmiao

unread,
Oct 24, 2025, 3:51:57 AMOct 24
to chao...@openatom.club, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com
To better implement the Rust PCF8574 bindings, move its struct definition to
the header file.

--
2.43.0

Chao Liu

unread,
Oct 24, 2025, 7:23:22 AMOct 24
to chenmiao, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com
Reviewed-by: Chao Liu <chao...@openatom.club>

chenmiao

unread,
Oct 25, 2025, 8:39:07 AMOct 25
to pbon...@redhat.com, manos.pit...@linaro.org, richard....@linaro.org, phi...@linaro.org, qemu...@nongnu.org, qemu-...@nongnu.org, hust-os-ker...@googlegroups.com
--
2.43.0
Reply all
Reply to author
Forward
0 new messages