49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "AtomicPosition.hpp"
|
|
#include "DirectPinRead.hpp"
|
|
#include "NumInterrupts.hpp"
|
|
#include <AH/Containers/Array.hpp>
|
|
#include <AH/Hardware/Arduino-Hardware-Types.hpp>
|
|
|
|
BEGIN_CS_NAMESPACE
|
|
|
|
#define CS_ENCODER_ISR_ATTR
|
|
#define CS_ENCODER_ARGLIST_SIZE CORE_NUM_INTERRUPT
|
|
|
|
class AHEncoder {
|
|
public:
|
|
AHEncoder(uint8_t pinA, uint8_t pinB);
|
|
AHEncoder(const AHEncoder &) = delete;
|
|
AHEncoder &operator=(const AHEncoder &) = delete;
|
|
AHEncoder(AHEncoder &&other);
|
|
AHEncoder &operator=(AHEncoder &&other);
|
|
~AHEncoder();
|
|
|
|
void begin();
|
|
void end();
|
|
|
|
int32_t read();
|
|
int32_t readAndReset(int32_t newpos = 0);
|
|
void write(int32_t p);
|
|
|
|
private:
|
|
AH::Array<uint8_t, 2> pins;
|
|
uint8_t interrupts_in_use = 0;
|
|
uint8_t state = 0;
|
|
AH::Array<DirectPinRead, 2> direct_pins;
|
|
AtomicPosition<int32_t> position {0};
|
|
|
|
void update();
|
|
void attachInterruptCtx(uint8_t pin);
|
|
void detachInterruptCtx(uint8_t pin);
|
|
|
|
static AHEncoder *instance_table[CS_ENCODER_ARGLIST_SIZE];
|
|
friend void swap(AHEncoder &a, AHEncoder &b);
|
|
friend void encoder_gpio_callback(unsigned int, uint32_t);
|
|
};
|
|
|
|
END_CS_NAMESPACE
|
|
|
|
#include "AHEncoder.ipp"
|