handle S1, S2 and sel

also display pressed buttons
This commit is contained in:
Andy Killorin 2025-03-23 19:16:57 -04:00
parent e7e2f56db3
commit c6caef7ba0
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
2 changed files with 53 additions and 7 deletions

View file

@ -43,17 +43,31 @@ void ButtonInit(void)
// initialize interrupt controller to respond to timer interrupts
IntPrioritySet(INT_TIMER0A, BUTTON_INT_PRIORITY);
IntEnable(INT_TIMER0A);
/*
// GPIO PJ0 and PJ1 = EK-TM4C1294XL buttons 1 and 2
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1);
GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
// Button S1
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
GPIOPinTypeGPIOInput(GPIO_PORTH_BASE, GPIO_PIN_1);
GPIOPadConfigSet(GPIO_PORTH_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
// Button S2
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
GPIOPinTypeGPIOInput(GPIO_PORTK_BASE, GPIO_PIN_6);
GPIOPadConfigSet(GPIO_PORTK_BASE, GPIO_PIN_6, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
// Select Button
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_4);
GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
// analog input AIN13, at GPIO PD2 = BoosterPack Joystick HOR(X)
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_2);
// analog input AIN17, at GPIO PK1 = BoosterPack Joystick VER(Y)
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
//SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
GPIOPinTypeADC(GPIO_PORTK_BASE, GPIO_PIN_1);
// initialize ADC0 peripheral
@ -69,7 +83,6 @@ void ButtonInit(void)
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH13); // Joystick HOR(X)
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH17 | ADC_CTL_IE | ADC_CTL_END); // Joystick VER(Y)
ADCSequenceEnable(ADC0_BASE, 0);
*/
}
// update the debounced button state gButtons
@ -143,24 +156,39 @@ uint32_t ButtonAutoRepeat(void)
// ISR for scanning and debouncing buttons
void ButtonISR(void) {
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // clear interrupt flag
/*
// read hardware button state
uint32_t gpio_buttons =
~GPIOPinRead(GPIO_PORTJ_BASE, 0xff) & (GPIO_PIN_1 | GPIO_PIN_0); // EK-TM4C1294XL buttons in positions 0 and 1
uint32_t gpio_s1 =
GPIOPinRead(GPIO_PORTH_BASE, GPIO_PIN_1) >> 1; // S1
gpio_s1 ^= 1;
gpio_buttons |= gpio_s1 << 2;
uint32_t gpio_s2 =
GPIOPinRead(GPIO_PORTK_BASE, GPIO_PIN_6) >> 6; // S2
gpio_s2 ^= 1;
gpio_buttons |= gpio_s2 << 3;
uint32_t gpio_select =
GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_4) >> 4; // select
gpio_select ^= 1;
gpio_buttons |= gpio_select << 4;
uint32_t old_buttons = gButtons; // save previous button state
ButtonDebounce(gpio_buttons); // Run the button debouncer. The result is in gButtons.
ButtonReadJoystick(); // Convert joystick state to button presses. The result is in gButtons.
uint32_t presses = ~old_buttons & gButtons; // detect button presses (transitions from not pressed to pressed)
presses |= ButtonAutoRepeat(); // autorepeat presses if a button is held long enough
*/
static bool tic = false;
static bool running = true;
/*
if (presses & 1) { // EK-TM4C1294XL button 1 pressed
running = !running;
}
*/
if (presses & 2) { // EK-TM4C1294XL button 2 pressed
gTime = 0;
}
if (running) {
if (tic) gTime++; // increment time every other ISR call
tic = !tic;

18
main.c
View file

@ -58,6 +58,24 @@ int main(void)
snprintf(str, sizeof(str), "Time = %02u:%02u:%02u", minutes, seconds, hundredths); // convert time to string
GrContextForegroundSet(&sContext, ClrYellow); // yellow text
GrStringDraw(&sContext, str, /*length*/ -1, /*x*/ 0, /*y*/ 0, /*opaque*/ false);
// display button statuses
char labels[5][4] = {"sw1", "sw2", "s1", "s2", "sel"};
char statuses[2][15] = {"not pressed", "pressed"};
int offset = 20;
uint32_t buttons = gButtons;
uint8_t i;
for (i = 0; i < 5; i++) {
snprintf(str, sizeof(str), "%s: %s",
labels[i],
statuses[buttons & 1]
);
GrStringDraw(&sContext, str, /*length*/ -1, /*x*/ 0, /*y*/ offset, /*opaque*/ false);
offset += 10;
buttons >>= 1;
}
GrFlush(&sContext); // flush the frame buffer to the LCD
}
}