some fixes
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
|
||||
#include "adc_mux.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "board_handles.h"
|
||||
#include "main.h"
|
||||
|
||||
@ -117,35 +119,65 @@ uint16_t adc_mux_read_external_channel(uint8_t channel_index)
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t adc_mux_process_internal_adc_step(uint8_t step)
|
||||
static bool adc_mux_read_sequence(ADC_HandleTypeDef *hadc, uint16_t *output_buffer, uint8_t sample_count)
|
||||
{
|
||||
uint16_t output = 0u;
|
||||
uint8_t sample_index;
|
||||
|
||||
switch (step)
|
||||
if ((hadc == NULL) || (output_buffer == NULL) || (sample_count == 0u))
|
||||
{
|
||||
case 0u:
|
||||
HAL_ADC_Start(&hadc1);
|
||||
break;
|
||||
case 1u:
|
||||
HAL_ADC_PollForConversion(&hadc1, 100u);
|
||||
output = HAL_ADC_GetValue(&hadc1);
|
||||
break;
|
||||
case 2u:
|
||||
HAL_ADC_Stop(&hadc1);
|
||||
break;
|
||||
case 3u:
|
||||
HAL_ADC_Start(&hadc3);
|
||||
break;
|
||||
case 4u:
|
||||
HAL_ADC_PollForConversion(&hadc3, 100u);
|
||||
output = HAL_ADC_GetValue(&hadc3);
|
||||
break;
|
||||
case 5u:
|
||||
HAL_ADC_Stop(&hadc3);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
return output;
|
||||
if (HAL_ADC_Start(hadc) != HAL_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (sample_index = 0u; sample_index < sample_count; ++sample_index)
|
||||
{
|
||||
if (HAL_ADC_PollForConversion(hadc, 100u) != HAL_OK)
|
||||
{
|
||||
(void)HAL_ADC_Stop(hadc);
|
||||
return false;
|
||||
}
|
||||
|
||||
output_buffer[sample_index] = (uint16_t)HAL_ADC_GetValue(hadc);
|
||||
}
|
||||
|
||||
(void)HAL_ADC_Stop(hadc);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool adc_mux_capture_internal_telemetry(adc_internal_telemetry_t *telemetry)
|
||||
{
|
||||
uint16_t adc1_samples[5];
|
||||
uint16_t adc3_samples[3];
|
||||
|
||||
if (telemetry == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(telemetry, 0, sizeof(*telemetry));
|
||||
|
||||
if (!adc_mux_read_sequence(&hadc1, adc1_samples, 5u))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!adc_mux_read_sequence(&hadc3, adc3_samples, 3u))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
telemetry->external_temperature_1_raw = adc1_samples[0];
|
||||
telemetry->external_temperature_2_raw = adc1_samples[1];
|
||||
telemetry->rail_3v3_raw = adc1_samples[2];
|
||||
telemetry->rail_5v1_raw = adc1_samples[3];
|
||||
telemetry->rail_5v2_raw = adc1_samples[4];
|
||||
telemetry->input_pf3_raw = adc3_samples[0];
|
||||
telemetry->input_pf4_raw = adc3_samples[1];
|
||||
telemetry->rail_7v0_raw = adc3_samples[2];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user