cpu_spi.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016 Freie Universität Berlin
3  * SPDX-FileCopyrightText: 2017 OTA keys S.A.
4  * SPDX-License-Identifier: LGPL-2.1-only
5  */
6 
7 #pragma once
8 
20 #include <stdint.h>
21 
22 #include "cpu.h"
23 #include "macros/units.h"
24 #include "periph/cpu_dma.h"
25 #include "periph/cpu_gpio.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #ifndef DOXYGEN
32 /* resolve circular dependency by declaring spi_t here */
33 #define HAVE_SPI_T
34 typedef uint_fast8_t spi_t;
35 #endif
36 
43 #define SPI_HWCS_MASK (0xffffff00)
44 
51 #define SPI_HWCS(x) (SPI_HWCS_MASK | x)
52 
56 #define SPI_CS_UNDEF (GPIO_UNDEF)
57 
58 #ifndef DOXYGEN
63 #define HAVE_SPI_CS_T
64 typedef uint32_t spi_cs_t;
66 #endif
67 
73 #define PERIPH_SPI_NEEDS_TRANSFER_BYTE
75 #define PERIPH_SPI_NEEDS_TRANSFER_REG
77 #define PERIPH_SPI_NEEDS_TRANSFER_REGS
84 #define HAVE_SPI_CLK_T
85 enum {
91 };
92 
96 typedef uint32_t spi_clk_t;
102 typedef struct {
103  SPI_TypeDef *dev;
104  gpio_t mosi_pin;
105  gpio_t miso_pin;
106  gpio_t sclk_pin;
107  spi_cs_t cs_pin;
108 #ifndef CPU_FAM_STM32F1
113 #endif
114  uint32_t rccmask;
115  uint8_t apbbus;
116 #ifdef MODULE_PERIPH_DMA
117  dma_t tx_dma;
118  uint8_t tx_dma_chan;
119  dma_t rx_dma;
120  uint8_t rx_dma_chan;
121 #endif
122 } spi_conf_t;
123 
124 #ifndef DOXYGEN
125 gpio_t spi_pin_miso(spi_t bus);
126 gpio_t spi_pin_mosi(spi_t bus);
127 gpio_t spi_pin_clk(spi_t bus);
128 #endif
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
DMA CPU specific definitions for the STM32 family.
GPIO CPU definitions for the STM32 family.
uint32_t spi_clk_t
SPI clock type.
Definition: cpu_spi.h:96
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition: cpu_spi.h:90
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition: cpu_spi.h:89
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition: cpu_spi.h:87
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition: cpu_spi.h:88
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition: cpu_spi.h:86
gpio_af_t
Override alternative GPIO mode options.
Definition: periph_cpu.h:162
uint_fast8_t spi_t
Default type for SPI devices.
Definition: spi.h:127
gpio_t spi_pin_miso(spi_t dev)
Get the MISO pin of the given SPI bus.
gpio_t spi_pin_mosi(spi_t dev)
Get the MOSI pin of the given SPI bus.
gpio_t spi_pin_clk(spi_t dev)
Get the CLK pin of the given SPI bus.
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition: spi.h:135
unsigned dma_t
DMA channel type.
SPI device configuration.
Definition: periph_cpu.h:333
uint32_t rccmask
bit in the RCC peripheral enable register
Definition: cpu_spi.h:114
gpio_af_t miso_af
MISO pin alternate function.
Definition: cpu_spi.h:110
SPI_TypeDef * dev
SPI device base register address.
Definition: cpu_spi.h:103
gpio_af_t sclk_af
SCLK pin alternate function.
Definition: cpu_spi.h:111
gpio_af_t cs_af
HWCS pin alternate function.
Definition: cpu_spi.h:112
gpio_af_t mosi_af
MOSI pin alternate function.
Definition: cpu_spi.h:109
Unit helper macros.
#define MHZ(x)
A macro to return the Hz in x MHz.
Definition: units.h:48
#define KHZ(x)
A macro to return the Hz in x kHz.
Definition: units.h:43