Skip to content

Commit 9ba8191

Browse files
authored
Merge pull request adafruit#1855 from dhalbert/frequencyin-no-double-arith
avoid double float arithmetic in FrequencyIn
2 parents 909210e + f59dadb commit 9ba8191

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ void frequencyin_interrupt_handler(uint8_t index) {
103103
// record a new event count.
104104
if (current_ms - self->last_ms >= self->capture_period) {
105105
float new_factor = self->last_us + (1000 - current_us);
106-
self->factor = (current_ms - self->last_ms) + (new_factor / 1000);
106+
// ms difference will not need 64 bits. If we use 64 bits,
107+
// double-precision float routines are required, and we don't
108+
// want to include them because they're very large.
109+
self->factor = (uint32_t) (current_ms - self->last_ms) + (new_factor / 1000);
107110
self->last_ms = current_ms;
108111
self->last_us = current_us;
109112

ports/atmel-samd/timer_handler.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ void shared_timer_handler(bool is_tc, uint8_t index) {
4848
uint8_t handler = tc_handler[index];
4949
switch(handler) {
5050
case TC_HANDLER_PULSEOUT:
51+
#if CIRCUITPY_PULSEIO
5152
pulseout_interrupt_handler(index);
53+
#endif
5254
break;
5355
case TC_HANDLER_PEW:
5456
#if CIRCUITPY_PEW

0 commit comments

Comments
 (0)