diff options
author | Dave Hylands <dhylands@gmail.com> | 2014-09-26 09:04:05 -0700 |
---|---|---|
committer | Dave Hylands <dhylands@gmail.com> | 2014-09-27 19:40:37 -0700 |
commit | 39296b40d49b4b6b9373a80de67e017e540f1408 (patch) | |
tree | d622afcf1e1620b17444201f8cbc9d030e2f39ed /stmhal/modselect.c | |
parent | b766e79510d87db1b18028a0fae3f195091fcaf1 (diff) | |
download | micropython-39296b40d49b4b6b9373a80de67e017e540f1408.tar.gz micropython-39296b40d49b4b6b9373a80de67e017e540f1408.zip |
Fix timer overflow code.
Teensy doesn't need to worry about overflows since all of
its timers are only 16-bit.
For PWM, the pulse width needs to be able to vary from 0..period+1
(pulse-width == period+1 corresponds to 100% PWM)
I couldn't test the 0xffffffff cases since we can't currently get a
period that big in python. With a prescaler of 0, that corresponds
to a freq of 0.039 (i.e. cycle every 25.56 seconds), and we can't
set that using freq or period.
I also tested both stmhal and teensy with floats disabled, which
required a few other code changes to compile.
Diffstat (limited to 'stmhal/modselect.c')
-rw-r--r-- | stmhal/modselect.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/stmhal/modselect.c b/stmhal/modselect.c index bad535f210..a84c94554c 100644 --- a/stmhal/modselect.c +++ b/stmhal/modselect.c @@ -124,10 +124,14 @@ STATIC mp_obj_t select_select(uint n_args, const mp_obj_t *args) { mp_uint_t timeout = -1; if (n_args == 4) { if (args[3] != mp_const_none) { + #if MICROPY_PY_BUILTINS_FLOAT float timeout_f = mp_obj_get_float(args[3]); if (timeout_f >= 0) { timeout = (mp_uint_t)(timeout_f * 1000); } + #else + timeout = mp_obj_get_int(args[3]) * 1000; + #endif } } |