Move alarm rate from inside details to visible namespace

This commit is contained in:
BlackMark 2020-05-17 19:19:28 +02:00
parent ff52f4f152
commit 1bc7e66389
2 changed files with 33 additions and 25 deletions

24
alarms.hpp Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include <stdint.h>
namespace rtc {
enum class Alarm1Rate : uint8_t {
ONCE_PER_S = 0b1111,
WHEN_S_MATCH = 0b1110,
WHEN_M_S_MATCH = 0b1100,
WHEN_H_M_S_MATCH = 0b1000,
WHEN_DATE_H_M_S_MATCH = 0b00000,
WHEN_DAY_H_N_S_MATCH = 0b10000,
};
enum class Alarm2Rate : uint8_t {
ONCE_PER_M = 0b111,
WHEN_M_MATCH = 0b110,
WHEN_H_M_MATCH = 0b100,
WHEN_DATE_H_M_MATCH = 0b0000,
WHEN_DAY_H_N_MATCH = 0b1000,
};
} // namespace rtc

View File

@ -2,6 +2,7 @@
#include <stdint.h>
#include "alarms.hpp"
#include "flags.hpp"
namespace rtc {
@ -194,15 +195,6 @@ struct [[gnu::packed]] Alarm1Reg
uint8_t hours = 0;
uint8_t day_date = 0;
enum class AlarmRate {
ONCE_PER_S = 0b1111,
WHEN_S_MATCH = 0b1110,
WHEN_M_S_MATCH = 0b1100,
WHEN_H_M_S_MATCH = 0b1000,
WHEN_DATE_H_M_S_MATCH = 0b00000,
WHEN_DAY_H_N_S_MATCH = 0b10000,
};
//////////////////////////////////////////////////////////////////////////
inline uint8_t getSeconds() const
@ -225,7 +217,7 @@ struct [[gnu::packed]] Alarm1Reg
{
return getEncodedDate(date, day_date);
}
inline AlarmRate getAlarmRate() const
inline Alarm1Rate getAlarmRate() const
{
constexpr auto M_FLAG = 7;
const auto m1 = (seconds >> M_FLAG) & 1;
@ -236,9 +228,9 @@ struct [[gnu::packed]] Alarm1Reg
if (m == 0) {
constexpr auto DAY_FLAG = 6;
const auto dayFormat = ((day_date >> DAY_FLAG) & 1) << 4;
return static_cast<AlarmRate>(dayFormat);
return static_cast<Alarm1Rate>(dayFormat);
}
return static_cast<AlarmRate>(m);
return static_cast<Alarm1Rate>(m);
}
//////////////////////////////////////////////////////////////////////////
@ -263,7 +255,7 @@ struct [[gnu::packed]] Alarm1Reg
{
setEncodedDate(day_date, date);
}
inline void setAlarmRate(const AlarmRate &alarmRate)
inline void setAlarmRate(const Alarm1Rate &alarmRate)
{
const auto alarmRateFlags = static_cast<uint8_t>(alarmRate);
constexpr auto M_FLAG = 7;
@ -288,14 +280,6 @@ struct [[gnu::packed]] Alarm2Reg
uint8_t hours = 0;
uint8_t day_date = 0;
enum class AlarmRate {
ONCE_PER_M = 0b111,
WHEN_M_MATCH = 0b110,
WHEN_H_M_MATCH = 0b100,
WHEN_DATE_H_M_MATCH = 0b0000,
WHEN_DAY_H_N_MATCH = 0b1000,
};
//////////////////////////////////////////////////////////////////////////
inline uint8_t getMinutes() const
@ -314,7 +298,7 @@ struct [[gnu::packed]] Alarm2Reg
{
return getEncodedDate(date, day_date);
}
inline AlarmRate getAlarmRate() const
inline Alarm2Rate getAlarmRate() const
{
constexpr auto M_FLAG = 7;
const auto m2 = (minutes >> M_FLAG) & 1;
@ -324,9 +308,9 @@ struct [[gnu::packed]] Alarm2Reg
if (m == 0) {
constexpr auto DAY_FLAG = 6;
const auto dayFormat = ((day_date >> DAY_FLAG) & 1) << 3;
return static_cast<AlarmRate>(dayFormat);
return static_cast<Alarm2Rate>(dayFormat);
}
return static_cast<AlarmRate>(m);
return static_cast<Alarm2Rate>(m);
}
//////////////////////////////////////////////////////////////////////////
@ -347,7 +331,7 @@ struct [[gnu::packed]] Alarm2Reg
{
setEncodedDate(day_date, date);
}
inline void setAlarmRate(const AlarmRate &alarmRate)
inline void setAlarmRate(const Alarm2Rate &alarmRate)
{
const auto alarmRateFlags = static_cast<uint8_t>(alarmRate);
constexpr auto M_FLAG = 7;