Skip to content

Commit 8d6e536

Browse files
committed
[spi] optimize the spi transfer speed.
If the configurations are the same, we don't need to set again.
1 parent 78ad327 commit 8d6e536

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

components/drivers/spi/spi_core.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,20 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
9494

9595
RT_ASSERT(device != RT_NULL);
9696

97+
/* If the configurations are the same, we don't need to set again. */
98+
if(device->config.data_width == cfg->data_width &&
99+
device->config.mode == (cfg->mode & RT_SPI_MODE_MASK) &&
100+
device->config.max_hz == cfg->max_hz)
101+
{
102+
return RT_EOK;
103+
}
104+
97105
/* set configuration */
98106
device->config.data_width = cfg->data_width;
99-
device->config.mode = cfg->mode & RT_SPI_MODE_MASK ;
100-
device->config.max_hz = cfg->max_hz ;
107+
device->config.mode = cfg->mode & RT_SPI_MODE_MASK;
108+
device->config.max_hz = cfg->max_hz;
101109

110+
/* reset the CS pin */
102111
if (device->cs_pin != PIN_NONE)
103112
{
104113
if (device->config.mode & RT_SPI_CS_HIGH)

0 commit comments

Comments
 (0)