@@ -81,6 +81,8 @@ typedef struct _sdcard_obj_t {
81
81
// The card structure duplicates the host. It's not clear if we
82
82
// can avoid this given the way that it is copied.
83
83
sdmmc_card_t card ;
84
+ sdspi_device_config_t dev_config ;
85
+ sdspi_dev_handle_t sdspi_handle ;
84
86
} sdcard_card_obj_t ;
85
87
86
88
@@ -90,23 +92,6 @@ typedef struct _sdcard_obj_t {
90
92
#define _SECTOR_SIZE (self ) (self->card.csd.sector_size)
91
93
92
94
93
- static const sdspi_device_config_t spi_dev_defaults [2 ] = {
94
- {
95
- #if CONFIG_IDF_TARGET_ESP32
96
- .host_id = VSPI_HOST ,
97
- .gpio_cs = GPIO_NUM_5 ,
98
- #else
99
- .host_id = SPI3_HOST ,
100
- .gpio_cs = GPIO_NUM_34 ,
101
- #endif
102
- .gpio_cd = SDSPI_SLOT_NO_CD ,
103
- .gpio_wp = SDSPI_SLOT_NO_WP ,
104
- .gpio_int = SDSPI_SLOT_NO_INT ,
105
- },
106
- SDSPI_DEVICE_CONFIG_DEFAULT (), // HSPI (ESP32) / SPI2 (ESP32S3)
107
- };
108
-
109
-
110
95
static esp_err_t sdcard_ensure_card_init (sdcard_card_obj_t * self , bool force ) {
111
96
if (force || !(self -> flags & SDCARD_CARD_FLAGS_CARD_INIT_DONE )) {
112
97
@@ -178,7 +163,7 @@ static mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
178
163
is_spi = true;
179
164
} else {
180
165
slot_num = args [ARG_slot ].u_int ;
181
- is_spi = false
166
+ is_spi = false;
182
167
183
168
if (slot_num < 0 || slot_num > 3 ) {
184
169
mp_raise_ValueError (MP_ERROR_TEXT ("slot number must be between 0 and 3 inclusive" ));
@@ -202,30 +187,23 @@ static mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
202
187
203
188
if (is_spi ) {
204
189
// Needs to match spi_dev_defaults above.
205
- #if CONFIG_IDF_TARGET_ESP32
206
- self -> host .slot = slot_num ? HSPI_HOST : VSPI_HOST ;
207
- #else
208
- self -> host .slot = slot_num ? SPI2_HOST : SPI3_HOST ;
209
- #endif
190
+ self -> host .slot = slot_num ;
210
191
}
211
192
212
193
check_esp_err (self -> host .init ());
213
194
self -> flags |= SDCARD_CARD_FLAGS_HOST_INIT_DONE ;
214
195
215
196
if (is_spi ) {
216
197
// SPI interface
217
- spi_host_device_t spi_host_id = self -> host .slot ;
218
- sdspi_device_config_t dev_config = spi_dev_defaults [slot_num ];
219
-
220
- dev_config .gpio_cs = (int )args [ARG_cs ].u_int ;
221
- dev_config .gpio_cd = (int )args [ARG_cd ].u_int ;
222
- dev_config .gpio_wp = (int )args [ARG_wp ].u_int ;
223
-
224
- sdspi_dev_handle_t sdspi_handle ;
225
- esp_err_t ret = sdspi_host_init_device (& dev_config , & sdspi_handle );
226
-
227
- check_esp_err (ret );
198
+ self -> dev_config = (sdspi_device_config_t ){
199
+ .host_id = (spi_host_device_t )self -> host .slot ,
200
+ .gpio_cs = (int )args [ARG_cs ].u_int
201
+ .gpio_cd = (int )args [ARG_cd ].u_int ,
202
+ .gpio_wp = (int )args [ARG_wp ].u_int ,
203
+ .gpio_int = SDSPI_SLOT_NO_INT ,
204
+ }
228
205
206
+ check_esp_err (sdspi_host_init_device (& self -> dev_config , & self -> sdspi_handle ));
229
207
} else {
230
208
// SD/MMC interface
231
209
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT ();
0 commit comments