Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

cpp-interrupt-example

This show how to encapsulate late interrupt in a class

https://www.reddit.com/r/embedded/comments/10y3u3w/how_to_handle_interrupt_with_cpp/

class Uart {

  static constexpr size_t MAX_UARTS = 8;

  Uart(uint8_t index) {
    assert(index < MAX_UARTS);
    assert(registeredUarts[index] = nullptr);
    registeredUarts[index] = this;
  };
    
  static std::array<Uart*, MAX_UARTS> registeredUarts;
  static uint8_t getActiveUart() {
    // return which UART index the interrupt was for
  }
  static void onUartInterrupt() {
    Uart* u = registeredUarts[getActiveUart()];
    if (u) {
      u->doInterruptStuff();
    }
  }
}

About

This show how to encapsulate late interrupt in a class

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors