1 #include <rtthread.h>
2 #include <rtdevice.h>
3 #include <rthw.h>
4 
5 #ifndef __DRV_SPIM_H_
6 #define __DRV_SPIM_H_
7 
8 #ifdef BSP_USING_SPIM
9 
10 #include "nrfx_spim.h"
11 #include "nrf_spi.h"
12 #include "rtconfig.h"
13 
14 struct spi_dma_message
15 {
16     rt_base_t cs_pin;
17     unsigned cs_take;
18     unsigned cs_release;
19     #if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED)
20     bool use_hw_ss;
21     #endif
22     bool ss_active_high;
23     struct rt_completion *cpt;
24     uint32_t flags;
25     NRF_SPIM_Type* spim;
26 
27 };
28 
29 /**
30  * @brief Attach the spi device to SPIM bus, this function must be used after initialization.
31  * @param bus_name     spim bus name  "spim0"/"spim1"/"spim2"/"spim3"
32  * @param device_name  spim device name "spim0x"/"spim1x"/"spim2x"/"spim3x"
33  * @param ss_pin       spim ss pin number
34  * @retval  -RT_ERROR / RT_EOK
35 */
36 rt_err_t rt_hw_spim_device_attach(const char *bus_name, const char *device_name, rt_uint32_t ss_pin);
37 
38 /* SPIM bus config */
39 #ifdef BSP_USING_SPIM0
40 #define NRFX_SPIM0_CONFIG         \
41 {                                \
42     .bus_name = "spim0",          \
43     .spi = NRFX_SPIM_INSTANCE(0)  \
44 }
45 #endif
46 #ifdef BSP_USING_SPIM1
47 #define NRFX_SPIM1_CONFIG         \
48 {                                \
49     .bus_name = "spim1",          \
50     .spi = NRFX_SPIM_INSTANCE(1)  \
51 }
52 #endif
53 
54 #ifdef BSP_USING_SPIM2
55 #define NRFX_SPIM2_CONFIG         \
56 {                                \
57     .bus_name = "spim2",          \
58     .spi = NRFX_SPIM_INSTANCE(2)  \
59 }
60 #endif
61 
62 #ifdef BSP_USING_SPIM3
63 #define NRFX_SPIM3_CONFIG         \
64 {                                \
65     .bus_name = "spim3",          \
66     .spi = NRFX_SPIM_INSTANCE(3)  \
67 }
68 #endif
69 
70 
71 struct nrfx_drv_spim_config
72 {
73     char *bus_name;
74     nrfx_spim_t spi;
75 };
76 
77 struct nrfx_drv_spim
78 {
79     nrfx_spim_t spim;    /* nrfx spim driver instance. */
80     nrfx_spim_config_t   spim_config; /* nrfx spim config Configuration */
81     struct rt_spi_configuration *cfg;
82     struct rt_spi_bus spim_bus;
83 };
84 
85 struct nrfx_drv_spim_pin_config
86 {
87     rt_uint8_t sck_pin;
88     rt_uint8_t mosi_pin;
89     rt_uint8_t miso_pin;
90     rt_uint8_t ss_pin;
91 };
92 
93 #endif /* BSP_USING_SPIM */
94 
95 #endif /* __DRV_SPIM_H_ */
96 
97