|
|
@@ -108,14 +108,23 @@ static void spi_intr(void *arg);
|
|
|
|
|
|
esp_err_t spi_bus_initialize(spi_host_device_t host, const spi_bus_config_t *bus_config, int dma_chan)
|
|
|
{
|
|
|
- bool native, claimed;
|
|
|
+ bool native, spi_chan_claimed, dma_chan_claimed;
|
|
|
/* ToDo: remove this when we have flash operations cooperating with this */
|
|
|
SPI_CHECK(host!=SPI_HOST, "SPI1 is not supported", ESP_ERR_NOT_SUPPORTED);
|
|
|
|
|
|
SPI_CHECK(host>=SPI_HOST && host<=VSPI_HOST, "invalid host", ESP_ERR_INVALID_ARG);
|
|
|
+ SPI_CHECK( dma_chan >= 0 && dma_chan <= 2, "invalid dma channel", ESP_ERR_INVALID_ARG );
|
|
|
|
|
|
- claimed=spicommon_periph_claim(host);
|
|
|
- SPI_CHECK(claimed, "host already in use", ESP_ERR_INVALID_STATE);
|
|
|
+ spi_chan_claimed=spicommon_periph_claim(host);
|
|
|
+ SPI_CHECK(spi_chan_claimed, "host already in use", ESP_ERR_INVALID_STATE);
|
|
|
+
|
|
|
+ if ( dma_chan != 0 ) {
|
|
|
+ dma_chan_claimed=spicommon_dma_chan_claim(dma_chan);
|
|
|
+ if ( !dma_chan_claimed ) {
|
|
|
+ spicommon_periph_free( host );
|
|
|
+ SPI_CHECK(dma_chan_claimed, "dma channel already in use", ESP_ERR_INVALID_STATE);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
spihost[host]=malloc(sizeof(spi_host_t));
|
|
|
if (spihost[host]==NULL) goto nomem;
|
|
|
@@ -185,6 +194,10 @@ esp_err_t spi_bus_free(spi_host_device_t host)
|
|
|
for (x=0; x<NO_CS; x++) {
|
|
|
SPI_CHECK(spihost[host]->device[x]==NULL, "not all CSses freed", ESP_ERR_INVALID_STATE);
|
|
|
}
|
|
|
+
|
|
|
+ if ( spihost[host]->dma_chan > 0 ) {
|
|
|
+ spicommon_dma_chan_free ( spihost[host]->dma_chan );
|
|
|
+ }
|
|
|
spihost[host]->hw->slave.trans_inten=0;
|
|
|
spihost[host]->hw->slave.trans_done=0;
|
|
|
esp_intr_free(spihost[host]->intr);
|