2018-04-03 15:32:24 +00:00
|
|
|
/*
|
|
|
|
Manufacturing tests for the new cortex minimal system
|
|
|
|
Copyright (C) 2018 Andreas Mieke
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
}
|