Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
04019e36
Commit
04019e36
authored
Aug 09, 2014
by
Damien George
Browse files
stmhal, pin: Simplify default value for alternate function init.
parent
590b2abd
Changes
1
Hide whitespace changes
Inline
Side-by-side
stmhal/pin.c
View file @
04019e36
...
@@ -299,7 +299,7 @@ STATIC mp_obj_t pin_debug(uint n_args, mp_obj_t *args) {
...
@@ -299,7 +299,7 @@ STATIC mp_obj_t pin_debug(uint n_args, mp_obj_t *args) {
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
pin_debug_fun_obj
,
1
,
2
,
pin_debug
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
pin_debug_fun_obj
,
1
,
2
,
pin_debug
);
STATIC
MP_DEFINE_CONST_CLASSMETHOD_OBJ
(
pin_debug_obj
,
(
mp_obj_t
)
&
pin_debug_fun_obj
);
STATIC
MP_DEFINE_CONST_CLASSMETHOD_OBJ
(
pin_debug_obj
,
(
mp_obj_t
)
&
pin_debug_fun_obj
);
/// \method init(mode, pull=Pin.PULL_NONE, af=
None
)
/// \method init(mode, pull=Pin.PULL_NONE, af=
-1
)
/// Initialise the pin:
/// Initialise the pin:
///
///
/// - `mode` can be one of:
/// - `mode` can be one of:
...
@@ -320,7 +320,7 @@ STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, (mp_obj_t)&pin_debug_fun_o
...
@@ -320,7 +320,7 @@ STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, (mp_obj_t)&pin_debug_fun_o
STATIC
const
mp_arg_t
pin_init_args
[]
=
{
STATIC
const
mp_arg_t
pin_init_args
[]
=
{
{
MP_QSTR_mode
,
MP_ARG_REQUIRED
|
MP_ARG_INT
},
{
MP_QSTR_mode
,
MP_ARG_REQUIRED
|
MP_ARG_INT
},
{
MP_QSTR_pull
,
MP_ARG_INT
,
{.
u_int
=
GPIO_NOPULL
}},
{
MP_QSTR_pull
,
MP_ARG_INT
,
{.
u_int
=
GPIO_NOPULL
}},
{
MP_QSTR_af
,
MP_ARG_
OBJ
,
{.
u_
obj
=
mp_const_none
}},
{
MP_QSTR_af
,
MP_ARG_
INT
,
{.
u_
int
=
-
1
}},
};
};
#define PIN_INIT_NUM_ARGS MP_ARRAY_SIZE(pin_init_args)
#define PIN_INIT_NUM_ARGS MP_ARRAY_SIZE(pin_init_args)
...
@@ -342,13 +342,9 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, uint n_args, const mp
...
@@ -342,13 +342,9 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, uint n_args, const mp
}
}
// get af (alternate function)
// get af (alternate function)
mp_int_t
af_idx
=
-
1
;
mp_int_t
af
=
vals
[
2
].
u_int
;
mp_obj_t
af_obj
=
vals
[
2
].
u_obj
;
if
((
mode
==
GPIO_MODE_AF_PP
||
mode
==
GPIO_MODE_AF_OD
)
&&
!
IS_GPIO_AF
(
af
))
{
if
(
af_obj
!=
mp_const_none
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ValueError
,
"invalid pin af: %d"
,
af
));
af_idx
=
mp_obj_get_int
(
af_obj
);
}
if
((
mode
==
GPIO_MODE_AF_PP
||
mode
==
GPIO_MODE_AF_OD
)
&&
!
IS_GPIO_AF
(
af_idx
))
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ValueError
,
"invalid pin af: %d"
,
af_idx
));
}
}
// enable the peripheral clock for the port of this pin
// enable the peripheral clock for the port of this pin
...
@@ -391,7 +387,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, uint n_args, const mp
...
@@ -391,7 +387,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, uint n_args, const mp
GPIO_InitStructure
.
Mode
=
mode
;
GPIO_InitStructure
.
Mode
=
mode
;
GPIO_InitStructure
.
Pull
=
pull
;
GPIO_InitStructure
.
Pull
=
pull
;
GPIO_InitStructure
.
Speed
=
GPIO_SPEED_FAST
;
GPIO_InitStructure
.
Speed
=
GPIO_SPEED_FAST
;
GPIO_InitStructure
.
Alternate
=
af
_idx
;
GPIO_InitStructure
.
Alternate
=
af
;
HAL_GPIO_Init
(
self
->
gpio
,
&
GPIO_InitStructure
);
HAL_GPIO_Init
(
self
->
gpio
,
&
GPIO_InitStructure
);
return
mp_const_none
;
return
mp_const_none
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment