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

67 lines
1.8 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file adc_inputs.h
2017-11-24 14:40:20 -08:00
* @brief Low level internal ADC code
2015-07-10 06:01:56 -07:00
*
* @date Jan 14, 2013
2020-01-07 21:02:40 -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
2018-09-16 19:26:57 -07:00
#include "global.h"
2019-01-31 08:57:15 -08:00
#include "adc_math.h"
2015-07-10 06:01:56 -07:00
#define SLOW_ADC_RATE 500
static inline bool isAdcChannelValid(adc_channel_e hwChannel) {
if (hwChannel <= EFI_ADC_NONE) {
return false;
} else if (hwChannel >= EFI_ADC_LAST_CHANNEL) {
/* this should not happen!
* if we have enum out of range somewhere in settings
* that means something goes terribly wrong
* TODO: should we say something?
*/
return false;
} else {
return true;
}
}
2020-08-21 19:07:55 -07:00
#if HAL_USE_ADC
adc_channel_mode_e getAdcMode(adc_channel_e hwChannel);
void initAdcInputs();
2017-04-21 17:07:17 -07:00
// deprecated - migrate to 'getAdcChannelBrainPin'
int getAdcChannelPin(adc_channel_e hwChannel);
// deprecated - migrate to 'getAdcChannelBrainPin'
2016-12-27 11:04:04 -08:00
ioportid_t getAdcChannelPort(const char *msg, adc_channel_e hwChannel);
2017-04-21 17:07:17 -07:00
2015-07-10 06:01:56 -07:00
adc_channel_e getAdcChannel(brain_pin_e pin);
2017-04-21 17:07:17 -07:00
brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel);
2015-07-10 06:01:56 -07:00
// wait until at least 1 slowADC sampling is complete
2021-03-15 07:23:19 -07:00
void waitForSlowAdc(uint32_t lastAdcCounter = 0);
2018-01-22 14:45:10 -08:00
// get a number of completed slowADC samples
int getSlowAdcCounter();
2015-07-10 06:01:56 -07:00
int getAdcHardwareIndexByInternalIndex(int index);
2016-09-09 21:02:11 -07:00
void printFullAdcReportIfNeeded(Logging *log);
2015-07-10 06:01:56 -07:00
int getInternalAdcValue(const char *msg, adc_channel_e index);
2016-07-19 19:03:16 -07:00
float getMCUInternalTemperature(void);
2015-07-10 06:01:56 -07:00
void addChannel(const char *name, adc_channel_e setting, adc_channel_mode_e mode);
void removeChannel(const char *name, adc_channel_e setting);
2015-07-10 06:01:56 -07:00
#define getAdcValue(msg, hwChannel) getInternalAdcValue(msg, hwChannel)
#define adcToVoltsDivided(adc) (adcToVolts(adc) * engineConfiguration->analogInputDividerCoefficient)
#else
2016-01-11 16:02:19 -08:00
#define getAdcValue(msg, channel) 0
2015-07-10 06:01:56 -07:00
#endif /* HAL_USE_ADC */