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
9df6b3a2
Commit
9df6b3a2
authored
May 03, 2016
by
Damien George
Browse files
esp8266/modpybpin: Use enum+array instead of struct for parsing args.
parent
02fd83bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
esp8266/modpybpin.c
View file @
9df6b3a2
...
...
@@ -182,6 +182,7 @@ STATIC void pyb_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
// pin.init(mode, pull=Pin.PULL_NONE, af=-1)
STATIC
mp_obj_t
pyb_pin_obj_init_helper
(
pyb_pin_obj_t
*
self
,
mp_uint_t
n_args
,
const
mp_obj_t
*
pos_args
,
mp_map_t
*
kw_args
)
{
enum
{
ARG_mode
,
ARG_pull
,
ARG_value
};
static
const
mp_arg_t
allowed_args
[]
=
{
{
MP_QSTR_mode
,
MP_ARG_REQUIRED
|
MP_ARG_INT
},
{
MP_QSTR_pull
,
MP_ARG_INT
,
{.
u_int
=
GPIO_PULL_NONE
}},
...
...
@@ -189,24 +190,21 @@ STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, mp_uint_t n_args, c
};
// parse args
struct
{
mp_arg_val_t
mode
,
pull
,
value
;
}
args
;
mp_arg_parse_all
(
n_args
,
pos_args
,
kw_args
,
MP_ARRAY_SIZE
(
allowed_args
),
allowed_args
,
(
mp_arg_val_t
*
)
&
args
);
mp_arg_val_t
args
[
MP_ARRAY_SIZE
(
allowed_args
)];
mp_arg_parse_all
(
n_args
,
pos_args
,
kw_args
,
MP_ARRAY_SIZE
(
allowed_args
),
allowed_args
,
args
);
// get io mode
uint
mode
=
args
.
mode
.
u_int
;
uint
mode
=
args
[
ARG_
mode
]
.
u_int
;
// get pull mode
uint
pull
=
args
.
pull
.
u_int
;
uint
pull
=
args
[
ARG_
pull
]
.
u_int
;
// get initial value
int
value
;
if
(
args
.
value
.
u_obj
==
MP_OBJ_NULL
)
{
if
(
args
[
ARG_
value
]
.
u_obj
==
MP_OBJ_NULL
)
{
value
=
-
1
;
}
else
{
value
=
mp_obj_is_true
(
args
.
value
.
u_obj
);
value
=
mp_obj_is_true
(
args
[
ARG_
value
]
.
u_obj
);
}
// save the mode
...
...
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