rusefi-1/firmware/controllers/core/EfiWave.h

82 lines
2.3 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file EfiWave.h
*
* @date May 18, 2014
2017-01-03 03:05:22 -08:00
* @author Andrey Belomutskiy, (c) 2012-2017
2015-07-10 06:01:56 -07:00
*/
#ifndef EFI_WAVE_H_
#define EFI_WAVE_H_
2018-12-24 19:40:48 -08:00
#include "global.h"
2015-07-10 06:01:56 -07:00
#define PWM_PHASE_MAX_COUNT 252
#define PWM_PHASE_MAX_WAVE_PER_PWM 3
/**
* int8_t is probably less efficient then int32_t but we need
* to reduce memory footprint
*
2017-01-02 11:03:17 -08:00
* todo: migrate to bit-array to save memory?
* this would cost some CPU cycles. see std::vector<bool>
2015-07-10 06:01:56 -07:00
*/
2019-02-02 22:27:47 -08:00
typedef trigger_value_e pin_state_t;
2015-07-10 06:01:56 -07:00
/**
2018-12-24 19:40:48 -08:00
* This class represents one channel of a digital signal state sequence
* Each element represents either a HIGH or LOW state - while at the moment this
* is not implemented using a bit array, it could absolutely be a bit array
*
* This sequence does not know anything about signal lengths - only signal state at a given index
*
2015-07-10 06:01:56 -07:00
* @brief PWM configuration for the specific output pin
*/
2018-12-25 05:27:52 -08:00
class SingleWave {
2015-07-10 06:01:56 -07:00
public:
2018-12-25 05:27:52 -08:00
SingleWave();
SingleWave(pin_state_t *pinStates);
2015-07-10 06:01:56 -07:00
void init(pin_state_t *pinStates);
2018-12-24 19:40:48 -08:00
/**
* todo: confirm that we only deal with two states here, no magic '-1'?
* @return HIGH or LOW state at given index
*/
2019-02-02 22:19:16 -08:00
pin_state_t getState(int switchIndex);
void setState(int switchIndex, pin_state_t state);
2018-12-24 19:40:48 -08:00
2018-12-24 19:57:36 -08:00
// todo: make this private by using 'getState' and 'setState' methods
2015-07-10 06:01:56 -07:00
pin_state_t *pinStates;
};
2018-12-24 19:57:36 -08:00
/**
* This class represents multi-channel logical signals with shared time axis
*
*/
2018-12-08 13:59:16 -08:00
class MultiWave {
2015-07-10 06:01:56 -07:00
public:
void baseConstructor();
2018-12-08 13:59:16 -08:00
MultiWave();
2018-12-25 05:27:52 -08:00
MultiWave(float *switchTimes, SingleWave *waves);
void init(float *switchTimes, SingleWave *waves);
2015-07-10 06:01:56 -07:00
void reset(void);
2019-03-02 19:54:28 -08:00
float getSwitchTime(const int phaseIndex) const;
void setSwitchTime(const int phaseIndex, const float value);
void checkSwitchTimes(const int size);
pin_state_t getChannelState(const int channelIndex, const int phaseIndex) const;
2015-07-10 06:01:56 -07:00
2019-03-02 19:54:28 -08:00
int findAngleMatch(const float angle, const int size) const;
int findInsertionAngle(const float angle, const int size) const;
2015-07-10 06:01:56 -07:00
/**
2018-12-25 07:13:00 -08:00
* Number of signal channels
2015-07-10 06:01:56 -07:00
*/
int waveCount;
2018-12-25 07:13:00 -08:00
SingleWave *channels;
2015-07-10 06:01:56 -07:00
//private:
/**
* values in the (0..1] range which refer to points within the period at at which pin state should be changed
* So, in the simplest case we turn pin off at 0.3 and turn it on at 1 - that would give us a 70% duty cycle PWM
*/
float *switchTimes;
};
#endif /* EFI_WAVE_H_ */