Brian
_READ_PORT_MASK() is just a macro:
#define _READ_PORT_MASK(ref, mask) (GPIO##ref##_PDIR & (mask))
_READ_PORT_MASK(B, 0x00020000); is therefore
(GPIOB_PDIR & 0x00020000)
Which is what you need for your input.
I just check on a FRDM-K22F, adding the LEDs more or less as you suggest.Note that the FRDM-K22F has red,green and blue and not yellow (although yellow results when read and green are on).
I did have an error in the original code since there were two lines incrementing the counter. This is the correct code:
{
static int iPressInterval = 0;
if (_READ_PORT_MASK(B, PORTB_BIT17) == 0) { // is key pressed?
_SETBITS(A, PORTA_BIT2); // green LED off
if (++iPressInterval >= (2 * TICK_PER_SECOND)) { // pressed - count the duration
if (iPressInterval == (2 * TICK_PER_SECOND)) {
_CLEARBITS(A, PORTA_BIT1); // red LED on
}
else {
if (iPressInterval > (2 * TICK_PER_SECOND)) {
iPressInterval--; // peak hold the pressed duration until the key is released
_CLEARBITS(D, PORTD_BIT5); // blue LED on
}
}
}
}
else { // not pressed
iPressInterval = 0; // reset the press integrator
_CLEARBITS(A, PORTA_BIT2); // green LED on
_SETBITS(D, PORTD_BIT5); // blue LED off
}
}
I have attached a binary for the board showing it in operation plus a simulation (unzip the attached and start the simulation with a double click on uTaskerV1.4.12_FRDM-K22F_ButtonTest2s.exe. When it runs it looks like below and you can click on the button to hold it down and see the LED reacting (same as on the HW).
Regards
Mark
