Made beep functions available also for other variants

Beep function "short" and "long" can be used also for other variants than TRASNPOTTER
This commit is contained in:
EmanuelFeru 2019-12-23 10:11:48 +01:00
parent f253e6e29a
commit 814af15adc
2 changed files with 62 additions and 63 deletions

View File

@ -157,6 +157,10 @@ typedef struct {
uint16_t l_rx2; uint16_t l_rx2;
} adc_buf_t; } adc_buf_t;
// Define Beep functions
void longBeep(uint8_t freq);
void shortBeep(uint8_t freq);
// Define low-pass filter functions. Implementation is in main.c // Define low-pass filter functions. Implementation is in main.c
void filtLowPass16(int16_t u, uint16_t coef, int16_t *y); void filtLowPass16(int16_t u, uint16_t coef, int16_t *y);
void filtLowPass32(int32_t u, uint16_t coef, int32_t *y); void filtLowPass32(int32_t u, uint16_t coef, int32_t *y);

View File

@ -87,8 +87,6 @@ extern I2C_HandleTypeDef hi2c2;
int feedforward; int feedforward;
void saveConfig(void); void saveConfig(void);
void longBeep(void);
void shortBeep(uint8_t freq);
/* Virtual address defined by the user: 0xFFFF value is prohibited */ /* Virtual address defined by the user: 0xFFFF value is prohibited */
uint16_t VirtAddVarTab[NB_OF_VAR] = {0x1337}; uint16_t VirtAddVarTab[NB_OF_VAR] = {0x1337};
@ -377,7 +375,7 @@ int main(void) {
while(HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) { while(HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) {
HAL_Delay(10); HAL_Delay(10);
} }
longBeep(); longBeep(5);
HAL_Delay(350); HAL_Delay(350);
poweroff(); poweroff();
} else { } else {
@ -523,10 +521,8 @@ int main(void) {
#ifndef TRANSPOTTER #ifndef TRANSPOTTER
// ####### MOTOR ENABLING: Only if the initial input is very small (for SAFETY) ####### // ####### MOTOR ENABLING: Only if the initial input is very small (for SAFETY) #######
if (enable == 0 && (cmd1 > -50 && cmd1 < 50) && (cmd2 > -50 && cmd2 < 50)){ if (enable == 0 && (cmd1 > -50 && cmd1 < 50) && (cmd2 > -50 && cmd2 < 50)){
buzzerPattern = 0; shortBeep(6); // make 2 beeps indicating the motor enable
buzzerFreq = 6; HAL_Delay(100); // make 2 beeps indicating the motor enable shortBeep(4); HAL_Delay(100);
buzzerFreq = 4; HAL_Delay(200);
buzzerFreq = 0;
enable = 1; // enable motors enable = 1; // enable motors
} }
@ -587,7 +583,7 @@ int main(void) {
if ((distance / 1345.0) - setDistance > 0.5 && (lastDistance / 1345.0) - setDistance > 0.5) { // Error, robot too far away! if ((distance / 1345.0) - setDistance > 0.5 && (lastDistance / 1345.0) - setDistance > 0.5) { // Error, robot too far away!
enable = 0; enable = 0;
longBeep(); longBeep(5);
#ifdef SUPPORT_LCD #ifdef SUPPORT_LCD
LCD_ClearDisplay(&lcd); LCD_ClearDisplay(&lcd);
HAL_Delay(5); HAL_Delay(5);
@ -736,18 +732,6 @@ int main(void) {
} }
#ifdef TRANSPOTTER #ifdef TRANSPOTTER
void longBeep(){
buzzerFreq = 5;
HAL_Delay(500);
buzzerFreq = 0;
}
void shortBeep(uint8_t freq){
buzzerFreq = freq;
HAL_Delay(100);
buzzerFreq = 0;
}
void saveConfig() { void saveConfig() {
HAL_FLASH_Unlock(); HAL_FLASH_Unlock();
EE_WriteVariable(VirtAddVarTab[0], saveValue); EE_WriteVariable(VirtAddVarTab[0], saveValue);
@ -755,50 +739,17 @@ int main(void) {
} }
#endif #endif
/** System Clock Configuration void longBeep(uint8_t freq){
*/ buzzerFreq = freq;
void SystemClock_Config(void) { HAL_Delay(500);
RCC_OscInitTypeDef RCC_OscInitStruct; buzzerFreq = 0;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
// PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV8; // 8 MHz
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV4; // 16 MHz
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
} }
void shortBeep(uint8_t freq){
buzzerFreq = freq;
HAL_Delay(100);
buzzerFreq = 0;
}
// =========================================================== // ===========================================================
/* Low pass filter fixed-point 16 bits: fixdt(1,16,4) /* Low pass filter fixed-point 16 bits: fixdt(1,16,4)
@ -916,3 +867,47 @@ void rateLimiter16(int16_t u, int16_t rate, int16_t *y)
} }
// =========================================================== // ===========================================================
/** System Clock Configuration
*/
void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
// PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV8; // 8 MHz
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV4; // 16 MHz
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}