Loading...
Searching...
No Matches
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
21#ifndef PERIPH_CPU_SPI_H
22#define PERIPH_CPU_SPI_H
23
24#include <stdint.h>
25
26#include "cpu.h"
27#include "macros/units.h"
28#include "periph/cpu_dma.h"
29#include "periph/cpu_gpio.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#ifndef DOXYGEN
36/* resolve circular dependency by declaring spi_t here */
37#define HAVE_SPI_T
38typedef uint_fast8_t spi_t;
39#endif
40
47#define SPI_HWCS_MASK (0xffffff00)
48
55#define SPI_HWCS(x) (SPI_HWCS_MASK | x)
56
60#define SPI_CS_UNDEF (GPIO_UNDEF)
61
62#ifndef DOXYGEN
67#define HAVE_SPI_CS_T
68typedef uint32_t spi_cs_t;
70#endif
71
77#define PERIPH_SPI_NEEDS_TRANSFER_BYTE
79#define PERIPH_SPI_NEEDS_TRANSFER_REG
81#define PERIPH_SPI_NEEDS_TRANSFER_REGS
88#define HAVE_SPI_CLK_T
89enum {
95};
96
100typedef uint32_t spi_clk_t;
106typedef struct {
107 SPI_TypeDef *dev;
108 gpio_t mosi_pin;
109 gpio_t miso_pin;
110 gpio_t sclk_pin;
111 spi_cs_t cs_pin;
112#ifndef CPU_FAM_STM32F1
117#endif
118 uint32_t rccmask;
119 uint8_t apbbus;
120#ifdef MODULE_PERIPH_DMA
121 dma_t tx_dma;
122 uint8_t tx_dma_chan;
123 dma_t rx_dma;
124 uint8_t rx_dma_chan;
125#endif
126} spi_conf_t;
127
128#ifndef DOXYGEN
129gpio_t spi_pin_miso(spi_t bus);
130gpio_t spi_pin_mosi(spi_t bus);
131gpio_t spi_pin_clk(spi_t bus);
132#endif
133
134#ifdef __cplusplus
135}
136#endif
137
138#endif /* PERIPH_CPU_SPI_H */
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:100
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition cpu_spi.h:94
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition cpu_spi.h:93
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition cpu_spi.h:91
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition cpu_spi.h:92
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition cpu_spi.h:90
gpio_af_t
Override alternative GPIO mode options.
Definition periph_cpu.h:166
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:337
uint32_t rccmask
bit in the RCC peripheral enable register
Definition cpu_spi.h:118
gpio_af_t miso_af
MISO pin alternate function.
Definition cpu_spi.h:114
SPI_TypeDef * dev
SPI device base register address.
Definition cpu_spi.h:107
gpio_af_t sclk_af
SCLK pin alternate function.
Definition cpu_spi.h:115
gpio_af_t cs_af
HWCS pin alternate function.
Definition cpu_spi.h:116
gpio_af_t mosi_af
MOSI pin alternate function.
Definition cpu_spi.h:113
Unit helper macros.
#define MHZ(x)
A macro to return the Hz in x MHz.
Definition units.h:49
#define KHZ(x)
A macro to return the Hz in x kHz.
Definition units.h:44