Skip to content

Commit 2570818

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 2570818

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ config ARDUINO_MAX_TONES
3838
If set to -1 (or any other negative value), the maximum number will be
3939
determined from the system's digital pin configuration.
4040

41+
config ARDUINO_DELAY_US_COMPENSATION
42+
int "delayMicroseconds() compensation value (us)"
43+
default 1
44+
range 0 2147483647
45+
help
46+
Compensation value, in microseconds, subtracted from the requested
47+
delay in delayMicroseconds() to account for software overhead.
48+
This can improve short-delay accuracy.
49+
4150
endif
4251

4352
if USB_DEVICE_STACK_NEXT

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)