cc3200: Add `Pin.name()` method.

modjni
Daniel Campora 2015-06-28 12:53:37 +02:00
parent 778413168b
commit 813b581127
4 changed files with 39 additions and 7 deletions

View File

@ -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);

View File

@ -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

View File

@ -109,6 +109,7 @@ Q(tell)
// for Pin class
Q(Pin)
Q(cpu)
Q(init)
Q(value)
Q(low)

View File

@ -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.