Loading...
Searching...
No Matches
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
19
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
28extern "C" {
29#endif
30
31#ifndef DOXYGEN
32/* resolve circular dependency by declaring spi_t here */
33#define HAVE_SPI_T
34typedef 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
64typedef 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
79
84#define HAVE_SPI_CLK_T
85enum {
91};
92
96typedef uint32_t spi_clk_t;
98
102typedef struct {
103 SPI_TypeDef *dev;
104 gpio_t mosi_pin;
105 gpio_t miso_pin;
106 gpio_t sclk_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
125gpio_t spi_pin_miso(spi_t bus);
126gpio_t spi_pin_mosi(spi_t bus);
127gpio_t spi_pin_clk(spi_t bus);
128#endif
129
130#ifdef __cplusplus
131}
132#endif
133
spi_clk_t
Definition periph_cpu.h:348
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition periph_cpu.h:353
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition periph_cpu.h:352
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition periph_cpu.h:350
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition periph_cpu.h:351
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition periph_cpu.h:349
DMA CPU specific definitions for the STM32 family.
GPIO CPU definitions for the STM32 family.
gpio_af_t
Override alternative GPIO mode options.
Definition periph_cpu.h:162
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
gpio_t miso_pin
pin used for MISO
Definition periph_cpu.h:337
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
gpio_t mosi_pin
pin used for MOSI
Definition periph_cpu.h:338
gpio_t sclk_pin
SCLK pin.
Definition periph_cpu.h:409
SPI_t * dev
pointer to the used SPI device
Definition periph_cpu.h:334
spi_cs_t cs_pin
pin used for CS
Definition periph_cpu.h:296
uint8_t apbbus
APBx bus the device is connected to.
Definition periph_cpu.h:412
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