Skip to content

Commit 38d9422

Browse files
committed
esp32: Provide improved version of mp_hal_delay_us_fast.
This makes software I2C and SPI significantly faster.
1 parent d27026e commit 38d9422

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

esp32/mphalport.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ void mp_hal_delay_us(uint32_t us) {
9393
vTaskDelay(us / 1000 / portTICK_PERIOD_MS);
9494
}
9595

96+
// this function could do with improvements
97+
void mp_hal_delay_us_fast(uint32_t us) {
98+
uint32_t delay = ets_get_cpu_frequency() / 19;
99+
while (--us) {
100+
for (volatile uint32_t i = delay; i; --i) {
101+
}
102+
}
103+
}
104+
96105
/*
97106
extern int mp_stream_errno;
98107
int *__errno() {

esp32/mphalport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ __attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {
4242
}
4343

4444
void mp_hal_delay_us(uint32_t);
45+
void mp_hal_delay_us_fast(uint32_t);
4546
void mp_hal_set_interrupt_char(int c);
4647
uint32_t mp_hal_get_cpu_freq(void);
4748

48-
#define mp_hal_delay_us_fast(us) mp_hal_delay_us(us) // TODO
4949
#define mp_hal_quiet_timing_enter() disable_irq()
5050
#define mp_hal_quiet_timing_exit(irq_state) enable_irq(irq_state)
5151

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy