Interrupt not firing

I have a very simple button class that uses an interrupt port to raise pressed and released events for a hardware button. Button.State reports accurately, but the interrupt never fires. Can someone look at my code and see if I’m making some stupid mistake somewhere?

public class HardwareButton
{
    private InterruptPort port;
        
    public delegate void OnSwitch(HardwareButton sender);
    public event OnSwitch PressedEvent;
    public event OnSwitch ReleasedEvent;

    /// <summary>
    /// Gets or sets the input state considered to be active
    /// </summary>
    public bool ActiveState { get; set; }

    /// <summary>
    /// Gets the current state of the button
    /// </summary>
    public bool State { get { return port.Read() == ActiveState; } }

    public HardwareButton(Cpu.Pin input, Port.ResistorMode resistorMode = Port.ResistorMode.Disabled, bool activeState = false)
    {
        this.port = new InterruptPort(input, true, resistorMode, Port.InterruptMode.InterruptEdgeBoth);
        this.port.OnInterrupt += inputPort_OnInterrupt;
        this.ActiveState = activeState;
    }

    private void inputPort_OnInterrupt(uint port, uint state, DateTime time)
    {
        DebugHelper.Print("Button triggered");
        if(this.State)
        {
            if (this.PressedEvent != null)
            {
                this.PressedEvent(this);
            }
        }
        else
        {
            if(this.ReleasedEvent != null)
            {
                this.ReleasedEvent(this);
            }
        }
    }
}

When I try to validate the interrupt port in a test project it works.

public partial class Program
{
    void ProgramStarted()
    {
        InterruptPort port = new InterruptPort(GHI.Pins.G400.PA22, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
        port.OnInterrupt += port_OnInterrupt;
        Debug.Print("Program Started");
    }

    void port_OnInterrupt(uint data1, uint data2, DateTime time)
    {
        Debug.Print("Triggered");
    }
}

I can’t see the difference in InterruptPort implementation.

How do you use your HardwareButton? Is it possible that it is instantiated in a local scope and got garbage collected?

The HardwareButton instance is being instantiated inside a Singleton class with no chance of being garbage collected. As I mentioned in the top post, the Button.State member is reporting correctly. It is just that the interrupt itself is never firing.

The only other difference I see is the default parameter for pullup is Disabled in your class constructor and the second example uses PullUp.

@ bigtwisty -

not sure but look like you are missing:

@ Dat:
My original version had EnableInterrupt() and it still didn’t work. Non of the examples on your site used EnableInterrupt(), so I removed it. The test application in the OP does not use EnableInterrupt() either, but it works.

Edit @ Architect:
The demo was written to duplicate the actual instantiation in the Singleton class, so the pin and pullup are set identically in both apps.

Edit:

Solution found! I moved the button to GHI.Pins.G400.PB5. The original pin (PA22) can be used as SPI2_MOSI, but I am not using SPI2 at all. I was under the impression that all pins supported interrupt functionality. If this is not true it should probably be documented somewhere.

Thanks for the responses, guys!