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 <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2023-07-12 12:05:05 +02:00 committed by Carles Cufí
parent 8ce048b8e1
commit 2c3165d187

View file

@ -268,6 +268,16 @@ struct spi_cs_control {
#define SPI_CS_CONTROL_INIT_INST(inst, delay_) \ #define SPI_CS_CONTROL_INIT_INST(inst, delay_) \
SPI_CS_CONTROL_INIT(DT_DRV_INST(inst), delay_) SPI_CS_CONTROL_INIT(DT_DRV_INST(inst), delay_)
/**
* @typedef spi_operation_t
* Opaque type to hold the SPI operation flags.
*/
#if defined(CONFIG_SPI_EXTENDED_MODES)
typedef uint32_t spi_operation_t;
#else
typedef uint16_t spi_operation_t;
#endif
/** /**
* @brief SPI controller configuration structure * @brief SPI controller configuration structure
* *
@ -296,15 +306,8 @@ struct spi_cs_control {
*/ */
struct spi_config { struct spi_config {
uint32_t frequency; uint32_t frequency;
#if defined(CONFIG_SPI_EXTENDED_MODES) spi_operation_t operation;
uint32_t operation;
uint16_t slave; uint16_t slave;
uint16_t _unused;
#else
uint16_t operation;
uint16_t slave;
#endif /* CONFIG_SPI_EXTENDED_MODES */
struct spi_cs_control cs; struct spi_cs_control cs;
}; };