-
Notifications
You must be signed in to change notification settings - Fork 13
/
pcf8563.h
116 lines (95 loc) · 4.03 KB
/
pcf8563.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
MIT License
Copyright (c) 2020-2021 Mika Tuupola
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-cut-
This file is part of hardware agnostic I2C driver for PCF8563 RTC:
https://github.com/tuupola/pcf8563
SPDX-License-Identifier: MIT
*/
#ifndef _PCF8563_H
#define _PCF8563_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <time.h>
#define PCF8563_ADDRESS (0x51)
#define PCF8563_CONTROL_STATUS1 (0x00)
#define PCF8563_TESTC (0b00001000)
#define PCF8563_STOP (0b00100000)
#define PCF8563_TEST1 (0b10000000)
#define PCF8563_CONTROL_STATUS2 (0x01)
#define PCF8563_TIE (0b00000001)
#define PCF8563_AIE (0b00000010)
#define PCF8563_TF (0b00000100)
#define PCF8563_AF (0b00001000)
#define PCF8563_TI_TP (0b00010000)
#define PCF8563_SECONDS (0x02)
#define PCF8563_MINUTES (0x03)
#define PCF8563_HOURS (0x04)
#define PCF8563_DAY (0x05)
#define PCF8563_WEEKDAY (0x06)
#define PCF8563_MONTH (0x07)
#define PCF8563_YEAR (0x08)
#define PCF8563_TIME_SIZE (0x07)
#define PCF8563_CENTURY_BIT (0b10000000)
#define PCF8563_MINUTE_ALARM (0x09)
#define PCF8563_HOUR_ALARM (0x0a)
#define PCF8563_DAY_ALARM (0x0b)
#define PCF8563_WEEKDAY_ALARM (0x0c)
#define PCF8563_ALARM_DISABLE (0b10000000)
#define PCF8563_ALARM_NONE (0xff)
#define PCF8563_ALARM_SIZE (0x04)
#define PCF8563_TIMER_CONTROL (0x0e)
#define PCF8563_TIMER_ENABLE (0b10000000)
#define PCF8563_TIMER_4_096KHZ (0b00000000)
#define PCF8563_TIMER_64HZ (0b00000001)
#define PCF8563_TIMER_1HZ (0b00000010)
#define PCF8563_TIMER_1_60HZ (0b00000011)
#define PCF8563_TIMER (0x0f)
/* IOCTL commands */
#define PCF8563_ALARM_SET (0x0900)
#define PCF8563_ALARM_READ (0x0901)
#define PCF8563_CONTROL_STATUS1_READ (0x0000)
#define PCF8563_CONTROL_STATUS1_WRITE (0x0001)
#define PCF8563_CONTROL_STATUS2_READ (0x0100)
#define PCF8563_CONTROL_STATUS2_WRITE (0x0101)
#define PCF8563_TIMER_CONTROL_READ (0x0e00)
#define PCF8563_TIMER_CONTROL_WRITE (0x0e01)
#define PCF8563_TIMER_READ (0x0f00)
#define PCF8563_TIMER_WRITE (0x0f01)
/* Status codes. */
#define PCF8563_ERROR_NOTTY (-1)
#define PCF8563_OK (0x00)
#define PCF8563_ERR_LOW_VOLTAGE (0x80)
/* These should be provided by the HAL. */
typedef struct {
int32_t (* read)(void *handle, uint8_t address, uint8_t reg, uint8_t *buffer, uint16_t size);
int32_t (* write)(void *handle, uint8_t address, uint8_t reg, const uint8_t *buffer, uint16_t size);
void *handle;
} pcf8563_t;
typedef int32_t pcf8563_err_t;
pcf8563_err_t pcf8563_init(const pcf8563_t *pcf);
pcf8563_err_t pcf8563_read(const pcf8563_t *pcf, struct tm *time);
pcf8563_err_t pcf8563_write(const pcf8563_t *pcf, const struct tm *time);
pcf8563_err_t pcf8563_ioctl(const pcf8563_t *pcf, int16_t command, void *buffer);
pcf8563_err_t pcf8563_close(const pcf8563_t *pcf);
#ifdef __cplusplus
}
#endif
#endif