summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2023-06-10 15:21:17 -0400
committerMan, Jianting (Meco) <[email protected]>2023-06-10 18:59:23 -0400
commit8d6e536e88bd85ff5698b692c2e616b56863e6dd (patch)
tree0d7a941d5b80de432e10ff0db761e5beacce1550 /components/drivers
parent78ad327ff1e712ebe41c064ec660fdd061e929d5 (diff)
[spi] optimize the spi transfer speed.
If the configurations are the same, we don't need to set again.
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/spi/spi_core.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/components/drivers/spi/spi_core.c b/components/drivers/spi/spi_core.c
index 994faa4bf4..3209a54db9 100644
--- a/components/drivers/spi/spi_core.c
+++ b/components/drivers/spi/spi_core.c
@@ -94,11 +94,20 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
RT_ASSERT(device != RT_NULL);
+ /* If the configurations are the same, we don't need to set again. */
+ if(device->config.data_width == cfg->data_width &&
+ device->config.mode == (cfg->mode & RT_SPI_MODE_MASK) &&
+ device->config.max_hz == cfg->max_hz)
+ {
+ return RT_EOK;
+ }
+
/* set configuration */
device->config.data_width = cfg->data_width;
- device->config.mode = cfg->mode & RT_SPI_MODE_MASK ;
- device->config.max_hz = cfg->max_hz ;
+ device->config.mode = cfg->mode & RT_SPI_MODE_MASK;
+ device->config.max_hz = cfg->max_hz;
+ /* reset the CS pin */
if (device->cs_pin != PIN_NONE)
{
if (device->config.mode & RT_SPI_CS_HIGH)