ADC: AdcDevice::enableChannel: return channelAdcIndex or error

This value will be used as part of AdcToken for multi ADC support
This commit is contained in:
Andrey Gusakov 2024-06-20 12:58:42 +03:00 committed by rusefillc
parent dbbe6ace0a
commit 3ac25a82fb
2 changed files with 5 additions and 3 deletions

View File

@ -24,7 +24,7 @@
class AdcDevice {
public:
explicit AdcDevice(ADCConversionGroup* p_hwConfig, volatile adcsample_t *p_buf);
void enableChannel(adc_channel_e hwChannel);
int enableChannel(adc_channel_e hwChannel);
adc_channel_e getAdcChannelByInternalIndex(int index) const;
adcsample_t getAvgAdcValue(adc_channel_e hwChannel, size_t bufDepth);
FastAdcToken getAdcChannelToken(adc_channel_e hwChannel);

View File

@ -219,10 +219,10 @@ void AdcDevice::init(void) {
//hwConfig->sqr1 += ADC_SQR1_NUM_CH(size());
}
void AdcDevice::enableChannel(adc_channel_e hwChannel) {
int AdcDevice::enableChannel(adc_channel_e hwChannel) {
if ((channelCount + 1) >= ADC_MAX_CHANNELS_COUNT) {
criticalError("Too many ADC channels configured");
return;
return -1;
}
int logicChannel = channelCount++;
@ -248,6 +248,8 @@ void AdcDevice::enableChannel(adc_channel_e hwChannel) {
hwConfig->sqr5 |= channelAdcIndex << (5 * (logicChannel - 24));
}
#endif /* ADC_MAX_CHANNELS_COUNT */
return channelAdcIndex;
}
adcsample_t AdcDevice::getAvgAdcValue(adc_channel_e hwChannel, size_t bufDepth) {