cpu_spi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Freie Universität Berlin
3  * 2017 OTA keys S.A.
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
10 #pragma once
11 
23 #include <stdint.h>
24 
25 #include "cpu.h"
26 #include "macros/units.h"
27 #include "periph/cpu_dma.h"
28 #include "periph/cpu_gpio.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #ifndef DOXYGEN
35 /* resolve circular dependency by declaring spi_t here */
36 #define HAVE_SPI_T
37 typedef uint_fast8_t spi_t;
38 #endif
39 
46 #define SPI_HWCS_MASK (0xffffff00)
47 
54 #define SPI_HWCS(x) (SPI_HWCS_MASK | x)
55 
59 #define SPI_CS_UNDEF (GPIO_UNDEF)
60 
61 #ifndef DOXYGEN
66 #define HAVE_SPI_CS_T
67 typedef uint32_t spi_cs_t;
69 #endif
70 
76 #define PERIPH_SPI_NEEDS_TRANSFER_BYTE
78 #define PERIPH_SPI_NEEDS_TRANSFER_REG
80 #define PERIPH_SPI_NEEDS_TRANSFER_REGS
87 #define HAVE_SPI_CLK_T
88 enum {
94 };
95 
99 typedef uint32_t spi_clk_t;
105 typedef struct {
106  SPI_TypeDef *dev;
107  gpio_t mosi_pin;
108  gpio_t miso_pin;
109  gpio_t sclk_pin;
110  spi_cs_t cs_pin;
111 #ifndef CPU_FAM_STM32F1
116 #endif
117  uint32_t rccmask;
118  uint8_t apbbus;
119 #ifdef MODULE_PERIPH_DMA
120  dma_t tx_dma;
121  uint8_t tx_dma_chan;
122  dma_t rx_dma;
123  uint8_t rx_dma_chan;
124 #endif
125 } spi_conf_t;
126 
127 #ifndef DOXYGEN
128 gpio_t spi_pin_miso(spi_t bus);
129 gpio_t spi_pin_mosi(spi_t bus);
130 gpio_t spi_pin_clk(spi_t bus);
131 #endif
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
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:99
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition: cpu_spi.h:93
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition: cpu_spi.h:92
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition: cpu_spi.h:90
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition: cpu_spi.h:91
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition: cpu_spi.h:89
gpio_af_t
Override alternative GPIO mode options.
Definition: periph_cpu.h:165
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:336
uint32_t rccmask
bit in the RCC peripheral enable register
Definition: cpu_spi.h:117
gpio_af_t miso_af
MISO pin alternate function.
Definition: cpu_spi.h:113
SPI_TypeDef * dev
SPI device base register address.
Definition: cpu_spi.h:106
gpio_af_t sclk_af
SCLK pin alternate function.
Definition: cpu_spi.h:114
gpio_af_t cs_af
HWCS pin alternate function.
Definition: cpu_spi.h:115
gpio_af_t mosi_af
MOSI pin alternate function.
Definition: cpu_spi.h:112
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