Skip to content

Commit 61616e8

Browse files
dpgeorgepfalcon
authored andcommitted
extmod/machine_signal: Rename "inverted" arg to "invert", it's shorter.
A shorter name takes less code size, less room in scripts and is faster to type at the REPL. Tests and HW-API examples are updated to reflect the change.
1 parent 209eaec commit 61616e8

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

examples/hwapi/hwconfig_esp8266_esp12.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
# ESP12 module as used by many boards
44
# Blue LED on pin 2, active low (inverted)
5-
LED = Signal(Pin(2, Pin.OUT), inverted=True)
5+
LED = Signal(Pin(2, Pin.OUT), invert=True)

extmod/machine_signal.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
typedef struct _machine_signal_t {
4040
mp_obj_base_t base;
4141
mp_obj_t pin;
42-
bool inverted;
42+
bool invert;
4343
} machine_signal_t;
4444

4545
STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
4646
mp_obj_t pin = args[0];
47-
bool inverted = false;
47+
bool invert = false;
4848

4949
#if defined(MICROPY_PY_MACHINE_PIN_MAKE_NEW)
5050
mp_pin_p_t *pin_p = NULL;
@@ -55,7 +55,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
5555
}
5656

5757
if (pin_p == NULL) {
58-
// If first argument isn't a Pin-like object, we filter out "inverted"
58+
// If first argument isn't a Pin-like object, we filter out "invert"
5959
// from keyword arguments and pass them all to the exported Pin
6060
// constructor to create one.
6161
mp_obj_t pin_args[n_args + n_kw * 2];
@@ -64,8 +64,8 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
6464
mp_obj_t *dst = pin_args + n_args;
6565
mp_obj_t *sig_value = NULL;
6666
for (size_t cnt = n_kw; cnt; cnt--) {
67-
if (*src == MP_OBJ_NEW_QSTR(MP_QSTR_inverted)) {
68-
inverted = mp_obj_is_true(src[1]);
67+
if (*src == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) {
68+
invert = mp_obj_is_true(src[1]);
6969
n_kw--;
7070
} else {
7171
*dst++ = *src;
@@ -80,7 +80,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
8080
src += 2;
8181
}
8282

83-
if (inverted && sig_value != NULL) {
83+
if (invert && sig_value != NULL) {
8484
*sig_value = mp_obj_is_true(*sig_value) ? MP_OBJ_NEW_SMALL_INT(0) : MP_OBJ_NEW_SMALL_INT(1);
8585
}
8686

@@ -95,8 +95,8 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
9595
{
9696
if (n_args == 1) {
9797
if (n_kw == 0) {
98-
} else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_inverted)) {
99-
inverted = mp_obj_is_true(args[1]);
98+
} else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) {
99+
invert = mp_obj_is_true(args[1]);
100100
} else {
101101
goto error;
102102
}
@@ -109,7 +109,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
109109
machine_signal_t *o = m_new_obj(machine_signal_t);
110110
o->base.type = type;
111111
o->pin = pin;
112-
o->inverted = inverted;
112+
o->invert = invert;
113113
return MP_OBJ_FROM_PTR(o);
114114
}
115115

@@ -119,10 +119,10 @@ STATIC mp_uint_t signal_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg
119119

120120
switch (request) {
121121
case MP_PIN_READ: {
122-
return mp_virtual_pin_read(self->pin) ^ self->inverted;
122+
return mp_virtual_pin_read(self->pin) ^ self->invert;
123123
}
124124
case MP_PIN_WRITE: {
125-
mp_virtual_pin_write(self->pin, arg ^ self->inverted);
125+
mp_virtual_pin_write(self->pin, arg ^ self->invert);
126126
return 0;
127127
}
128128
}

tests/extmod/machine_signal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def value(self, v=None):
3333

3434
# test inverted, and using on/off methods
3535
p = Pin()
36-
s = machine.Signal(p, inverted=True)
36+
s = machine.Signal(p, invert=True)
3737
s.off()
3838
print(p.value(), s.value())
3939
s.on()

0 commit comments

Comments
 (0)