@@ -23,42 +23,42 @@ extern "C" {
23
23
24
24
#define SPI_NUM_MAX 2
25
25
26
- // SPI bus CPOL and CPHA definition
26
+ /* SPI bus CPOL and CPHA definition */
27
27
#define SPI_CPOL_LOW 0
28
28
#define SPI_CPOL_HIGH 1
29
29
#define SPI_CPHA_LOW 0
30
30
#define SPI_CPHA_HIGH 1
31
31
32
- // SPI bus data sequence definition
32
+ /* SPI bus data sequence definition */
33
33
#define SPI_BIT_ORDER_MSB_FIRST 1
34
34
#define SPI_BIT_ORDER_LSB_FIRST 0
35
35
#define SPI_BYTE_ORDER_MSB_FIRST 1
36
36
#define SPI_BYTE_ORDER_LSB_FIRST 0
37
37
38
- // SPI default bus interface parameter definition
39
- // CS_EN:1, MISO_EN:1, MOSI_EN:1, BYTE_TX_ORDER:1, BYTE_TX_ORDER:1, BIT_RX_ORDER:0, BIT_TX_ORDER:0, CPHA:0, CPOL:0
40
- #define SPI_DEFAULT_INTERFACE 0x1F0
38
+ /* SPI default bus interface parameter definition */
39
+ #define SPI_DEFAULT_INTERFACE 0x1F0 /* CS_EN:1, MISO_EN:1, MOSI_EN:1, BYTE_TX_ORDER:1, BYTE_TX_ORDER:1, BIT_RX_ORDER:0, BIT_TX_ORDER:0, CPHA:0, CPOL:0 */
41
40
42
- // SPI master default interrupt enable definition
43
- // TRANS_DONE: true, WRITE_STATUS: false, READ_STATUS: false, WRITE_BUFFER: false, READ_BUFFER: false
44
- #define SPI_MASTER_DEFAULT_INTR_ENABLE 0x10
41
+ /* SPI master default interrupt enable definition */
42
+ #define SPI_MASTER_DEFAULT_INTR_ENABLE 0x10 /* TRANS_DONE: true, WRITE_STATUS: false, READ_STATUS: false, WRITE_BUFFER: false, READ_BUFFER: false */
45
43
46
- // SPI slave default interrupt enable definition
47
- // TRANS_DONE: false, WRITE_STATUS: true, READ_STATUS: true, WRITE_BUFFER: true, READ_BUFFER: ture
48
- #define SPI_SLAVE_DEFAULT_INTR_ENABLE 0x0F
44
+ /* SPI slave default interrupt enable definition */
45
+ #define SPI_SLAVE_DEFAULT_INTR_ENABLE 0x0F /* TRANS_DONE: false, WRITE_STATUS: true, READ_STATUS: true, WRITE_BUFFER: true, READ_BUFFER: ture */
49
46
50
- // SPI event definition
47
+ /* SPI event definition */
51
48
#define SPI_INIT_EVENT 0
52
49
#define SPI_TRANS_START_EVENT 1
53
50
#define SPI_TRANS_DONE_EVENT 2
54
51
#define SPI_DEINIT_EVENT 3
55
52
53
+ /* SPI data cmd definition */
56
54
#define SPI_MASTER_WRITE_DATA_TO_SLAVE_CMD 2
57
55
#define SPI_MASTER_READ_DATA_FROM_SLAVE_CMD 3
58
56
57
+ /* SPI status cmd definition */
59
58
#define SPI_MASTER_WRITE_STATUS_TO_SLAVE_CMD 1
60
59
#define SPI_MASTER_READ_STATUS_FROM_SLAVE_CMD 4
61
60
61
+ /* SPI slave transfer done interrupt status definition */
62
62
#define SPI_SLV_RD_BUF_DONE (BIT(0))
63
63
#define SPI_SLV_WR_BUF_DONE (BIT(1))
64
64
#define SPI_SLV_RD_STA_DONE (BIT(2))
@@ -67,14 +67,19 @@ extern "C" {
67
67
68
68
typedef void (* spi_event_callback_t )(int event , void * arg );
69
69
70
- // ESP8266 has two hardware SPI, CSPI and HSPI. Currently, HSPI can be used arbitrarily.
71
- // SPI peripheral enumeration
70
+ /**
71
+ * @brief SPI peripheral enumeration
72
+ *
73
+ * @note ESP8266 has two hardware SPI, CSPI and HSPI. Currently, HSPI can be used arbitrarily.
74
+ */
72
75
typedef enum {
73
76
CSPI_HOST = 0 ,
74
77
HSPI_HOST
75
78
} spi_host_t ;
76
79
77
- // SPI clock division factor enumeration
80
+ /**
81
+ * @brief SPI clock division factor enumeration
82
+ */
78
83
typedef enum {
79
84
SPI_2MHz_DIV = 40 ,
80
85
SPI_4MHz_DIV = 20 ,
@@ -87,13 +92,17 @@ typedef enum {
87
92
SPI_80MHz_DIV = 1 ,
88
93
} spi_clk_div_t ;
89
94
90
- // SPI working mode enumeration
95
+ /**
96
+ * @brief SPI working mode enumeration
97
+ */
91
98
typedef enum {
92
99
SPI_MASTER_MODE ,
93
100
SPI_SLAVE_MODE
94
101
} spi_mode_t ;
95
102
96
- // SPI interrupt enable union type definition
103
+ /**
104
+ * @brief SPI interrupt enable union type definition
105
+ */
97
106
typedef union {
98
107
struct {
99
108
uint32_t read_buffer : 1 ;
@@ -106,24 +115,28 @@ typedef union {
106
115
uint32_t val ;
107
116
} spi_intr_enable_t ;
108
117
109
- // SPI bus interface parameter union type definition
118
+ /**
119
+ * @brief SPI bus interface parameter union type definition
120
+ */
110
121
typedef union {
111
122
struct {
112
- uint32_t cpol : 1 ; // Clock Polarity
113
- uint32_t cpha : 1 ; // Clock Phase
114
- uint32_t bit_tx_order : 1 ;
115
- uint32_t bit_rx_order : 1 ;
116
- uint32_t byte_tx_order : 1 ;
117
- uint32_t byte_rx_order : 1 ;
118
- uint32_t mosi_en : 1 ;
119
- uint32_t miso_en : 1 ;
120
- uint32_t cs_en : 1 ;
121
- uint32_t reserved9 : 23 ;
123
+ uint32_t cpol : 1 ; /*!< Clock Polarity */
124
+ uint32_t cpha : 1 ; /*!< Clock Phase */
125
+ uint32_t bit_tx_order : 1 ; /*!< Tx bit order */
126
+ uint32_t bit_rx_order : 1 ; /*!< Rx bit order */
127
+ uint32_t byte_tx_order : 1 ; /*!< Tx byte order */
128
+ uint32_t byte_rx_order : 1 ; /*!< Rx byte order */
129
+ uint32_t mosi_en : 1 ; /*!< MOSI line enable */
130
+ uint32_t miso_en : 1 ; /*!< MISO line enable */
131
+ uint32_t cs_en : 1 ; /*!< CS line enable */
132
+ uint32_t reserved9 : 23 ; /*!< resserved */
122
133
};
123
134
uint32_t val ;
124
135
} spi_interface_t ;
125
136
126
- // SPI transmission parameter structure type definition
137
+ /**
138
+ * @brief SPI transmission parameter structure type definition
139
+ */
127
140
typedef struct {
128
141
uint16_t * cmd ;
129
142
uint32_t * addr ;
@@ -140,7 +153,9 @@ typedef struct {
140
153
} bits ;
141
154
} spi_trans_t ;
142
155
143
- // SPI initialization parameter structure type definition
156
+ /**
157
+ * @brief SPI initialization parameter structure type definition
158
+ */
144
159
typedef struct {
145
160
spi_interface_t interface ;
146
161
spi_intr_enable_t intr_enable ;
0 commit comments