Create release.yml
[betaflight.git] / src / main / pg / bus_spi.c
blob72c3726d5c5d6ba692a254667ee4f3d4008490d9
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 "platform.h"
23 #ifdef USE_SPI
25 #include "drivers/dma_reqmap.h"
26 #include "drivers/io.h"
28 #include "pg/bus_spi.h"
29 #include "pg/pg.h"
30 #include "pg/pg_ids.h"
32 #include "bus_spi.h"
34 typedef struct spiDefaultConfig_s {
35 SPIDevice device;
36 ioTag_t sck;
37 ioTag_t miso;
38 ioTag_t mosi;
39 dmaoptValue_t txDmaopt;
40 dmaoptValue_t rxDmaopt;
41 } spiDefaultConfig_t;
43 const spiDefaultConfig_t spiDefaultConfig[] = {
44 #ifdef USE_SPI_DEVICE_1
45 { SPIDEV_1, IO_TAG(SPI1_SCK_PIN), IO_TAG(SPI1_MISO_PIN), IO_TAG(SPI1_MOSI_PIN), SPI1_TX_DMA_OPT, SPI1_RX_DMA_OPT },
46 #endif
47 #ifdef USE_SPI_DEVICE_2
48 { SPIDEV_2, IO_TAG(SPI2_SCK_PIN), IO_TAG(SPI2_MISO_PIN), IO_TAG(SPI2_MOSI_PIN), SPI2_TX_DMA_OPT, SPI2_RX_DMA_OPT },
49 #endif
50 #ifdef USE_SPI_DEVICE_3
51 { SPIDEV_3, IO_TAG(SPI3_SCK_PIN), IO_TAG(SPI3_MISO_PIN), IO_TAG(SPI3_MOSI_PIN), SPI3_TX_DMA_OPT, SPI3_RX_DMA_OPT },
52 #endif
53 #ifdef USE_SPI_DEVICE_4
54 { SPIDEV_4, IO_TAG(SPI4_SCK_PIN), IO_TAG(SPI4_MISO_PIN), IO_TAG(SPI4_MOSI_PIN), SPI4_TX_DMA_OPT, SPI4_RX_DMA_OPT },
55 #endif
56 #ifdef USE_SPI_DEVICE_5
57 { SPIDEV_5, IO_TAG(SPI5_SCK_PIN), IO_TAG(SPI5_MISO_PIN), IO_TAG(SPI5_MOSI_PIN), SPI5_TX_DMA_OPT, SPI5_RX_DMA_OPT },
58 #endif
59 #ifdef USE_SPI_DEVICE_6
60 { SPIDEV_6, IO_TAG(SPI6_SCK_PIN), IO_TAG(SPI6_MISO_PIN), IO_TAG(SPI6_MOSI_PIN), SPI6_TX_DMA_OPT, SPI6_RX_DMA_OPT },
61 #endif
64 PG_REGISTER_ARRAY_WITH_RESET_FN(spiPinConfig_t, SPIDEV_COUNT, spiPinConfig, PG_SPI_PIN_CONFIG, 1);
66 void pgResetFn_spiPinConfig(spiPinConfig_t *spiPinConfig)
68 for (size_t i = 0; i < SPIDEV_COUNT; i++) {
69 spiPinConfig[i].txDmaopt = -1;
70 spiPinConfig[i].rxDmaopt = -1;
73 for (size_t i = 0 ; i < ARRAYLEN(spiDefaultConfig) ; i++) {
74 const spiDefaultConfig_t *defconf = &spiDefaultConfig[i];
75 spiPinConfig[defconf->device].ioTagSck = defconf->sck;
76 spiPinConfig[defconf->device].ioTagMiso = defconf->miso;
77 spiPinConfig[defconf->device].ioTagMosi = defconf->mosi;
78 spiPinConfig[defconf->device].txDmaopt = defconf->txDmaopt;
79 spiPinConfig[defconf->device].rxDmaopt = defconf->rxDmaopt;
82 #endif