adc: avoid two lookup tables
This commit is contained in:
parent
7e509c432e
commit
207a3d8c98
|
@ -30,7 +30,7 @@ class AdcDevice {
|
||||||
public:
|
public:
|
||||||
explicit AdcDevice(ADCConversionGroup* hwConfig, adcsample_t *buf, size_t buf_len);
|
explicit AdcDevice(ADCConversionGroup* hwConfig, adcsample_t *buf, size_t buf_len);
|
||||||
void enableChannel(adc_channel_e hwChannelIndex);
|
void enableChannel(adc_channel_e hwChannelIndex);
|
||||||
adc_channel_e getAdcHardwareIndexByInternalIndex(int index) const;
|
adc_channel_e getAdcChannelByInternalIndex(int index) const;
|
||||||
uint8_t internalAdcIndexByHardwareIndex[EFI_ADC_TOTAL_CHANNELS];
|
uint8_t internalAdcIndexByHardwareIndex[EFI_ADC_TOTAL_CHANNELS];
|
||||||
int size() const;
|
int size() const;
|
||||||
void init(void);
|
void init(void);
|
||||||
|
@ -46,9 +46,6 @@ private:
|
||||||
* Number of ADC channels in use
|
* Number of ADC channels in use
|
||||||
*/
|
*/
|
||||||
size_t channelCount = 0;
|
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];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HAL_USE_ADC */
|
#endif /* HAL_USE_ADC */
|
||||||
|
|
|
@ -65,7 +65,6 @@ AdcDevice::AdcDevice(ADCConversionGroup* p_hwConfig, adcsample_t *p_buf, size_t
|
||||||
hwConfig->sqr4 = 0;
|
hwConfig->sqr4 = 0;
|
||||||
hwConfig->sqr5 = 0;
|
hwConfig->sqr5 = 0;
|
||||||
#endif /* ADC_MAX_CHANNELS_COUNT */
|
#endif /* ADC_MAX_CHANNELS_COUNT */
|
||||||
memset(hardwareIndexByIndernalAdcIndex, EFI_ADC_NONE, sizeof(hardwareIndexByIndernalAdcIndex));
|
|
||||||
memset(internalAdcIndexByHardwareIndex, 0xFF, sizeof(internalAdcIndexByHardwareIndex));
|
memset(internalAdcIndexByHardwareIndex, 0xFF, sizeof(internalAdcIndexByHardwareIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,7 +259,6 @@ void AdcDevice::enableChannel(adc_channel_e hwChannel) {
|
||||||
size_t channelAdcIndex = hwChannel - EFI_ADC_0;
|
size_t channelAdcIndex = hwChannel - EFI_ADC_0;
|
||||||
|
|
||||||
internalAdcIndexByHardwareIndex[hwChannel] = logicChannel;
|
internalAdcIndexByHardwareIndex[hwChannel] = logicChannel;
|
||||||
hardwareIndexByIndernalAdcIndex[logicChannel] = hwChannel;
|
|
||||||
if (logicChannel < 6) {
|
if (logicChannel < 6) {
|
||||||
hwConfig->sqr3 |= channelAdcIndex << (5 * logicChannel);
|
hwConfig->sqr3 |= channelAdcIndex << (5 * logicChannel);
|
||||||
} else if (logicChannel < 12) {
|
} else if (logicChannel < 12) {
|
||||||
|
@ -278,8 +276,13 @@ void AdcDevice::enableChannel(adc_channel_e hwChannel) {
|
||||||
#endif /* ADC_MAX_CHANNELS_COUNT */
|
#endif /* ADC_MAX_CHANNELS_COUNT */
|
||||||
}
|
}
|
||||||
|
|
||||||
adc_channel_e AdcDevice::getAdcHardwareIndexByInternalIndex(int hwChannel) const {
|
adc_channel_e AdcDevice::getAdcChannelByInternalIndex(int hwChannel) const {
|
||||||
return hardwareIndexByIndernalAdcIndex[hwChannel];
|
for (size_t idx = EFI_ADC_0; idx < EFI_ADC_TOTAL_CHANNELS; idx++) {
|
||||||
|
if (internalAdcIndexByHardwareIndex[idx] == hwChannel) {
|
||||||
|
return (adc_channel_e)idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return EFI_ADC_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EFI_USE_FAST_ADC
|
#endif // EFI_USE_FAST_ADC
|
||||||
|
@ -298,7 +301,7 @@ void printFullAdcReport(void) {
|
||||||
efiPrintf("fast %d samples", fastAdc.conversionCount);
|
efiPrintf("fast %d samples", fastAdc.conversionCount);
|
||||||
|
|
||||||
for (int internalIndex = 0; internalIndex < fastAdc.size(); internalIndex++) {
|
for (int internalIndex = 0; internalIndex < fastAdc.size(); internalIndex++) {
|
||||||
adc_channel_e hwChannel = fastAdc.getAdcHardwareIndexByInternalIndex(internalIndex);
|
adc_channel_e hwChannel = fastAdc.getAdcChannelByInternalIndex(internalIndex);
|
||||||
|
|
||||||
if (isAdcChannelValid(hwChannel)) {
|
if (isAdcChannelValid(hwChannel)) {
|
||||||
ioportid_t port = getAdcChannelPort("print", hwChannel);
|
ioportid_t port = getAdcChannelPort("print", hwChannel);
|
||||||
|
|
|
@ -66,8 +66,6 @@ void waitForSlowAdc(uint32_t lastAdcCounter = 0);
|
||||||
// get a number of completed slowADC samples
|
// get a number of completed slowADC samples
|
||||||
int getSlowAdcCounter();
|
int getSlowAdcCounter();
|
||||||
|
|
||||||
int getAdcHardwareIndexByInternalIndex(int index);
|
|
||||||
|
|
||||||
void printFullAdcReportIfNeeded(void);
|
void printFullAdcReportIfNeeded(void);
|
||||||
int getInternalAdcValue(const char *msg, adc_channel_e index);
|
int getInternalAdcValue(const char *msg, adc_channel_e index);
|
||||||
float getMCUInternalTemperature(void);
|
float getMCUInternalTemperature(void);
|
||||||
|
|
Loading…
Reference in New Issue