diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-15 11:58:59 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-19 20:15:16 -0700 |
commit | 936fd0145896acbf55de496f036af55a01b80e82 (patch) | |
tree | a81cfff1fe552a184d614e7a0639583f0a8f8252 /libhw_generic/include/libhw/generic/spi.h | |
parent | 573b0f7d4d4a7e84ae8d1e4a7c0611dd9f513fa2 (diff) |
libhw_generic: Split into a separate library
Diffstat (limited to 'libhw_generic/include/libhw/generic/spi.h')
-rw-r--r-- | libhw_generic/include/libhw/generic/spi.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/libhw_generic/include/libhw/generic/spi.h b/libhw_generic/include/libhw/generic/spi.h new file mode 100644 index 0000000..2207a2c --- /dev/null +++ b/libhw_generic/include/libhw/generic/spi.h @@ -0,0 +1,47 @@ +/* libhw/generic/spi.h - Device-independent SPI definitions + * + * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#ifndef _LIBHW_GENERIC_SPI_H_ +#define _LIBHW_GENERIC_SPI_H_ + +#include <stddef.h> /* for size_t */ + +enum spi_mode { + SPI_MODE_0 = 0, /* clk_polarity=0 (idle low), clk_phase=0 (sample on rise) */ + SPI_MODE_1 = 1, /* clk_polarity=0 (idle low), clk_phase=1 (sample on fall) */ + SPI_MODE_2 = 2, /* clk_polarity=1 (idle high), clk_phase=0 (sample on rise) */ + 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; +}; + +struct spi_vtable; + +typedef struct { + struct spi_vtable *vtable; +} implements_spi; + +/* 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 + * hardware, and that the RP2040 is somewhat unusual in that it allows + * frames of any length 4-16 bits (we disconnect the CS pin from the + * PL022 SSP and manually GPIO it from the CPU in order to achieve + * longer frames). + * + * But, more relevantly: The W5500's protocol uses frames that are 4-N + * octets; so we have no need for an API that allows a + * non-multiple-of-8 number of bits. + */ +struct spi_vtable { + void (*readwritev)(implements_spi *, const struct bidi_iovec *iov, int iovcnt); +}; + +#endif /* _LIBHW_GENERIC_SPI_H_ */ |