8000 Merge pull request #8 from robert-hh1/w600_pin · retryfail/micropython@dc7a80d · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit dc7a80d

Browse files
authored
Merge pull request micropython#8 from robert-hh1/w600_pin
machine.pin.c: Some modifications to the Pin module
2 parents 7093aa8 + d7f8848 commit dc7a80d

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

ports/w60x/machine/machine_pin.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,21 @@ STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
137137

138138
// pin.init(direction, attribute, value)
139139
STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
140-
enum { ARG_direc, ARG_attr, ARG_value };
140+
enum { ARG_mode, ARG_pull, ARG_value };
141141
static const mp_arg_t allowed_args[] = {
142-
{ MP_QSTR_mode, MP_ARG_INT, {.u_int = 0} },
143-
{ MP_QSTR_pull, MP_ARG_INT, {.u_int = 0} },
144-
{ MP_QSTR_value, MP_ARG_INT, {.u_int = 0} },
142+
{ MP_QSTR_mode, MP_ARG_INT, {.u_int = WM_GPIO_DIR_INPUT} },
143+
{ MP_QSTR_pull, MP_ARG_INT, {.u_int = WM_GPIO_ATTR_FLOATING} },
144+
{ MP_QSTR_value, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
145145
};
146146

147147
// parse args
148148
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
149149
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
150150

151-
if (n_args >= 2)
152-
tls_gpio_cfg(self->id, args[ARG_direc].u_int, args[ARG_attr].u_int);
151+
tls_gpio_cfg(self->id, args[ARG_mode].u_int, args[ARG_pull].u_int);
153152

154-
if (n_args == 3)
155-
tls_gpio_write(self->id, args[ARG_value].u_int);
153+
if (args[ARG_value].u_obj != MP_OBJ_NULL)
154+
tls_gpio_write(self->id, mp_obj_is_true(args[ARG_value].u_obj));
156155

157156
return mp_const_none;
158157
}
@@ -207,12 +206,29 @@ STATIC mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) {
207206
}
208207
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value);
209208

209+
// pin.off()
210+
STATIC mp_obj_t machine_pin_off(mp_obj_t self_in) {
211+
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
212+
tls_gpio_write(self->id, 0);
213+
return mp_const_none;
214+
}
215+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_off_obj, machine_pin_off);
216+
217+
// pin.on()
218+
STATIC mp_obj_t machine_pin_on(mp_obj_t self_in) {
219+
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
220+
tls_gpio_write(self->id, 1);
221+
return mp_const_none;
222+
}
223+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_on_obj, machine_pin_on);
224+
210225
STATIC void machine_pin_irq_callback(void *p) {
211226
machine_pin_obj_t *self = p;
212227
tls_clr_gpio_irq_status(self->id);
213228
machine_pin_isr_handler(self);
214229
}
215230

231+
216232
// pin.irq(trigger_mode)
217233
STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
218234
enum { ARG_handler, ARG_trigger };
@@ -246,6 +262,8 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = {
246262
// instance methods
247263
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_pin_init_obj) },
248264
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&machine_pin_value_obj) },
265+
{ MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&machine_pin_off_obj) },
266+
{ MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&machine_pin_on_obj) },
249267
{ MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&machine_pin_irq_obj) },
250268

251269
// class constants

0 commit comments

Comments
 (0)
0