Skip to content

Commit 30b8ac2

Browse files
committed
Expose status LED lock
Add `GetLock()` to the status LED API and implement it to return the internal lock flag, allowing callers to query whether mode changes are currently locked. The update also removes an unused `<concepts>` include and modernizes the static lock flag initialization.
1 parent 49756be commit 30b8ac2

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

lib-board/include/board_statusled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ enum class Mode { kOffOff, kOffOn, kNormal, kData, kFast, kReboot, kUnknown };
3434
namespace global {
3535
extern Mode g_status_led_mode;
3636
} // namespace global
37-
3837
void SetModeWithLock(Mode mode, bool do_lock);
3938
void SetMode(Mode mode);
4039
inline Mode GetMode() {
4140
return global::g_status_led_mode;
4241
}
42+
bool GetLock();
4343
void SetFrequency(uint32_t frequency_hz);
4444
void Event(Mode mode);
4545
} // namespace board::statusled

lib-board/src/board_statusled.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
#include <concepts>
2625
#if defined(DEBUG_HAL)
2726
#undef NDEBUG
2827
#endif
@@ -37,7 +36,7 @@ namespace global {
3736
Mode g_status_led_mode;
3837
} // namespace global
3938

40-
static bool s_do_lock;
39+
static auto s_do_lock = false;
4140

4241
enum class ModeToFrequency { kOffOff = 0, kNormal = 1, kData = 3, kFast = 5, kReboot = 8, kOffOn = 255 };
4342

@@ -55,6 +54,10 @@ void SetModeWithLock(Mode mode, bool do_lock) {
5554
s_do_lock = do_lock;
5655
}
5756

57+
bool GetLock() {
58+
return s_do_lock;
59+
}
60+
5861
void SetMode(board::statusled::Mode mode) {
5962
if (s_do_lock || (global::g_status_led_mode == mode)) {
6063
return;

lib-device/src/max7219matrix.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
static uint8_t spi_data[64] __attribute__((aligned(4)));
3434
static constexpr auto kFontSize = Cp437FontSize();
35-
static uint8_t s_font[kFontSize] __attribute__((aligned(4)));
35+
static uint8_t s_font[kFontSize * 8] __attribute__((aligned(4)));
3636

3737
static constexpr uint8_t Rotate(uint32_t r, uint32_t x) {
3838
uint8_t byte = 0;
@@ -47,8 +47,9 @@ static constexpr uint8_t Rotate(uint32_t r, uint32_t x) {
4747

4848
Max7219Matrix::Max7219Matrix() {
4949
DEBUG_ENTRY();
50+
DEBUG_PRINTF("kFontSize=%u, &s_font=%p:%p", static_cast<unsigned>(kFontSize), reinterpret_cast<void*>(s_font), reinterpret_cast<void*>(s_font + kFontSize));
5051

51-
auto dst = s_font;
52+
auto* dst = s_font;
5253

5354
for (uint32_t i = 0; i < kFontSize; i++) {
5455
for (uint32_t j = 0; j < 8; j++) {
@@ -105,16 +106,16 @@ void Max7219Matrix::Write(const char* buffer, uint16_t count) {
105106
}
106107

107108
while (--k >= 0) {
108-
auto c = static_cast<uint32_t>(buffer[k]);
109+
auto character = static_cast<uint32_t>(buffer[k]);
109110

110-
if (c >= kFontSize) {
111-
c = ' ';
111+
if (character >= kFontSize) {
112+
character = ' ';
112113
}
113114

114-
const auto kP = &s_font[c * 8];
115+
auto* const kCharacter = &s_font[character * 8];
115116

116117
spi_data[j++] = static_cast<uint8_t>(i);
117-
spi_data[j++] = kP[i - 1];
118+
spi_data[j++] = kCharacter[i - 1];
118119
}
119120

120121
Spi::Write(reinterpret_cast<const char*>(spi_data), j, true);
@@ -126,7 +127,7 @@ void Max7219Matrix::UpdateCharacter(uint32_t c, const uint8_t bytes[8]) {
126127
return;
127128
}
128129

129-
auto font = &s_font[c * 8];
130+
auto* destination = &s_font[c * 8];
130131

131132
for (uint32_t j = 0; j < 8; j++) {
132133
uint8_t b = 0;
@@ -136,7 +137,7 @@ void Max7219Matrix::UpdateCharacter(uint32_t c, const uint8_t bytes[8]) {
136137
b |= static_cast<uint8_t>((kSet != 0) ? (1U << y) : 0);
137138
}
138139

139-
font[j] = b;
140+
destination[j] = b;
140141
}
141142
}
142143

0 commit comments

Comments
 (0)