Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit03ca196

Browse files
committed
extends SDCard driver so custom MMC pins can be supplied.
1 parent2f4752b commit03ca196

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

‎micropy_updates/esp32/machine_sdcard.c‎

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,28 @@ static mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
116116
ARG_width,
117117
ARG_cd,
118118
ARG_wp,
119+
ARG_cmd,
120+
ARG_clk,
121+
ARG_data_pins,
119122
ARG_spi_bus,
120123
ARG_cs,
121124
ARG_freq,
122125
};
123126

124127
staticconstmp_arg_tmake_new_args[]= {
125-
{MP_QSTR_slot,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=1} },
126-
{MP_QSTR_width,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=1} },
127-
{MP_QSTR_cd,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=-1} },
128-
{MP_QSTR_wp,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=-1} },
128+
{MP_QSTR_slot,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=1} },
129+
{MP_QSTR_width,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=1} },
130+
{MP_QSTR_cd,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=-1} },
131+
{MP_QSTR_wp,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=-1} },
132+
// Added so a user can set their own custom data pins
133+
{MP_QSTR_cmd,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=-1} },
134+
{MP_QSTR_clk,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=-1} },
135+
{MP_QSTR_data_pins,MP_ARG_KW_ONLY |MP_ARG_OBJ, {.u_obj=mp_const_none} },
129136
// These are only needed if using SPI mode
130-
{MP_QSTR_spi_bus,MP_ARG_KW_ONLY |MP_ARG_OBJ, {.u_obj=mp_const_none} },
131-
{MP_QSTR_cs,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=-1} },
137+
{MP_QSTR_spi_bus,MP_ARG_KW_ONLY |MP_ARG_OBJ, {.u_obj=mp_const_none} },
138+
{MP_QSTR_cs,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=-1} },
132139
// freq is valid for both SPI and SDMMC interfaces
133-
{MP_QSTR_freq,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=20000000} },
140+
{MP_QSTR_freq,MP_ARG_KW_ONLY |MP_ARG_INT, {.u_int=20000000} },
134141
};
135142

136143
mp_arg_val_targs[MP_ARRAY_SIZE(make_new_args)];
@@ -211,7 +218,34 @@ static mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
211218
slot_config.gpio_cd= (int)args[ARG_cd].u_int;
212219
slot_config.gpio_wp= (int)args[ARG_wp].u_int;
213220

214-
intwidth=args[ARG_width].u_int;
221+
intclk= (int)args[ARG_clk].u_int;
222+
intcmd= (int)args[ARG_cmd].u_int;
223+
intwidth= (int)args[ARG_width].u_int;
224+
225+
if (clk!=-1)slot_config.clk=clk;
226+
if (cmd!=-1)slot_config.cmd=cmd;
227+
228+
if (args[ARG_data_pins].u_obj!=mp_const_none) {
229+
mp_obj_tuple_t*t=MP_OBJ_TO_PTR(args[ARG_data_pins].u_obj);
230+
if ((int)t->len!=width) {
231+
mp_raise_ValueError(MP_ERROR_TEXT("width does not match the number of data pins provided"));
232+
}
233+
234+
slot_config.d0= (int)mp_obj_get_int(t->items[0]);
235+
236+
if (width >=4) {
237+
slot_config.d1= (int)mp_obj_get_int(t->items[1]);
238+
slot_config.d2= (int)mp_obj_get_int(t->items[2]);
239+
slot_config.d3= (int)mp_obj_get_int(t->items[3]);
240+
}
241+
if (width==8) {
242+
slot_config.d4= (int)mp_obj_get_int(t->items[4]);
243+
slot_config.d5= (int)mp_obj_get_int(t->items[5]);
244+
slot_config.d6= (int)mp_obj_get_int(t->items[6]);
245+
slot_config.d7= (int)mp_obj_get_int(t->items[7]);
246+
}
247+
}
248+
215249
if (width==1||width==4|| (width==8&&slot_num==0)) {
216250
slot_config.width=width;
217251
}else {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp