summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--cc3200/application.mk1
-rw-r--r--cc3200/misc/pin_defs_cc3200.c55
-rw-r--r--cc3200/misc/pin_defs_cc3200.h41
-rw-r--r--cc3200/misc/pin_named_pins.c21
-rw-r--r--cc3200/mods/pybpin.c138
-rw-r--r--cc3200/mods/pybpin.h13
-rw-r--r--cc3200/mpconfigport.h1
-rw-r--r--cc3200/qstrdefsport.h14
8 files changed, 40 insertions, 244 deletions
diff --git a/cc3200/application.mk b/cc3200/application.mk
index a8ba287d5d..48db12b2aa 100644
--- a/cc3200/application.mk
+++ b/cc3200/application.mk
@@ -80,7 +80,6 @@ APP_MISC_SRC_C = $(addprefix misc/,\
mperror.c \
mpexception.c \
mpsystick.c \
- pin_defs_cc3200.c \
)
APP_MODS_SRC_C = $(addprefix mods/,\
diff --git a/cc3200/misc/pin_defs_cc3200.c b/cc3200/misc/pin_defs_cc3200.c
deleted file mode 100644
index a9b9413a12..0000000000
--- a/cc3200/misc/pin_defs_cc3200.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * This file is part of the Micro Python project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2013, 2014 Damien P. George
- * Copyright (c) 2015 Daniel Campora
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "py/mpconfig.h"
-#include MICROPY_HAL_H
-#include "py/obj.h"
-#include "inc/hw_types.h"
-#include "inc/hw_gpio.h"
-#include "inc/hw_ints.h"
-#include "inc/hw_memmap.h"
-#include "rom_map.h"
-#include "gpio.h"
-#include "pin.h"
-#include "pybpin.h"
-
-
-
-// Returns the pin mode. This value returned by this macro should be one of:
-// GPIO_DIR_MODE_IN or GPIO_DIR_MODE_OUT
-uint32_t pin_get_mode (const pin_obj_t *self) {
- return self->mode;
-}
-
-uint32_t pin_get_type (const pin_obj_t *self) {
- return self->type;
-}
-
-uint32_t pin_get_strenght (const pin_obj_t *self) {
- return self->strength;
-}
-
diff --git a/cc3200/misc/pin_defs_cc3200.h b/cc3200/misc/pin_defs_cc3200.h
deleted file mode 100644
index 6ba1640d65..0000000000
--- a/cc3200/misc/pin_defs_cc3200.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * This file is part of the Micro Python project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2013, 2014 Damien P. George
- * Copyright (c) 2015 Daniel Campora
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-// This file contains pin definitions that are specific to the cc3200 port.
-// This file should only ever be #included by pybgpio.h and not directly.
-
-
-//*****************************************************************************
-// Define types
-//*****************************************************************************
-
-enum {
- PORT_A0 = GPIOA0_BASE,
- PORT_A1 = GPIOA1_BASE,
- PORT_A2 = GPIOA2_BASE,
- PORT_A3 = GPIOA3_BASE
-};
diff --git a/cc3200/misc/pin_named_pins.c b/cc3200/misc/pin_named_pins.c
index 19321f4fac..66ddc7fdc6 100644
--- a/cc3200/misc/pin_named_pins.c
+++ b/cc3200/misc/pin_named_pins.c
@@ -37,17 +37,6 @@
#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);
@@ -58,16 +47,6 @@ pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
return NULL;
}
-pin_obj_t *pin_find_pin(const mp_obj_dict_t *named_pins, uint pin_num) {
- mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)named_pins);
- for (uint i = 0; i < named_map->used; i++) {
- if (((pin_obj_t *)named_map->table[i].value)->pin_num == pin_num) {
- return named_map->table[i].value;
- }
- }
- return NULL;
-}
-
pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit) {
mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)named_pins);
for (uint i = 0; i < named_map->used; i++) {
diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c
index 08a63e5678..e1e7e4871b 100644
--- a/cc3200/mods/pybpin.c
+++ b/cc3200/mods/pybpin.c
@@ -61,29 +61,7 @@
///
/// Usage Model:
///
-/// All CPU Pins are predefined as pyb.Pin.cpu.Name
-///
-/// GPIO9_pin = pyb.Pin.cpu.GPIO9
-///
-/// g = pyb.Pin(pyb.Pin.cpu.GPIO9, 0, pyb.Pin.IN)
-///
-/// CPU pins which correspond to the board pins are available
-/// as `pyb.cpu.Name`.
-///
-/// You can also use strings:
-///
-/// g = pyb.Pin('GPIO9', 0)
-///
-/// And finally, you can also pass a pin number directly:
-///
-/// g = pyb.Pin(64, 0)
-///
-/// To summarise, the following order determines how things get mapped into
-/// an ordinal pin number:
-///
-/// 1. Directly specify a Pin object
-/// 2. Supply a string which matches a CPU pin name
-/// 3. Provide a pin number
+/// g = pyb.Pin('GPIO9', af=0, mode=pyb.Pin.IN, type=pyb.Pin.STD, strength=pyb.Pin.S2MA)
///
/// \Interrupts:
//// You can also configure the Pin to generate interrupts
@@ -91,7 +69,7 @@
/// Example callback:
///
/// def pincb(pin):
-/// print(pin.pin())
+/// print(pin.get_config().name)
///
/// extint = pyb.Pin('GPIO10', 0, pyb.Pin.INT_RISING, pyb.GPIO.STD_PD, pyb.S2MA)
/// extint.callback (intmode=pyb.Pin.INT_RISING, handler=pincb)
@@ -166,28 +144,18 @@ void pin_init0(void) {
pin_obj_t *pin_find(mp_obj_t user_obj) {
pin_obj_t *pin_obj;
- // If a pin was provided, then use it
+ // if a pin was provided, use it
if (MP_OBJ_IS_TYPE(user_obj, &pin_type)) {
pin_obj = user_obj;
return pin_obj;
}
- // See if the pin name matches a cpu pin
+ // otherwise see if the pin name matches a cpu pin
pin_obj = pin_find_named_pin(&pin_cpu_pins_locals_dict, user_obj);
if (pin_obj) {
return pin_obj;
}
- // See if the pin number matches a cpu pin
- mp_int_t pin_num;
- if (mp_obj_get_int_maybe(user_obj, &pin_num)) {
- // The Pins dictionary has pin indexes, so we must substract one from the value passed
- pin_obj = pin_find_pin(&pin_cpu_pins_locals_dict, (pin_num - 1));
- if (pin_obj) {
- return pin_obj;
- }
- }
-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
}
@@ -387,7 +355,7 @@ STATIC const mp_arg_t pin_init_args[] = {
{ MP_QSTR_af, MP_ARG_REQUIRED | MP_ARG_INT },
{ MP_QSTR_mode, MP_ARG_INT, {.u_int = GPIO_DIR_MODE_OUT} },
{ MP_QSTR_type, MP_ARG_INT, {.u_int = PIN_TYPE_STD} },
- { MP_QSTR_str, MP_ARG_INT, {.u_int = PIN_STRENGTH_4MA} },
+ { MP_QSTR_strength, MP_ARG_INT, {.u_int = PIN_STRENGTH_4MA} },
};
#define pin_INIT_NUM_ARGS MP_ARRAY_SIZE(pin_init_args)
@@ -431,17 +399,18 @@ STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, mp_uint_t n_args, const mp_
/// Return a string describing the pin object.
STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pin_obj_t *self = self_in;
- uint32_t af = MAP_PinModeGet(self->pin_num);
- uint32_t type = pin_get_type(self);
- uint32_t strength = pin_get_strenght(self);
+ uint32_t af = self->af;
+ uint32_t type = self->type;
+ uint32_t strength = self->strength;
// pin name
mp_printf(print, "<Pin.cpu.%q, af=%u", self->name, af);
+ // pin mode
if (af == PIN_MODE_0) {
// IO mode
qstr mode_qst;
- uint32_t mode = pin_get_mode(self);
+ uint32_t mode = self->mode;
if (mode == GPIO_DIR_MODE_IN) {
mode_qst = MP_QSTR_IN;
} else {
@@ -465,9 +434,9 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
} else {
type_qst = MP_QSTR_OD_PD;
}
- mp_printf(print, ", pull=Pin.%q", type_qst);
+ mp_printf(print, ", type=Pin.%q", type_qst);
- // Strength
+ // pin strength
qstr str_qst;
if (strength == PIN_STRENGTH_2MA) {
str_qst = MP_QSTR_S2MA;
@@ -554,65 +523,25 @@ 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()
-/// Get the pin name.
-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 port()
-/// Get the pin port.
-STATIC mp_obj_t pin_port(mp_obj_t self_in) {
- pin_obj_t *self = self_in;
- return mp_obj_new_int(self->port);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port);
-
-/// \method pin()
-/// Get the pin number.
-STATIC mp_obj_t pin_pin(mp_obj_t self_in) {
- pin_obj_t *self = self_in;
- return MP_OBJ_NEW_SMALL_INT(self->pin_num);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin);
-
-/// \method mode()
-/// Returns the currently configured mode of the gpio pin. The integer returned
-/// will match one of the allowed constants for the mode argument to the init
-/// function.
-STATIC mp_obj_t pin_mode(mp_obj_t self_in) {
- return MP_OBJ_NEW_SMALL_INT(pin_get_mode(self_in));
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_mode_obj, pin_mode);
-
-/// \method type()
-/// Returns the currently configured type of the pin. The integer returned
-/// will match one of the allowed constants for the type argument to the init
-/// function.
-STATIC mp_obj_t pin_type_get(mp_obj_t self_in) {
- return MP_OBJ_NEW_SMALL_INT(pin_get_type(self_in));
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_type_obj, pin_type_get);
-
-/// \method strength()
-/// Returns the currently configured drive strength of the pin. The integer returned
-/// will match one of the allowed constants for the strength argument to the init
-/// function.
-STATIC mp_obj_t pin_strength(mp_obj_t self_in) {
- return MP_OBJ_NEW_SMALL_INT(pin_get_strenght(self_in));
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_strenght_obj, pin_strength);
+/// \method get_config()
+/// Returns a named tupple with the current configuration of the gpio pin
+STATIC mp_obj_t pin_get_config(mp_obj_t self_in) {
+ STATIC const qstr pin_config_fields[] = {
+ MP_QSTR_name, MP_QSTR_af, MP_QSTR_mode,
+ MP_QSTR_type, MP_QSTR_strength
+ };
-/// \method af()
-/// Returns the currently configured alternate function of the gpio pin. The integer returned
-/// will match one of the allowed constants for the af argument to the init function.
-STATIC mp_obj_t pin_af(mp_obj_t self_in) {
pin_obj_t *self = self_in;
- return MP_OBJ_NEW_SMALL_INT(MAP_PinModeGet(self->pin_num));
+ mp_obj_t pin_config[5];
+ pin_config[0] = MP_OBJ_NEW_QSTR(self->name);
+ pin_config[1] = mp_obj_new_int(self->af);
+ pin_config[2] = mp_obj_new_int(self->mode);
+ pin_config[3] = mp_obj_new_int(self->type);
+ pin_config[4] = mp_obj_new_int(self->strength);
+
+ return mp_obj_new_attrtuple(pin_config_fields, 5, pin_config);
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_get_config_obj, pin_get_config);
/// \method callback(method, intmode, priority, pwrmode)
/// Creates a callback object associated to a pin
@@ -750,18 +679,9 @@ 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_port), (mp_obj_t)&pin_port_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_pin), (mp_obj_t)&pin_pin_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_mode), (mp_obj_t)&pin_mode_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_type), (mp_obj_t)&pin_type_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_strength), (mp_obj_t)&pin_strenght_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_af), (mp_obj_t)&pin_af_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_get_config), (mp_obj_t)&pin_get_config_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/mods/pybpin.h b/cc3200/mods/pybpin.h
index 417e91bf62..a31a41528f 100644
--- a/cc3200/mods/pybpin.h
+++ b/cc3200/mods/pybpin.h
@@ -28,13 +28,15 @@
#ifndef PYBPIN_H_
#define PYBPIN_H_
-// This file requires pin_defs_xxx.h (which has port specific enums and
-// defines, so we include it here. It should never be included directly
-
-#include MICROPY_PIN_DEFS_PORT_H
-
#define PYBPIN_ANALOG_TYPE 0xFF
+enum {
+ PORT_A0 = GPIOA0_BASE,
+ PORT_A1 = GPIOA1_BASE,
+ PORT_A2 = GPIOA2_BASE,
+ PORT_A3 = GPIOA3_BASE
+};
+
typedef struct {
const mp_obj_base_t base;
const qstr name;
@@ -70,7 +72,6 @@ void pin_config(pin_obj_t *self, uint af, uint mode, uint type, uint strength);
void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority);
pin_obj_t *pin_find(mp_obj_t user_obj);
pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
-pin_obj_t *pin_find_pin(const mp_obj_dict_t *named_pins, uint pin_num);
pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit);
uint32_t pin_get_mode(const pin_obj_t *self);
uint32_t pin_get_type(const pin_obj_t *self);
diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h
index 17dc630e29..73accda5fc 100644
--- a/cc3200/mpconfigport.h
+++ b/cc3200/mpconfigport.h
@@ -171,7 +171,6 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
#include "mpconfigboard.h"
#define MICROPY_HAL_H "cc3200_hal.h"
-#define MICROPY_PIN_DEFS_PORT_H "pin_defs_cc3200.h"
#define MICROPY_PORT_HAS_TELNET (1)
#define MICROPY_PORT_HAS_FTP (1)
#define MICROPY_PY_SYS_PLATFORM "WiPy"
diff --git a/cc3200/qstrdefsport.h b/cc3200/qstrdefsport.h
index e06f1ad178..9bce1c2aab 100644
--- a/cc3200/qstrdefsport.h
+++ b/cc3200/qstrdefsport.h
@@ -109,19 +109,13 @@ Q(init)
Q(value)
Q(low)
Q(high)
+Q(toggle)
+Q(get_config)
Q(name)
-Q(port)
-Q(pin)
-Q(cpu)
+Q(af)
Q(mode)
-Q(pull)
-Q(index)
+Q(type)
Q(strength)
-Q(af)
-Q(intenable)
-Q(intdisable)
-Q(intmode)
-Q(swint)
Q(IN)
Q(OUT)
Q(STD)