diff options
author | Daniel Campora <daniel@wipy.io> | 2015-08-23 13:52:31 +0200 |
---|---|---|
committer | Daniel Campora <daniel@wipy.io> | 2015-09-10 07:59:16 +0200 |
commit | 475c60eefcaae55a5ddeed95587ed262a663a735 (patch) | |
tree | 9c4b3af9635edbaea68f64172391b67a5514dec1 | |
parent | 86854c70719954f0de3a64a331f787d0676eac7f (diff) | |
download | micropython-475c60eefcaae55a5ddeed95587ed262a663a735.tar.gz micropython-475c60eefcaae55a5ddeed95587ed262a663a735.zip |
cc3200: Add alt param to Pin constructor.
-rw-r--r-- | cc3200/mods/pybpin.c | 7 | ||||
-rw-r--r-- | cc3200/qstrdefsport.h | 1 |
2 files changed, 7 insertions, 1 deletions
diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c index 28c33654fc..bbf40b5859 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 963b5be36d..ff0d26d9d2 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) |