summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cc3200/misc/pin_named_pins.c14
-rw-r--r--cc3200/mods/pybpin.c14
-rw-r--r--cc3200/qstrdefsport.h1
-rw-r--r--docs/library/pyb.Pin.rst17
4 files changed, 39 insertions, 7 deletions
diff --git a/cc3200/misc/pin_named_pins.c b/cc3200/misc/pin_named_pins.c
index 66ddc7fdc..f6c5e8c74 100644
--- a/cc3200/misc/pin_named_pins.c
+++ b/cc3200/misc/pin_named_pins.c
@@ -30,14 +30,26 @@
#include <string.h>
#include "py/mpconfig.h"
+#include MICROPY_HAL_H
#include "py/obj.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "pybpin.h"
-#include MICROPY_HAL_H
+STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
+ pin_named_pins_obj_t *self = self_in;
+ mp_printf(print, "<Pin.%q>", self->name);
+}
+
+const mp_obj_type_t pin_cpu_pins_obj_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_cpu,
+ .print = pin_named_pins_obj_print,
+ .locals_dict = (mp_obj_t)&pin_cpu_pins_locals_dict,
+};
+
pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)named_pins);
mp_map_elem_t *named_elem = mp_map_lookup(named_map, name, MP_MAP_LOOKUP);
diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c
index 248ddafa0..8efc3cd6a 100644
--- a/cc3200/mods/pybpin.c
+++ b/cc3200/mods/pybpin.c
@@ -69,7 +69,7 @@
/// Example callback:
///
/// def pincb(pin):
-/// print(pin.get_config().name)
+/// print(pin.name())
///
/// extint = pyb.Pin('GPIO10', 0, pyb.Pin.INT_RISING, pyb.GPIO.STD_PD, pyb.S2MA)
/// extint.callback (mode=pyb.Pin.INT_RISING, handler=pincb)
@@ -525,6 +525,14 @@ STATIC mp_obj_t pin_toggle(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_toggle_obj, pin_toggle);
+/// \method name()
+/// Returns the qstr name of the pin
+STATIC mp_obj_t pin_name(mp_obj_t self_in) {
+ pin_obj_t *self = self_in;
+ return MP_OBJ_NEW_QSTR(self->name);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name);
+
/// \method info()
/// Returns a named tupple with the current configuration of the gpio pin
STATIC mp_obj_t pin_info(mp_obj_t self_in) {
@@ -681,9 +689,13 @@ STATIC const mp_map_elem_t pin_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_low), (mp_obj_t)&pin_low_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_high), (mp_obj_t)&pin_high_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_toggle), (mp_obj_t)&pin_toggle_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&pin_name_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pin_info_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&pin_callback_obj },
+ // class attributes
+ { MP_OBJ_NEW_QSTR(MP_QSTR_cpu), (mp_obj_t)&pin_cpu_pins_obj_type },
+
// class constants
/// \constant IN - set the pin to input mode
/// \constant OUT - set the pin to output mode
diff --git a/cc3200/qstrdefsport.h b/cc3200/qstrdefsport.h
index 9f50dc7ad..8ef6c739f 100644
--- a/cc3200/qstrdefsport.h
+++ b/cc3200/qstrdefsport.h
@@ -109,6 +109,7 @@ Q(tell)
// for Pin class
Q(Pin)
+Q(cpu)
Q(init)
Q(value)
Q(low)
diff --git a/docs/library/pyb.Pin.rst b/docs/library/pyb.Pin.rst
index 77a96494e..092af11c7 100644
--- a/docs/library/pyb.Pin.rst
+++ b/docs/library/pyb.Pin.rst
@@ -72,7 +72,7 @@ Usage Model:
You can also configure the Pin to generate interrupts. For instance::
def pincb(pin):
- print(pin.info().name)
+ print(pin.name())
pin_int = pyb.Pin('GPIO10', af=0, mode=Pin.IN, type=pyb.Pin.STD_PD, strength=pyb.Pin.S2MA)
pin_int.callback (mode=pyb.Pin.INT_RISING, handler=pincb)
@@ -229,10 +229,12 @@ Methods
will match one of the allowed constants for the mode argument to the init
function.
- .. method:: pin.name()
-
- Get the pin name.
-
+.. method:: pin.name()
+
+ Get the pin name.
+
+.. only:: port_pyboard
+
.. method:: pin.names()
Returns the cpu and board names for this pin.
@@ -262,6 +264,11 @@ Methods
Return a 5-tuple with the configuration of the pin:
``(name, alternate-function, mode, type, strength)``
+ .. warning::
+ This method cannot be called within a callback (interrupt-context)
+ because it needs to allocate memory to return the tuple and memory
+ allocations are disabled while interrupts are being serviced.
+
.. method:: pin.callback(\*, mode, priority=1, handler=None, wakes=pyb.Sleep.ACTIVE)
Create a callback to be triggered when the input level at the pin changes.