Fix function brace style
[betaflight.git] / src / main / drivers / bus_spi_impl.h
blob83aa4468105ffb8b54b11c737dc2adb3122e59cc
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 #pragma once
23 #define SPI_TIMEOUT_US 10000
25 #if defined(STM32F4) || defined(STM32G4)
26 #define MAX_SPI_PIN_SEL 2
27 #elif defined(STM32F7)
28 #define MAX_SPI_PIN_SEL 4
29 #elif defined(STM32H7)
30 #define MAX_SPI_PIN_SEL 5
31 #else
32 #error Unknown MCU family
33 #endif
35 #define BUS_SPI_FREE 0x0
37 typedef struct spiPinDef_s {
38 ioTag_t pin;
39 #if defined(STM32F7) || defined(STM32H7) || defined(STM32G4)
40 uint8_t af;
41 #endif
42 } spiPinDef_t;
44 typedef struct spiHardware_s {
45 SPIDevice device;
46 SPI_TypeDef *reg;
47 spiPinDef_t sckPins[MAX_SPI_PIN_SEL];
48 spiPinDef_t misoPins[MAX_SPI_PIN_SEL];
49 spiPinDef_t mosiPins[MAX_SPI_PIN_SEL];
50 #ifndef STM32F7
51 uint8_t af;
52 #endif
53 rccPeriphTag_t rcc;
54 #ifdef USE_DMA
55 uint8_t dmaIrqHandler;
56 #endif
57 } spiHardware_t;
59 extern const spiHardware_t spiHardware[];
61 typedef struct SPIDevice_s {
62 SPI_TypeDef *dev;
63 ioTag_t sck;
64 ioTag_t miso;
65 ioTag_t mosi;
66 #if defined(STM32F7) || defined(STM32H7) || defined(STM32G4)
67 uint8_t sckAF;
68 uint8_t misoAF;
69 uint8_t mosiAF;
70 #else
71 uint8_t af;
72 #endif
73 #if defined(HAL_SPI_MODULE_ENABLED)
74 SPI_HandleTypeDef hspi;
75 #endif
76 rccPeriphTag_t rcc;
77 volatile uint16_t errorCount;
78 bool leadingEdge;
79 #ifdef USE_DMA
80 uint8_t dmaIrqHandler;
81 #endif
82 } spiDevice_t;
84 extern spiDevice_t spiDevice[SPIDEV_COUNT];
86 void spiInitDevice(SPIDevice device);
87 void spiInternalInitStream(const extDevice_t *dev, bool preInit);
88 void spiInternalStartDMA(const extDevice_t *dev);
89 void spiInternalStopDMA (const extDevice_t *dev);
90 void spiInternalResetStream(dmaChannelDescriptor_t *descriptor);
91 void spiInternalResetDescriptors(busDevice_t *bus);
92 void spiSequenceStart(const extDevice_t *dev);