|
41 | 41 | #include "shared-bindings/digitalio/DigitalInOut.h" |
42 | 42 | #include "shared-bindings/digitalio/DriveMode.h" |
43 | 43 | #include "shared-bindings/busio/SPI.h" |
| 44 | +#include "shared-bindings/microcontroller/Pin.h" |
44 | 45 |
|
45 | 46 | #include "shared-module/network/__init__.h" |
46 | 47 | #include "shared-module/wiznet/wiznet5k.h" |
|
56 | 57 | //| |
57 | 58 | //| :param spi: spi bus to use |
58 | 59 | //| :param cs: pin to use for Chip Select |
59 | | -//| :param rst: pin to sue for Reset |
| 60 | +//| :param rst: pin to use for Reset |
60 | 61 | //| |
61 | 62 |
|
62 | | -STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { |
63 | | - // check arguments |
64 | | - mp_arg_check_num(n_args, kw_args, 3, 3, false); |
65 | | - |
66 | | - return wiznet5k_create(args[0], args[1], args[2]); |
| 63 | +STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { |
| 64 | + enum { ARG_spi, ARG_cs, ARG_rst, ARG_dhcp }; |
| 65 | + static const mp_arg_t allowed_args[] = { |
| 66 | + { MP_QSTR_spi, MP_ARG_REQUIRED | MP_ARG_OBJ }, |
| 67 | + { MP_QSTR_cs, MP_ARG_REQUIRED | MP_ARG_OBJ }, |
| 68 | + { MP_QSTR_rst, MP_ARG_REQUIRED | MP_ARG_OBJ }, |
| 69 | + { MP_QSTR_dhcp, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = true } }, |
| 70 | + }; |
| 71 | + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; |
| 72 | + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); |
| 73 | + // XXX check type of ARG_spi? |
| 74 | + // XXX should ARG_rst be optional? |
| 75 | + assert_pin(args[ARG_cs].u_obj, false); |
| 76 | + assert_pin(args[ARG_rst].u_obj, false); |
| 77 | + |
| 78 | + mp_obj_t ret = wiznet5k_create(args[ARG_spi].u_obj, args[ARG_cs].u_obj, args[ARG_rst].u_obj); |
| 79 | + if (args[ARG_dhcp].u_bool) wiznet5k_start_dhcp(); |
| 80 | + return ret; |
67 | 81 | } |
68 | 82 |
|
69 | 83 | //| .. attribute:: connected |
@@ -99,9 +113,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_dhcp_get_value_obj, wiznet5k_dhcp_get_ |
99 | 113 | STATIC mp_obj_t wiznet5k_dhcp_set_value(mp_obj_t self_in, mp_obj_t value) { |
100 | 114 | (void)self_in; |
101 | 115 | if (mp_obj_is_true(value)) { |
102 | | - wiznet5k_start_dhcp(); |
| 116 | + int ret = wiznet5k_start_dhcp(); |
| 117 | + if (ret) mp_raise_OSError(ret); |
103 | 118 | } else { |
104 | | - wiznet5k_stop_dhcp(); |
| 119 | + int ret = wiznet5k_stop_dhcp(); |
| 120 | + if (ret) mp_raise_OSError(ret); |
105 | 121 | } |
106 | 122 | return mp_const_none; |
107 | 123 | } |
|
0 commit comments