Create release.yml
[betaflight.git] / src / main / pg / sdcard.c
blobc19b71ee81f97cb1610df9f0b7a250bebf066cb5
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
24 #include "platform.h"
26 #ifdef USE_SDCARD
28 #include "pg/pg.h"
29 #include "pg/pg_ids.h"
31 #include "sdcard.h"
32 #include "drivers/bus_spi.h"
33 #include "drivers/io.h"
34 #include "drivers/dma.h"
35 #include "drivers/dma_reqmap.h"
37 PG_REGISTER_WITH_RESET_FN(sdcardConfig_t, sdcardConfig, PG_SDCARD_CONFIG, 2);
39 void pgResetFn_sdcardConfig(sdcardConfig_t *config)
41 config->cardDetectTag = IO_TAG(SDCARD_DETECT_PIN);
42 config->cardDetectInverted = SDCARD_DETECT_IS_INVERTED;
44 // We can safely handle SPI and SDIO cases separately on custom targets, as these are exclusive per target.
45 // On generic targets, SPI has precedence over SDIO; SDIO must be post-flash configured.
46 config->device = SPI_DEV_TO_CFG(SPIINVALID);
48 #ifdef CONFIG_IN_SDCARD
49 // CONFIG_ID_SDDCARD requires a default mode.
50 #if defined(USE_SDCARD_SDIO)
51 config->mode = SDCARD_MODE_SDIO;
52 #elif defined(USE_SDCARD_SPI)
53 config->mode = SDCARD_MODE_SPI;
54 #endif
55 #else
56 config->mode = SDCARD_MODE_NONE;
57 #endif
59 #if defined(STM32H7) && defined(USE_SDCARD_SDIO) // H7 only for now, likely should be applied to F4/F7 too
60 config->mode = SDCARD_MODE_SDIO;
61 #endif
63 #ifdef USE_SDCARD_SPI
64 // These settings do not work for Unified Targets
65 // They are only left in place to support legacy targets
66 SPIDevice spidevice = spiDeviceByInstance(SDCARD_SPI_INSTANCE);
67 config->device = SPI_DEV_TO_CFG(spidevice);
68 config->chipSelectTag = IO_TAG(SDCARD_SPI_CS_PIN);
70 if (spidevice != SPIINVALID && config->chipSelectTag) {
71 config->mode = SDCARD_MODE_SPI;
73 #endif
75 #endif