|
|
@@ -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
|
|
|
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 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
|
|
|
dev->trans_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_config->duty_cycle_pos==0) dev_config->duty_cycle_pos=128;
|
|
|
+ if (!dev->trans_queue || !dev->ret_queue) goto nomem;
|
|
|
dev->host=spihost[host];
|
|
|
|
|
|
//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));
|
|
|
+ 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.
|
|
|
- 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
|
|
|
if (dev_config->spics_io_num >= 0) {
|