44 lines
892 B
C
44 lines
892 B
C
#include <stdbool.h>
|
|
|
|
#include <main.h>
|
|
#include <adc.h>
|
|
|
|
#include <frontend.h>
|
|
|
|
#include <logger.h>
|
|
|
|
|
|
|
|
|
|
static volatile uint16_t frontendAdcThreshold = 0;
|
|
static volatile bool frontendEnabled = false;
|
|
|
|
|
|
void frontendInit() {
|
|
HAL_ADCEx_Calibration_Start(&frontendAdc);
|
|
logMsg("frontendInit, calibration done");
|
|
HAL_ADC_Start_IT(&frontendAdc);
|
|
logMsg("frontendInit, adc started");
|
|
}
|
|
|
|
void frontendSetThreshold(uint16_t threshold) {
|
|
frontendAdcThreshold = threshold;
|
|
}
|
|
|
|
void frontendEnable() {
|
|
frontendEnabled = true;
|
|
}
|
|
|
|
void frontendDisable() {
|
|
frontendEnabled = false;
|
|
}
|
|
|
|
void frontendAdcCallback(ADC_HandleTypeDef* hadc) {
|
|
HAL_GPIO_TogglePin(Debug_Signal_1_GPIO_Port, Debug_Signal_1_Pin);
|
|
uint32_t rawValue = HAL_ADC_GetValue(hadc);
|
|
if (rawValue > frontendAdcThreshold) {
|
|
HAL_GPIO_TogglePin(Frontend_Out_GPIO_Port, Frontend_Out_Pin);
|
|
}
|
|
|
|
}
|