AMTS/Mieke/SW/MT/piezo.c

49 lines
987 B
C
Raw Normal View History

2018-03-18 22:43:59 +00:00
#include "piezo.h"
volatile uint32_t *PiezoSTick, PiezoSTickCur, Freq;
void init_piezo(volatile uint32_t *SysTickCnt)
{
2018-04-03 15:18:28 +00:00
// Enable GPIOB clock
2018-03-18 22:43:59 +00:00
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
2018-04-03 15:18:28 +00:00
// Create gpio struct and fill it with default values
2018-03-18 22:43:59 +00:00
GPIO_InitTypeDef gpio;
GPIO_StructInit(&gpio);
2018-04-03 15:18:28 +00:00
// Set PB0 to output push pull
2018-03-18 22:43:59 +00:00
gpio.GPIO_Mode = GPIO_Mode_Out_PP;
gpio.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOB, &gpio);
PiezoSTick = SysTickCnt;
return;
}
void run_piezo()
{
uint8_t pstate = 0x0;
PiezoSTickCur = *PiezoSTick;
2018-04-03 15:18:28 +00:00
// Run for one second
2018-03-18 22:43:59 +00:00
while((*PiezoSTick - PiezoSTickCur) <= 1000)
{
Freq = *PiezoSTick;
2018-04-03 15:18:28 +00:00
// Wait for 1 millisecond
2018-03-18 22:43:59 +00:00
while((*PiezoSTick - Freq) <= 1);
2018-04-03 15:18:28 +00:00
// Toggle output
2018-03-18 22:43:59 +00:00
if (pstate) {
pstate = ~pstate;
GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_SET);
} else {
pstate = ~pstate;
GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_RESET);
}
}
return;
}
void deinit_piezo(void)
{
return;
}