summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cc3200/mods/pybpin.c7
-rw-r--r--cc3200/qstrdefsport.h1
2 files changed, 7 insertions, 1 deletions
diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c
index 28c33654f..bbf40b585 100644
--- a/cc3200/mods/pybpin.c
+++ b/cc3200/mods/pybpin.c
@@ -418,6 +418,7 @@ STATIC void EXTI_Handler(uint port) {
/// - `Pin.LOW_POWER` - 2ma drive strength
/// - `Pin.MED_POWER` - 4ma drive strength
/// - `Pin.HIGH_POWER` - 6ma drive strength
+/// - `alt` selects the alternate function (a number from 0 to 15).
///
/// Returns: `None`.
STATIC const mp_arg_t pin_init_args[] = {
@@ -425,6 +426,7 @@ STATIC const mp_arg_t pin_init_args[] = {
{ MP_QSTR_pull, MP_ARG_INT, {.u_int = PIN_TYPE_STD} },
{ MP_QSTR_value, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_drive, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = PIN_STRENGTH_4MA} },
+ { MP_QSTR_alt, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
};
#define pin_INIT_NUM_ARGS MP_ARRAY_SIZE(pin_init_args)
@@ -455,7 +457,10 @@ STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, mp_uint_t n_args, const mp_
uint strength = args[3].u_int;
pin_validate_drive(strength);
- int af = (mode == GPIO_DIR_MODE_ALT || mode == GPIO_DIR_MODE_ALT_OD) ? -1 : PIN_MODE_0;
+ int af = args[4].u_int;
+ if ((af > 0 && (mode != GPIO_DIR_MODE_ALT || mode != GPIO_DIR_MODE_ALT_OD)) || af > 15) {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
+ }
// configure the pin as requested
pin_config (self, af, mode, pull, value, strength);
diff --git a/cc3200/qstrdefsport.h b/cc3200/qstrdefsport.h
index 963b5be36..ff0d26d9d 100644
--- a/cc3200/qstrdefsport.h
+++ b/cc3200/qstrdefsport.h
@@ -120,6 +120,7 @@ Q(id)
Q(mode)
Q(pull)
Q(drive)
+Q(alt)
Q(IN)
Q(OUT)
Q(OPEN_DRAIN)