Skip to content

Commit 1d16cc6

Browse files
committed
arduino: add Kconfig for delayMicroseconds() compensation
Add CONFIG_ARDUINO_DELAY_US_COMPENSATION for generalize the delayMicroseconds() compensation. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent c5c264f commit 1d16cc6

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ config ARDUINO_MAX_TONES
4040

4141
endif
4242

43+
config ARDUINO_DELAY_US_COMPENSATION
44+
int "delayMicroseconds() compensation value (us)"
45+
default 1
46+
help
47+
Compensation value, in microseconds, subtracted from the requested
48+
delay in delayMicroseconds() to account for software overhead.
49+
This can improve short-delay accuracy.
50+
4351
if USB_DEVICE_STACK_NEXT
4452

4553
config USB_DEVICE_PRODUCT

cores/arduino/inlines.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ inline __attribute__((always_inline)) void delay(unsigned long ms) {
1818
}
1919

2020
inline __attribute__((always_inline)) void delayMicroseconds(unsigned int us) {
21+
#if CONFIG_ARDUINO_DELAY_US_COMPENSATION < 2
2122
if (us == 0) {
2223
return;
2324
}
24-
k_busy_wait(us - 1);
25+
#else
26+
if (us < CONFIG_ARDUINO_DELAY_US_COMPENSATION) {
27+
return;
28+
}
29+
#endif
30+
k_busy_wait(us - CONFIG_ARDUINO_DELAY_US_COMPENSATION);
2531
}
2632

2733
#endif /* __INLINES_H__ */

0 commit comments

Comments
 (0)