Skip to content

Commit 2c3165d

Browse files
gmarullcarlescufi
authored andcommitted
drivers: spi: add opaque type to encode SPI operation flags
Since flags can use either 16/32-bit depending on CONFIG_SPI_EXTENDED_MODES, add a new opaque type that uses the correct bit-width depending on that option. This allows us to simplify the structure layout. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 8ce048b commit 2c3165d

File tree

1 file changed

+11
-8
lines changed
  • include/zephyr/drivers

1 file changed

+11
-8
lines changed

include/zephyr/drivers/spi.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,16 @@ struct spi_cs_control {
268268
#define SPI_CS_CONTROL_INIT_INST(inst, delay_) \
269269
SPI_CS_CONTROL_INIT(DT_DRV_INST(inst), delay_)
270270

271+
/**
272+
* @typedef spi_operation_t
273+
* Opaque type to hold the SPI operation flags.
274+
*/
275+
#if defined(CONFIG_SPI_EXTENDED_MODES)
276+
typedef uint32_t spi_operation_t;
277+
#else
278+
typedef uint16_t spi_operation_t;
279+
#endif
280+
271281
/**
272282
* @brief SPI controller configuration structure
273283
*
@@ -296,15 +306,8 @@ struct spi_cs_control {
296306
*/
297307
struct spi_config {
298308
uint32_t frequency;
299-
#if defined(CONFIG_SPI_EXTENDED_MODES)
300-
uint32_t operation;
309+
spi_operation_t operation;
301310
uint16_t slave;
302-
uint16_t _unused;
303-
#else
304-
uint16_t operation;
305-
uint16_t slave;
306-
#endif /* CONFIG_SPI_EXTENDED_MODES */
307-
308311
struct spi_cs_control cs;
309312
};
310313

0 commit comments

Comments
 (0)