Skip to content

Commit 264fc2b

Browse files
committed
Make wiznet5k RST pin optional #1800
1 parent 24934a1 commit 264fc2b

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

shared-bindings/wiznet/wiznet5k.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,14 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, cons
6666
static const mp_arg_t allowed_args[] = {
6767
{ MP_QSTR_spi, MP_ARG_REQUIRED | MP_ARG_OBJ },
6868
{ MP_QSTR_cs, MP_ARG_REQUIRED | MP_ARG_OBJ },
69-
{ MP_QSTR_rst, MP_ARG_REQUIRED | MP_ARG_OBJ },
69+
{ MP_QSTR_rst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
7070
{ MP_QSTR_dhcp, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = true } },
7171
};
7272
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
7373
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
7474
// XXX check type of ARG_spi?
75-
// XXX should ARG_rst be optional?
7675
assert_pin(args[ARG_cs].u_obj, false);
77-
assert_pin(args[ARG_rst].u_obj, false);
76+
assert_pin(args[ARG_rst].u_obj, true); // may be NULL
7877

7978
mp_obj_t ret = wiznet5k_create(args[ARG_spi].u_obj, args[ARG_cs].u_obj, args[ARG_rst].u_obj);
8079
if (args[ARG_dhcp].u_bool) wiznet5k_start_dhcp();

shared-module/wiznet/wiznet5k.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,6 @@ mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in) {
364364
wiznet5k_obj.base.type = (mp_obj_type_t*)&mod_network_nic_type_wiznet5k;
365365
wiznet5k_obj.cris_state = 0;
366366
wiznet5k_obj.spi = MP_OBJ_TO_PTR(spi_in);
367-
common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.cs, cs_in);
368-
common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.rst, rst_in);
369367
wiznet5k_obj.socket_used = 0;
370368
wiznet5k_obj.dhcp_socket = -1;
371369

@@ -380,13 +378,17 @@ mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in) {
380378
8 // 8 BITS
381379
);
382380

381+
common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.cs, cs_in);
383382
common_hal_digitalio_digitalinout_switch_to_output(&wiznet5k_obj.cs, 1, DRIVE_MODE_PUSH_PULL);
384-
common_hal_digitalio_digitalinout_switch_to_output(&wiznet5k_obj.rst, 1, DRIVE_MODE_PUSH_PULL);
385383

386-
common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 0);
387-
mp_hal_delay_us(10); // datasheet says 2us
388-
common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 1);
389-
mp_hal_delay_ms(160); // datasheet says 150ms
384+
if (rst_in) {
385+
common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.rst, rst_in);
386+
common_hal_digitalio_digitalinout_switch_to_output(&wiznet5k_obj.rst, 1, DRIVE_MODE_PUSH_PULL);
387+
common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 0);
388+
mp_hal_delay_us(10); // datasheet says 2us
389+
common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 1);
390+
mp_hal_delay_ms(160); // datasheet says 150ms
391+
}
390392

391393
reg_wizchip_cris_cbfunc(wiz_cris_enter, wiz_cris_exit);
392394
reg_wizchip_cs_cbfunc(wiz_cs_select, wiz_cs_deselect);

0 commit comments

Comments
 (0)