Skip to content

Commit 74f056d

Browse files
committed
include: drivers: spi.h: Add word delay parameter to config
Add inter-word delay parameter to spi_config struct. If value is 0, the value will be half of the period. Signed-off-by: Declan Snyder <[email protected]>
1 parent e705959 commit 74f056d

File tree

1 file changed

+29
-0
lines changed
  • include/zephyr/drivers

1 file changed

+29
-0
lines changed

include/zephyr/drivers/spi.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,36 @@ struct spi_config {
458458
* if not used).
459459
*/
460460
struct spi_cs_control cs;
461+
/**
462+
* @brief Delay between SPI words on SCK line in nanoseconds, if supported.
463+
* Value of zero will attempt to use half of the SCK period.
464+
*/
465+
uint16_t word_delay;
461466
};
462467

468+
/** @cond INTERNAL_HIDDEN */
469+
/* converts from the special DT zero value to half of the frequency, for drivers usage mostly */
470+
static inline uint16_t spi_get_word_delay(const struct spi_config *cfg)
471+
{
472+
uint32_t freq = cfg->frequency;
473+
474+
if (cfg->word_delay != 0) {
475+
return cfg->word_delay;
476+
}
477+
478+
if (freq == 0) {
479+
return 0;
480+
}
481+
482+
uint64_t period_ns = NSEC_PER_SEC / freq;
483+
484+
period_ns = MIN(period_ns, UINT16_MAX);
485+
period_ns /= 2;
486+
487+
return (uint16_t)period_ns;
488+
}
489+
/** @endcond */
490+
463491
/**
464492
* @brief Structure initializer for spi_config from devicetree
465493
*
@@ -483,6 +511,7 @@ struct spi_config {
483511
COND_CODE_1(DT_PROP(node_id, spi_lsb_first), SPI_TRANSFER_LSB, (0)), \
484512
.slave = DT_REG_ADDR(node_id), \
485513
.cs = SPI_CS_CONTROL_INIT(node_id), \
514+
.word_delay = DT_PROP(node_id, spi_delay_ns), \
486515
}
487516

488517
/**

0 commit comments

Comments
 (0)