Skip to content

Commit 513b20f

Browse files
Merge pull request #4780 from haukepetersen/opt_periph_spi2
drivers/spi: reworked SPI driver interface
2 parents b101c70 + 422763e commit 513b20f

File tree

212 files changed

+5672
-8259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+5672
-8259
lines changed

boards/airfy-beacon/include/periph_conf.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
22
* Copyright (C) 2014 Christian Mehlis <[email protected]>
33
*
4-
* This file is subject to the terms and conditions of the GNU Lesser General
5-
* Public License v2.1. See the file LICENSE in the top level directory for more
6-
* details.
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
77
*/
88

99
/**
@@ -83,15 +83,16 @@ static const timer_conf_t timer_config[] = {
8383
* @name SPI configuration
8484
* @{
8585
*/
86-
#define SPI_NUMOF (1U)
87-
#define SPI_0_EN 1
88-
#define SPI_IRQ_PRIO 1
89-
90-
/* SPI_0 device configuration */
91-
#define SPI_0_DEV NRF_SPI0
92-
#define SPI_0_PIN_MOSI 13
93-
#define SPI_0_PIN_MISO 14
94-
#define SPI_0_PIN_SCK 15
86+
static const spi_conf_t spi_config[] = {
87+
{
88+
.dev = NRF_SPI0,
89+
.sclk = 15,
90+
.mosi = 13,
91+
.miso = 14
92+
}
93+
};
94+
95+
#define SPI_NUMOF (sizeof(spi_config) / sizeof(spi_config[0]))
9596
/** @} */
9697

9798
/**

boards/arduino-due/include/periph_conf.h

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,18 @@ static const uart_conf_t uart_config[] = {
8888
* @name SPI configuration
8989
* @{
9090
*/
91-
#define SPI_NUMOF (1U)
92-
#define SPI_0_EN 1
93-
94-
/* SPI 0 device config */
95-
#define SPI_0_DEV SPI0
96-
#define SPI_0_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_SPI0));
97-
#define SPI_0_CLKDIS() (PMC->PMC_PCER0 &= ~(1 << ID_SPI0));
98-
#define SPI_0_IRQ SPI0_IRQn
99-
#define SPI_0_IRQ_HANDLER isr_spi0
100-
#define SPI_0_IRQ_PRIO 1
101-
102-
/* SPI 0 pin configuration */
103-
#define SPI_0_MISO_PIN PIO_PA25A_SPI0_MISO
104-
#define SPI_0_MOSI_PIN PIO_PA26A_SPI0_MOSI
105-
#define SPI_0_SCK_PIN PIO_PA27A_SPI0_SPCK
106-
#define SPI_0_MISO_PORT PIOA
107-
#define SPI_0_MOSI_PORT PIOA
108-
#define SPI_0_SCK_PORT PIOA
109-
#define SPI_0_MISO_PORT_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_PIOA));
110-
#define SPI_0_MOSI_PORT_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_PIOA));
111-
#define SPI_0_SCK_PORT_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_PIOA));
91+
static const spi_conf_t spi_config[] = {
92+
{
93+
.dev = SPI0,
94+
.id = ID_SPI0,
95+
.clk = GPIO_PIN(PA, 27),
96+
.mosi = GPIO_PIN(PA, 26),
97+
.miso = GPIO_PIN(PA, 25),
98+
.mux = GPIO_MUX_A
99+
}
100+
};
101+
102+
#define SPI_NUMOF (sizeof(spi_config) / sizeof(spi_config[0]))
112103
/** @} */
113104

114105
/**
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (C) 2017 Michel Rottleuthner <[email protected]>
3+
* 2017 Freie Universität Berlin
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+
/**
11+
* @ingroup boards_arduino-due
12+
* @{
13+
*
14+
* @file
15+
* @brief SD card configuration for the Arduino due
16+
*
17+
* @author Michel Rottleuthner <[email protected]>
18+
* @author Hauke Petersen <[email protected]>
19+
*/
20+
21+
#ifndef SDCARD_SPI_PARAMS_H
22+
#define SDCARD_SPI_PARAMS_H
23+
24+
#include "board.h"
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
/**
31+
* @brief Set default configuration parameters for the sdcard_spi driver
32+
* @{
33+
*/
34+
#ifndef SDCARD_SPI_PARAM_SPI
35+
#define SDCARD_SPI_PARAM_SPI (SPI_DEV(0))
36+
#endif
37+
#ifndef SDCARD_SPI_PARAM_CS
38+
#define SDCARD_SPI_PARAM_CS (GPIO_PIN(PA, 29))
39+
#endif
40+
#ifndef SDCARD_SPI_PARAM_CLK
41+
#define SDCARD_SPI_PARAM_CLK (GPIO_PIN(PA, 27))
42+
#endif
43+
#ifndef SDCARD_SPI_PARAM_MOSI
44+
#define SDCARD_SPI_PARAM_MOSI (GPIO_PIN(PA, 26))
45+
#endif
46+
#ifndef SDCARD_SPI_PARAM_MISO
47+
#define SDCARD_SPI_PARAM_MISO (GPIO_PIN(PA, 25))
48+
#endif
49+
#ifndef SDCARD_SPI_PARAM_POWER
50+
#define SDCARD_SPI_PARAM_POWER (GPIO_UNDEF)
51+
#endif
52+
#ifndef SDCARD_SPI_PARAM_POWER_AH
53+
/** treated as 'don't care' if SDCARD_SPI_PARAM_POWER is GPIO_UNDEF */
54+
#define SDCARD_SPI_PARAM_POWER_AH (true)
55+
#endif
56+
/** @} */
57+
58+
/**
59+
* @brief sdcard_spi configuration
60+
*/
61+
static const sdcard_spi_params_t sdcard_spi_params[] = {
62+
{
63+
.spi_dev = SDCARD_SPI_PARAM_SPI,
64+
.cs = SDCARD_SPI_PARAM_CS,
65+
.clk = SDCARD_SPI_PARAM_CLK,
66+
.mosi = SDCARD_SPI_PARAM_MOSI,
67+
.miso = SDCARD_SPI_PARAM_MISO,
68+
.power = SDCARD_SPI_PARAM_POWER,
69+
.power_act_high = SDCARD_SPI_PARAM_POWER_AH
70+
},
71+
};
72+
/** @} */
73+
74+
#ifdef __cplusplus
75+
}
76+
#endif
77+
78+
#endif /* SDCARD_SPI_PARAMS_H */
79+
/** @} */

boards/arduino-due/include/w5100_params.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ extern "C" {
2828
* @{
2929
*/
3030
#ifndef W5100_PARAM_SPI
31-
#define W5100_PARAM_SPI (SPI_0)
31+
#define W5100_PARAM_SPI (SPI_DEV(0))
3232
#endif
33-
#ifndef W5100_PARAM_SPI_SPEED
34-
#define W5100_PARAM_SPI_SPEED (SPI_SPEED_5MHZ)
33+
#ifndef W5100_PARAM_SPI_CLK
34+
#define W5100_PARAM_SPI_CLK (SPI_CLK_5MHZ)
3535
#endif
3636
#ifndef W5100_PARAM_CS
3737
#define W5100_PARAM_CS (GPIO_PIN(2, 29))
@@ -46,10 +46,10 @@ extern "C" {
4646
*/
4747
static const w5100_params_t w5100_params[] = {
4848
{
49-
.spi = W5100_PARAM_SPI,
50-
.spi_speed = W5100_PARAM_SPI_SPEED,
51-
.cs = W5100_PARAM_CS,
52-
.evt = W5100_PARAM_EVT
49+
.spi = W5100_PARAM_SPI,
50+
.clk = W5100_PARAM_SPI_CLK,
51+
.cs = W5100_PARAM_CS,
52+
.evt = W5100_PARAM_EVT
5353
},
5454
};
5555
/** @} */

boards/arduino-zero/include/periph_conf.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,21 @@ static const pwm_conf_t pwm_config[] = {
183183
* @name SPI configuration
184184
* @{
185185
*/
186-
#define SPI_NUMOF (1)
187-
#define SPI_0_EN 1
188-
189-
/* SPI0 */
190-
#define SPI_0_DEV SERCOM4->SPI
191-
#define SPI_IRQ_0 SERCOM4_IRQn
192-
#define SPI_0_GCLK_ID SERCOM4_GCLK_ID_CORE
193-
/* SPI 0 pin configuration */
194-
#define SPI_0_SCLK GPIO_PIN(PB, 11)
195-
#define SPI_0_SCLK_MUX GPIO_MUX_D
196-
#define SPI_0_MISO GPIO_PIN(PA, 12)
197-
#define SPI_0_MISO_MUX GPIO_MUX_D
198-
#define SPI_0_MISO_PAD SPI_PAD_MISO_0
199-
#define SPI_0_MOSI GPIO_PIN(PB, 10)
200-
#define SPI_0_MOSI_MUX GPIO_MUX_D
201-
#define SPI_0_MOSI_PAD SPI_PAD_MOSI_2_SCK_3
186+
static const spi_conf_t spi_config[] = {
187+
{
188+
.dev = &SERCOM4->SPI,
189+
.miso_pin = GPIO_PIN(PA, 12),
190+
.mosi_pin = GPIO_PIN(PB, 10),
191+
.clk_pin = GPIO_PIN(PB, 11),
192+
.miso_mux = GPIO_MUX_D,
193+
.mosi_mux = GPIO_MUX_D,
194+
.clk_mux = GPIO_MUX_D,
195+
.miso_pad = SPI_PAD_MISO_0,
196+
.mosi_pad = SPI_PAD_MOSI_2_SCK_3
197+
}
198+
};
202199

200+
#define SPI_NUMOF (sizeof(spi_config) / sizeof(spi_config[0]))
203201
/** @} */
204202

205203
/**

boards/cc2538dk/include/periph_conf.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ static const timer_conf_t timer_config[] = {
5858
#define TIMER_IRQ_PRIO 1
5959
/** @} */
6060

61-
6261
/**
6362
* @name UART configuration
6463
* @{
@@ -112,22 +111,36 @@ static const i2c_conf_t i2c_config[I2C_NUMOF] = {
112111
};
113112
/** @} */
114113

114+
/**
115+
* @brief Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz)
116+
*
117+
* Calculated with (CPSR * (SCR + 1)) = (CLOCK_CORECLOCK / bus_freq), where
118+
* 1 < CPSR < 255 and
119+
* 0 < SCR < 256
120+
*/
121+
static const spi_clk_conf_t spi_clk_config[] = {
122+
{ .cpsr = 10, .scr = 31 }, /* 100khz */
123+
{ .cpsr = 2, .scr = 39 }, /* 400khz */
124+
{ .cpsr = 2, .scr = 15 }, /* 1MHz */
125+
{ .cpsr = 2, .scr = 2 }, /* ~4.5MHz */
126+
{ .cpsr = 2, .scr = 1 } /* ~10.7MHz */
127+
};
128+
115129
/**
116130
* @name SPI configuration
117131
* @{
118132
*/
119-
#define SPI_NUMOF 1
120-
#define SPI_0_EN 1
121-
122-
static const periph_spi_conf_t spi_config[SPI_NUMOF] = {
133+
static const spi_conf_t spi_config[] = {
123134
{
124135
.dev = SSI0,
125136
.mosi_pin = GPIO_PA4,
126137
.miso_pin = GPIO_PA5,
127138
.sck_pin = GPIO_PA2,
128-
.cs_pin = GPIO_PD0,
129-
},
139+
.cs_pin = GPIO_PD0
140+
}
130141
};
142+
143+
#define SPI_NUMOF (sizeof(spi_config) / sizeof(spi_config[0]))
131144
/** @} */
132145

133146
/**

boards/fox/include/board.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ extern "C" {
4343
*
4444
* {spi bus, spi speed, cs pin, int pin, reset pin, sleep pin}
4545
*/
46-
#define AT86RF2XX_PARAMS_BOARD {.spi = SPI_0, \
47-
.spi_speed = SPI_SPEED_5MHZ, \
46+
#define AT86RF2XX_PARAMS_BOARD {.spi = SPI_DEV(0), \
47+
.spi_clk = SPI_CLK_5MHZ, \
4848
.cs_pin = GPIO_PIN(PORT_A, 1), \
4949
.int_pin = GPIO_PIN(PORT_C, 2), \
5050
.sleep_pin = GPIO_PIN(PORT_A, 0), \

boards/fox/include/periph_conf.h

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,42 @@ static const uart_conf_t uart_config[] = {
115115
/** @} */
116116

117117
/**
118-
* @brief SPI configuration
118+
* @brief SPI configuration
119+
*
120+
* @note The spi_divtable is auto-generated from
121+
* `cpu/stm32_common/dist/spi_divtable/spi_divtable.c`
119122
* @{
120123
*/
121-
#define SPI_NUMOF (1U)
122-
#define SPI_0_EN 1
123-
124-
/* SPI 0 device configuration */
125-
#define SPI_0_DEV SPI2
126-
#define SPI_0_CLKEN() (periph_clk_en(APB1, RCC_APB1ENR_SPI2EN))
127-
#define SPI_0_CLKDIS() (periph_clk_dis(APB1, RCC_APB1ENR_SPI2EN))
128-
#define SPI_0_BUS_DIV 0 /* 1 -> SPI runs with full CPU clock, 0 -> half CPU clock */
129-
/* SPI 0 pin configuration */
130-
#define SPI_0_CLK_PIN GPIO_PIN(PORT_B,13)
131-
#define SPI_0_MOSI_PIN GPIO_PIN(PORT_B,15)
132-
#define SPI_0_MISO_PIN GPIO_PIN(PORT_B,14)
124+
static const uint8_t spi_divtable[2][5] = {
125+
{ /* for APB1 @ 36000000Hz */
126+
7, /* -> 140625Hz */
127+
6, /* -> 281250Hz */
128+
4, /* -> 1125000Hz */
129+
2, /* -> 4500000Hz */
130+
1 /* -> 9000000Hz */
131+
},
132+
{ /* for APB2 @ 72000000Hz */
133+
7, /* -> 281250Hz */
134+
7, /* -> 281250Hz */
135+
5, /* -> 1125000Hz */
136+
3, /* -> 4500000Hz */
137+
2 /* -> 9000000Hz */
138+
}
139+
};
140+
141+
static const spi_conf_t spi_config[] = {
142+
{
143+
.dev = SPI2,
144+
.mosi_pin = GPIO_PIN(PORT_B, 15),
145+
.miso_pin = GPIO_PIN(PORT_B, 14),
146+
.sclk_pin = GPIO_PIN(PORT_B, 13),
147+
.cs_pin = GPIO_UNDEF,
148+
.rccmask = RCC_APB1ENR_SPI2EN,
149+
.apbbus = APB1
150+
}
151+
};
152+
153+
#define SPI_NUMOF (sizeof(spi_config) / sizeof(spi_config[0]))
133154
/** @} */
134155

135156
/**

0 commit comments

Comments
 (0)