[qspi]修复qspi配置未生效问题

This commit is contained in:
yangpeng 2024-02-06 13:33:07 +08:00 committed by Meco Man
parent 0c000b403f
commit 02eaf76d7b
3 changed files with 45 additions and 30 deletions

View File

@ -181,9 +181,12 @@ rt_err_t rt_spi_bus_attach_device(struct rt_spi_device *device,
rt_err_t rt_spi_bus_attach_device_cspin(struct rt_spi_device *device,
const char *name,
const char *bus_name,
rt_base_t cs_pin,
rt_base_t cs_pin,
void *user_data);
/* re-configure SPI bus */
rt_err_t rt_spi_bus_configure(struct rt_spi_device *device);
/**
* This function takes SPI bus.
*

View File

@ -15,21 +15,27 @@ rt_err_t rt_qspi_configure(struct rt_qspi_device *device, struct rt_qspi_configu
RT_ASSERT(device != RT_NULL);
RT_ASSERT(cfg != RT_NULL);
struct rt_qspi_device *qspi_device = (struct rt_qspi_device *)device;
rt_err_t result = RT_EOK;
/* If the configurations are the same, we don't need to set again. */
if (device->config.medium_size == cfg->medium_size &&
device->config.ddr_mode == cfg->ddr_mode &&
device->config.qspi_dl_width == cfg->qspi_dl_width &&
device->config.parent.data_width == cfg->parent.data_width &&
device->config.parent.mode == (cfg->parent.mode & RT_SPI_MODE_MASK) &&
device->config.parent.max_hz == cfg->parent.max_hz)
{
return RT_EOK;
}
/* copy configuration items */
qspi_device->config.parent.mode = cfg->parent.mode;
qspi_device->config.parent.max_hz = cfg->parent.max_hz;
qspi_device->config.parent.data_width = cfg->parent.data_width;
qspi_device->config.parent.reserved = cfg->parent.reserved;
qspi_device->config.medium_size = cfg->medium_size;
qspi_device->config.ddr_mode = cfg->ddr_mode;
qspi_device->config.qspi_dl_width = cfg->qspi_dl_width;
device->config.parent.mode = cfg->parent.mode;
device->config.parent.max_hz = cfg->parent.max_hz;
device->config.parent.data_width = cfg->parent.data_width;
device->config.parent.reserved = cfg->parent.reserved;
device->config.medium_size = cfg->medium_size;
device->config.ddr_mode = cfg->ddr_mode;
device->config.qspi_dl_width = cfg->qspi_dl_width;
result = rt_spi_configure(&device->parent, &cfg->parent);
return result;
return rt_spi_bus_configure(&device->parent);
}
rt_err_t rt_qspi_bus_register(struct rt_spi_bus *bus, const char *name, const struct rt_spi_ops *ops)

View File

@ -87,26 +87,10 @@ rt_err_t rt_spi_bus_attach_device(struct rt_spi_device *device,
return rt_spi_bus_attach_device_cspin(device, name, bus_name, PIN_NONE, user_data);
}
rt_err_t rt_spi_configure(struct rt_spi_device *device,
struct rt_spi_configuration *cfg)
rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
{
rt_err_t result = -RT_ERROR;
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;
/* reset the CS pin */
if (device->cs_pin != PIN_NONE)
{
@ -144,6 +128,28 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
return result;
}
rt_err_t rt_spi_configure(struct rt_spi_device *device,
struct rt_spi_configuration *cfg)
{
RT_ASSERT(device != RT_NULL);
RT_ASSERT(cfg != 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;
return rt_spi_bus_configure(device);
}
rt_err_t rt_spi_send_then_send(struct rt_spi_device *device,
const void *send_buf1,
rt_size_t send_length1,