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
10#pragma once
11
22
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
31extern "C" {
32#endif
33
34#ifndef DOXYGEN
35/* resolve circular dependency by declaring spi_t here */
36#define HAVE_SPI_T
37typedef 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
67typedef 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
82
87#define HAVE_SPI_CLK_T
88enum {
94};
95
99typedef uint32_t spi_clk_t;
101
105typedef struct {
106 SPI_TypeDef *dev;
107 gpio_t mosi_pin;
108 gpio_t miso_pin;
109 gpio_t sclk_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
128gpio_t spi_pin_miso(spi_t bus);
129gpio_t spi_pin_mosi(spi_t bus);
130gpio_t spi_pin_clk(spi_t bus);
131#endif
132
133#ifdef __cplusplus
134}
135#endif
136
spi_clk_t
Definition periph_cpu.h:351
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition periph_cpu.h:356
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition periph_cpu.h:355
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition periph_cpu.h:353
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition periph_cpu.h:354
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition periph_cpu.h:352
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:165
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
gpio_t miso_pin
pin used for MISO
Definition periph_cpu.h:340
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
gpio_t mosi_pin
pin used for MOSI
Definition periph_cpu.h:341
gpio_t sclk_pin
SCLK pin.
Definition periph_cpu.h:412
SPI_t * dev
pointer to the used SPI device
Definition periph_cpu.h:337
spi_cs_t cs_pin
pin used for CS
Definition periph_cpu.h:299
uint8_t apbbus
APBx bus the device is connected to.
Definition periph_cpu.h:415
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