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
dbc81df5
Commit
dbc81df5
authored
Apr 26, 2014
by
Damien George
Browse files
Simplify names for argcheck.c / arg parsing.
parent
6d3c5e43
Changes
8
Hide whitespace changes
Inline
Side-by-side
py/argcheck.c
View file @
dbc81df5
...
@@ -34,12 +34,12 @@ void mp_arg_check_num(uint n_args, uint n_kw, uint n_args_min, uint n_args_max,
...
@@ -34,12 +34,12 @@ void mp_arg_check_num(uint n_args, uint n_kw, uint n_args_min, uint n_args_max,
}
}
}
}
void
mp_arg_parse_all
(
uint
n_pos
,
const
mp_obj_t
*
pos
,
mp_map_t
*
kws
,
uint
n_allowed
,
const
mp_arg_
parse_
t
*
allowed
,
mp_arg_
parse_
val_t
*
out_vals
)
{
void
mp_arg_parse_all
(
uint
n_pos
,
const
mp_obj_t
*
pos
,
mp_map_t
*
kws
,
uint
n_allowed
,
const
mp_arg_t
*
allowed
,
mp_arg_val_t
*
out_vals
)
{
uint
pos_found
=
0
,
kws_found
=
0
;
uint
pos_found
=
0
,
kws_found
=
0
;
for
(
uint
i
=
0
;
i
<
n_allowed
;
i
++
)
{
for
(
uint
i
=
0
;
i
<
n_allowed
;
i
++
)
{
mp_obj_t
given_arg
;
mp_obj_t
given_arg
;
if
(
i
<
n_pos
)
{
if
(
i
<
n_pos
)
{
if
(
allowed
[
i
].
flags
&
MP_ARG_
PARSE_
KW_ONLY
)
{
if
(
allowed
[
i
].
flags
&
MP_ARG_KW_ONLY
)
{
goto
extra_positional
;
goto
extra_positional
;
}
}
pos_found
++
;
pos_found
++
;
...
@@ -47,7 +47,7 @@ void mp_arg_parse_all(uint n_pos, const mp_obj_t *pos, mp_map_t *kws, uint n_all
...
@@ -47,7 +47,7 @@ void mp_arg_parse_all(uint n_pos, const mp_obj_t *pos, mp_map_t *kws, uint n_all
}
else
{
}
else
{
mp_map_elem_t
*
kw
=
mp_map_lookup
(
kws
,
MP_OBJ_NEW_QSTR
(
allowed
[
i
].
qstr
),
MP_MAP_LOOKUP
);
mp_map_elem_t
*
kw
=
mp_map_lookup
(
kws
,
MP_OBJ_NEW_QSTR
(
allowed
[
i
].
qstr
),
MP_MAP_LOOKUP
);
if
(
kw
==
NULL
)
{
if
(
kw
==
NULL
)
{
if
(
allowed
[
i
].
flags
&
MP_ARG_
PARSE_
REQUIRED
)
{
if
(
allowed
[
i
].
flags
&
MP_ARG_REQUIRED
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"'%s' argument required"
,
qstr_str
(
allowed
[
i
].
qstr
)));
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"'%s' argument required"
,
qstr_str
(
allowed
[
i
].
qstr
)));
}
}
out_vals
[
i
]
=
allowed
[
i
].
defval
;
out_vals
[
i
]
=
allowed
[
i
].
defval
;
...
@@ -57,11 +57,11 @@ void mp_arg_parse_all(uint n_pos, const mp_obj_t *pos, mp_map_t *kws, uint n_all
...
@@ -57,11 +57,11 @@ void mp_arg_parse_all(uint n_pos, const mp_obj_t *pos, mp_map_t *kws, uint n_all
given_arg
=
kw
->
value
;
given_arg
=
kw
->
value
;
}
}
}
}
if
((
allowed
[
i
].
flags
&
MP_ARG_
PARSE_
KIND_MASK
)
==
MP_ARG_
PARSE_
BOOL
)
{
if
((
allowed
[
i
].
flags
&
MP_ARG_KIND_MASK
)
==
MP_ARG_BOOL
)
{
out_vals
[
i
].
u_bool
=
mp_obj_is_true
(
given_arg
);
out_vals
[
i
].
u_bool
=
mp_obj_is_true
(
given_arg
);
}
else
if
((
allowed
[
i
].
flags
&
MP_ARG_
PARSE_
KIND_MASK
)
==
MP_ARG_
PARSE_
INT
)
{
}
else
if
((
allowed
[
i
].
flags
&
MP_ARG_KIND_MASK
)
==
MP_ARG_INT
)
{
out_vals
[
i
].
u_int
=
mp_obj_get_int
(
given_arg
);
out_vals
[
i
].
u_int
=
mp_obj_get_int
(
given_arg
);
}
else
if
((
allowed
[
i
].
flags
&
MP_ARG_
PARSE_
KIND_MASK
)
==
MP_ARG_
PARSE_
OBJ
)
{
}
else
if
((
allowed
[
i
].
flags
&
MP_ARG_KIND_MASK
)
==
MP_ARG_OBJ
)
{
out_vals
[
i
].
u_obj
=
given_arg
;
out_vals
[
i
].
u_obj
=
given_arg
;
}
else
{
}
else
{
assert
(
0
);
assert
(
0
);
...
...
py/runtime.h
View file @
dbc81df5
...
@@ -5,31 +5,31 @@ typedef enum {
...
@@ -5,31 +5,31 @@ typedef enum {
}
mp_vm_return_kind_t
;
}
mp_vm_return_kind_t
;
typedef
enum
{
typedef
enum
{
MP_ARG_
PARSE_
BOOL
=
0x001
,
MP_ARG_BOOL
=
0x001
,
MP_ARG_
PARSE_
INT
=
0x002
,
MP_ARG_INT
=
0x002
,
MP_ARG_
PARSE_
OBJ
=
0x003
,
MP_ARG_OBJ
=
0x003
,
MP_ARG_
PARSE_
KIND_MASK
=
0x0ff
,
MP_ARG_KIND_MASK
=
0x0ff
,
MP_ARG_
PARSE_
REQUIRED
=
0x100
,
MP_ARG_REQUIRED
=
0x100
,
MP_ARG_
PARSE_
KW_ONLY
=
0x200
,
MP_ARG_KW_ONLY
=
0x200
,
}
mp_arg_
parse_
flag_t
;
}
mp_arg_flag_t
;
typedef
union
_mp_arg_
parse_
val_t
{
typedef
union
_mp_arg_val_t
{
bool
u_bool
;
bool
u_bool
;
machine_int_t
u_int
;
machine_int_t
u_int
;
mp_obj_t
u_obj
;
mp_obj_t
u_obj
;
}
mp_arg_
parse_
val_t
;
}
mp_arg_val_t
;
typedef
struct
_mp_arg_
parse_
t
{
typedef
struct
_mp_arg_t
{
qstr
qstr
;
qstr
qstr
;
machine_uint_t
flags
;
machine_uint_t
flags
;
mp_arg_
parse_
val_t
defval
;
mp_arg_val_t
defval
;
}
mp_arg_
parse_
t
;
}
mp_arg_t
;
void
mp_init
(
void
);
void
mp_init
(
void
);
void
mp_deinit
(
void
);
void
mp_deinit
(
void
);
void
mp_arg_check_num
(
uint
n_args
,
uint
n_kw
,
uint
n_args_min
,
uint
n_args_max
,
bool
takes_kw
);
void
mp_arg_check_num
(
uint
n_args
,
uint
n_kw
,
uint
n_args_min
,
uint
n_args_max
,
bool
takes_kw
);
void
mp_arg_parse_all
(
uint
n_pos
,
const
mp_obj_t
*
pos
,
mp_map_t
*
kws
,
uint
n_allowed
,
const
mp_arg_
parse_
t
*
allowed
,
mp_arg_
parse_
val_t
*
out_vals
);
void
mp_arg_parse_all
(
uint
n_pos
,
const
mp_obj_t
*
pos
,
mp_map_t
*
kws
,
uint
n_allowed
,
const
mp_arg_t
*
allowed
,
mp_arg_val_t
*
out_vals
);
mp_obj_dict_t
*
mp_locals_get
(
void
);
mp_obj_dict_t
*
mp_locals_get
(
void
);
void
mp_locals_set
(
mp_obj_dict_t
*
d
);
void
mp_locals_set
(
mp_obj_dict_t
*
d
);
...
...
stmhal/dac.c
View file @
dbc81df5
...
@@ -162,19 +162,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_write_obj, pyb_dac_write);
...
@@ -162,19 +162,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_write_obj, pyb_dac_write);
// TODO add callback argument, to call when transfer is finished
// TODO add callback argument, to call when transfer is finished
// TODO add double buffer argument
// TODO add double buffer argument
STATIC
const
mp_arg_
parse_
t
pyb_dac_write_timed_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_dac_write_timed_args
[]
=
{
{
MP_QSTR_data
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_data
,
MP_ARG_REQUIRED
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_freq
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_freq
,
MP_ARG_REQUIRED
|
MP_ARG_INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_mode
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
DMA_NORMAL
}
},
{
MP_QSTR_mode
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
DMA_NORMAL
}
},
};
};
#define PYB_DAC_WRITE_TIMED_NUM_ARGS ARRAY_SIZE(pyb_dac_write_timed_
accepted_
args)
#define PYB_DAC_WRITE_TIMED_NUM_ARGS ARRAY_SIZE(pyb_dac_write_timed_args)
mp_obj_t
pyb_dac_write_timed
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
mp_obj_t
pyb_dac_write_timed
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
pyb_dac_obj_t
*
self
=
args
[
0
];
pyb_dac_obj_t
*
self
=
args
[
0
];
// parse args
// parse args
mp_arg_
parse_
val_t
vals
[
PYB_DAC_WRITE_TIMED_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_DAC_WRITE_TIMED_NUM_ARGS
];
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_DAC_WRITE_TIMED_NUM_ARGS
,
pyb_dac_write_timed_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_DAC_WRITE_TIMED_NUM_ARGS
,
pyb_dac_write_timed_args
,
vals
);
// get the data to write
// get the data to write
mp_buffer_info_t
bufinfo
;
mp_buffer_info_t
bufinfo
;
...
...
stmhal/extint.c
View file @
dbc81df5
...
@@ -239,13 +239,13 @@ STATIC mp_obj_t extint_regs(void) {
...
@@ -239,13 +239,13 @@ STATIC mp_obj_t extint_regs(void) {
// line_obj = pyb.ExtInt(pin, mode, pull, callback)
// line_obj = pyb.ExtInt(pin, mode, pull, callback)
STATIC
const
mp_arg_
parse_
t
pyb_extint_make_new_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_extint_make_new_args
[]
=
{
{
MP_QSTR_pin
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_pin
,
MP_ARG_REQUIRED
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_mode
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_mode
,
MP_ARG_REQUIRED
|
MP_ARG_INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_pull
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_pull
,
MP_ARG_REQUIRED
|
MP_ARG_INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_callback
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_callback
,
MP_ARG_REQUIRED
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
};
};
#define PYB_EXTINT_MAKE_NEW_NUM_ARGS ARRAY_SIZE(pyb_extint_make_new_
accepted_
args)
#define PYB_EXTINT_MAKE_NEW_NUM_ARGS ARRAY_SIZE(pyb_extint_make_new_args)
STATIC
mp_obj_t
extint_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
STATIC
mp_obj_t
extint_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
// type_in == extint_obj_type
// type_in == extint_obj_type
...
@@ -253,8 +253,8 @@ STATIC mp_obj_t extint_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
...
@@ -253,8 +253,8 @@ STATIC mp_obj_t extint_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
// parse args
// parse args
mp_map_t
kw_args
;
mp_map_t
kw_args
;
mp_map_init_fixed_table
(
&
kw_args
,
n_kw
,
args
+
n_args
);
mp_map_init_fixed_table
(
&
kw_args
,
n_kw
,
args
+
n_args
);
mp_arg_
parse_
val_t
vals
[
PYB_EXTINT_MAKE_NEW_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_EXTINT_MAKE_NEW_NUM_ARGS
];
mp_arg_parse_all
(
n_args
,
args
,
&
kw_args
,
PYB_EXTINT_MAKE_NEW_NUM_ARGS
,
pyb_extint_make_new_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
,
args
,
&
kw_args
,
PYB_EXTINT_MAKE_NEW_NUM_ARGS
,
pyb_extint_make_new_args
,
vals
);
extint_obj_t
*
self
=
m_new_obj
(
extint_obj_t
);
extint_obj_t
*
self
=
m_new_obj
(
extint_obj_t
);
self
->
base
.
type
=
type_in
;
self
->
base
.
type
=
type_in
;
...
...
stmhal/i2c.c
View file @
dbc81df5
...
@@ -176,18 +176,18 @@ STATIC void pyb_i2c_print(void (*print)(void *env, const char *fmt, ...), void *
...
@@ -176,18 +176,18 @@ STATIC void pyb_i2c_print(void (*print)(void *env, const char *fmt, ...), void *
}
}
}
}
STATIC
const
mp_arg_
parse_
t
pyb_i2c_init_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_i2c_init_args
[]
=
{
{
MP_QSTR_mode
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_mode
,
MP_ARG_REQUIRED
|
MP_ARG_INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_addr
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
0x12
}
},
{
MP_QSTR_addr
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
0x12
}
},
{
MP_QSTR_baudrate
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
400000
}
},
{
MP_QSTR_baudrate
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
400000
}
},
{
MP_QSTR_gencall
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
BOOL
,
{.
u_bool
=
false
}
},
{
MP_QSTR_gencall
,
MP_ARG_KW_ONLY
|
MP_ARG_BOOL
,
{.
u_bool
=
false
}
},
};
};
#define PYB_I2C_INIT_NUM_ARGS ARRAY_SIZE(pyb_i2c_init_
accepted_
args)
#define PYB_I2C_INIT_NUM_ARGS ARRAY_SIZE(pyb_i2c_init_args)
STATIC
mp_obj_t
pyb_i2c_init_helper
(
const
pyb_i2c_obj_t
*
self
,
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
STATIC
mp_obj_t
pyb_i2c_init_helper
(
const
pyb_i2c_obj_t
*
self
,
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
// parse args
// parse args
mp_arg_
parse_
val_t
vals
[
PYB_I2C_INIT_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_I2C_INIT_NUM_ARGS
];
mp_arg_parse_all
(
n_args
,
args
,
kw_args
,
PYB_I2C_INIT_NUM_ARGS
,
pyb_i2c_init_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
,
args
,
kw_args
,
PYB_I2C_INIT_NUM_ARGS
,
pyb_i2c_init_args
,
vals
);
// set the I2C configuration values
// set the I2C configuration values
I2C_InitTypeDef
*
init
=
&
self
->
i2c
->
Init
;
I2C_InitTypeDef
*
init
=
&
self
->
i2c
->
Init
;
...
@@ -295,19 +295,19 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
...
@@ -295,19 +295,19 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
pyb_i2c_scan_obj
,
pyb_i2c_scan
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
pyb_i2c_scan_obj
,
pyb_i2c_scan
);
STATIC
const
mp_arg_
parse_
t
pyb_i2c_send_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_i2c_send_args
[]
=
{
{
MP_QSTR_send
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_send
,
MP_ARG_REQUIRED
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_addr
,
MP_ARG_
PARSE_
INT
,
{.
u_int
=
PYB_I2C_MASTER_ADDRESS
}
},
{
MP_QSTR_addr
,
MP_ARG_INT
,
{.
u_int
=
PYB_I2C_MASTER_ADDRESS
}
},
{
MP_QSTR_timeout
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
5000
}
},
{
MP_QSTR_timeout
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
5000
}
},
};
};
#define PYB_I2C_SEND_NUM_ARGS ARRAY_SIZE(pyb_i2c_send_
accepted_
args)
#define PYB_I2C_SEND_NUM_ARGS ARRAY_SIZE(pyb_i2c_send_args)
STATIC
mp_obj_t
pyb_i2c_send
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
STATIC
mp_obj_t
pyb_i2c_send
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
pyb_i2c_obj_t
*
self
=
args
[
0
];
pyb_i2c_obj_t
*
self
=
args
[
0
];
// parse args
// parse args
mp_arg_
parse_
val_t
vals
[
PYB_I2C_SEND_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_I2C_SEND_NUM_ARGS
];
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_I2C_SEND_NUM_ARGS
,
pyb_i2c_send_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_I2C_SEND_NUM_ARGS
,
pyb_i2c_send_args
,
vals
);
// get the buffer to send from
// get the buffer to send from
mp_buffer_info_t
bufinfo
;
mp_buffer_info_t
bufinfo
;
...
@@ -335,19 +335,19 @@ STATIC mp_obj_t pyb_i2c_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
...
@@ -335,19 +335,19 @@ STATIC mp_obj_t pyb_i2c_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_i2c_send_obj
,
1
,
pyb_i2c_send
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_i2c_send_obj
,
1
,
pyb_i2c_send
);
STATIC
const
mp_arg_
parse_
t
pyb_i2c_recv_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_i2c_recv_args
[]
=
{
{
MP_QSTR_recv
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_recv
,
MP_ARG_REQUIRED
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_addr
,
MP_ARG_
PARSE_
INT
,
{.
u_int
=
PYB_I2C_MASTER_ADDRESS
}
},
{
MP_QSTR_addr
,
MP_ARG_INT
,
{.
u_int
=
PYB_I2C_MASTER_ADDRESS
}
},
{
MP_QSTR_timeout
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
5000
}
},
{
MP_QSTR_timeout
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
5000
}
},
};
};
#define PYB_I2C_RECV_NUM_ARGS ARRAY_SIZE(pyb_i2c_recv_
accepted_
args)
#define PYB_I2C_RECV_NUM_ARGS ARRAY_SIZE(pyb_i2c_recv_args)
STATIC
mp_obj_t
pyb_i2c_recv
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
STATIC
mp_obj_t
pyb_i2c_recv
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
pyb_i2c_obj_t
*
self
=
args
[
0
];
pyb_i2c_obj_t
*
self
=
args
[
0
];
// parse args
// parse args
mp_arg_
parse_
val_t
vals
[
PYB_I2C_RECV_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_I2C_RECV_NUM_ARGS
];
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_I2C_RECV_NUM_ARGS
,
pyb_i2c_recv_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_I2C_RECV_NUM_ARGS
,
pyb_i2c_recv_args
,
vals
);
// get the buffer to receive into
// get the buffer to receive into
mp_buffer_info_t
bufinfo
;
mp_buffer_info_t
bufinfo
;
...
@@ -379,13 +379,13 @@ STATIC mp_obj_t pyb_i2c_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
...
@@ -379,13 +379,13 @@ STATIC mp_obj_t pyb_i2c_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_i2c_recv_obj
,
1
,
pyb_i2c_recv
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_i2c_recv_obj
,
1
,
pyb_i2c_recv
);
STATIC
const
mp_arg_
parse_
t
pyb_i2c_mem_read_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_i2c_mem_read_args
[]
=
{
{
MP_QSTR_data
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_data
,
MP_ARG_REQUIRED
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_addr
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_addr
,
MP_ARG_REQUIRED
|
MP_ARG_INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_memaddr
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_memaddr
,
MP_ARG_REQUIRED
|
MP_ARG_INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_timeout
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
5000
}
},
{
MP_QSTR_timeout
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
5000
}
},
};
};
#define PYB_I2C_MEM_READ_NUM_ARGS ARRAY_SIZE(pyb_i2c_mem_read_
accepted_
args)
#define PYB_I2C_MEM_READ_NUM_ARGS ARRAY_SIZE(pyb_i2c_mem_read_args)
STATIC
mp_obj_t
pyb_i2c_mem_read
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
STATIC
mp_obj_t
pyb_i2c_mem_read
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
pyb_i2c_obj_t
*
self
=
args
[
0
];
pyb_i2c_obj_t
*
self
=
args
[
0
];
...
@@ -395,8 +395,8 @@ STATIC mp_obj_t pyb_i2c_mem_read(uint n_args, const mp_obj_t *args, mp_map_t *kw
...
@@ -395,8 +395,8 @@ STATIC mp_obj_t pyb_i2c_mem_read(uint n_args, const mp_obj_t *args, mp_map_t *kw
}
}
// parse args
// parse args
mp_arg_
parse_
val_t
vals
[
PYB_I2C_MEM_READ_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_I2C_MEM_READ_NUM_ARGS
];
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_I2C_MEM_READ_NUM_ARGS
,
pyb_i2c_mem_read_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_I2C_MEM_READ_NUM_ARGS
,
pyb_i2c_mem_read_args
,
vals
);
// get the buffer to read into
// get the buffer to read into
mp_buffer_info_t
bufinfo
;
mp_buffer_info_t
bufinfo
;
...
@@ -430,8 +430,8 @@ STATIC mp_obj_t pyb_i2c_mem_write(uint n_args, const mp_obj_t *args, mp_map_t *k
...
@@ -430,8 +430,8 @@ STATIC mp_obj_t pyb_i2c_mem_write(uint n_args, const mp_obj_t *args, mp_map_t *k
}
}
// parse args (same as mem_read)
// parse args (same as mem_read)
mp_arg_
parse_
val_t
vals
[
PYB_I2C_MEM_READ_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_I2C_MEM_READ_NUM_ARGS
];
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_I2C_MEM_READ_NUM_ARGS
,
pyb_i2c_mem_read_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_I2C_MEM_READ_NUM_ARGS
,
pyb_i2c_mem_read_args
,
vals
);
// get the buffer to write from
// get the buffer to write from
mp_buffer_info_t
bufinfo
;
mp_buffer_info_t
bufinfo
;
...
...
stmhal/spi.c
View file @
dbc81df5
...
@@ -194,24 +194,24 @@ STATIC void pyb_spi_print(void (*print)(void *env, const char *fmt, ...), void *
...
@@ -194,24 +194,24 @@ STATIC void pyb_spi_print(void (*print)(void *env, const char *fmt, ...), void *
}
}
}
}
STATIC
const
mp_arg_
parse_
t
pyb_spi_init_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_spi_init_args
[]
=
{
{
MP_QSTR_mode
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_mode
,
MP_ARG_REQUIRED
|
MP_ARG_INT
,
{.
u_int
=
0
}
},
{
MP_QSTR_baudrate
,
MP_ARG_
PARSE_
INT
,
{.
u_int
=
328125
}
},
{
MP_QSTR_baudrate
,
MP_ARG_INT
,
{.
u_int
=
328125
}
},
{
MP_QSTR_polarity
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
1
}
},
{
MP_QSTR_polarity
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
1
}
},
{
MP_QSTR_phase
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
1
}
},
{
MP_QSTR_phase
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
1
}
},
{
MP_QSTR_dir
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
SPI_DIRECTION_2LINES
}
},
{
MP_QSTR_dir
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
SPI_DIRECTION_2LINES
}
},
{
MP_QSTR_bits
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
8
}
},
{
MP_QSTR_bits
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
8
}
},
{
MP_QSTR_nss
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
SPI_NSS_SOFT
}
},
{
MP_QSTR_nss
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
SPI_NSS_SOFT
}
},
{
MP_QSTR_firstbit
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
SPI_FIRSTBIT_MSB
}
},
{
MP_QSTR_firstbit
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
SPI_FIRSTBIT_MSB
}
},
{
MP_QSTR_ti
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
BOOL
,
{.
u_bool
=
false
}
},
{
MP_QSTR_ti
,
MP_ARG_KW_ONLY
|
MP_ARG_BOOL
,
{.
u_bool
=
false
}
},
{
MP_QSTR_crc
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
mp_const_none
}
},
{
MP_QSTR_crc
,
MP_ARG_KW_ONLY
|
MP_ARG_OBJ
,
{.
u_obj
=
mp_const_none
}
},
};
};
#define PYB_SPI_INIT_NUM_ARGS ARRAY_SIZE(pyb_spi_init_
accepted_
args)
#define PYB_SPI_INIT_NUM_ARGS ARRAY_SIZE(pyb_spi_init_args)
STATIC
mp_obj_t
pyb_spi_init_helper
(
const
pyb_spi_obj_t
*
self
,
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
STATIC
mp_obj_t
pyb_spi_init_helper
(
const
pyb_spi_obj_t
*
self
,
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
// parse args
// parse args
mp_arg_
parse_
val_t
vals
[
PYB_SPI_INIT_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_SPI_INIT_NUM_ARGS
];
mp_arg_parse_all
(
n_args
,
args
,
kw_args
,
PYB_SPI_INIT_NUM_ARGS
,
pyb_spi_init_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
,
args
,
kw_args
,
PYB_SPI_INIT_NUM_ARGS
,
pyb_spi_init_args
,
vals
);
// set the SPI configuration values
// set the SPI configuration values
SPI_InitTypeDef
*
init
=
&
self
->
spi
->
Init
;
SPI_InitTypeDef
*
init
=
&
self
->
spi
->
Init
;
...
@@ -295,11 +295,11 @@ STATIC mp_obj_t pyb_spi_deinit(mp_obj_t self_in) {
...
@@ -295,11 +295,11 @@ STATIC mp_obj_t pyb_spi_deinit(mp_obj_t self_in) {
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
pyb_spi_deinit_obj
,
pyb_spi_deinit
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
pyb_spi_deinit_obj
,
pyb_spi_deinit
);
STATIC
const
mp_arg_
parse_
t
pyb_spi_send_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_spi_send_args
[]
=
{
{
MP_QSTR_send
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_send
,
MP_ARG_REQUIRED
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_timeout
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
5000
}
},
{
MP_QSTR_timeout
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
5000
}
},
};
};
#define PYB_SPI_SEND_NUM_ARGS ARRAY_SIZE(pyb_spi_send_
accepted_
args)
#define PYB_SPI_SEND_NUM_ARGS ARRAY_SIZE(pyb_spi_send_args)
STATIC
mp_obj_t
pyb_spi_send
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
STATIC
mp_obj_t
pyb_spi_send
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
// TODO assumes transmission size is 8-bits wide
// TODO assumes transmission size is 8-bits wide
...
@@ -307,8 +307,8 @@ STATIC mp_obj_t pyb_spi_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
...
@@ -307,8 +307,8 @@ STATIC mp_obj_t pyb_spi_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
pyb_spi_obj_t
*
self
=
args
[
0
];
pyb_spi_obj_t
*
self
=
args
[
0
];
// parse args
// parse args
mp_arg_
parse_
val_t
vals
[
PYB_SPI_SEND_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_SPI_SEND_NUM_ARGS
];
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_SPI_SEND_NUM_ARGS
,
pyb_spi_send_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_SPI_SEND_NUM_ARGS
,
pyb_spi_send_args
,
vals
);
// get the buffer to send from
// get the buffer to send from
mp_buffer_info_t
bufinfo
;
mp_buffer_info_t
bufinfo
;
...
@@ -327,11 +327,11 @@ STATIC mp_obj_t pyb_spi_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
...
@@ -327,11 +327,11 @@ STATIC mp_obj_t pyb_spi_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_spi_send_obj
,
1
,
pyb_spi_send
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_spi_send_obj
,
1
,
pyb_spi_send
);
STATIC
const
mp_arg_
parse_
t
pyb_spi_recv_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_spi_recv_args
[]
=
{
{
MP_QSTR_recv
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_recv
,
MP_ARG_REQUIRED
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_timeout
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
5000
}
},
{
MP_QSTR_timeout
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
5000
}
},
};
};
#define PYB_SPI_RECV_NUM_ARGS ARRAY_SIZE(pyb_spi_recv_
accepted_
args)
#define PYB_SPI_RECV_NUM_ARGS ARRAY_SIZE(pyb_spi_recv_args)
STATIC
mp_obj_t
pyb_spi_recv
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
STATIC
mp_obj_t
pyb_spi_recv
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
// TODO assumes transmission size is 8-bits wide
// TODO assumes transmission size is 8-bits wide
...
@@ -339,8 +339,8 @@ STATIC mp_obj_t pyb_spi_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
...
@@ -339,8 +339,8 @@ STATIC mp_obj_t pyb_spi_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
pyb_spi_obj_t
*
self
=
args
[
0
];
pyb_spi_obj_t
*
self
=
args
[
0
];
// parse args
// parse args
mp_arg_
parse_
val_t
vals
[
PYB_SPI_RECV_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_SPI_RECV_NUM_ARGS
];
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_SPI_RECV_NUM_ARGS
,
pyb_spi_recv_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_SPI_RECV_NUM_ARGS
,
pyb_spi_recv_args
,
vals
);
// get the buffer to receive into
// get the buffer to receive into
mp_buffer_info_t
bufinfo
;
mp_buffer_info_t
bufinfo
;
...
@@ -363,12 +363,12 @@ STATIC mp_obj_t pyb_spi_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
...
@@ -363,12 +363,12 @@ STATIC mp_obj_t pyb_spi_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_spi_recv_obj
,
1
,
pyb_spi_recv
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_spi_recv_obj
,
1
,
pyb_spi_recv
);
STATIC
const
mp_arg_
parse_
t
pyb_spi_send_recv_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_spi_send_recv_args
[]
=
{
{
MP_QSTR_send
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_send
,
MP_ARG_REQUIRED
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_recv
,
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_recv
,
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_timeout
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
5000
}
},
{
MP_QSTR_timeout
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
5000
}
},
};
};
#define PYB_SPI_SEND_RECV_NUM_ARGS ARRAY_SIZE(pyb_spi_send_recv_
accepted_
args)
#define PYB_SPI_SEND_RECV_NUM_ARGS ARRAY_SIZE(pyb_spi_send_recv_args)
STATIC
mp_obj_t
pyb_spi_send_recv
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
STATIC
mp_obj_t
pyb_spi_send_recv
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
// TODO assumes transmission size is 8-bits wide
// TODO assumes transmission size is 8-bits wide
...
@@ -376,8 +376,8 @@ STATIC mp_obj_t pyb_spi_send_recv(uint n_args, const mp_obj_t *args, mp_map_t *k
...
@@ -376,8 +376,8 @@ STATIC mp_obj_t pyb_spi_send_recv(uint n_args, const mp_obj_t *args, mp_map_t *k
pyb_spi_obj_t
*
self
=
args
[
0
];
pyb_spi_obj_t
*
self
=
args
[
0
];
// parse args
// parse args
mp_arg_
parse_
val_t
vals
[
PYB_SPI_SEND_RECV_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_SPI_SEND_RECV_NUM_ARGS
];
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_SPI_SEND_RECV_NUM_ARGS
,
pyb_spi_send_recv_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
-
1
,
args
+
1
,
kw_args
,
PYB_SPI_SEND_RECV_NUM_ARGS
,
pyb_spi_send_recv_args
,
vals
);
// get buffers to send from/receive to
// get buffers to send from/receive to
mp_buffer_info_t
bufinfo_send
;
mp_buffer_info_t
bufinfo_send
;
...
...
stmhal/timer.c
View file @
dbc81df5
...
@@ -173,19 +173,19 @@ STATIC void pyb_timer_print(void (*print)(void *env, const char *fmt, ...), void
...
@@ -173,19 +173,19 @@ STATIC void pyb_timer_print(void (*print)(void *env, const char *fmt, ...), void
}
}
}
}
STATIC
const
mp_arg_
parse_
t
pyb_timer_init_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_timer_init_args
[]
=
{
{
MP_QSTR_freq
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
0xffffffff
}
},
{
MP_QSTR_freq
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
0xffffffff
}
},
{
MP_QSTR_prescaler
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
0xffffffff
}
},
{
MP_QSTR_prescaler
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
0xffffffff
}
},
{
MP_QSTR_period
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
0xffffffff
}
},
{
MP_QSTR_period
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
0xffffffff
}
},
{
MP_QSTR_mode
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
TIM_COUNTERMODE_UP
}
},
{
MP_QSTR_mode
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
TIM_COUNTERMODE_UP
}
},
{
MP_QSTR_div
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
TIM_CLOCKDIVISION_DIV1
}
},
{
MP_QSTR_div
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
TIM_CLOCKDIVISION_DIV1
}
},
};
};
#define PYB_TIMER_INIT_NUM_ARGS ARRAY_SIZE(pyb_timer_init_
accepted_
args)
#define PYB_TIMER_INIT_NUM_ARGS ARRAY_SIZE(pyb_timer_init_args)
STATIC
mp_obj_t
pyb_timer_init_helper
(
pyb_timer_obj_t
*
self
,
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
STATIC
mp_obj_t
pyb_timer_init_helper
(
pyb_timer_obj_t
*
self
,
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
// parse args
// parse args
mp_arg_
parse_
val_t
vals
[
PYB_TIMER_INIT_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_TIMER_INIT_NUM_ARGS
];
mp_arg_parse_all
(
n_args
,
args
,
kw_args
,
PYB_TIMER_INIT_NUM_ARGS
,
pyb_timer_init_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
,
args
,
kw_args
,
PYB_TIMER_INIT_NUM_ARGS
,
pyb_timer_init_args
,
vals
);
// set the TIM configuration values
// set the TIM configuration values
TIM_Base_InitTypeDef
*
init
=
&
self
->
tim
.
Init
;
TIM_Base_InitTypeDef
*
init
=
&
self
->
tim
.
Init
;
...
...
stmhal/uart.c
View file @
dbc81df5
...
@@ -225,18 +225,18 @@ STATIC void pyb_uart_print(void (*print)(void *env, const char *fmt, ...), void
...
@@ -225,18 +225,18 @@ STATIC void pyb_uart_print(void (*print)(void *env, const char *fmt, ...), void
}
}
}
}
STATIC
const
mp_arg_
parse_
t
pyb_uart_init_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_uart_init_args
[]
=
{
{
MP_QSTR_baudrate
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
9600
}
},
{
MP_QSTR_baudrate
,
MP_ARG_REQUIRED
|
MP_ARG_INT
,
{.
u_int
=
9600
}
},
{
MP_QSTR_bits
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
8
}
},
{
MP_QSTR_bits
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
8
}
},
{
MP_QSTR_stop
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
1
}
},
{
MP_QSTR_stop
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
1
}
},
{
MP_QSTR_parity
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
mp_const_none
}
},
{
MP_QSTR_parity
,
MP_ARG_KW_ONLY
|
MP_ARG_OBJ
,
{.
u_obj
=
mp_const_none
}
},
};
};
#define PYB_UART_INIT_NUM_ARGS ARRAY_SIZE(pyb_uart_init_
accepted_
args)
#define PYB_UART_INIT_NUM_ARGS ARRAY_SIZE(pyb_uart_init_args)
STATIC
mp_obj_t
pyb_uart_init_helper
(
pyb_uart_obj_t
*
self
,
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
STATIC
mp_obj_t
pyb_uart_init_helper
(
pyb_uart_obj_t
*
self
,
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
// parse args
// parse args
mp_arg_
parse_
val_t
vals
[
PYB_UART_INIT_NUM_ARGS
];
mp_arg_val_t
vals
[
PYB_UART_INIT_NUM_ARGS
];
mp_arg_parse_all
(
n_args
,
args
,
kw_args
,
PYB_UART_INIT_NUM_ARGS
,
pyb_uart_init_
accepted_
args
,
vals
);
mp_arg_parse_all
(
n_args
,
args
,
kw_args
,
PYB_UART_INIT_NUM_ARGS
,
pyb_uart_init_args
,
vals
);
// set the UART configuration values
// set the UART configuration values
memset
(
&
self
->
uart
,
0
,
sizeof
(
self
->
uart
));
memset
(
&
self
->
uart
,
0
,
sizeof
(
self
->
uart
));
...
@@ -327,11 +327,11 @@ STATIC mp_obj_t pyb_uart_any(mp_obj_t self_in) {
...
@@ -327,11 +327,11 @@ STATIC mp_obj_t pyb_uart_any(mp_obj_t self_in) {
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
pyb_uart_any_obj
,
pyb_uart_any
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
pyb_uart_any_obj
,
pyb_uart_any
);
STATIC
const
mp_arg_
parse_
t
pyb_uart_send_
accepted_
args
[]
=
{
STATIC
const
mp_arg_t
pyb_uart_send_args
[]
=
{
{
MP_QSTR_send
,
MP_ARG_
PARSE_
REQUIRED
|
MP_ARG_
PARSE_
OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_send
,
MP_ARG_REQUIRED
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
{
MP_QSTR_timeout
,
MP_ARG_
PARSE_
KW_ONLY
|
MP_ARG_
PARSE_
INT
,
{.
u_int
=
5000
}
},
{
MP_QSTR_timeout
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
5000
}
},
};
};
#define PYB_UART_SEND_NUM_ARGS ARRAY_SIZE(pyb_uart_send_
accepted_
args)
#define PYB_UART_SEND_NUM_ARGS ARRAY_SIZE(pyb_uart_send_args)
STATIC
mp_obj_t
pyb_uart_send
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
STATIC
mp_obj_t
pyb_uart_send
(
uint
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
// TODO assumes transmission size is 8-bits wide
// TODO assumes transmission size is 8-bits wide
...
@@ -339,8 +339,8 @@ STATIC mp_obj_t pyb_uart_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_ar
...
@@ -339,8 +339,8 @@ STATIC mp_obj_t pyb_uart_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_ar
pyb_uart_obj_t
*
self
=
args
[
0
];
pyb_uart_obj_t
*
self
=
args
[
0
];
// parse args
// parse args