2020-04-26 11:06:28 -07:00
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
2020-04-26 11:06:28 -07:00
|
|
|
|
|
|
|
#include "gppwm_channel.h"
|
|
|
|
|
2020-05-08 19:05:44 -07:00
|
|
|
static GppwmChannel channels[GPPWM_CHANNELS];
|
|
|
|
static OutputPin pins[GPPWM_CHANNELS];
|
|
|
|
static SimplePwm outputs[GPPWM_CHANNELS];
|
2020-04-26 11:06:28 -07:00
|
|
|
|
2021-06-03 11:30:25 -07:00
|
|
|
static gppwm_Map3D_t table1;
|
|
|
|
static gppwm_Map3D_t table2;
|
|
|
|
static gppwm_Map3D_t table3;
|
|
|
|
static gppwm_Map3D_t table4;
|
2020-04-26 11:06:28 -07:00
|
|
|
|
|
|
|
static gppwm_Map3D_t* tables[] = {
|
|
|
|
&table1,
|
|
|
|
&table2,
|
|
|
|
&table3,
|
|
|
|
&table4,
|
|
|
|
};
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void initGpPwm() {
|
2020-04-26 11:06:28 -07:00
|
|
|
for (size_t i = 0; i < efi::size(channels); i++) {
|
2021-11-17 00:54:21 -08:00
|
|
|
auto& cfg = engineConfiguration->gppwm[i];
|
2020-04-26 11:06:28 -07:00
|
|
|
|
|
|
|
// If no pin, don't enable this channel.
|
2021-01-08 17:01:26 -08:00
|
|
|
if (!isBrainPinValid(cfg.pin)) {
|
2020-10-21 19:13:18 -07:00
|
|
|
continue;
|
|
|
|
}
|
2020-04-26 11:06:28 -07:00
|
|
|
|
|
|
|
// Determine frequency and whether PWM is enabled
|
|
|
|
float freq = cfg.pwmFrequency;
|
|
|
|
bool usePwm = freq > 0;
|
|
|
|
|
|
|
|
// Setup pin & pwm
|
|
|
|
pins[i].initPin("gp pwm", cfg.pin);
|
2021-09-06 05:09:14 -07:00
|
|
|
if (usePwm) {
|
|
|
|
startSimplePwm(&outputs[i], "gp pwm", &engine->executor, &pins[i], freq, 0);
|
|
|
|
}
|
2020-04-26 11:06:28 -07:00
|
|
|
|
|
|
|
// Set up this channel's lookup table
|
|
|
|
tables[i]->init(cfg.table, cfg.loadBins, cfg.rpmBins);
|
|
|
|
|
|
|
|
// Finally configure the channel
|
2020-06-11 17:43:26 -07:00
|
|
|
channels[i].init(usePwm, &outputs[i], &pins[i], tables[i], &cfg);
|
2020-04-26 11:06:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateGppwm() {
|
2020-10-21 19:49:38 -07:00
|
|
|
// There are only 8 debug float fields, this will overflow if more channels
|
|
|
|
static_assert(efi::size(channels) <= 8);
|
|
|
|
|
2020-04-26 11:06:28 -07:00
|
|
|
for (size_t i = 0; i < efi::size(channels); i++) {
|
2020-10-21 19:49:38 -07:00
|
|
|
float result = channels[i].update();
|
|
|
|
|
|
|
|
#ifdef EFI_TUNER_STUDIO
|
2021-11-17 00:54:21 -08:00
|
|
|
if (engineConfiguration->debugMode == DBG_GPPWM) {
|
2021-12-07 17:18:47 -08:00
|
|
|
scaled_channel<float>* debugFloats = &engine->outputChannels.debugFloatField1;
|
2020-10-21 19:49:38 -07:00
|
|
|
debugFloats[i] = result;
|
|
|
|
}
|
|
|
|
#endif
|
2020-04-26 11:06:28 -07:00
|
|
|
}
|
|
|
|
}
|