8000 Caching IDR pointer · ArduinoWorks/Arduino_STM32@0f6d909 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f6d909

Browse files
committed
Caching IDR pointer
1 parent 4a84203 commit 0f6d909

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

STM32F1/cores/maple/stm32f1/wiring_pulse_f1.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
*/
3030
uint32_t pulseIn( uint32_t pin, uint32_t state, uint32_t timeout )
3131
{
32-
// cache the reg map and bit of the pin in order to speed up the
32+
// cache the IDR address and bit of the pin in order to speed up the
3333
// pulse width measuring loop and achieve finer resolution. calling
3434
// digitalRead() instead yields much coarser resolution.
3535

36-
const gpio_reg_map * const regs = digitalPinToPort(pin)->regs;
36+
__io uint32_t * const idr = portInputRegister(digitalPinToPort(pin));
3737
const uint32_t bit = digitalPinToBitMask(pin);
3838
const uint32_t stateMask = (state ? bit:0);
3939

@@ -46,23 +46,23 @@ uint32_t pulseIn( uint32_t pin, uint32_t state, uint32_t timeout )
4646
volatile uint32_t dummyWidth=0;
4747

4848
// wait for any previous pulse to end
49-
while ((regs->IDR & bit) == stateMask) {
49+
while ((*idr & bit) == stateMask) {
5050
if (numloops++ == maxloops) {
5151
return 0;
5252
}
5353
dummyWidth++;
5454
}
5555

5656
// wait for the pulse to start
57-
while ((regs->IDR & bit) != stateMask) {
57+
while ((*idr & bit) != stateMask) {
5858
if (numloops++ == maxloops) {
5959
return 0;
6060
}
6161
dummyWidth++;
6262
}
6363

6464
// wait for the pulse to stop
65-
while ((regs->IDR & bit) == stateMask) {
65+
while ((*idr & bit) == stateMask) {
6666
if (numloops++ == maxloops) {
6767
return 0;
6868
}

0 commit comments

Comments
 (0)
0