Skip to content

Commit f54a96d

Browse files
committed
stmhal/timer: Use mp_float_t instead of float.
This way mp_float_t can be changed to, eg, double.
1 parent 3ff259a commit f54a96d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

stmhal/timer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,13 @@ STATIC uint32_t compute_pwm_value_from_percent(uint32_t period, mp_obj_t percent
361361
if (0) {
362362
#if MICROPY_PY_BUILTINS_FLOAT
363363
} else if (MP_OBJ_IS_TYPE(percent_in, &mp_type_float)) {
364-
float percent = mp_obj_get_float(percent_in);
364+
mp_float_t percent = mp_obj_get_float(percent_in);
365365
if (percent <= 0.0) {
366366
cmp = 0;
367367
} else if (percent >= 100.0) {
368368
cmp = period;
369369
} else {
370-
cmp = percent / 100.0 * ((float)period);
370+
cmp = percent / 100.0 * ((mp_float_t)period);
371371
}
372372
#endif
373373
} else {
@@ -391,11 +391,11 @@ STATIC uint32_t compute_pwm_value_from_percent(uint32_t period, mp_obj_t percent
391391
// Helper function to compute percentage from timer perion and PWM value.
392392
STATIC mp_obj_t compute_percent_from_pwm_value(uint32_t period, uint32_t cmp) {
393393
#if MICROPY_PY_BUILTINS_FLOAT
394-
float percent;
394+
mp_float_t percent;
395395
if (cmp >= period) {
396396
percent = 100.0;
397397
} else {
398-
percent = (float)cmp * 100.0 / ((float)period);
398+
percent = (mp_float_t)cmp * 100.0 / ((mp_float_t)period);
399399
}
400400
return mp_obj_new_float(percent);
401401
#else

0 commit comments

Comments
 (0)