Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/drivers/include/drivers/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
32 changes: 19 additions & 13 deletions components/drivers/spi/qspi_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

result = rt_spi_configure(&device->parent, &cfg->parent);

return result;
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;

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)
Expand Down
40 changes: 23 additions & 17 deletions components/drivers/spi/spi_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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,
Expand Down