mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 04:04:31 +02:00
Merge branch 'bugfix/spi_master_const_dev_config_t' into 'master'
spi master: use constant dev_config parameter in spi_bus_add_device See merge request idf/esp-idf!2082
This commit is contained in:
@@ -160,7 +160,7 @@ esp_err_t spi_bus_free(spi_host_device_t host);
|
|||||||
* - ESP_ERR_NO_MEM if out of memory
|
* - ESP_ERR_NO_MEM if out of memory
|
||||||
* - ESP_OK on success
|
* - ESP_OK on success
|
||||||
*/
|
*/
|
||||||
esp_err_t spi_bus_add_device(spi_host_device_t host, spi_device_interface_config_t *dev_config, spi_device_handle_t *handle);
|
esp_err_t spi_bus_add_device(spi_host_device_t host, const spi_device_interface_config_t *dev_config, spi_device_handle_t *handle);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -242,7 +242,7 @@ esp_err_t spi_bus_free(spi_host_device_t host)
|
|||||||
Add a device. This allocates a CS line for the device, allocates memory for the device structure and hooks
|
Add a device. This allocates a CS line for the device, allocates memory for the device structure and hooks
|
||||||
up the CS pin to whatever is specified.
|
up the CS pin to whatever is specified.
|
||||||
*/
|
*/
|
||||||
esp_err_t spi_bus_add_device(spi_host_device_t host, spi_device_interface_config_t *dev_config, spi_device_handle_t *handle)
|
esp_err_t spi_bus_add_device(spi_host_device_t host, const spi_device_interface_config_t *dev_config, spi_device_handle_t *handle)
|
||||||
{
|
{
|
||||||
int freecs;
|
int freecs;
|
||||||
int apbclk=APB_CLK_FREQ;
|
int apbclk=APB_CLK_FREQ;
|
||||||
@@ -271,14 +271,14 @@ esp_err_t spi_bus_add_device(spi_host_device_t host, spi_device_interface_config
|
|||||||
//Allocate queues, set defaults
|
//Allocate queues, set defaults
|
||||||
dev->trans_queue=xQueueCreate(dev_config->queue_size, sizeof(spi_trans_priv));
|
dev->trans_queue=xQueueCreate(dev_config->queue_size, sizeof(spi_trans_priv));
|
||||||
dev->ret_queue=xQueueCreate(dev_config->queue_size, sizeof(spi_trans_priv));
|
dev->ret_queue=xQueueCreate(dev_config->queue_size, sizeof(spi_trans_priv));
|
||||||
if (!dev->trans_queue || !dev->ret_queue) goto nomem;
|
if (!dev->trans_queue || !dev->ret_queue) goto nomem;
|
||||||
if (dev_config->duty_cycle_pos==0) dev_config->duty_cycle_pos=128;
|
|
||||||
dev->host=spihost[host];
|
dev->host=spihost[host];
|
||||||
|
|
||||||
//We want to save a copy of the dev config in the dev struct.
|
//We want to save a copy of the dev config in the dev struct.
|
||||||
memcpy(&dev->cfg, dev_config, sizeof(spi_device_interface_config_t));
|
memcpy(&dev->cfg, dev_config, sizeof(spi_device_interface_config_t));
|
||||||
|
if (dev->cfg.duty_cycle_pos==0) dev->cfg.duty_cycle_pos=128;
|
||||||
// TODO: if we have to change the apb clock among transactions, re-calculate this each time the apb clock lock is acquired.
|
// TODO: if we have to change the apb clock among transactions, re-calculate this each time the apb clock lock is acquired.
|
||||||
dev->clk_cfg.eff_clk = spi_cal_clock(apbclk, dev_config->clock_speed_hz, dev_config->duty_cycle_pos, (uint32_t*)&dev->clk_cfg.reg);
|
dev->clk_cfg.eff_clk = spi_cal_clock(apbclk, dev->cfg.clock_speed_hz, dev->cfg.duty_cycle_pos, (uint32_t*)&dev->clk_cfg.reg);
|
||||||
|
|
||||||
//Set CS pin, CS options
|
//Set CS pin, CS options
|
||||||
if (dev_config->spics_io_num >= 0) {
|
if (dev_config->spics_io_num >= 0) {
|
||||||
|
Reference in New Issue
Block a user