led_blink.c 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "stm32f4xx_hal.h"
  2. #include "stm32f4xx_hal_gpio.h"
  3. unsigned int blinkLed = 0;
  4. // Interface function to blink the green LED
  5. void blinkTheLED() {
  6. blinkLed++;
  7. }
  8. enum {
  9. MODE_INACTIVE,
  10. MODE_ON,
  11. MODE_OFF,
  12. MODE_SWITCH, // Just have been off
  13. };
  14. void rxLed() {
  15. static unsigned long timer = 0;
  16. static int mode = MODE_INACTIVE;
  17. switch( mode ) {
  18. case MODE_INACTIVE:
  19. if( blinkLed > 0 ) {
  20. blinkLed--;
  21. mode = MODE_ON;
  22. timer = 1;
  23. HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,(GPIO_PinState)1);
  24. }
  25. break;
  26. case MODE_ON:
  27. timer--;
  28. if( timer == 0 ) {
  29. mode = MODE_OFF;
  30. HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,(GPIO_PinState)0);
  31. timer = 1;
  32. }
  33. break;
  34. case MODE_OFF:
  35. timer--;
  36. if( timer == 0 ) {
  37. mode = MODE_INACTIVE;
  38. HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,(GPIO_PinState)0);
  39. break;
  40. }
  41. }
  42. }
  43. // 10Hz timer interrupt function
  44. void led_interrupt(){
  45. rxLed();
  46. }