RotaryEncoder icon indicating copy to clipboard operation
RotaryEncoder copied to clipboard

Implementation of digitalFASTread() possibility

Open JoJos1220 opened this issue 1 year ago • 1 comments

I wanted to avoid digitalRead()/digitalWrite() operation within my Project. Therefore I made a split-up of the tick() function - to enable the possibility to read the Encoder-State within my loop function and the usage of a digitalFASTread() Operation and overload it to the tick function directly.

JoJos1220 avatar Jun 06 '24 11:06 JoJos1220

I made successfull Comissioning on ESP32-WROOM by implementing: encoder.tick(digitalFASTRead(encoderPinB), digitalFASTRead(encoderPinA)); Instead of: encoder.tick(); And it worked to me perfectly. My used digitalFASTREAD() function I used is: /*-----------------------------------------------------------------------------

  • digitalFASTRead(): Function to read a GPIO Pin State as fast alternative to digitalRead()

*/ int digitalFASTRead(uint8_t pin) { if (pin < 0 || pin >= 40) { // Pinnumber outside of valid area! return false; }

uint32_t bit = digitalPinToBitMask(pin); uint32_t port = digitalPinToPort(pin);

if (port == NOT_A_PIN) { // Invalid Pinnumber return false; }

// Pointer on GPIO-Register volatile uint32_t *reg = portInputRegister(port);

// Read Pin State bool state = ((*reg) & bit) != 0;

return state; }

JoJos1220 avatar Jun 07 '24 19:06 JoJos1220

@JoJos1220 : Thank you for the contribution.

mathertel avatar Oct 25 '25 15:10 mathertel