libyggdrasil
v1.0.0
rtc.hpp
Go to the documentation of this file.
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
* _____.___. .___ .__.__ *
3
* \__ | | ____ ____ __| _/___________ _____|__| | *
4
* / | |/ ___\ / ___\ / __ |\_ __ \__ \ / ___/ | | *
5
* \____ / /_/ > /_/ > /_/ | | | \// __ \_\___ \| | |__ *
6
* / ______\___ /\___ /\____ | |__| (____ /____ >__|____/ *
7
* \/ /_____//_____/ \/ \/ \/ *
8
* - Yggdrasil - *
9
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
10
* This software can be used by students and other personal of the *
11
* Bern University of Applied Sciences under the terms of the MIT *
12
* license. *
13
* For other persons this software is under the terms of the GNU *
14
* General Public License version 2. *
15
* *
16
* Copyright © 2021, Bern University of Applied Sciences. *
17
* All rights reserved. *
18
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
26
#pragma once
27
28
#include <
cpp/common/attributes.hpp
>
29
#include <
cpp/common/types.hpp
>
30
#include <
cpp/common/utils.hpp
>
31
#include <time.h>
32
33
namespace
bsp::ygg::prph
{
34
38
class
RealTimeClock
{
39
public
:
40
RealTimeClock
() =
delete
;
41
47
static
bool
init
() {
48
return
true
;
49
}
50
56
static
time_t
getTime
() {
57
return
bsp::I2CA::read<time_t>(DeviceAddress,
enumValue
(RegisterID::UnixTime0));
58
}
59
65
static
void
setTime
(time_t time) {
66
bsp::I2CA::write<time_t>(DeviceAddress,
enumValue
(RegisterID::UnixTime0), time);
67
}
68
69
private
:
70
74
enum class
RegisterID :
u8
{
75
// Clock registers
76
Seconds = 0x00,
77
Minutes = 0x01,
78
Hours = 0x02,
79
80
// Calendar registers
81
Weekday = 0x03,
82
Date = 0x04,
83
Month = 0x05,
84
Year = 0x06,
85
86
// Alarm registers
87
MinutesAlarm = 0x07,
88
HoursAlarm = 0x08,
89
DateAlarm = 0x09,
90
91
// Periodic countdown timer registers
92
TimerValue0 = 0x0A,
93
TimerValue1 = 0x0B,
94
TimerStatus0 = 0x0C,
95
TimerStatus1 = 0x0D,
96
97
// Configuration registers
98
Status = 0x0E,
99
Control1 = 0x0F,
100
Control2 = 0x10,
101
GPBits = 0x11,
102
ClockIntMask = 0x12,
103
104
// Eventcontrol / timestamp registers
105
EventControl = 0x13,
106
Count_TS = 0x14,
107
Seconds_TS = 0x15,
108
Minutes_TS = 0x16,
109
Hours_TS = 0x17,
110
Date_TS = 0x18,
111
Month_TS = 0x19,
112
Year_TS = 0x1A,
113
114
// Unix time registers
115
UnixTime0 = 0x1B,
116
UnixTime1 = 0x1C,
117
UnixTime2 = 0x1D,
118
UnixTime3 = 0x1E,
119
120
// RAM registers
121
UserRam1 = 0x1F,
122
UserRam2 = 0x20,
123
124
//Password registers
125
Password0 = 0x21,
126
Password1 = 0x22,
127
Password2 = 0x23,
128
Password3 = 0x24,
129
130
//EEPROM memory control registers
131
EEAddress = 0x25,
132
EEData = 0x26,
133
EECommand = 0x27,
134
135
//ID register
136
ID = 0x28,
137
138
};
139
140
constexpr
static
inline
u8
DeviceAddress = 0xA4;
141
145
struct
RawData {
146
u8
sec;
147
u8
min;
148
u8
hrs;
149
u8
weekday;
150
u8
date;
151
u8
month;
152
u8
year;
153
};
154
155
};
156
157
}
bsp::ygg::prph::RealTimeClock::setTime
static void setTime(time_t time)
Set the time in the RTC.
Definition:
rtc.hpp:65
utils.hpp
Commonly used helper functions.
u8
uint8_t u8
Unsigned integer definitions.
Definition:
types.h:36
types.hpp
Commonly used type definitions and helper templates.
bsp::ygg::prph::RealTimeClock::getTime
static time_t getTime()
Get the time saved in the RTC.
Definition:
rtc.hpp:56
bsp::ygg::prph::RealTimeClock::init
static bool init()
Initialization function.
Definition:
rtc.hpp:47
bsp::enumValue
auto enumValue(T value)
Casts a scoped enum type into its underlying value.
Definition:
utils.hpp:151
attributes.hpp
Commonly used C++ and GNU attributes.
bsp::ygg::prph::RealTimeClock
RTC driver RV-3028-C7.
Definition:
rtc.hpp:38
bsp::ygg::prph::RealTimeClock::RealTimeClock
RealTimeClock()=delete
bsp::ygg::prph
Definition:
color_sensor.hpp:32
Inc
cpp
yggdrasil
peripherals
rtc.hpp
Generated by
1.8.20