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:
parent
f253e6e29a
commit
814af15adc
|
@ -157,6 +157,10 @@ typedef struct {
|
|||
uint16_t l_rx2;
|
||||
} 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
|
||||
void filtLowPass16(int16_t u, uint16_t coef, int16_t *y);
|
||||
void filtLowPass32(int32_t u, uint16_t coef, int32_t *y);
|
||||
|
|
119
Src/main.c
119
Src/main.c
|
@ -87,8 +87,6 @@ extern I2C_HandleTypeDef hi2c2;
|
|||
int feedforward;
|
||||
|
||||
void saveConfig(void);
|
||||
void longBeep(void);
|
||||
void shortBeep(uint8_t freq);
|
||||
|
||||
/* Virtual address defined by the user: 0xFFFF value is prohibited */
|
||||
uint16_t VirtAddVarTab[NB_OF_VAR] = {0x1337};
|
||||
|
@ -377,7 +375,7 @@ int main(void) {
|
|||
while(HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) {
|
||||
HAL_Delay(10);
|
||||
}
|
||||
longBeep();
|
||||
longBeep(5);
|
||||
HAL_Delay(350);
|
||||
poweroff();
|
||||
} else {
|
||||
|
@ -523,10 +521,8 @@ int main(void) {
|
|||
#ifndef TRANSPOTTER
|
||||
// ####### MOTOR ENABLING: Only if the initial input is very small (for SAFETY) #######
|
||||
if (enable == 0 && (cmd1 > -50 && cmd1 < 50) && (cmd2 > -50 && cmd2 < 50)){
|
||||
buzzerPattern = 0;
|
||||
buzzerFreq = 6; HAL_Delay(100); // make 2 beeps indicating the motor enable
|
||||
buzzerFreq = 4; HAL_Delay(200);
|
||||
buzzerFreq = 0;
|
||||
shortBeep(6); // make 2 beeps indicating the motor enable
|
||||
shortBeep(4); HAL_Delay(100);
|
||||
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!
|
||||
enable = 0;
|
||||
longBeep();
|
||||
longBeep(5);
|
||||
#ifdef SUPPORT_LCD
|
||||
LCD_ClearDisplay(&lcd);
|
||||
HAL_Delay(5);
|
||||
|
@ -736,8 +732,15 @@ int main(void) {
|
|||
}
|
||||
|
||||
#ifdef TRANSPOTTER
|
||||
void longBeep(){
|
||||
buzzerFreq = 5;
|
||||
void saveConfig() {
|
||||
HAL_FLASH_Unlock();
|
||||
EE_WriteVariable(VirtAddVarTab[0], saveValue);
|
||||
HAL_FLASH_Lock();
|
||||
}
|
||||
#endif
|
||||
|
||||
void longBeep(uint8_t freq){
|
||||
buzzerFreq = freq;
|
||||
HAL_Delay(500);
|
||||
buzzerFreq = 0;
|
||||
}
|
||||
|
@ -748,58 +751,6 @@ int main(void) {
|
|||
buzzerFreq = 0;
|
||||
}
|
||||
|
||||
void saveConfig() {
|
||||
HAL_FLASH_Unlock();
|
||||
EE_WriteVariable(VirtAddVarTab[0], saveValue);
|
||||
HAL_FLASH_Lock();
|
||||
}
|
||||
#endif
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
||||
|
||||
// ===========================================================
|
||||
/* Low pass filter fixed-point 16 bits: fixdt(1,16,4)
|
||||
* Max: 2047.9375
|
||||
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue