Sound Byte Libs
1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
src
sbl
components
display
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
12
namespace
sbl
{
13
namespace
core {
14
namespace
components {
15
namespace
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
*/
25
template
<
typename
GpioPinImpl>
26
class
Led
{
27
public
:
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
94
private
:
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_
sbl::core::components::display::Led
LED control interface.
Definition
led.hpp:26
sbl::core::components::display::Led::on
void on()
Turn LED on.
Definition
led.hpp:42
sbl::core::components::display::Led::Led
Led(bool active_high=true)
Construct LED controller.
Definition
led.hpp:33
sbl::core::components::display::Led::toggle
void toggle()
Toggle LED state.
Definition
led.hpp:58
sbl::core::components::display::Led::off
void off()
Turn LED off.
Definition
led.hpp:50
sbl::core::components::display::Led::isOn
bool isOn() const
Get current LED state.
Definition
led.hpp:82
sbl::core::components::display::Led::set
void set(bool state)
Set LED state.
Definition
led.hpp:70
sbl::core::components::display::Led::isOff
bool isOff() const
Get current LED state.
Definition
led.hpp:90
sbl
Root namespace for all Sound Byte Libs functionality.
Definition
aliases.hpp:24
Generated by
1.9.8