led.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "led.h"
  2. #include "board.h"
  3. uint16_t beepOnTimeOut;
  4. uint8_t beepFrequence = 1;
  5. //·äÃùÆ÷ IO³õʼ»¯
  6. void beep_init(void)
  7. {
  8. GPIO_InitTypeDef GPIO_InitStructure;
  9. GPIO_InitStructure.GPIO_Pin = BOARD_PIN_BEEP;
  10. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  11. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  12. GPIO_Init(BOARD_PORT_BEEP, &GPIO_InitStructure);
  13. GPIO_WriteBit(BOARD_PORT_BEEP, BOARD_PIN_BEEP, BEEP_OFF);
  14. }
  15. void beep_onDriver(void)
  16. {
  17. static uint8_t freqCount = 0;
  18. freqCount ++;
  19. if (freqCount >= beepFrequence)
  20. {
  21. freqCount = 0;
  22. if (beepOnTimeOut)
  23. {
  24. GPIO_WriteBit(BOARD_PORT_BEEP, BOARD_PIN_BEEP,
  25. (BitAction)!GPIO_ReadOutputDataBit(BOARD_PORT_BEEP, BOARD_PIN_BEEP));
  26. }
  27. }
  28. if (beepOnTimeOut)
  29. {
  30. beepOnTimeOut --;
  31. if (beepOnTimeOut == 0)
  32. {
  33. GPIO_WriteBit(BOARD_PORT_BEEP, BOARD_PIN_BEEP, BEEP_OFF);
  34. }
  35. }
  36. }
  37. void beep_setFreq(uint8_t freq)
  38. {
  39. beepFrequence = freq;
  40. }
  41. void beep_longBeep(void)
  42. {
  43. beepOnTimeOut = 200;
  44. }
  45. void beep_shortBeep(void)
  46. {
  47. beepOnTimeOut = 60;
  48. }
  49. //LED IO³õʼ»¯
  50. void LED_Init(void)
  51. {
  52. GPIO_InitTypeDef GPIO_InitStructure;
  53. GPIO_InitStructure.GPIO_Pin = BOARD_PIN_LED1;
  54. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  55. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  56. GPIO_Init(BOARD_PORT_LED1, &GPIO_InitStructure);
  57. GPIO_InitStructure.GPIO_Pin = BOARD_PIN_LED2;
  58. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  59. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  60. GPIO_Init(BOARD_PORT_LED2, &GPIO_InitStructure);
  61. GPIO_WriteBit(BOARD_PORT_LED1, BOARD_PIN_LED1, LED_OFF);
  62. GPIO_WriteBit(BOARD_PORT_LED2, BOARD_PIN_LED2, LED_OFF);
  63. }
  64. void testAllLed(void)
  65. {
  66. static uint8_t ledSta = 1;
  67. GPIO_WriteBit(BOARD_PORT_LED1, BOARD_PIN_LED1, LED_OFF);
  68. GPIO_WriteBit(BOARD_PORT_LED2, BOARD_PIN_LED2, LED_OFF);
  69. switch (ledSta)
  70. {
  71. case 1:
  72. GPIO_WriteBit(BOARD_PORT_LED1, BOARD_PIN_LED1, LED_ON);
  73. break;
  74. case 2:
  75. GPIO_WriteBit(BOARD_PORT_LED2, BOARD_PIN_LED2, LED_ON);
  76. break;
  77. default:
  78. break;
  79. }
  80. ledSta ++;
  81. if (ledSta == 3)
  82. {
  83. ledSta = 0;
  84. }
  85. }