Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
led.hpp
Go to the documentation of this file.
1/**
2 * @file led.hpp
3 * @brief LED control interface for status indication
4 * @ingroup components
5 */
6
7#ifndef SBL_CORE_COMPONENTS_DISPLAY_LED_HPP_
8#define SBL_CORE_COMPONENTS_DISPLAY_LED_HPP_
9
10#include <sbl/hal/gpio_pin.hpp>
11
12namespace sbl {
13namespace core {
14namespace components {
15namespace display {
16
17/**
18 * @brief LED control interface
19 *
20 * Wraps GPIO pin operations with LED-specific semantics.
21 * Template-based design provides compile-time optimization.
22 *
23 * @tparam GpioPinImpl GPIO pin implementation type
24 */
25template<typename GpioPinImpl>
26class Led {
27public:
28 /**
29 * @brief Construct LED controller
30 *
31 * @param active_high true if LED is on when pin is high
32 */
33 explicit Led(bool active_high = true)
34 : active_high_(active_high), is_on_(false) {
35 GpioPinImpl::setMode(sbl::core::hal::PinMode::Output);
36 off(); // Start in known state
37 }
38
39 /**
40 * @brief Turn LED on
41 */
42 void on() {
43 is_on_ = true;
44 GpioPinImpl::write(active_high_ ? sbl::core::hal::PinLevel::High : sbl::core::hal::PinLevel::Low);
45 }
46
47 /**
48 * @brief Turn LED off
49 */
50 void off() {
51 is_on_ = false;
52 GpioPinImpl::write(active_high_ ? sbl::core::hal::PinLevel::Low : sbl::core::hal::PinLevel::High);
53 }
54
55 /**
56 * @brief Toggle LED state
57 */
58 void toggle() {
59 if (is_on_) {
60 off();
61 } else {
62 on();
63 }
64 }
65
66 /**
67 * @brief Set LED state
68 * @param state true to turn on, false to turn off
69 */
70 void set(bool state) {
71 if (state) {
72 on();
73 } else {
74 off();
75 }
76 }
77
78 /**
79 * @brief Get current LED state
80 * @return true if LED is on
81 */
82 bool isOn() const {
83 return is_on_;
84 }
85
86 /**
87 * @brief Get current LED state
88 * @return true if LED is off
89 */
90 bool isOff() const {
91 return !is_on_;
92 }
93
94private:
95 bool active_high_;
96 bool is_on_;
97};
98
99} // namespace display
100} // namespace components
101} // namespace core
102} // namespace sbl
103
104#endif // SBL_CORE_COMPONENTS_DISPLAY_LED_HPP_
LED control interface.
Definition led.hpp:26
Led(bool active_high=true)
Construct LED controller.
Definition led.hpp:33
void toggle()
Toggle LED state.
Definition led.hpp:58
void off()
Turn LED off.
Definition led.hpp:50
bool isOn() const
Get current LED state.
Definition led.hpp:82
void set(bool state)
Set LED state.
Definition led.hpp:70
bool isOff() const
Get current LED state.
Definition led.hpp:90
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24