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__)
@ -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() {