File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -233,13 +233,20 @@ void ICACHE_RAM_ATTR SoftwareSerial::preciseDelay(bool sync) {
233
233
{
234
234
// Reenable interrupts while delaying to avoid other tasks piling up
235
235
if (!m_intTxEnabled) { xt_wsr_ps (m_savedPS); }
236
- auto expired = ESP.getCycleCount () - m_periodStart;
237
- if (expired < m_periodDuration)
236
+ const auto expired = ESP.getCycleCount () - m_periodStart;
237
+ const auto ms = (m_periodDuration - expired) / ESP.getCpuFreqMHz () / 1000UL ;
238
+ if (ms)
238
239
{
239
- auto ms = (m_periodDuration - expired) / ESP.getCpuFreqMHz () / 1000UL ;
240
- if (ms) delay (ms);
240
+ delay (ms);
241
+ }
242
+ else
243
+ {
244
+ do
245
+ {
246
+ optimistic_yield (10000UL );
247
+ }
248
+ while ((ESP.getCycleCount () - m_periodStart) < m_periodDuration);
241
249
}
242
- while ((ESP.getCycleCount () - m_periodStart) < m_periodDuration) { optimistic_yield (10000UL ); }
243
250
// Disable interrupts again
244
251
if (!m_intTxEnabled) { m_savedPS = xt_rsil (15 ); }
245
252
}
You can’t perform that action at this time.
0 commit comments