Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
023ae75b
Commit
023ae75b
authored
Aug 02, 2021
by
me-no-dev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rework pulseIn to work on ESP32-C3
Fixes:
https://github.com/espressif/arduino-esp32/issues/5488
parent
c5a1f3ef
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
7 deletions
+5
-7
cores/esp32/wiring_pulse.c
cores/esp32/wiring_pulse.c
+5
-7
No files found.
cores/esp32/wiring_pulse.c
View file @
023ae75b
...
@@ -17,13 +17,11 @@
...
@@ -17,13 +17,11 @@
//#include <limits.h>
//#include <limits.h>
#include "wiring_private.h"
#include "wiring_private.h"
#include "pins_arduino.h"
#include "pins_arduino.h"
#include <hal/cpu_hal.h>
extern
uint32_t
xthal_get_ccount
();
#define WAIT_FOR_PIN_STATE(state) \
#define WAIT_FOR_PIN_STATE(state) \
while (digitalRead(pin) != (state)) { \
while (digitalRead(pin) != (state)) { \
if (
xthal_get_c
count() - start_cycle_count > timeout_cycles) { \
if (
cpu_hal_get_cycle_
count() - start_cycle_count > timeout_cycles) { \
return 0; \
return 0; \
} \
} \
}
}
...
@@ -36,12 +34,12 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
...
@@ -36,12 +34,12 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
timeout
=
max_timeout_us
;
timeout
=
max_timeout_us
;
}
}
const
uint32_t
timeout_cycles
=
microsecondsToClockCycles
(
timeout
);
const
uint32_t
timeout_cycles
=
microsecondsToClockCycles
(
timeout
);
const
uint32_t
start_cycle_count
=
xthal_get_c
count
();
const
uint32_t
start_cycle_count
=
cpu_hal_get_cycle_
count
();
WAIT_FOR_PIN_STATE
(
!
state
);
WAIT_FOR_PIN_STATE
(
!
state
);
WAIT_FOR_PIN_STATE
(
state
);
WAIT_FOR_PIN_STATE
(
state
);
const
uint32_t
pulse_start_cycle_count
=
xthal_get_c
count
();
const
uint32_t
pulse_start_cycle_count
=
cpu_hal_get_cycle_
count
();
WAIT_FOR_PIN_STATE
(
!
state
);
WAIT_FOR_PIN_STATE
(
!
state
);
return
clockCyclesToMicroseconds
(
xthal_get_c
count
()
-
pulse_start_cycle_count
);
return
clockCyclesToMicroseconds
(
cpu_hal_get_cycle_
count
()
-
pulse_start_cycle_count
);
}
}
unsigned
long
pulseInLong
(
uint8_t
pin
,
uint8_t
state
,
unsigned
long
timeout
)
unsigned
long
pulseInLong
(
uint8_t
pin
,
uint8_t
state
,
unsigned
long
timeout
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment