Skip to content

Commit 22310ae

Browse files
robert-hhdpgeorge
authored andcommitted
cc3200/mods/pybpin: Implement Pin.toggle() method.
Tested with a WiPy 1 board. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent e009ab0 commit 22310ae

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ports/cc3200/mods/pybpin.c

+15
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,20 @@ static mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) {
680680
}
681681
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
682682

683+
// pin.toggle()
684+
static mp_obj_t pin_toggle(mp_obj_t self_in) {
685+
pin_obj_t *self = self_in;
686+
if (self->value) {
687+
self->value = 0;
688+
MAP_GPIOPinWrite(self->port, self->bit, 0);
689+
} else {
690+
self->value = 1;
691+
MAP_GPIOPinWrite(self->port, self->bit, self->bit);
692+
}
693+
return mp_const_none;
694+
}
695+
static MP_DEFINE_CONST_FUN_OBJ_1(pin_toggle_obj, pin_toggle);
696+
683697
static mp_obj_t pin_id(mp_obj_t self_in) {
684698
pin_obj_t *self = self_in;
685699
return MP_OBJ_NEW_QSTR(self->name);
@@ -902,6 +916,7 @@ static const mp_rom_map_elem_t pin_locals_dict_table[] = {
902916
// instance methods
903917
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) },
904918
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pin_value_obj) },
919+
{ MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&pin_toggle_obj) },
905920
{ MP_ROM_QSTR(MP_QSTR_id), MP_ROM_PTR(&pin_id_obj) },
906921
{ MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&pin_mode_obj) },
907922
{ MP_ROM_QSTR(MP_QSTR_pull), MP_ROM_PTR(&pin_pull_obj) },

0 commit comments

Comments
 (0)