parent
5678190d5a
commit
98605677f6
|
@ -24,8 +24,7 @@ public:
|
|||
void enableChannel(adc_channel_e hwChannelIndex);
|
||||
void enableChannelAndPin(const char *msg, adc_channel_e hwChannelIndex);
|
||||
adc_channel_e getAdcHardwareIndexByInternalIndex(int index) const;
|
||||
/* We use adc_channel_e as index for following array */
|
||||
char internalAdcIndexByHardwareIndex[EFI_ADC_LAST + 1];
|
||||
int internalAdcIndexByHardwareIndex[ADC_MAX_CHANNELS_COUNT + 4];
|
||||
bool isHwUsed(adc_channel_e hwChannel) const;
|
||||
int size() const;
|
||||
void init(void);
|
||||
|
@ -39,14 +38,13 @@ public:
|
|||
int getAdcValueByHwChannel(adc_channel_e hwChannel) const;
|
||||
|
||||
adc_state values;
|
||||
int channelCount;
|
||||
private:
|
||||
ADCConversionGroup* hwConfig;
|
||||
/**
|
||||
* Number of ADC channels in use
|
||||
*/
|
||||
unsigned char channelCount;
|
||||
|
||||
/* STM32 has up-to 4 additional channels routed to internal voltage sources */
|
||||
|
||||
adc_channel_e hardwareIndexByIndernalAdcIndex[ADC_MAX_CHANNELS_COUNT + 4];
|
||||
};
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ AdcDevice::AdcDevice(ADCConversionGroup* hwConfig, adcsample_t *buf) {
|
|||
hwConfig->sqr5 = 0;
|
||||
#endif /* ADC_MAX_CHANNELS_COUNT */
|
||||
memset(hardwareIndexByIndernalAdcIndex, EFI_ADC_NONE, sizeof(hardwareIndexByIndernalAdcIndex));
|
||||
memset(internalAdcIndexByHardwareIndex, EFI_ADC_ERROR, sizeof(internalAdcIndexByHardwareIndex));
|
||||
memset(internalAdcIndexByHardwareIndex, 0xFFFFFFFF, sizeof(internalAdcIndexByHardwareIndex));
|
||||
}
|
||||
|
||||
#if !defined(GPT_FREQ_FAST) || !defined(GPT_PERIOD_FAST)
|
||||
|
@ -315,21 +315,13 @@ int AdcDevice::size() const {
|
|||
return channelCount;
|
||||
}
|
||||
|
||||
int AdcDevice::getAdcValueByIndex(int internalIndex) const {
|
||||
if (internalIndex >= size()) {
|
||||
firmwareError(OBD_PCM_Processor_Fault, "ADC channel index out of range %d", internalIndex);
|
||||
return 0;
|
||||
}
|
||||
int AdcDevice::getAdcValueByHwChannel(adc_channel_e hwChannel) const {
|
||||
int internalIndex = internalAdcIndexByHardwareIndex[hwChannel];
|
||||
return values.adc_data[internalIndex];
|
||||
}
|
||||
|
||||
int AdcDevice::getAdcValueByHwChannel(adc_channel_e hwChannel) const {
|
||||
if (hwChannel >= ARRAY_SIZE(internalAdcIndexByHardwareIndex)) {
|
||||
firmwareError(OBD_PCM_Processor_Fault, "ADC hwChannel out of range");
|
||||
return 0;
|
||||
}
|
||||
int internalIndex = internalAdcIndexByHardwareIndex[hwChannel];
|
||||
return getAdcValueByIndex(internalIndex);
|
||||
int AdcDevice::getAdcValueByIndex(int internalIndex) const {
|
||||
return values.adc_data[internalIndex];
|
||||
}
|
||||
|
||||
void AdcDevice::invalidateSamplesCache() {
|
||||
|
@ -359,7 +351,7 @@ bool AdcDevice::isHwUsed(adc_channel_e hwChannelIndex) const {
|
|||
}
|
||||
|
||||
void AdcDevice::enableChannel(adc_channel_e hwChannel) {
|
||||
if (channelCount >= ADC_MAX_CHANNELS_COUNT) {
|
||||
if (channelCount >= efi::size(values.adc_data)) {
|
||||
firmwareError(OBD_PCM_Processor_Fault, "Too many ADC channels configured");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue