Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
trigger.hpp
Go to the documentation of this file.
1#ifndef SBL_CORE_COMPONENTS_CV_TRIGGER_HPP_
2#define SBL_CORE_COMPONENTS_CV_TRIGGER_HPP_
3
4/**
5 * @file trigger.hpp
6 * @brief CV trigger pulse generator
7 * @ingroup components
8 */
9
11
12namespace sbl {
13namespace core {
14namespace components {
15namespace cv {
16
17/**
18 * @brief CV trigger pulse generator
19 *
20 * Generates precise trigger pulses for Eurorack CV outputs.
21 * Standard 10ms pulse duration with configurable timing.
22 *
23 * @tparam PinImpl GPIO pin implementation
24 * @tparam TimerImpl Timer implementation for pulse timing
25 */
26template<typename PinImpl, typename TimerImpl>
27class Trigger {
28public:
29 /**
30 * @brief Construct trigger generator
31 * @param pin GPIO pin for trigger output
32 * @param pulse_ms Pulse duration in milliseconds (default: 10ms)
33 */
34 Trigger(PinImpl& pin, uint32_t pulse_ms = 10)
35 : pin_(pin), pulseDuration_(pulse_ms), active_(false) {
36 pin_.setMode(sbl::core::hal::PinMode::Output);
37 pin_.write(false);
38 }
39
40 /**
41 * @brief Fire trigger pulse
42 *
43 * Starts trigger pulse. Call update() regularly to handle timing.
44 */
45 void fire() {
46 pin_.write(true);
47 pulseTimer_.start(pulseDuration_);
48 active_ = true;
49 }
50
51 /**
52 * @brief Update trigger state
53 *
54 * Call regularly from main loop to handle pulse timing.
55 */
56 void update() {
57 if (active_ && pulseTimer_.hasExpired()) {
58 pin_.write(false);
59 active_ = false;
60 }
61 }
62
63 /**
64 * @brief Check if trigger is currently active
65 * @return true if pulse is active
66 */
67 bool isActive() const {
68 return active_;
69 }
70
71private:
72 PinImpl& pin_;
74 uint32_t pulseDuration_;
75 bool active_;
76};
77
78} // namespace cv
79} // namespace components
80} // namespace core
81} // namespace sbl
82
83#endif // SBL_CORE_COMPONENTS_CV_TRIGGER_HPP_
CV trigger pulse generator.
Definition trigger.hpp:27
Trigger(PinImpl &pin, uint32_t pulse_ms=10)
Construct trigger generator.
Definition trigger.hpp:34
void update()
Update trigger state.
Definition trigger.hpp:56
void fire()
Fire trigger pulse.
Definition trigger.hpp:45
bool isActive() const
Check if trigger is currently active.
Definition trigger.hpp:67
Simple non-blocking delay using system time.
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24
Non-blocking delay utilities for cooperative scheduling.