Speeduino
Loading...
Searching...
No Matches
decoder_t.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
5
7static constexpr uint8_t TRIGGER_EDGE_NONE = 99;
8
11{
12 using callback_t = void(*)(void);
13
18
19 constexpr interrupt_t() = default;
20 constexpr interrupt_t(callback_t _callback, uint8_t _edge)
21 : callback(_callback)
22 , edge(_edge)
23 {
24 }
25
26 bool isSetup(void) const
27 {
28 return edge!=TRIGGER_EDGE_NONE
29 && callback!=nullptr;
30 }
31
33 uint8_t attach(uint8_t pin);
34
36 void detach(uint8_t pin);
37
43 bool isTriggered(void) const;
44
46 bool isValid(void) const
47 {
48 return isSetup()
49 && _pin.isValid();
50 }
51
52 bool isPinHigh(void) const {
53 return _pin.isPinHigh();
54 }
55
57};
58
62enum class SyncStatus : uint8_t {
64 None,
68 Partial,
70 Full,
71};
72
79
80
94
100{
107
109
119 using getRevolutionTime_t = uint32_t(*)(void);
122
124
125 using getCrankAngle_t = int16_t(*)(uint32_t);
128
130
131 int16_t getCrankAngle(void) const {
132 return pGetCrankAngle(micros());
133 };
135
137
138 using setEndTeeth_t = void(*)(void);
141
143
144 using reset_t = void(*)(void);
147
149
158 using engine_running_t = bool(*)(uint32_t);
161
163
164#pragma GCC diagnostic push
165#pragma GCC diagnostic ignored "-Wnoexcept-type"
166 using status_fun_t = decoder_status_t(*)(void)noexcept;
167#pragma GCC diagnostic pop
170
172
176};
To avoid circular header dependencies boardInputPin_t is a forward declared typedef; include this fil...
A class for input pin operations that is faster than standard Arduino digitalRead()
Definition fastInputPin.h:10
bool isValid(void) const noexcept
Is the pin set?
Definition fastInputPin.h:28
bool isPinHigh(void) const noexcept
Check if the pin is set high.
Definition fastInputPin.h:18
SyncStatus
The decoder trigger status.
Definition decoder_t.h:62
static constexpr uint8_t TRIGGER_EDGE_NONE
This constant represents no trigger edge.
Definition decoder_t.h:7
Definition decoder_t.h:81
decoder_features_t(void)
‍Whether or not the decoder supports per-tooth ignition
Definition decoder_t.h:87
bool supportsPerToothIgnition
‍Whether or not the decoder supports fixed cranking timing
Definition decoder_t.h:85
bool supportsSequential
‍The use of the 2nd derivative calculation is limited to certain decoders.
Definition decoder_t.h:83
bool supports2ndDeriv
Definition decoder_t.h:82
bool hasFixedCrankingTiming
‍Whether or not the decoder supports sequential operation
Definition decoder_t.h:84
Current decoder status.
Definition decoder_t.h:74
SyncStatus syncStatus
‍Whether or not the triggerToothAngle variable is currently accurate. Some patterns have times when t...
Definition decoder_t.h:77
bool toothAngleIsCorrect
‍Is set true when the last trigger (Primary or secondary) was valid (ie passed filters)
Definition decoder_t.h:76
bool validTrigger
Definition decoder_t.h:75
This structure represents a decoder configuration.
Definition decoder_t.h:100
void(*)(void) setEndTeeth_t
The function to set the end teeth for ignition calculations.
Definition decoder_t.h:138
decoder_status_t(*)(void) noexcept status_fun_t
The function to get the current decoder status.
Definition decoder_t.h:166
int16_t(*)(uint32_t) getCrankAngle_t
The function to get the crank angle.
Definition decoder_t.h:125
reset_t reset
The function to reset the decoder. Called when the engine is stopped, or when the engine is started.
Definition decoder_t.h:145
bool(*)(uint32_t) engine_running_t
The function to test if the engine is running.
Definition decoder_t.h:158
feature_fun_t getFeatures
The function to get the current decoder feature set.
Definition decoder_t.h:174
getCrankAngle_t pGetCrankAngle
The function to get the crank angle.
Definition decoder_t.h:126
void(*)(void) reset_t
The function to reset the decoder. Called when the engine is stopped, or when the engine is started.
Definition decoder_t.h:144
interrupt_t tertiary
The tertiary interrupt configuration - for decoders that use a 3rd input. E.g. VVT.
Definition decoder_t.h:106
engine_running_t isEngineRunning
The function to test if the engine is running.
Definition decoder_t.h:159
setEndTeeth_t setEndTeeth
The function to set the end teeth for ignition calculations.
Definition decoder_t.h:139
int16_t getCrankAngle(void) const
The function to get the crank angle.
Definition decoder_t.h:131
interrupt_t secondary
The secondary interrupt configuration - usually the cam trigger.
Definition decoder_t.h:104
interrupt_t primary
The primary interrupt configuration - usually the crank trigger.
Definition decoder_t.h:102
status_fun_t getStatus
The function to get the current decoder status.
Definition decoder_t.h:168
getRevolutionTime_t getRevolutionTime
The function to get the current crank revolution time.
Definition decoder_t.h:120
uint32_t(*)(void) getRevolutionTime_t
The function to get the current crank revolution time.
Definition decoder_t.h:119
decoder_features_t(*)(void) feature_fun_t
The function to get the current decoder feature set.
Definition decoder_t.h:173
This structure represents a trigger interrupt.
Definition decoder_t.h:11
void detach(uint8_t pin)
Detach the interrupt from a pin.
Definition decoder_t.cpp:27
uint8_t attach(uint8_t pin)
Attach the interrupt to a pin.
Definition decoder_t.cpp:13
uint8_t edge
The edge type for the interrupt. E.g. RISING, FALLING, CHANGE.
Definition decoder_t.h:17
void(*)(void) callback_t
Definition decoder_t.h:12
constexpr interrupt_t(callback_t _callback, uint8_t _edge)
Definition decoder_t.h:20
bool isSetup(void) const
Definition decoder_t.h:26
callback_t callback
The callback function to be called on interrupt.
Definition decoder_t.h:15
boardInputPin_t _pin
Definition decoder_t.h:56
constexpr interrupt_t()=default
bool isValid(void) const
Is the interrupt configured correctly?
Definition decoder_t.h:46
bool isTriggered(void) const
Does the pin state match the edge setting?
Definition decoder_t.cpp:33
bool isPinHigh(void) const
Definition decoder_t.h:52