/
sdcard.c
82 lines (70 loc) · 2.51 KB
/
sdcard.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* 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"
#include "drivers/dma_reqmap.h"
PG_REGISTER_WITH_RESET_FN(sdcardConfig_t, sdcardConfig, PG_SDCARD_CONFIG, 1);
void pgResetFn_sdcardConfig(sdcardConfig_t *config)
{
config->cardDetectTag = IO_TAG(SDCARD_DETECT_PIN);
config->cardDetectInverted = SDCARD_DETECT_IS_INVERTED;
// 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.
config->useDma = false;
config->device = SPI_DEV_TO_CFG(SPIINVALID);
#ifdef CONFIG_IN_SDCARD
// CONFIG_ID_SDDCARD requires a default mode.
#if defined(USE_SDCARD_SDIO)
config->mode = SDCARD_MODE_SDIO;
#elif defined(USE_SDCARD_SPI)
config->mode = SDCARD_MODE_SPI;
#endif
#else
config->mode = SDCARD_MODE_NONE;
#endif
#ifdef USE_SDCARD_SPI
// These settings do not work for Unified Targets
// They are only left in place to support legacy targets
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
#ifndef USE_DMA_SPEC
#ifdef USE_SDCARD_SPI
#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);
#endif
#endif
#endif // !USE_DMA_SPEC
}
#endif