extra flexibility to facilitate ports

This commit is contained in:
rusefillc 2023-05-31 23:36:30 -04:00
parent 965cdd466c
commit 1c49d77fff
2 changed files with 18 additions and 16 deletions

View File

@ -32,6 +32,17 @@ static inline bool isAdcChannelValid(adc_channel_e hwChannel) {
}
}
#if !defined(GPT_FREQ_FAST) || !defined(GPT_PERIOD_FAST)
/**
* 8000 RPM is 133Hz
* If we want to sample MAP once per 5 degrees we need 133Hz * (360 / 5) = 9576Hz of fast ADC
*/
// todo: migrate to continuous ADC mode? probably not - we cannot afford the callback in
// todo: continuous mode. todo: look into our options
#define GPT_FREQ_FAST 100000 /* PWM clock frequency. I wonder what does this setting mean? */
#define GPT_PERIOD_FAST 10 /* PWM period (in PWM ticks). */
#endif /* GPT_FREQ_FAST GPT_PERIOD_FAST */
#if HAL_USE_ADC
typedef enum {
@ -70,17 +81,6 @@ void removeChannel(const char *name, adc_channel_e setting);
#define adcToVoltsDivided(adc, hwChannel) (adcToVolts(adc) * getAnalogInputDividerCoefficient(hwChannel))
#if !defined(GPT_FREQ_FAST) || !defined(GPT_PERIOD_FAST)
/**
* 8000 RPM is 133Hz
* If we want to sample MAP once per 5 degrees we need 133Hz * (360 / 5) = 9576Hz of fast ADC
*/
// todo: migrate to continuous ADC mode? probably not - we cannot afford the callback in
// todo: continuous mode. todo: look into our options
#define GPT_FREQ_FAST 100000 /* PWM clock frequency. I wonder what does this setting mean? */
#define GPT_PERIOD_FAST 10 /* PWM period (in PWM ticks). */
#endif /* GPT_FREQ_FAST GPT_PERIOD_FAST */
// This callback is called by the ADC driver when a new fast ADC sample is ready
void onFastAdcComplete(adcsample_t* samples);

View File

@ -16,7 +16,9 @@
#define DELTA_THRESHOLD_CNT_LOW (GPT_FREQ_FAST / GPT_PERIOD_FAST / 32) // ~1/32 second?
#define DELTA_THRESHOLD_CNT_HIGH (GPT_FREQ_FAST / GPT_PERIOD_FAST / 4) // ~1/4 second?
#if HAL_USE_ADC
#define triggerVoltsToAdcDivided(volts) (voltsToAdc(volts) / trigAdcState.triggerInputDividerCoefficient)
#endif // HAL_USE_ADC
// hardware-dependent part
#if (EFI_SHAFT_POSITION_INPUT && HAL_TRIGGER_USE_ADC && HAL_USE_ADC) || defined(__DOXYGEN__)
@ -71,7 +73,7 @@ void setTriggerAdcMode(triggerAdcMode_t adcMode) {
trigAdcState.curAdcMode = adcMode;
trigAdcState.modeSwitchCnt++;
palSetPadMode(triggerInputPort, triggerInputPin,
palSetPadMode(triggerInputPort, triggerInputPin,
(adcMode == TRIGGER_ADC_ADC) ? PAL_MODE_INPUT_ANALOG : PAL_MODE_EXTINT);
}
@ -118,9 +120,9 @@ int adcTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
ioline_t pal_line = PAL_LINE(triggerInputPort, triggerInputPin);
efiPrintf("turnOnTriggerInputPin %s l=%d", hwPortname(brainPin), pal_line);
efiExtiEnablePin(msg, brainPin, PAL_EVENT_MODE_BOTH_EDGES, isTriggerShaft ? shaft_callback : cam_callback, (void *)pal_line);
// ADC mode is default, because we don't know if the wheel is already spinning
setTriggerAdcMode(TRIGGER_ADC_ADC);
@ -178,7 +180,7 @@ void onTriggerChanged(efitick_t stamp, bool isPrimary, bool isRising) {
void TriggerAdcDetector::init() {
#if ! EFI_SIMULATOR
#if ! EFI_SIMULATOR && HAL_USE_ADC
// todo: move some of these to config
@ -212,7 +214,7 @@ void TriggerAdcDetector::init() {
modeSwitchCnt = 0;
reset();
#endif // ! EFI_SIMULATOR
#endif // ! EFI_SIMULATOR && HAL_USE_ADC
}
void TriggerAdcDetector::reset() {