[spi] optimize the spi transfer speed.

If the configurations are the same, we don't need to set again.
This commit is contained in:
Meco Man 2023-06-10 15:21:17 -04:00 committed by Man, Jianting (Meco)
parent 78ad327ff1
commit 8d6e536e88
1 changed files with 11 additions and 2 deletions

View File

@ -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)