application: add button
This commit is contained in:
parent
517f58d463
commit
51cf8b0f95
|
@ -803,7 +803,15 @@ void main(void)
|
|||
rcc_periph_clock_enable(GPIO_RCC(CONTROL_POWER_RED_LED_PIN)); // enable clock for GPIO port peripheral
|
||||
gpio_clear(GPIO_PORT(CONTROL_POWER_RED_LED_PIN), GPIO_PIN(CONTROL_POWER_RED_LED_PIN)); // switch LED off
|
||||
gpio_set_mode(GPIO_PORT(CONTROL_POWER_RED_LED_PIN), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(CONTROL_POWER_RED_LED_PIN)); // set pin as output push-pull to be able to power LED
|
||||
// play/pause button is configured by global
|
||||
// play/pause button
|
||||
rcc_periph_clock_enable(GPIO_RCC(CONTROL_PLAY_BUTTON_LED_PIN)); // enable clock for button
|
||||
gpio_set_mode(GPIO_PORT(CONTROL_PLAY_BUTTON_LED_PIN), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_PIN(CONTROL_PLAY_BUTTON_LED_PIN)); // set button pin to input
|
||||
rcc_periph_clock_enable(RCC_AFIO); // enable alternate function clock for external interrupt
|
||||
exti_select_source(GPIO_EXTI(CONTROL_PLAY_BUTTON_LED_PIN), GPIO_PORT(CONTROL_PLAY_BUTTON_LED_PIN)); // mask external interrupt of this pin only for this port
|
||||
gpio_set(GPIO_PORT(CONTROL_PLAY_BUTTON_LED_PIN), GPIO_PIN(CONTROL_PLAY_BUTTON_LED_PIN)); // pull up to be able to detect button push (go low)
|
||||
exti_set_trigger(GPIO_EXTI(CONTROL_PLAY_BUTTON_LED_PIN), EXTI_TRIGGER_FALLING); // trigger when button is pressed
|
||||
exti_enable_request(GPIO_EXTI(CONTROL_PLAY_BUTTON_LED_PIN)); // enable external interrupt
|
||||
nvic_enable_irq(GPIO_NVIC_EXTI_IRQ(CONTROL_PLAY_BUTTON_LED_PIN)); // enable interrupt
|
||||
puts("OK\n");
|
||||
|
||||
puts("setup heating bed pins: ");
|
||||
|
@ -987,11 +995,7 @@ void main(void)
|
|||
if (button_flag) { // user pressed button
|
||||
action = true; // action has been performed
|
||||
sleep_ms(100); // wait a bit to remove noise
|
||||
#if (0 == BUTTON_PRESSED)
|
||||
if (!gpio_get(GPIO_PORT(BUTTON_PIN), GPIO_PIN(BUTTON_PIN))) {
|
||||
#else
|
||||
if (gpio_get(GPIO_PORT(BUTTON_PIN), GPIO_PIN(BUTTON_PIN))) {
|
||||
#endif
|
||||
if (!gpio_get(GPIO_PORT(CONTROL_PLAY_BUTTON_LED_PIN), GPIO_PIN(CONTROL_PLAY_BUTTON_LED_PIN))) {
|
||||
puts("button pressed\n");
|
||||
gpio_toggle(GPIO_PORT(CONTROL_PLAY_ORANGE_LED_PIN), GPIO_PIN(CONTROL_PLAY_ORANGE_LED_PIN));
|
||||
gpio_toggle(GPIO_PORT(CONTROL_PLAY_GREEN_LED_PIN), GPIO_PIN(CONTROL_PLAY_GREEN_LED_PIN));
|
||||
|
@ -1098,3 +1102,10 @@ void rtc_isr(void)
|
|||
tick = RTC_TICKS_SECOND; // reset count down
|
||||
}
|
||||
}
|
||||
|
||||
/** interrupt service routine called when button is pressed */
|
||||
void GPIO_EXTI_ISR(CONTROL_PLAY_BUTTON_LED_PIN)(void)
|
||||
{
|
||||
exti_reset_request(GPIO_EXTI(CONTROL_PLAY_BUTTON_LED_PIN)); // reset interrupt
|
||||
button_flag = true; // perform button action
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue