-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds3234.h
77 lines (62 loc) · 2.41 KB
/
ds3234.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
#ifndef __ds3234_h_
#define __ds3234_h_
#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#define SECONDS_FROM_1970_TO_2000 946684800
// control register bits
#define DS3234_A1IE 0x1
#define DS3234_A2IE 0x2
#define DS3234_INTCN 0x4
// status register bits
#define DS3234_A1F 0x1
#define DS3234_A2F 0x2
#define DS3234_OSF 0x80
struct ts {
uint8_t sec; /* seconds */
uint8_t min; /* minutes */
uint8_t hour; /* hours */
uint8_t mday; /* day of the month */
uint8_t mon; /* month */
int year; /* year */
uint8_t wday; /* day of the week */
uint8_t yday; /* day in the year */
uint8_t isdst; /* daylight saving time */
uint8_t year_s; /* year in short notation*/
};
void DS3234_init(const uint8_t pin, const uint8_t creg);
void DS3234_set(const uint8_t pin, struct ts t);
void DS3234_get(const uint8_t pin, struct ts *t);
void DS3234_set_addr(const uint8_t pin, const uint8_t addr, const uint8_t val);
uint8_t DS3234_get_addr(const uint8_t pin, const uint8_t addr);
// control/status register
void DS3234_set_creg(const uint8_t pin, const uint8_t val);
void DS3234_set_sreg(const uint8_t pin, const uint8_t mask);
uint8_t DS3234_get_sreg(const uint8_t pin);
// aging offset register
void DS3234_set_aging(const uint8_t pin, const int8_t value);
int8_t DS3234_get_aging(const uint8_t pin);
// temperature register
float DS3234_get_treg(const uint8_t pin);
// alarms
void DS3234_set_a1(const uint8_t pin, const uint8_t s, const uint8_t mi, const uint8_t h, const uint8_t d,
const uint8_t * flags);
void DS3234_get_a1(const uint8_t pin, char *buf, const uint8_t len);
void DS3234_clear_a1f(const uint8_t pin);
uint8_t DS3234_triggered_a1(const uint8_t pin);
void DS3234_set_a2(const uint8_t pin, const uint8_t mi, const uint8_t h, const uint8_t d,
const uint8_t * flags);
void DS3234_get_a2(const uint8_t pin, char *buf, const uint8_t len);
void DS3234_clear_a2f(const uint8_t pin);
uint8_t DS3234_triggered_a2(const uint8_t pin);
// sram
void DS3234_set_sram_8b(const uint8_t pin, const uint8_t address, const uint8_t value);
uint8_t DS3234_get_sram_8b(const uint8_t pin, const uint8_t address);
// helpers
uint32_t get_unixtime(struct ts t);
uint8_t dectobcd(const uint8_t val);
uint8_t bcdtodec(const uint8_t val);
uint8_t inp2toi(const char *cmd, const uint16_t seek);
#endif