rusefi-1/firmware/hw_layer/adc/AdcConfiguration.h

53 lines
1.3 KiB
C
Raw Normal View History

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
#ifndef ADC_MAX_CHANNELS_COUNT
#define ADC_MAX_CHANNELS_COUNT 16
#endif /* ADC_MAX_CHANNELS_COUNT */
// 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:
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);
adc_channel_e getAdcHardwareIndexByInternalIndex(int index) const;
uint8_t internalAdcIndexByHardwareIndex[EFI_ADC_LAST_CHANNEL];
bool isHwUsed(adc_channel_e hwChannel) const;
int size() const;
2015-07-10 06:01:56 -07:00
void init(void);
uint32_t conversionCount = 0;
uint32_t errorsCount = 0;
int getAdcValueByIndex(int internalIndex) const;
adcsample_t *samples;
size_t buf_len;
2015-07-10 06:01:56 -07: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
*/
size_t channelCount = 0;
/* STM32 has up-to 4 additional channels routed to internal voltage sources */
adc_channel_e hardwareIndexByIndernalAdcIndex[ADC_MAX_CHANNELS_COUNT + 4];
2015-07-10 06:01:56 -07:00
};
#endif /* HAL_USE_ADC */