Skip to content

Commit

Permalink
Merge pull request #5 from ziteh:main
Browse files Browse the repository at this point in the history
Add simple button debounce
  • Loading branch information
ziteh authored Aug 17, 2022
2 parents 1f77001 + 4366f93 commit aa55c18
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define USART_BAUDRATE (9600)
#define BUTTON_SEND_DATA ((uint8_t)0xF0)
#define DELAY_VALUE ((uint32_t)250000)
#define DEBOUNCE_DELAY_VALUE ((uint32_t)20000)

#define USB_USART (USART2)
#define RCC_USB_USART (RCC_USART2)
Expand Down Expand Up @@ -175,9 +176,14 @@ void exti15_10_isr(void)
// Clear flag first.
exti_reset_request(BUTTON_EXTI);

usart_send_blocking(USB_USART, BUTTON_SEND_DATA);
usart_send_blocking(USB_USART, ASCII_CR);
usart_send_blocking(USB_USART, ASCII_LF);
// Simple button debounce.
delay(DEBOUNCE_DELAY_VALUE);
if(gpio_get(BUTTON_PORT, BUTTON_PIN) == 0)
{
usart_send_blocking(USB_USART, BUTTON_SEND_DATA);
usart_send_blocking(USB_USART, ASCII_CR);
usart_send_blocking(USB_USART, ASCII_LF);
}
}

/**
Expand Down

0 comments on commit aa55c18

Please sign in to comment.