File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -113,7 +113,28 @@ void mp_hal_delay_ms(uint32_t ms) {
113113}
114114
115115void mp_hal_delay_us (uint32_t us ) {
116- ets_delay_us (us );
116+ // these constants are tested for a 240MHz clock
117+ const uint32_t this_overhead = 5 ;
118+ const uint32_t pend_overhead = 150 ;
119+
120+ // return if requested delay is less than calling overhead
121+ if (us < this_overhead ) {
122+ return ;
123+ }
124+ us -= this_overhead ;
125+
126+ uint64_t t0 = esp_timer_get_time ();
127+ for (;;) {
128+ uint64_t dt = esp_timer_get_time () - t0 ;
129+ if (dt >= us ) {
130+ return ;
131+ }
132+ if (dt + pend_overhead < us ) {
133+ // we have enough time to service pending events
134+ // (don't use MICROPY_EVENT_POLL_HOOK because it also yields)
135+ mp_handle_pending ();
136+ }
137+ }
117138}
118139
119140// this function could do with improvements (eg use ets_delay_us)
You can’t perform that action at this time.
0 commit comments