GPIO Interrupt from a class file

chukitoes
Posts: 10
Joined: Mon Jan 17, 2022 5:50 pm

Re: GPIO Interrupt from a class file

Postby chukitoes » Sun Feb 06, 2022 11:51 pm

So, it's now working as expected. There were a few things:

For the files i posted here:
  • I used the change proposed by boarchuz, but instead of using it in the main.c, it was the solution for one of the issues from the main.cpp.
    boarchuz wrote: You could change

    Code: Select all

    uint32_t C_cnt;
    ->

    Code: Select all

    extern uint32_t C_cnt;
    in ANSI_Encoder.h, so the linker knows to go looking for it somewhere else for main.c.
  • I think that by updating to esp-idf v4.4 as I mentioned in a previous post really was a key aspect to reach the solution, since before that the main.c interrupt wasn't working, but after that it worked.
    Otherwise, maybe it still wouldn't work with the CPP files.
For the full files I was using before this I even made this post:
  • From this liebman's reply, although it didn't break the program by not using the configs as static, because it's a short program and they weren't swapped out yet in memory, it will definitely be helpful following his instructions.
    liebman wrote: In `encoder_init`. You have `encoder_isr_config_t isr_args;`. thats on the stack and is no longer valid after the function returns. You need to declare that as static. You also need one for each interrupt, you're overwriting the first when you setup the second.
  • In the GPIO configs I was using
    1. gpio_conf.pin_bit_mask = 0x1<<this->enc1_pin | 0x1<<this->enc2_pin;
    instead of
    1. gpio_conf.pin_bit_mask = 1ULL<<this->enc1_pin | 1ULL<<this->enc2_pin;
    which didn't really configured the right pins.
In the end, both declaring a function outside the class but inside it's file and a static method inside the class worked as interrupt handlers.

A huge thank you for everyone that replied and helped me!!

boarchuz
Posts: 605
Joined: Tue Aug 21, 2018 5:28 am

Re: GPIO Interrupt from a class file

Postby boarchuz » Mon Feb 07, 2022 2:20 am

chukitoes wrote:
Sun Feb 06, 2022 6:31 pm
But, it actually does work
Sorry, I think I was off the mark - I was mixed up with the common case where the header would have 'static' variables, in which case they would be 'duplicated' wherever that header is included.

chukitoes
Posts: 10
Joined: Mon Jan 17, 2022 5:50 pm

Re: GPIO Interrupt from a class file

Postby chukitoes » Mon Feb 07, 2022 3:24 am

boarchuz wrote:
Mon Feb 07, 2022 2:20 am
chukitoes wrote:
Sun Feb 06, 2022 6:31 pm
But, it actually does work
Sorry, I think I was off the mark - I was mixed up with the common case where the header would have 'static' variables, in which case they would be 'duplicated' wherever that header is included.
Don't be sorry, that was the final piece of the puzzle to solving the cpp handler issue!

Who is online

Users browsing this forum: No registered users and 49 guests