Skip to content

Commit 57d7d78

Browse files
committed
Applying Google C++ Style Guide
1 parent 730cff7 commit 57d7d78

File tree

16 files changed

+423
-413
lines changed

16 files changed

+423
-413
lines changed

lib-configstore/include/configstore.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "configurationstore.h"
3333
#include "global.h"
3434
#include "softwaretimers.h"
35-
3635
#include "debug.h"
3736

3837
class ConfigStore : StoreDevice
@@ -545,7 +544,7 @@ class ConfigStore : StoreDevice
545544
DEBUG_ENTRY
546545
DEBUG_PRINTF("s_timer_id=%d", s_timer_id);
547546

548-
if (s_timer_id != TIMER_ID_NONE)
547+
if (s_timer_id != kTimerIdNone)
549548
{
550549
DEBUG_EXIT
551550
return;
@@ -562,7 +561,7 @@ class ConfigStore : StoreDevice
562561
DEBUG_ENTRY
563562
DEBUG_PRINTF("s_timer_id=%d", s_timer_id);
564563

565-
if (s_timer_id == TIMER_ID_NONE)
564+
if (s_timer_id == kTimerIdNone)
566565
{
567566
return;
568567
DEBUG_EXIT
@@ -675,7 +674,7 @@ class ConfigStore : StoreDevice
675674
static inline uint32_t s_start_address{0};
676675
static inline bool s_have_device{false};
677676
static inline State s_state{State::kIdle};
678-
static inline TimerHandle_t s_timer_id = TIMER_ID_NONE;
677+
static inline TimerHandle_t s_timer_id = kTimerIdNone;
679678
static inline ConfigStore* s_this;
680679
};
681680

lib-display/src/sleep/display.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#include "debug.h"
3535

36-
static TimerHandle_t s_timer_id = TIMER_ID_NONE;
36+
static TimerHandle_t s_timer_id = kTimerIdNone;
3737

3838
static void SleepTimer([[maybe_unused]] TimerHandle_t handle)
3939
{
@@ -53,7 +53,7 @@ void Display::SetSleepTimer(bool active)
5353
return;
5454
}
5555

56-
if (s_timer_id == TIMER_ID_NONE)
56+
if (s_timer_id == kTimerIdNone)
5757
{
5858
s_timer_id = SoftwareTimerAdd(sleep_timeout_, SleepTimer);
5959
DEBUG_EXIT

lib-hal/include/hal_api.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,3 @@
3333
#else
3434
#include "rpi/hal_api.h"
3535
#endif
36-
37-
#ifdef __cplusplus
38-
#if !defined(UDELAY)
39-
#define UDELAY
40-
#include <cstdint>
41-
void udelay(uint32_t us, uint32_t offset = 0);
42-
#endif
43-
#endif

lib-hal/include/hal_i2c.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#endif
3434
#endif
3535

36-
#include "hal_api.h"
36+
#include "hal_udelay.h"
3737

3838
#if defined(__linux__) || defined(__APPLE__)
3939
#include "linux/hal_api.h"
@@ -239,7 +239,7 @@ class HAL_I2C
239239
return Read16();
240240
}
241241

242-
uint16_t ReadRegister16DelayUs(uint8_t reg, uint32_t nDelayUs)
242+
uint16_t ReadRegister16DelayUs(uint8_t reg, uint32_t delay_us)
243243
{
244244
char buf[2] = {0};
245245

@@ -248,7 +248,7 @@ class HAL_I2C
248248
Setup();
249249
FUNC_PREFIX(I2cWrite(&buf[0], 1));
250250

251-
udelay(nDelayUs);
251+
udelay(delay_us);
252252

253253
FUNC_PREFIX(I2cRead(buf, 2));
254254

lib-hal/include/hal_udelay.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @file hal_udelay.h
3+
*
4+
*/
5+
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
#ifdef __cplusplus
27+
#if !defined(UDELAY)
28+
#define UDELAY
29+
#include <cstdint>
30+
void udelay(uint32_t us, uint32_t offset = 0);
31+
#endif
32+
#endif

lib-hal/include/hwclock.h

Lines changed: 68 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
#pragma once
12
/**
23
* @file hwclock.h
34
*
45
*/
5-
/* Copyright (C) 2020-2023 by Arjan van Vught mailto:info@gd32-dmx.org
6+
/* Copyright (C) 2020-2025 by Arjan van Vught mailto:info@gd32-dmx.org
67
*
78
* Permission is hereby granted, free of charge, to any person obtaining a copy
89
* of this software and associated documentation files (the "Software"), to deal
@@ -23,82 +24,75 @@
2324
* THE SOFTWARE.
2425
*/
2526

26-
#ifndef HWCLOCK_H_
27-
#define HWCLOCK_H_
28-
2927
#include <cstdint>
3028
#include <time.h>
3129
#include <sys/time.h>
3230

33-
namespace rtc {
34-
enum class Type : uint8_t {
35-
MCP7941X, DS3231, PCF8563, SOC_INTERNAL, UNKNOWN
36-
};
37-
} // namespace rtc
38-
39-
class HwClock {
40-
public:
41-
HwClock();
42-
void RtcProbe();
43-
44-
void HcToSys(); // Set the System Clock from the Hardware Clock
45-
void SysToHc(); // Set the Hardware Clock from the System Clock
46-
47-
bool Set(const struct tm *pTime);
48-
bool Get(struct tm *pTime) {
49-
return RtcGet(pTime);
50-
}
51-
52-
bool AlarmSet(const struct tm *pTime) {
53-
return RtcSetAlarm(pTime);
54-
}
55-
bool AlarmGet(struct tm *pTime) {
56-
return RtcGetAlarm(pTime);
57-
}
58-
void AlarmEnable(const bool bEnable) {
59-
m_bRtcAlarmEnabled = bEnable;
60-
}
61-
bool AlarmIsEnabled() const {
62-
return m_bRtcAlarmEnabled;
63-
}
64-
65-
bool IsConnected() const {
66-
return is_connected_;
67-
}
68-
69-
void Run(const bool bDoRun) {
70-
if (!bDoRun || !is_connected_) {
71-
return;
72-
}
73-
Process();
74-
}
75-
76-
void Print();
77-
78-
static HwClock *Get() {
79-
return s_this;
80-
}
81-
82-
private:
83-
void Process();
84-
bool RtcSet(const struct tm *pime);
85-
bool RtcGet(struct tm *pTime);
86-
bool RtcSetAlarm(const struct tm *pTime);
87-
bool RtcGetAlarm(struct tm *pTime);
88-
int MCP794xxAlarmWeekday(struct tm *pTime);
89-
void PCF8563GetAlarmMode();
90-
void PCF8563SetAlarmMode();
91-
92-
private:
93-
uint32_t m_nSetDelayMicros { 0 };
94-
uint32_t m_nLastHcToSysMillis { 0 };
95-
uint8_t address_ { 0 };
96-
rtc::Type m_Type { rtc::Type::UNKNOWN };
97-
bool is_connected_ { false };
98-
bool m_bRtcAlarmEnabled { false };
99-
bool m_bRtcAlarmPending { false };
100-
101-
static inline HwClock *s_this;
31+
namespace rtc
32+
{
33+
enum class Type : uint8_t
34+
{
35+
kMcP7941X,
36+
kDS3231,
37+
kPcF8563,
38+
kSocInternal,
39+
kUnknown
10240
};
41+
} // namespace rtc
42+
43+
class HwClock
44+
{
45+
public:
46+
HwClock();
47+
void RtcProbe();
48+
49+
void HcToSys(); // Set the System Clock from the Hardware Clock
50+
void SysToHc(); // Set the Hardware Clock from the System Clock
51+
52+
bool Set(const struct tm* time);
53+
bool Get(struct tm* time) { return RtcGet(time); }
54+
55+
bool AlarmSet(const struct tm* time) { return RtcSetAlarm(time); }
56+
57+
bool AlarmGet(struct tm* time) { return RtcGetAlarm(time); }
58+
59+
void AlarmEnable(bool enable) { m_bRtcAlarmEnabled = enable; }
10360

104-
#endif /* HWCLOCK_H_ */
61+
bool AlarmIsEnabled() const { return m_bRtcAlarmEnabled; }
62+
63+
bool IsConnected() const { return is_connected_; }
64+
65+
void Run(bool do_run)
66+
{
67+
if (!do_run || !is_connected_)
68+
{
69+
return;
70+
}
71+
Process();
72+
}
73+
74+
void Print();
75+
76+
static HwClock* Get() { return s_this; }
77+
78+
private:
79+
void Process();
80+
bool RtcSet(const struct tm* time);
81+
bool RtcGet(struct tm* time);
82+
bool RtcSetAlarm(const struct tm* time);
83+
bool RtcGetAlarm(struct tm* time);
84+
int MCP794xxAlarmWeekday(struct tm* time);
85+
void PCF8563GetAlarmMode();
86+
void PCF8563SetAlarmMode();
87+
88+
private:
89+
uint32_t m_nSetDelayMicros{0};
90+
uint32_t m_nLastHcToSysMillis{0};
91+
uint8_t address_{0};
92+
rtc::Type m_Type{rtc::Type::kUnknown};
93+
bool is_connected_{false};
94+
bool m_bRtcAlarmEnabled{false};
95+
bool m_bRtcAlarmPending{false};
96+
97+
static inline HwClock* s_this;
98+
};

lib-hal/include/softwaretimers.h

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,43 +26,47 @@
2626

2727
#include <cstdint>
2828

29-
namespace hal {
30-
static constexpr uint32_t SOFTWARE_TIMERS_MAX =
29+
namespace hal
30+
{
31+
static constexpr uint32_t kSoftwareTimersMax =
3132
#if defined(CONFIG_HAL_TIMERS_COUNT)
32-
CONFIG_HAL_TIMERS_COUNT;
33+
CONFIG_HAL_TIMERS_COUNT;
3334
#else
34-
12;
35+
12;
3536
#endif
3637
} // namespace hal
3738

3839
#if defined(USE_FREE_RTOS)
39-
# ifdef __cplusplus
40-
# pragma GCC diagnostic push
41-
# pragma GCC diagnostic ignored "-Wold-style-cast"
42-
# endif
43-
# include "../FreeRTOS/FreeRTOS-Kernel/include/FreeRTOS.h"
44-
# include "../FreeRTOS/FreeRTOS-Kernel/include/timers.h"
45-
# define TIMER_ID_NONE nullptr
46-
inline TimerHandle_t SoftwareTimerAdd(const uint32_t nIntervalMillis, const TimerCallbackFunction_t pCallbackFunction) {
47-
const auto xTimer = xTimerCreate("", nIntervalMillis / portTICK_PERIOD_MS, pdTRUE, nullptr, pCallbackFunction);
48-
if (xTimer != nullptr) xTimerStart( xTimer, 0);
49-
return xTimer;
40+
#ifdef __cplusplus
41+
#pragma GCC diagnostic push
42+
#pragma GCC diagnostic ignored "-Wold-style-cast"
43+
#endif
44+
#include "../FreeRTOS/FreeRTOS-Kernel/include/FreeRTOS.h"
45+
#include "../FreeRTOS/FreeRTOS-Kernel/include/timers.h"
46+
#define kTimerIdNone nullptr
47+
inline TimerHandle_t SoftwareTimerAdd(const uint32_t nIntervalMillis, const TimerCallbackFunction_t pCallbackFunction)
48+
{
49+
const auto xTimer = xTimerCreate("", nIntervalMillis / portTICK_PERIOD_MS, pdTRUE, nullptr, pCallbackFunction);
50+
if (xTimer != nullptr) xTimerStart(xTimer, 0);
51+
return xTimer;
5052
}
5153

52-
inline bool SoftwareTimerDelete(TimerHandle_t& nId) {
53-
TimerHandle_t t = nId;
54-
const auto b = (xTimerDelete(t, 0) != pdFAIL);
55-
if (b) nId = TIMER_ID_NONE;
56-
return b;
54+
inline bool SoftwareTimerDelete(TimerHandle_t& nId)
55+
{
56+
TimerHandle_t t = nId;
57+
const auto b = (xTimerDelete(t, 0) != pdFAIL);
58+
if (b) nId = kTimerIdNone;
59+
return b;
5760
}
5861

59-
inline bool SoftwareTimerChange(const TimerHandle_t nId, const uint32_t nIntervalMillis) {
60-
return xTimerChangePeriod(nId, nIntervalMillis / portTICK_PERIOD_MS, 0) != pdFAIL;
62+
inline bool SoftwareTimerChange(const TimerHandle_t nId, const uint32_t nIntervalMillis)
63+
{
64+
return xTimerChangePeriod(nId, nIntervalMillis / portTICK_PERIOD_MS, 0) != pdFAIL;
6165
}
62-
# ifdef __cplusplus
63-
# pragma GCC diagnostic pop
64-
# endif
66+
#ifdef __cplusplus
67+
#pragma GCC diagnostic pop
68+
#endif
6569
#else
66-
# include "superloop/softwaretimers.h"
67-
static constexpr TimerHandle_t TIMER_ID_NONE = -1;
70+
#include "superloop/softwaretimers.h"
71+
static constexpr TimerHandle_t kTimerIdNone = -1;
6872
#endif

lib-hal/include/utc.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,7 @@ struct Offset
5757
/**
5858
* @brief List of valid fractional UTC offsets.
5959
*/
60-
constexpr Offset kValidOffsets[] =
61-
{
62-
{-9, 30},
63-
{-3, 30},
64-
{3, 30},
65-
{4, 30},
66-
{5, 30},
67-
{5, 45},
68-
{6, 30},
69-
{8, 45},
70-
{9, 30},
71-
{10, 30},
72-
{12, 45}
73-
};
60+
constexpr Offset kValidOffsets[] = {{-9, 30}, {-3, 30}, {3, 30}, {4, 30}, {5, 30}, {5, 45}, {6, 30}, {8, 45}, {9, 30}, {10, 30}, {12, 45}};
7461

7562
/**
7663
* @brief Validates (hours, minutes) and converts to UTC offset in seconds.

0 commit comments

Comments
 (0)