5#include <AH/STL/utility>
9#ifndef CS_CUSTOM_INTERRUPT_TO_INDEX
25 if (
other.interrupts_in_use)
26 FATAL_ERROR(F(
"Cannot move from initialized AHEncoder."), 0x9311);
37 std::swap(
a.pins, b.
pins);
50 std::swap(
a.state, b.
state);
53 if (
a.interrupts_in_use > 0) {
97#if defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_RP2040)
114 FATAL_ERROR(F(
"Multiple encoders on the same pin"), 0x7283);
119#ifdef ARDUINO_ARCH_RP2040
135#ifdef ARDUINO_ARCH_RP2040
static interrupt_index_t interruptToIndex(interrupt_index_t i)
void swap(AHEncoder &a, AHEncoder &b)
decltype(digitalPinToInterrupt(0)) interrupt_index_t
#define CS_ENCODER_ARGLIST_SIZE
constexpr PinMode_t INPUT_PULLUP
DirectPinRead direct_pin_read(uint8_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(uint8_t pinA, uint8_t pinB)
Constructor.
~AHEncoder()
Destructor, detaches the interrupts.
uint8_t interrupts_in_use
AH::Array< uint8_t, 2 > pins
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.
friend void swap(AHEncoder &a, AHEncoder &b)
Swap two Encoder objects.
AH::Array< DirectPinRead, 2 > direct_pins
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.
An array wrapper for easy copying, comparing, and iterating.