2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file AdcConfiguration.h
|
|
|
|
*
|
|
|
|
* @date May 3, 2014
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2020-02-18 05:16:19 -08:00
|
|
|
|
|
|
|
#pragma once
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-12 17:52:51 -07:00
|
|
|
#if HAL_USE_ADC
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2020-09-07 12:50:37 -07:00
|
|
|
#ifndef ADC_MAX_CHANNELS_COUNT
|
2019-07-05 17:34:41 -07:00
|
|
|
#define ADC_MAX_CHANNELS_COUNT 16
|
2020-09-07 12:50:37 -07:00
|
|
|
#endif /* ADC_MAX_CHANNELS_COUNT */
|
2019-07-05 17:34:41 -07:00
|
|
|
|
2022-07-26 04:12:00 -07:00
|
|
|
#ifndef SLOW_ADC_CHANNEL_COUNT
|
|
|
|
#ifdef ADC_MUX_PIN
|
|
|
|
#define SLOW_ADC_CHANNEL_COUNT 32
|
|
|
|
#else // not ADC_MUX_PIN
|
|
|
|
#define SLOW_ADC_CHANNEL_COUNT 16
|
|
|
|
#endif // def ADC_MUX_PIN
|
|
|
|
#endif // SLOW_ADC_CHANNEL_COUNT
|
|
|
|
|
2019-07-05 17:34:41 -07:00
|
|
|
// this structure contains one multi-channel ADC state snapshot
|
|
|
|
typedef struct {
|
|
|
|
volatile adcsample_t adc_data[ADC_MAX_CHANNELS_COUNT];
|
|
|
|
} adc_state;
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
class AdcDevice {
|
|
|
|
public:
|
2020-12-05 07:14:33 -08:00
|
|
|
explicit AdcDevice(ADCConversionGroup* hwConfig, adcsample_t *buf, size_t buf_len);
|
2016-07-19 18:04:11 -07:00
|
|
|
void enableChannel(adc_channel_e hwChannelIndex);
|
2019-06-08 06:51:36 -07:00
|
|
|
adc_channel_e getAdcHardwareIndexByInternalIndex(int index) const;
|
2021-05-13 12:51:18 -07:00
|
|
|
uint8_t internalAdcIndexByHardwareIndex[EFI_ADC_LAST_CHANNEL];
|
2019-06-08 06:51:36 -07:00
|
|
|
bool isHwUsed(adc_channel_e hwChannel) const;
|
|
|
|
int size() const;
|
2015-07-10 06:01:56 -07:00
|
|
|
void init(void);
|
2020-12-03 04:27:27 -08:00
|
|
|
uint32_t conversionCount = 0;
|
|
|
|
uint32_t errorsCount = 0;
|
2019-06-08 06:51:36 -07:00
|
|
|
int getAdcValueByIndex(int internalIndex) const;
|
2019-06-23 06:21:12 -07:00
|
|
|
|
2020-09-08 14:20:55 -07:00
|
|
|
adcsample_t *samples;
|
2020-12-05 07:14:33 -08:00
|
|
|
size_t buf_len;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2020-11-22 09:23:27 -08:00
|
|
|
int getAdcValueByHwChannel(adc_channel_e hwChannel) const;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
adc_state values;
|
|
|
|
private:
|
|
|
|
ADCConversionGroup* hwConfig;
|
|
|
|
/**
|
|
|
|
* Number of ADC channels in use
|
|
|
|
*/
|
2021-05-13 12:51:18 -07:00
|
|
|
size_t channelCount = 0;
|
|
|
|
|
|
|
|
/* STM32 has up-to 4 additional channels routed to internal voltage sources */
|
2020-09-07 12:50:37 -07:00
|
|
|
adc_channel_e hardwareIndexByIndernalAdcIndex[ADC_MAX_CHANNELS_COUNT + 4];
|
2015-07-10 06:01:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* HAL_USE_ADC */
|
|
|
|
|