5#include <AH/STL/utility>
45 int int1 = digitalPinToInterrupt(a.
pins[0]);
46 if (int1 != NOT_AN_INTERRUPT)
48 int int2 = digitalPinToInterrupt(a.
pins[1]);
49 if (int2 != NOT_AN_INTERRUPT)
53 int int1 = digitalPinToInterrupt(b.
pins[0]);
54 if (int1 != NOT_AN_INTERRUPT)
56 int int2 = digitalPinToInterrupt(b.
pins[1]);
57 if (int2 != NOT_AN_INTERRUPT)
76 delayMicroseconds(2000);
86#if defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_RP2040)
101 if (interrupt != NOT_AN_INTERRUPT) {
103 FATAL_ERROR(F(
"Multiple encoders on the same pin"), 0x7283);
108#ifdef ARDUINO_ARCH_RP2040
109 gpio_set_irq_enabled_with_callback(
110 interrupt, GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE,
true,
111 [](uint gpio, uint32_t) {
116 attachInterrupt(interrupt,
get_isr(interrupt), CHANGE);
122 if (interrupt != NOT_AN_INTERRUPT) {
123#ifdef ARDUINO_ARCH_RP2040
124 gpio_set_irq_enabled(interrupt, GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE,
127 detachInterrupt(interrupt);
void swap(AHEncoder &a, AHEncoder &b)
#define CS_ENCODER_ARGLIST_SIZE
constexpr PinMode_t INPUT_PULLUP
DirectPinRead direct_pin_read(ArduinoPin_t pin)
#define BEGIN_CS_NAMESPACE
Class for reading quadrature encoders, heavily influenced by http://www.pjrc.com/teensy/td_libs_Encod...
AtomicPosition< int32_t > position
static isr_func_t get_isr(unsigned interrupt)
Get a pointer to the interrupt handler function for the given interrupt.
static AHEncoder * instance_table[NUM_DIGITAL_PINS]
Array of pointers to all instances with active interrupts.
void attachInterruptCtx(int interrupt)
Register the interrupt handler for this instance.
void detachInterruptCtx(int interrupt)
Un-register the interrupt handler for this instance.
~AHEncoder()
Destructor, detaches the interrupts.
AHEncoder(ArduinoPin_t pinA, ArduinoPin_t pinB)
Constructor.
uint8_t interrupts_in_use
int32_t read()
Read the current absolute position of the encoder.
void end()
Disable the interrupts used by this encoder.
void begin()
Initialize this encoder by enabling the pull-up resistors and attaching the interrupts handlers (if i...
AHEncoder & operator=(const AHEncoder &)=delete
Copy assignment: copying an Encoder object is semantically meaningless, so it has been deleted.
DirectPinRead direct_pins[2]
friend void swap(AHEncoder &a, AHEncoder &b)
Swap two Encoder objects.
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.