update serTcpOpen declaration to fix compile errors (#14113)
[betaflight.git] / src / main / pg / bus_spi.c
blob1a24e9a5b7ad6b13bbd7c222e62aabdbfb0d07cf
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 #ifndef SPI1_SCK_PIN
35 #define SPI1_SCK_PIN NONE
36 #define SPI1_SDI_PIN NONE
37 #define SPI1_SDO_PIN NONE
38 #endif
40 #ifndef SPI2_SCK_PIN
41 #define SPI2_SCK_PIN NONE
42 #define SPI2_SDI_PIN NONE
43 #define SPI2_SDO_PIN NONE
44 #endif
46 #ifndef SPI3_SCK_PIN
47 #define SPI3_SCK_PIN NONE
48 #define SPI3_SDI_PIN NONE
49 #define SPI3_SDO_PIN NONE
50 #endif
52 #ifndef SPI4_SCK_PIN
53 #define SPI4_SCK_PIN NONE
54 #define SPI4_SDI_PIN NONE
55 #define SPI4_SDO_PIN NONE
56 #endif
58 #ifndef SPI5_SCK_PIN
59 #define SPI5_SCK_PIN NONE
60 #define SPI5_SDI_PIN NONE
61 #define SPI5_SDO_PIN NONE
62 #endif
64 #ifndef SPI6_SCK_PIN
65 #define SPI6_SCK_PIN NONE
66 #define SPI6_SDI_PIN NONE
67 #define SPI6_SDO_PIN NONE
68 #endif
70 typedef struct spiDefaultConfig_s {
71 SPIDevice device;
72 ioTag_t sck;
73 ioTag_t miso;
74 ioTag_t mosi;
75 dmaoptValue_t txDmaopt;
76 dmaoptValue_t rxDmaopt;
77 } spiDefaultConfig_t;
79 const spiDefaultConfig_t spiDefaultConfig[] = {
80 #ifdef USE_SPI_DEVICE_1
81 { SPIDEV_1, IO_TAG(SPI1_SCK_PIN), IO_TAG(SPI1_SDI_PIN ), IO_TAG(SPI1_SDO_PIN ), SPI1_TX_DMA_OPT, SPI1_RX_DMA_OPT },
82 #endif
83 #ifdef USE_SPI_DEVICE_2
84 { SPIDEV_2, IO_TAG(SPI2_SCK_PIN), IO_TAG(SPI2_SDI_PIN ), IO_TAG(SPI2_SDO_PIN ), SPI2_TX_DMA_OPT, SPI2_RX_DMA_OPT },
85 #endif
86 #ifdef USE_SPI_DEVICE_3
87 { SPIDEV_3, IO_TAG(SPI3_SCK_PIN), IO_TAG(SPI3_SDI_PIN ), IO_TAG(SPI3_SDO_PIN ), SPI3_TX_DMA_OPT, SPI3_RX_DMA_OPT },
88 #endif
89 #ifdef USE_SPI_DEVICE_4
90 { SPIDEV_4, IO_TAG(SPI4_SCK_PIN), IO_TAG(SPI4_SDI_PIN ), IO_TAG(SPI4_SDO_PIN ), SPI4_TX_DMA_OPT, SPI4_RX_DMA_OPT },
91 #endif
92 #ifdef USE_SPI_DEVICE_5
93 { SPIDEV_5, IO_TAG(SPI5_SCK_PIN), IO_TAG(SPI5_SDI_PIN), IO_TAG(SPI5_SDO_PIN), SPI5_TX_DMA_OPT, SPI5_RX_DMA_OPT },
94 #endif
95 #ifdef USE_SPI_DEVICE_6
96 { SPIDEV_6, IO_TAG(SPI6_SCK_PIN), IO_TAG(SPI6_SDI_PIN), IO_TAG(SPI6_SDO_PIN), SPI6_TX_DMA_OPT, SPI6_RX_DMA_OPT },
97 #endif
100 PG_REGISTER_ARRAY_WITH_RESET_FN(spiPinConfig_t, SPIDEV_COUNT, spiPinConfig, PG_SPI_PIN_CONFIG, 1);
102 void pgResetFn_spiPinConfig(spiPinConfig_t *spiPinConfig)
104 for (size_t i = 0; i < SPIDEV_COUNT; i++) {
105 spiPinConfig[i].txDmaopt = -1;
106 spiPinConfig[i].rxDmaopt = -1;
109 for (size_t i = 0 ; i < ARRAYLEN(spiDefaultConfig) ; i++) {
110 const spiDefaultConfig_t *defconf = &spiDefaultConfig[i];
111 spiPinConfig[defconf->device].ioTagSck = defconf->sck;
112 spiPinConfig[defconf->device].ioTagMiso = defconf->miso;
113 spiPinConfig[defconf->device].ioTagMosi = defconf->mosi;
114 spiPinConfig[defconf->device].txDmaopt = defconf->txDmaopt;
115 spiPinConfig[defconf->device].rxDmaopt = defconf->rxDmaopt;
118 #endif