#include "led.h" #include "board.h" uint16_t beepOnTimeOut; uint8_t beepFrequence = 1; //·äÃùÆ÷ IO³õʼ»¯ void beep_init(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = BOARD_PIN_BEEP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(BOARD_PORT_BEEP, &GPIO_InitStructure); GPIO_WriteBit(BOARD_PORT_BEEP, BOARD_PIN_BEEP, BEEP_OFF); } void beep_onDriver(void) { static uint8_t freqCount = 0; freqCount ++; if (freqCount >= beepFrequence) { freqCount = 0; if (beepOnTimeOut) { GPIO_WriteBit(BOARD_PORT_BEEP, BOARD_PIN_BEEP, (BitAction)!GPIO_ReadOutputDataBit(BOARD_PORT_BEEP, BOARD_PIN_BEEP)); } } if (beepOnTimeOut) { beepOnTimeOut --; if (beepOnTimeOut == 0) { GPIO_WriteBit(BOARD_PORT_BEEP, BOARD_PIN_BEEP, BEEP_OFF); } } } void beep_setFreq(uint8_t freq) { beepFrequence = freq; } void beep_longBeep(void) { beepOnTimeOut = 200; } void beep_shortBeep(void) { beepOnTimeOut = 60; } //LED IO³õʼ»¯ void LED_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = BOARD_PIN_LED1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(BOARD_PORT_LED1, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = BOARD_PIN_LED2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(BOARD_PORT_LED2, &GPIO_InitStructure); GPIO_WriteBit(BOARD_PORT_LED1, BOARD_PIN_LED1, LED_OFF); GPIO_WriteBit(BOARD_PORT_LED2, BOARD_PIN_LED2, LED_OFF); } void testAllLed(void) { static uint8_t ledSta = 1; GPIO_WriteBit(BOARD_PORT_LED1, BOARD_PIN_LED1, LED_OFF); GPIO_WriteBit(BOARD_PORT_LED2, BOARD_PIN_LED2, LED_OFF); switch (ledSta) { case 1: GPIO_WriteBit(BOARD_PORT_LED1, BOARD_PIN_LED1, LED_ON); break; case 2: GPIO_WriteBit(BOARD_PORT_LED2, BOARD_PIN_LED2, LED_ON); break; default: break; } ledSta ++; if (ledSta == 3) { ledSta = 0; } }