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
f54a96d6
Commit
f54a96d6
authored
Dec 09, 2015
by
Damien George
Browse files
stmhal/timer: Use mp_float_t instead of float.
This way mp_float_t can be changed to, eg, double.
parent
3ff259a2
Changes
1
Hide whitespace changes
Inline
Side-by-side
stmhal/timer.c
View file @
f54a96d6
...
...
@@ -361,13 +361,13 @@ STATIC uint32_t compute_pwm_value_from_percent(uint32_t period, mp_obj_t percent
if
(
0
)
{
#if MICROPY_PY_BUILTINS_FLOAT
}
else
if
(
MP_OBJ_IS_TYPE
(
percent_in
,
&
mp_type_float
))
{
float
percent
=
mp_obj_get_float
(
percent_in
);
mp_
float
_t
percent
=
mp_obj_get_float
(
percent_in
);
if
(
percent
<=
0
.
0
)
{
cmp
=
0
;
}
else
if
(
percent
>=
100
.
0
)
{
cmp
=
period
;
}
else
{
cmp
=
percent
/
100
.
0
*
((
float
)
period
);
cmp
=
percent
/
100
.
0
*
((
mp_
float
_t
)
period
);
}
#endif
}
else
{
...
...
@@ -391,11 +391,11 @@ STATIC uint32_t compute_pwm_value_from_percent(uint32_t period, mp_obj_t percent
// Helper function to compute percentage from timer perion and PWM value.
STATIC
mp_obj_t
compute_percent_from_pwm_value
(
uint32_t
period
,
uint32_t
cmp
)
{
#if MICROPY_PY_BUILTINS_FLOAT
float
percent
;
mp_
float
_t
percent
;
if
(
cmp
>=
period
)
{
percent
=
100
.
0
;
}
else
{
percent
=
(
float
)
cmp
*
100
.
0
/
((
float
)
period
);
percent
=
(
mp_
float
_t
)
cmp
*
100
.
0
/
((
mp_
float
_t
)
period
);
}
return
mp_obj_new_float
(
percent
);
#else
...
...
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