I'm using the MCUXpresso (v10.2.1) IDE to make software for my FRDM-KE06Z board. (SDK v2.4.1)
I have an application where I need to use both SW2 and SW3 to control two different actions. I've initialized them both as such:
kbi_config_t sKBIConfig;
sKBIConfig.pinsEnabled = 18000000; //both SW2 and SW3
sKBIConfig.pinsEdge = 0; //falling edge
sKBIConfig.mode = kKBI_EdgesDetect; //just on edges
KBI_Init(KBI1, &sKBIConfig);
KBI_ClearInterruptFlag(KBI1);
KBI_EnableInterrupts(KBI1);
In order to differentiate between the two buttons, I was thinking on using
KBI_GetSourcePinStatus(KBI1)
to read the source pin value in order to determine which button is being pressed. I'm doing it like this in the handler function:
if (KBI_IsInterruptRequestDetected(KBI1)){
KBI_DisableInterrupts(KBI1);
KBI_ClearInterruptFlag(KBI1);
if (KBI_GetSourcePinStatus(KBI1) == 134217728){ //SW3
//function1()
}
else if (KBI_GetSourcePinStatus(KBI1) == 268435456){ //SW2
//function2()
}
KBI_EnableInterrupts(KBI1);
}
What I've noticed in breakpoints is that when the application first loads, if I stick to pressing only one of the two buttons, I'll get the proper return value from the source pin status function. But if I then press the other button, that same function returns a value of 402653184 (the values of SW2 and SW3 combined). And if I go back to pressing the button that I was pressing before, I'll still get 402653184. That value will stay the same no matter which button until I reset the application.
I'm not sure whether it's a matter of a flag not getting cleared properly. According to fsl_kbi.h, the clear interrupt flag function modifies base->sc, while the source pin status function is reading from base->sp. In addition, I was unable to find any information on how to properly "reset" the pins, as I'm not modifying arrays directly the way I'm doing it here.
Is there something I'm overlooking?