Skip to content

Commit 475c60e

Browse files
author
Daniel Campora
committed
cc3200: Add alt param to Pin constructor.
1 parent 86854c7 commit 475c60e

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

cc3200/mods/pybpin.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,15 @@ STATIC void EXTI_Handler(uint port) {
418418
/// - `Pin.LOW_POWER` - 2ma drive strength
419419
/// - `Pin.MED_POWER` - 4ma drive strength
420420
/// - `Pin.HIGH_POWER` - 6ma drive strength
421+
/// - `alt` selects the alternate function (a number from 0 to 15).
421422
///
422423
/// Returns: `None`.
423424
STATIC const mp_arg_t pin_init_args[] = {
424425
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT },
425426
{ MP_QSTR_pull, MP_ARG_INT, {.u_int = PIN_TYPE_STD} },
426427
{ MP_QSTR_value, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
427428
{ MP_QSTR_drive, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = PIN_STRENGTH_4MA} },
429+
{ MP_QSTR_alt, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
428430
};
429431
#define pin_INIT_NUM_ARGS MP_ARRAY_SIZE(pin_init_args)
430432

@@ -455,7 +457,10 @@ STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, mp_uint_t n_args, const mp_
455457
uint strength = args[3].u_int;
456458
pin_validate_drive(strength);
457459

458-
int af = (mode == GPIO_DIR_MODE_ALT || mode == GPIO_DIR_MODE_ALT_OD) ? -1 : PIN_MODE_0;
460+
int af = args[4].u_int;
461+
if ((af > 0 && (mode != GPIO_DIR_MODE_ALT || mode != GPIO_DIR_MODE_ALT_OD)) || af > 15) {
462+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
463+
}
459464

460465
// configure the pin as requested
461466
pin_config (self, af, mode, pull, value, strength);

cc3200/qstrdefsport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Q(id)
120120
Q(mode)
121121
Q(pull)
122122
Q(drive)
123+
Q(alt)
123124
Q(IN)
124125
Q(OUT)
125126
Q(OPEN_DRAIN)

0 commit comments

Comments
 (0)