aboutsummaryrefslogtreecommitdiffstats
path: root/source/rtc.cpp
blob: ec7f5db51213ddfdf57b0cc56661a4e7e55da195 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 * @file rtc.cpp
 * @brief Prepares and uses the RTC to count time.
 *
 * Copyright (C) 2019 Clyne Sullivan
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

#include "rtc.hpp"
#include <bluefruit.h>

nrf_drv_rtc_t RTC::rtc = NRF_DRV_RTC_INSTANCE(2);
uint32_t RTC::rtcCount = 0;

void RTC::begin(void)
{
	//Initialize RTC instance
	nrf_drv_rtc_config_t rtc_config = {
		4095,
		RTC_DEFAULT_CONFIG_IRQ_PRIORITY,
		RTC_US_TO_TICKS(NRF_MAXIMUM_LATENCY_US, RTC_DEFAULT_CONFIG_FREQUENCY),
		RTC_DEFAULT_CONFIG_RELIABLE
	};
	
	Serial.println(nrf_drv_rtc_init(&rtc, &rtc_config, handler));
	nrf_drv_rtc_tick_enable(&rtc, true);
	nrf_drv_rtc_enable(&rtc);
}

const char *RTC::getDate(char *buf)
{
	
}

void RTC::handler([[maybe_unused]] nrf_drv_rtc_int_type_t int_type)
{
  static unsigned char counter = 0;
  if (int_type == NRF_DRV_RTC_INT_TICK) {
          if (++counter == 8) {
        	  counter = 0;
		  if (++rtcCount == 86400)
			  rtcCount = 0;
          }
  }
}