Skip to content

Commit 181f7d1

Browse files
committed
extmod/machine_signal: Implement Signal .on() and .off() methods.
Each method asserts and deasserts signal respectively. They are equivalent to .value(1) and .value(0) but conceptually simpler (and may help to avoid confusion with inverted signals, where "asserted" state means logical 0 output).
1 parent 7ae9bee commit 181f7d1

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

extmod/machine_signal.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,22 @@ STATIC mp_obj_t signal_value(size_t n_args, const mp_obj_t *args) {
9292
}
9393
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(signal_value_obj, 1, 2, signal_value);
9494

95+
STATIC mp_obj_t signal_on(mp_obj_t self_in) {
96+
mp_virtual_pin_write(self_in, 1);
97+
return mp_const_none;
98+
}
99+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(signal_on_obj, signal_on);
100+
101+
STATIC mp_obj_t signal_off(mp_obj_t self_in) {
102+
mp_virtual_pin_write(self_in, 0);
103+
return mp_const_none;
104+
}
105+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(signal_off_obj, signal_off);
106+
95107
STATIC const mp_rom_map_elem_t signal_locals_dict_table[] = {
96108
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&signal_value_obj) },
109+
{ MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&signal_on_obj) },
110+
{ MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&signal_off_obj) },
97111
};
98112

99113
STATIC MP_DEFINE_CONST_DICT(signal_locals_dict, signal_locals_dict_table);

0 commit comments

Comments
 (0)