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)
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/>.
28 #include "drivers/io.h"
29 #include "drivers/resource.h"
30 #include "drivers/system.h"
32 #include "drivers/flash.h"
33 #include "drivers/max7456.h"
34 #include "drivers/rx/rx_spi.h"
35 #include "drivers/sdcard.h"
38 #include "pg/max7456.h"
39 #include "pg/rx_spi.h"
40 #include "pg/sdcard.h"
42 typedef struct spiPreinit_s
{
48 static spiPreinit_t spiPreinitArray
[SPI_PREINIT_COUNT
];
49 static int spiPreinitCount
= 0;
51 void spiPreinitRegister(ioTag_t iotag
, uint8_t iocfg
, bool init
)
57 if (spiPreinitCount
== SPI_PREINIT_COUNT
) {
58 indicateFailure(FAILURE_DEVELOPER
, 5);
62 spiPreinitArray
[spiPreinitCount
].iotag
= iotag
;
63 spiPreinitArray
[spiPreinitCount
].iocfg
= iocfg
;
64 spiPreinitArray
[spiPreinitCount
].init
= init
;
68 static void spiPreinitPin(spiPreinit_t
*preinit
, int index
)
70 IO_t io
= IOGetByTag(preinit
->iotag
);
71 IOInit(io
, OWNER_PREINIT
, RESOURCE_INDEX(index
));
72 IOConfigGPIO(io
, preinit
->iocfg
);
83 sdcard_preInit(sdcardConfig());
86 #if defined(RTC6705_CS_PIN) && !defined(USE_VTX_RTC6705_SOFTSPI) // RTC6705 soft SPI initialisation handled elsewhere.
87 // XXX Waiting for "RTC6705 cleanup #7114" to be done
91 flashPreInit(flashConfig());
94 #if defined(USE_RX_SPI)
95 rxSpiDevicePreInit(rxSpiConfig());
99 max7456PreInit(max7456Config());
102 for (int i
= 0; i
< spiPreinitCount
; i
++) {
103 spiPreinitPin(&spiPreinitArray
[i
], i
);
107 void spiPreinitByIO(IO_t io
)
109 for (int i
= 0; i
< spiPreinitCount
; i
++) {
110 if (io
== IOGetByTag(spiPreinitArray
[i
].iotag
)) {
111 spiPreinitPin(&spiPreinitArray
[i
], i
);
117 void spiPreinitByTag(ioTag_t tag
)
119 spiPreinitByIO(IOGetByTag(tag
));