Skip to content

Commit

Permalink
add encoder module
Browse files Browse the repository at this point in the history
  • Loading branch information
Watanabe1101 committed Oct 5, 2023
1 parent e8b4720 commit 7b4571c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@
#include <driver/pcnt.h>
#include <soc/pcnt_struct.h>

// static void IRAM_ATTR caller(void *arg);
// int intr_count = 0;
// pcnt_isr_handle_t user_isr_handle = NULL;

class encoder {
private:
int intr_count = 0;
pcnt_isr_handle_t user_isr_handle = NULL;
pcnt_unit_t pcnt_unit;
static pcnt_unit_t next_pcnt_unit;

public:
encoder(pcnt_unit_t unit) : pcnt_unit(unit) {}
encoder();
void begin(int pinA, int pinB);
int32_t getcount();
static void IRAM_ATTR caller(void *arg);
void processInterrupt();
};

pcnt_unit_t encoder::next_pcnt_unit = PCNT_UNIT_0;

encoder::encoder() {
pcnt_unit = next_pcnt_unit;
next_pcnt_unit = static_cast<pcnt_unit_t>(static_cast<int>(next_pcnt_unit) + 1);
}

void encoder::begin(int pinA, int pinB) {
pcnt_config_t pcnt_config_A = {
.pulse_gpio_num = pinA,
Expand Down

0 comments on commit 7b4571c

Please sign in to comment.