1
6
7
8
9
15
16
17
18
19
20
21
22
23
24
26
27
29
30
31
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
68
79
80
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/* ... */
#pragma once
#include <stdint.h>
#include <stddef.h>
#include "esp_err.h"
#include "sd_protocol_types.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"6 includes
#ifdef __cplusplus
extern "C" {
#endif
typedef int sdspi_dev_handle_t;
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
#define SDSPI_DEFAULT_HOST HSPI_HOST
#define SDSPI_DEFAULT_DMA SDSPI_DEFAULT_HOST/* ... */
#else
#define SDSPI_DEFAULT_HOST SPI2_HOST
#define SDSPI_DEFAULT_DMA SPI_DMA_CH_AUTO/* ... */
#endif
/* ... */
#define SDSPI_HOST_DEFAULT() {\
.flags = SDMMC_HOST_FLAG_SPI | SDMMC_HOST_FLAG_DEINIT_ARG, \
.slot = SDSPI_DEFAULT_HOST, \
.max_freq_khz = SDMMC_FREQ_DEFAULT, \
.io_voltage = 3.3f, \
.driver_strength = SDMMC_DRIVER_STRENGTH_B, \
.current_limit = SDMMC_CURRENT_LIMIT_200MA, \
.init = &sdspi_host_init, \
.set_bus_width = NULL, \
.get_bus_width = NULL, \
.set_bus_ddr_mode = NULL, \
.set_card_clk = &sdspi_host_set_card_clk, \
.set_cclk_always_on = NULL, \
.do_transaction = &sdspi_host_do_transaction, \
.deinit_p = &sdspi_host_remove_device, \
.io_int_enable = &sdspi_host_io_int_enable, \
.io_int_wait = &sdspi_host_io_int_wait, \
.command_timeout_ms = 0, \
.get_real_freq = &sdspi_host_get_real_freq, \
.input_delay_phase = SDMMC_DELAY_PHASE_0, \
.set_input_delay = NULL, \
.dma_aligned_buffer = NULL, \
.pwr_ctrl_handle = NULL, \
.get_dma_info = &sdspi_host_get_dma_info, \
.is_slot_set_to_uhs1 = NULL, \
}{...}
/* ... */
typedef struct {
spi_host_device_t host_id;
gpio_num_t gpio_cs;
gpio_num_t gpio_cd;
gpio_num_t gpio_wp;
gpio_num_t gpio_int;
bool gpio_wp_polarity;
/* ... */
uint16_t duty_cycle_pos;
}{ ... } sdspi_device_config_t;
#define SDSPI_SLOT_NO_CS GPIO_NUM_NC
#define SDSPI_SLOT_NO_CD GPIO_NUM_NC
#define SDSPI_SLOT_NO_WP GPIO_NUM_NC
#define SDSPI_SLOT_NO_INT GPIO_NUM_NC
#define SDSPI_IO_ACTIVE_LOW 0
/* ... */
#define SDSPI_DEVICE_CONFIG_DEFAULT() {\
.host_id = SDSPI_DEFAULT_HOST, \
.gpio_cs = GPIO_NUM_13, \
.gpio_cd = SDSPI_SLOT_NO_CD, \
.gpio_wp = SDSPI_SLOT_NO_WP, \
.gpio_int = GPIO_NUM_NC, \
.gpio_wp_polarity = SDSPI_IO_ACTIVE_LOW, \
.duty_cycle_pos = 0,\
}{...}
6 defines
/* ... */
esp_err_t sdspi_host_init(void);
/* ... */
esp_err_t sdspi_host_init_device(const sdspi_device_config_t* dev_config, sdspi_dev_handle_t* out_handle);
/* ... */
esp_err_t sdspi_host_remove_device(sdspi_dev_handle_t handle);
/* ... */
esp_err_t sdspi_host_do_transaction(sdspi_dev_handle_t handle, sdmmc_command_t *cmdinfo);
/* ... */
esp_err_t sdspi_host_set_card_clk(sdspi_dev_handle_t host, uint32_t freq_khz);
/* ... */
esp_err_t sdspi_host_get_real_freq(sdspi_dev_handle_t handle, int* real_freq_khz);
/* ... */
esp_err_t sdspi_host_deinit(void);
/* ... */
esp_err_t sdspi_host_io_int_enable(sdspi_dev_handle_t handle);
/* ... */
esp_err_t sdspi_host_io_int_wait(sdspi_dev_handle_t handle, TickType_t timeout_ticks);
/* ... */
esp_err_t sdspi_host_get_dma_info(int slot, esp_dma_mem_info_t *dma_mem_info);
#ifdef __cplusplus
}{...}
#endif