mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
77 lines
2.3 KiB
C
77 lines
2.3 KiB
C
/*
|
|
* This file is part of Cleanflight and Betaflight.
|
|
*
|
|
* Cleanflight and Betaflight are free software. You can redistribute
|
|
* this software and/or modify this software under the terms of the
|
|
* GNU General Public License as published by the Free Software
|
|
* Foundation, either version 3 of the License, or (at your option)
|
|
* any later version.
|
|
*
|
|
* Cleanflight and Betaflight are distributed in the hope that they
|
|
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this software.
|
|
*
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#include "platform.h"
|
|
|
|
#ifdef USE_SDCARD
|
|
|
|
#include "pg/pg.h"
|
|
#include "pg/pg_ids.h"
|
|
|
|
#include "sdcard.h"
|
|
#include "drivers/bus_spi.h"
|
|
#include "drivers/io.h"
|
|
#include "drivers/dma.h"
|
|
|
|
PG_REGISTER_WITH_RESET_FN(sdcardConfig_t, sdcardConfig, PG_SDCARD_CONFIG, 1);
|
|
|
|
void pgResetFn_sdcardConfig(sdcardConfig_t *config)
|
|
{
|
|
config->useDma = false;
|
|
config->device = SPI_DEV_TO_CFG(SPIINVALID);
|
|
config->mode = SDCARD_MODE_NONE;
|
|
|
|
// We can safely handle SPI and SDIO cases separately on custom targets, as these are exclusive per target.
|
|
// On generic targets, SPI has precedence over SDIO; SDIO must be post-flash configured.
|
|
|
|
#ifdef USE_SDCARD_SDIO
|
|
config->mode = SDCARD_MODE_SDIO;
|
|
#endif
|
|
|
|
#ifdef USE_SDCARD_SPI
|
|
SPIDevice spidevice = spiDeviceByInstance(SDCARD_SPI_INSTANCE);
|
|
config->device = SPI_DEV_TO_CFG(spidevice);
|
|
config->chipSelectTag = IO_TAG(SDCARD_SPI_CS_PIN);
|
|
|
|
if (spidevice != SPIINVALID && config->chipSelectTag) {
|
|
config->mode = SDCARD_MODE_SPI;
|
|
}
|
|
#endif
|
|
|
|
config->cardDetectTag = IO_TAG(SDCARD_DETECT_PIN);
|
|
config->cardDetectInverted = SDCARD_DETECT_IS_INVERTED;
|
|
|
|
#if defined(SDCARD_DMA_STREAM_TX_FULL)
|
|
config->dmaIdentifier = (uint8_t)dmaGetIdentifier(SDCARD_DMA_STREAM_TX_FULL);
|
|
#elif defined(SDCARD_DMA_CHANNEL_TX)
|
|
config->dmaIdentifier = (uint8_t)dmaGetIdentifier(SDCARD_DMA_CHANNEL_TX);
|
|
#elif defined(SDIO_DMA)
|
|
config->dmaIdentifier = (uint8_t)dmaGetIdentifier(SDIO_DMA);
|
|
config->useDma = true;
|
|
#endif
|
|
|
|
#if defined(SDCARD_DMA_CHANNEL)
|
|
config->dmaChannel = SDCARD_DMA_CHANNEL;
|
|
#endif
|
|
}
|
|
#endif
|