1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/*
* Copyright (c) 2006-2025, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-05-19 Sherman first version
* 2023-01-28 Andrew add Nrf5340 support
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <rthw.h>
#ifndef __DRV_SPI_H_
#define __DRV_SPI_H_
#ifdef BSP_USING_SPI
#if defined(SOC_NRF5340)
#include "nrfx_spim.h"
/**
* @brief Attach the spi device to SPI bus, this function must be used after initialization.
* @param bus_name spi bus name "spi0"/"spi1"/"spi2"
* @param device_name spi device name "spi0x"/"spi1x"/"spi2x"
* @param ss_pin spi ss pin number
* @retval -RT_ERROR / RT_EOK
*/
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_uint32_t ss_pin);
/* SPI bus config */
#ifdef BSP_USING_SPI0
#define NRFX_SPI0_CONFIG \
{ \
.bus_name = "spi0", \
.spi = NRFX_SPIM_INSTANCE(0) \
}
#endif
#ifdef BSP_USING_SPI1
#define NRFX_SPI1_CONFIG \
{ \
.bus_name = "spi1", \
.spi = NRFX_SPIM_INSTANCE(1) \
}
#endif
#ifdef BSP_USING_SPI2
#define NRFX_SPI2_CONFIG \
{ \
.bus_name = "spi2", \
.spi = NRFX_SPIM_INSTANCE(2) \
}
#endif
#ifdef BSP_USING_SPI3
#define NRFX_SPI3_CONFIG \
{ \
.bus_name = "spi3", \
.spi = NRFX_SPIM_INSTANCE(3) \
}
#endif
#ifdef BSP_USING_SPI4
#define NRFX_SPI4_CONFIG \
{ \
.bus_name = "spi4", \
.spi = NRFX_SPIM_INSTANCE(4) \
}
#endif
struct nrfx_drv_spi_config
{
char *bus_name;
nrfx_spim_t spi;
};
struct nrfx_drv_spi
{
nrfx_spim_t spi; /* nrfx spi driver instance. */
nrfx_spim_config_t spi_config; /* nrfx spi config Configuration */
struct rt_spi_configuration *cfg;
struct rt_spi_bus spi_bus;
};
struct nrfx_drv_spi_pin_config
{
rt_uint8_t sck_pin;
rt_uint8_t mosi_pin;
rt_uint8_t miso_pin;
rt_uint8_t ss_pin;
};
#else
#include "nrfx_spi.h"
/**
* @brief Attach the spi device to SPI bus, this function must be used after initialization.
* @param bus_name spi bus name "spi0"/"spi1"/"spi2"
* @param device_name spi device name "spi0x"/"spi1x"/"spi2x"
* @param ss_pin spi ss pin number
* @retval -RT_ERROR / RT_EOK
*/
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_uint32_t ss_pin);
/* SPI bus config */
#ifdef BSP_USING_SPI0
#define NRFX_SPI0_CONFIG \
{ \
.bus_name = "spi0", \
.spi = NRFX_SPI_INSTANCE(0) \
}
#endif
#ifdef BSP_USING_SPI1
#define NRFX_SPI1_CONFIG \
{ \
.bus_name = "spi1", \
.spi = NRFX_SPI_INSTANCE(1) \
}
#endif
#ifdef BSP_USING_SPI2
#define NRFX_SPI2_CONFIG \
{ \
.bus_name = "spi2", \
.spi = NRFX_SPI_INSTANCE(2) \
}
#endif
struct nrfx_drv_spi_config
{
char *bus_name;
nrfx_spi_t spi;
};
struct nrfx_drv_spi
{
nrfx_spi_t spi; /* nrfx spi driver instance. */
nrfx_spi_config_t spi_config; /* nrfx spi config Configuration */
struct rt_spi_configuration *cfg;
struct rt_spi_bus spi_bus;
};
struct nrfx_drv_spi_pin_config
{
rt_uint8_t sck_pin;
rt_uint8_t mosi_pin;
rt_uint8_t miso_pin;
rt_uint8_t ss_pin;
};
#endif
#endif /* BSP_USING_SPI */
#endif /*__DRV_SPI_H_*/
|