diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-02-23 09:24:31 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-25 18:36:39 -0600 |
commit | 654b1940705197f22ffeebd73e62cea2282bdbda (patch) | |
tree | 6e912d5d76d2d660d80cdee1e2217ed72af0063d | |
parent | 188ac62a0c0f5519f5d45519fa7d224cb25305c6 (diff) |
Pull iovec definitions out into libhw/generic/io.h
-rw-r--r-- | libhw/rp2040_hwspi.c | 4 | ||||
-rw-r--r-- | libhw/w5500_ll.h | 4 | ||||
-rw-r--r-- | libhw_generic/include/libhw/generic/io.h | 29 | ||||
-rw-r--r-- | libhw_generic/include/libhw/generic/net.h | 10 | ||||
-rw-r--r-- | libhw_generic/include/libhw/generic/spi.h | 9 |
5 files changed, 36 insertions, 20 deletions
diff --git a/libhw/rp2040_hwspi.c b/libhw/rp2040_hwspi.c index 23f3e8c..c60d6b9 100644 --- a/libhw/rp2040_hwspi.c +++ b/libhw/rp2040_hwspi.c @@ -83,7 +83,7 @@ void _rp2040_hwspi_init(struct rp2040_hwspi *self, self->pin_cs = pin_cs; } -static void rp2040_hwspi_readwritev(struct rp2040_hwspi *self, const struct bidi_iovec *iov, int iovcnt) { +static void rp2040_hwspi_readwritev(struct rp2040_hwspi *self, const struct duplex_iovec *iov, int iovcnt) { assert(self); spi_inst_t *inst = self->inst; @@ -101,7 +101,7 @@ static void rp2040_hwspi_readwritev(struct rp2040_hwspi *self, const struct bidi else if (iov[i].iov_read_dst) spi_read_blocking(inst, 0, iov[i].iov_read_dst, iov[i].iov_len); else - assert_notreached("bidi_iovec is neither read nor write"); + assert_notreached("duplex_iovec is neither read nor write"); } gpio_put(self->pin_cs, 1); } diff --git a/libhw/w5500_ll.h b/libhw/w5500_ll.h index 92d9f14..2b89353 100644 --- a/libhw/w5500_ll.h +++ b/libhw/w5500_ll.h @@ -89,7 +89,7 @@ w5500ll_write( (uint8_t)(addr & 0xFF), (block & CTL_MASK_BLOCK) | CTL_W | CTL_OM_VDM, }; - struct bidi_iovec iov[] = { + struct duplex_iovec iov[] = { {.iov_read_dst = NULL, .iov_write_src = header, .iov_len = sizeof(header)}, {.iov_read_dst = NULL, .iov_write_src = data, .iov_len = data_len}, }; @@ -119,7 +119,7 @@ w5500ll_read( (uint8_t)(addr & 0xFF), (block & CTL_MASK_BLOCK) | CTL_R | CTL_OM_VDM, }; - struct bidi_iovec iov[] = { + struct duplex_iovec iov[] = { {.iov_read_dst = NULL, .iov_write_src = header, .iov_len = sizeof(header)}, {.iov_read_dst = data, .iov_write_src = NULL, .iov_len = data_len}, }; diff --git a/libhw_generic/include/libhw/generic/io.h b/libhw_generic/include/libhw/generic/io.h new file mode 100644 index 0000000..681c5ef --- /dev/null +++ b/libhw_generic/include/libhw/generic/io.h @@ -0,0 +1,29 @@ +/* libhw/generic/io.h - Device-independent I/O definitions + * + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#ifndef _LIBHW_GENERIC_IO_H_ +#define _LIBHW_GENERIC_IO_H_ + +#include <stddef.h> /* for size_t */ + +/* structs ********************************************************************/ + +#if __unix__ +#include <sys/uio.h> +#else +struct iovec { + void *iov_base; + size_t iov_len; +}; +#endif + +struct duplex_iovec { + void *iov_read_dst; + void *iov_write_src; + size_t iov_len; +}; + +#endif /* _LIBHW_GENERIC_IO_H_ */ diff --git a/libhw_generic/include/libhw/generic/net.h b/libhw_generic/include/libhw/generic/net.h index 8d81573..0386e12 100644 --- a/libhw_generic/include/libhw/generic/net.h +++ b/libhw_generic/include/libhw/generic/net.h @@ -13,16 +13,8 @@ #include <stdint.h> /* for uint{n}_t} */ #include <sys/types.h> /* for ssize_t */ -#if __unix__ -#include <sys/uio.h> -#else -struct iovec { - void *iov_base; - size_t iov_len; -}; -#endif - #include <libobj/obj.h> +#include <libhw/generic/io.h> /* Errnos *********************************************************************/ diff --git a/libhw_generic/include/libhw/generic/spi.h b/libhw_generic/include/libhw/generic/spi.h index aeeca37..c97232a 100644 --- a/libhw_generic/include/libhw/generic/spi.h +++ b/libhw_generic/include/libhw/generic/spi.h @@ -10,6 +10,7 @@ #include <stddef.h> /* for size_t */ #include <libobj/obj.h> +#include <libhw/generic/io.h> enum spi_mode { SPI_MODE_0 = 0, /* clk_polarity=0 (idle low), clk_phase=0 (sample on rise) */ @@ -18,12 +19,6 @@ enum spi_mode { SPI_MODE_3 = 3, /* clk_polarity=1 (idle high), clk_phase=1 (sample on fall) */ }; -struct bidi_iovec { - void *iov_read_dst; - void *iov_write_src; - size_t iov_len; -}; - /* This API assumes that an SPI frame is a multiple of 8-bits. * * It is my understanding that this is a common constraint of SPI @@ -37,7 +32,7 @@ struct bidi_iovec { * non-multiple-of-8 number of bits. */ #define spi_LO_IFACE \ - LO_FUNC(void, readwritev, const struct bidi_iovec *iov, int iovcnt) + LO_FUNC(void, readwritev, const struct duplex_iovec *iov, int iovcnt) LO_INTERFACE(spi) #endif /* _LIBHW_GENERIC_SPI_H_ */ |