Commit 61616e84 authored by Damien George's avatar Damien George Committed by Paul Sokolovsky
Browse files

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.
parent 209eaec5
...@@ -2,4 +2,4 @@ from machine import Pin, Signal ...@@ -2,4 +2,4 @@ from machine import Pin, Signal
# ESP12 module as used by many boards # ESP12 module as used by many boards
# Blue LED on pin 2, active low (inverted) # Blue LED on pin 2, active low (inverted)
LED = Signal(Pin(2, Pin.OUT), inverted=True) LED = Signal(Pin(2, Pin.OUT), invert=True)
...@@ -39,12 +39,12 @@ ...@@ -39,12 +39,12 @@
typedef struct _machine_signal_t { typedef struct _machine_signal_t {
mp_obj_base_t base; mp_obj_base_t base;
mp_obj_t pin; mp_obj_t pin;
bool inverted; bool invert;
} machine_signal_t; } machine_signal_t;
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) { 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) {
mp_obj_t pin = args[0]; mp_obj_t pin = args[0];
bool inverted = false; bool invert = false;
#if defined(MICROPY_PY_MACHINE_PIN_MAKE_NEW) #if defined(MICROPY_PY_MACHINE_PIN_MAKE_NEW)
mp_pin_p_t *pin_p = NULL; 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 ...@@ -55,7 +55,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
} }
if (pin_p == NULL) { if (pin_p == NULL) {
// If first argument isn't a Pin-like object, we filter out "inverted" // If first argument isn't a Pin-like object, we filter out "invert"
// from keyword arguments and pass them all to the exported Pin // from keyword arguments and pass them all to the exported Pin
// constructor to create one. // constructor to create one.
mp_obj_t pin_args[n_args + n_kw * 2]; 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 ...@@ -64,8 +64,8 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
mp_obj_t *dst = pin_args + n_args; mp_obj_t *dst = pin_args + n_args;
mp_obj_t *sig_value = NULL; mp_obj_t *sig_value = NULL;
for (size_t cnt = n_kw; cnt; cnt--) { for (size_t cnt = n_kw; cnt; cnt--) {
if (*src == MP_OBJ_NEW_QSTR(MP_QSTR_inverted)) { if (*src == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) {
inverted = mp_obj_is_true(src[1]); invert = mp_obj_is_true(src[1]);
n_kw--; n_kw--;
} else { } else {
*dst++ = *src; *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 ...@@ -80,7 +80,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
src += 2; src += 2;
} }
if (inverted && sig_value != NULL) { if (invert && sig_value != NULL) {
*sig_value = mp_obj_is_true(*sig_value) ? MP_OBJ_NEW_SMALL_INT(0) : MP_OBJ_NEW_SMALL_INT(1); *sig_value = mp_obj_is_true(*sig_value) ? MP_OBJ_NEW_SMALL_INT(0) : MP_OBJ_NEW_SMALL_INT(1);
} }
...@@ -95,8 +95,8 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t ...@@ -95,8 +95,8 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
{ {
if (n_args == 1) { if (n_args == 1) {
if (n_kw == 0) { if (n_kw == 0) {
} else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_inverted)) { } else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) {
inverted = mp_obj_is_true(args[1]); invert = mp_obj_is_true(args[1]);
} else { } else {
goto error; goto error;
} }
...@@ -109,7 +109,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t ...@@ -109,7 +109,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
machine_signal_t *o = m_new_obj(machine_signal_t); machine_signal_t *o = m_new_obj(machine_signal_t);
o->base.type = type; o->base.type = type;
o->pin = pin; o->pin = pin;
o->inverted = inverted; o->invert = invert;
return MP_OBJ_FROM_PTR(o); return MP_OBJ_FROM_PTR(o);
} }
...@@ -119,10 +119,10 @@ STATIC mp_uint_t signal_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg ...@@ -119,10 +119,10 @@ STATIC mp_uint_t signal_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg
switch (request) { switch (request) {
case MP_PIN_READ: { case MP_PIN_READ: {
return mp_virtual_pin_read(self->pin) ^ self->inverted; return mp_virtual_pin_read(self->pin) ^ self->invert;
} }
case MP_PIN_WRITE: { case MP_PIN_WRITE: {
mp_virtual_pin_write(self->pin, arg ^ self->inverted); mp_virtual_pin_write(self->pin, arg ^ self->invert);
return 0; return 0;
} }
} }
......
...@@ -33,7 +33,7 @@ print(p.value(), s.value()) ...@@ -33,7 +33,7 @@ print(p.value(), s.value())
# test inverted, and using on/off methods # test inverted, and using on/off methods
p = Pin() p = Pin()
s = machine.Signal(p, inverted=True) s = machine.Signal(p, invert=True)
s.off() s.off()
print(p.value(), s.value()) print(p.value(), s.value())
s.on() s.on()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment