ESP32Encoder
ESP32Encoder.h
Go to the documentation of this file.
1 #pragma once
2 #include <Arduino.h>
3 #include <driver/gpio.h>
4 #include <driver/pcnt.h>
5 #define MAX_ESP32_ENCODERS PCNT_UNIT_MAX
6 #define _INT16_MAX 32766
7 #define _INT16_MIN -32766
8 
9 enum encType {
13 };
14 enum puType {
18 };
19 class ESP32Encoder {
20 private:
21  void attach(int aPintNumber, int bPinNumber, enum encType et);
22  boolean attached=false;
23 
24 
25  static pcnt_isr_handle_t user_isr_handle; //user's ISR service handle
26  bool direction;
27  bool working;
28 
29  static bool attachedInterrupt;
30  int64_t getCountRaw();
31 public:
32  ESP32Encoder();
33  ~ESP32Encoder();
34  void attachHalfQuad(int aPintNumber, int bPinNumber);
35  void attachFullQuad(int aPintNumber, int bPinNumber);
36  void attachSingleEdge(int aPintNumber, int bPinNumber);
37  int64_t getCount();
38  int64_t clearCount();
39  int64_t pauseCount();
40  int64_t resumeCount();
41 
42  boolean isAttached(){return attached;}
43  void setCount(int64_t value);
44  void setFilter(uint16_t value);
46  gpio_num_t aPinNumber;
47  gpio_num_t bPinNumber;
48  pcnt_unit_t unit;
49  bool fullQuad=false;
50  int countsMode = 2;
51  volatile int64_t count=0;
52  pcnt_config_t r_enc_config;
54 };
55 
56 //Added by Sloeber
57 #pragma once
58 
pcnt_config_t r_enc_config
Definition: ESP32Encoder.h:52
encType
Definition: ESP32Encoder.h:9
int64_t resumeCount()
void setFilter(uint16_t value)
void attachHalfQuad(int aPintNumber, int bPinNumber)
void attachSingleEdge(int aPintNumber, int bPinNumber)
void setCount(int64_t value)
static pcnt_isr_handle_t user_isr_handle
Definition: ESP32Encoder.h:25
int64_t pauseCount()
pcnt_unit_t unit
Definition: ESP32Encoder.h:48
volatile int64_t count
Definition: ESP32Encoder.h:51
#define MAX_ESP32_ENCODERS
Definition: ESP32Encoder.h:5
void attach(int aPintNumber, int bPinNumber, enum encType et)
gpio_num_t aPinNumber
Definition: ESP32Encoder.h:46
boolean attached
Definition: ESP32Encoder.h:22
int64_t getCount()
static ESP32Encoder * encoders[MAX_ESP32_ENCODERS]
Definition: ESP32Encoder.h:45
puType
Definition: ESP32Encoder.h:14
gpio_num_t bPinNumber
Definition: ESP32Encoder.h:47
static enum puType useInternalWeakPullResistors
Definition: ESP32Encoder.h:53
static bool attachedInterrupt
Definition: ESP32Encoder.h:29
void attachFullQuad(int aPintNumber, int bPinNumber)
int64_t getCountRaw()
int64_t clearCount()
boolean isAttached()
Definition: ESP32Encoder.h:42