libws libws
WSwan hardware library for the Wonderful toolchain
Loading...
Searching...
No Matches
rtc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Adrian "asie" Siekierka
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 *
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 *
20 * 3. This notice may not be removed or altered from any source distribution.
21 */
22
27#ifndef __WF_LIBWS_RTC_H__
28#define __WF_LIBWS_RTC_H__
29
30#include <stdbool.h>
31#include <stdint.h>
32#include "hardware.h"
33#include "util.h"
34
40#define RTC_MONTH_AMPM 0x80
41#define RTC_MONTH_AM 0x80
42#define RTC_MONTH_PM 0x80
43
44typedef struct {
45 uint8_t year;
46 uint8_t month;
47 uint8_t date;
48 uint8_t day;
50
51typedef struct {
52 uint8_t hour;
53 uint8_t minute;
54 uint8_t second;
56
61
62#define RTC_STATUS_POWER_LOST 0x80
63#define RTC_STATUS_12_HOUR 0x00
64#define RTC_STATUS_24_HOUR 0x40
65#define RTC_STATUS_INTAE 0x20
66#define RTC_STATUS_INTME 0x08
67#define RTC_STATUS_INTFE 0x02
68#define RTC_STATUS_INT_OFF 0
69#define RTC_STATUS_INT_FREQ_STEADY (RTC_STATUS_INTFE)
70#define RTC_STATUS_INT_MINUTE_EDGE (RTC_STATUS_INTME)
71#define RTC_STATUS_INT_MINUTE_STEADY (RTC_STATUS_INTME | RTC_STATUS_INTFE)
72#define RTC_STATUS_INT_ALARM (RTC_STATUS_INTAE)
73
74int16_t ws_rtc_low_read_byte(uint16_t timeout);
75bool ws_rtc_low_write_byte(uint8_t value, uint16_t timeout);
76bool ws_rtc_low_write_ctrl(uint8_t value, uint16_t timeout);
77
78// TODO: high-level commands
79
82#endif /* __WF_LIBWS_RTC_H__ */
bool ws_rtc_low_write_byte(uint8_t value, uint16_t timeout)
bool ws_rtc_low_write_ctrl(uint8_t value, uint16_t timeout)
int16_t ws_rtc_low_read_byte(uint16_t timeout)
uint8_t date
Definition rtc.h:47
uint8_t month
Definition rtc.h:46
uint8_t day
Definition rtc.h:48
uint8_t year
Definition rtc.h:45
ws_rtc_time_t time
Definition rtc.h:59
ws_rtc_date_t date
Definition rtc.h:58
uint8_t second
Definition rtc.h:54
uint8_t minute
Definition rtc.h:53
uint8_t hour
Definition rtc.h:52