update serTcpOpen declaration to fix compile errors (#14113)
[betaflight.git] / src / main / pg / sdcard.c
bloba2a201a87746eb19dfc4b070a25ff2066cae1ced
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/sdio.h"
34 #include "drivers/io.h"
35 #include "drivers/dma.h"
36 #include "drivers/dma_reqmap.h"
38 #ifdef USE_SDCARD_SPI
39 #ifndef SDCARD_SPI_INSTANCE
40 #define SDCARD_SPI_INSTANCE NULL
41 #endif
42 #ifndef SDCARD_SPI_CS_PIN
43 #define SDCARD_SPI_CS_PIN NONE
44 #endif
45 #endif // USE_SDCARD_SPI
47 #ifndef SDCARD_DETECT_PIN
48 #define SDCARD_DETECT_PIN NONE
49 #endif
51 #ifdef SDCARD_DETECT_INVERTED
52 #define SDCARD_DETECT_IS_INVERTED 1
53 #else
54 #define SDCARD_DETECT_IS_INVERTED 0
55 #endif
57 PG_REGISTER_WITH_RESET_FN(sdcardConfig_t, sdcardConfig, PG_SDCARD_CONFIG, 2);
59 void pgResetFn_sdcardConfig(sdcardConfig_t *config)
61 config->cardDetectTag = IO_TAG(SDCARD_DETECT_PIN);
62 config->cardDetectInverted = SDCARD_DETECT_IS_INVERTED;
64 // We can safely handle SPI and SDIO cases separately on custom targets, as these are exclusive per target.
65 // On generic targets, SPI has precedence over SDIO; SDIO must be post-flash configured.
66 config->device = SPI_DEV_TO_CFG(SPIINVALID);
68 #ifdef CONFIG_IN_SDCARD
69 // CONFIG_ID_SDDCARD requires a default mode.
70 #if defined(USE_SDCARD_SDIO)
71 config->mode = SDCARD_MODE_SDIO;
72 #elif defined(USE_SDCARD_SPI)
73 config->mode = SDCARD_MODE_SPI;
74 #endif
75 #else
76 config->mode = SDCARD_MODE_NONE;
77 #endif
79 #if defined(STM32H7) && defined(USE_SDCARD_SDIO) // H7 only for now, likely should be applied to F4/F7 too
80 config->mode = SDCARD_MODE_SDIO;
81 #endif
83 #ifdef USE_SDCARD_SPI
84 // These settings do not work for Unified Targets
85 // They are only left in place to support legacy targets
86 SPIDevice spidevice = spiDeviceByInstance(SDCARD_SPI_INSTANCE);
87 config->device = SPI_DEV_TO_CFG(spidevice);
88 config->chipSelectTag = IO_TAG(SDCARD_SPI_CS_PIN);
90 if (spidevice != SPIINVALID && config->chipSelectTag) {
91 config->mode = SDCARD_MODE_SPI;
93 #endif
95 #if defined(USE_SDCARD_SDIO) && defined(SDIO_DEVICE)
96 if (SDIO_DEVICE != SDIOINVALID) {
97 config->mode = SDCARD_MODE_SDIO;
99 #endif
101 #endif