summaryrefslogtreecommitdiff
path: root/bsp/nrf5x/libraries/drivers/drv_spim.h
blob: f26230d46ca76ddc707e196a67961a4868541766 (plain)
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
#include <rtthread.h>
#include <rtdevice.h>
#include <rthw.h>

#ifndef __DRV_SPIM_H_
#define __DRV_SPIM_H_

#ifdef BSP_USING_SPIM

#include "nrfx_spim.h"
#include "nrf_spi.h"
#include "rtconfig.h"

struct spi_dma_message
{
    rt_base_t cs_pin;
    unsigned cs_take;
    unsigned cs_release;
    #if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED)
    bool use_hw_ss;
    #endif
    bool ss_active_high;
    struct rt_completion *cpt;
    uint32_t flags;
    NRF_SPIM_Type* spim;

};

/**
 * @brief Attach the spi device to SPIM bus, this function must be used after initialization.
 * @param bus_name     spim bus name  "spim0"/"spim1"/"spim2"/"spim3"
 * @param device_name  spim device name "spim0x"/"spim1x"/"spim2x"/"spim3x"
 * @param ss_pin       spim ss pin number
 * @retval  -RT_ERROR / RT_EOK
*/
rt_err_t rt_hw_spim_device_attach(const char *bus_name, const char *device_name, rt_uint32_t ss_pin);

/* SPIM bus config */
#ifdef BSP_USING_SPIM0
#define NRFX_SPIM0_CONFIG         \
{                                \
    .bus_name = "spim0",          \
    .spi = NRFX_SPIM_INSTANCE(0)  \
}
#endif
#ifdef BSP_USING_SPIM1
#define NRFX_SPIM1_CONFIG         \
{                                \
    .bus_name = "spim1",          \
    .spi = NRFX_SPIM_INSTANCE(1)  \
}
#endif

#ifdef BSP_USING_SPIM2
#define NRFX_SPIM2_CONFIG         \
{                                \
    .bus_name = "spim2",          \
    .spi = NRFX_SPIM_INSTANCE(2)  \
}
#endif

#ifdef BSP_USING_SPIM3
#define NRFX_SPIM3_CONFIG         \
{                                \
    .bus_name = "spim3",          \
    .spi = NRFX_SPIM_INSTANCE(3)  \
}
#endif


struct nrfx_drv_spim_config
{
    char *bus_name;
    nrfx_spim_t spi;
};

struct nrfx_drv_spim
{
    nrfx_spim_t spim;    /* nrfx spim driver instance. */
    nrfx_spim_config_t   spim_config; /* nrfx spim config Configuration */
    struct rt_spi_configuration *cfg;
    struct rt_spi_bus spim_bus;
};

struct nrfx_drv_spim_pin_config
{
    rt_uint8_t sck_pin;
    rt_uint8_t mosi_pin;
    rt_uint8_t miso_pin;
    rt_uint8_t ss_pin;
};

#endif /* BSP_USING_SPIM */

#endif /* __DRV_SPIM_H_ */