ds3231.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
31 #ifndef DS3231_H
32 #define DS3231_H
33 
34 #include <time.h>
35 #include <errno.h>
36 
37 #include "periph/i2c.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
46 #define DS3231_I2C_ADDR 0x68
47 
51 enum {
52  DS3231_OPT_BAT_ENABLE = 0x01, /* enable backup battery on startup */
53  DS2321_OPT_32KHZ_ENABLE = 0x02, /* enable 32KHz output */
54 };
55 
59 typedef struct {
61 } ds3231_t;
62 
66 typedef struct {
68  uint8_t opt;
70 
80 int ds3231_init(ds3231_t *dev, const ds3231_params_t *params);
81 
91 int ds3231_get_time(const ds3231_t *dev, struct tm *time);
92 
102 int ds3231_set_time(const ds3231_t *dev, const struct tm *time);
103 
113 int ds3231_get_aging_offset(const ds3231_t *dev, int8_t *offset);
114 
124 int ds3231_set_aging_offset(const ds3231_t *dev, int8_t offset);
125 
135 int ds3231_get_temp(const ds3231_t *dev, int16_t *temp);
136 
145 int ds3231_enable_bat(const ds3231_t *dev);
146 
155 int ds3231_disable_bat(const ds3231_t *dev);
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif /* DS3231_H */
162 
ds3231_t
Device descriptor for DS3231 devices.
Definition: ds3231.h:59
ds3231_set_time
int ds3231_set_time(const ds3231_t *dev, const struct tm *time)
Set date and time of the device.
ds3231_enable_bat
int ds3231_enable_bat(const ds3231_t *dev)
Enable the backup battery.
ds3231_set_aging_offset
int ds3231_set_aging_offset(const ds3231_t *dev, int8_t offset)
Set the aging offset (see datasheet for more information)
ds3231_t::bus
i2c_t bus
I2C bus the device is connected to.
Definition: ds3231.h:60
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
ds3231_disable_bat
int ds3231_disable_bat(const ds3231_t *dev)
Disable the backup battery.
ds3231_params_t::opt
uint8_t opt
additional options
Definition: ds3231.h:68
ds3231_params_t
Set of configuration parameters for DS3231 devices.
Definition: ds3231.h:66
ds3231_params_t::bus
i2c_t bus
I2C bus the device is connected to.
Definition: ds3231.h:67
ds3231_get_aging_offset
int ds3231_get_aging_offset(const ds3231_t *dev, int8_t *offset)
Get the configured aging offset (see datasheet for more information)
ds3231_init
int ds3231_init(ds3231_t *dev, const ds3231_params_t *params)
Initialize the given DS3231 device.
ds3231_get_temp
int ds3231_get_temp(const ds3231_t *dev, int16_t *temp)
Get temperature from the device.
i2c.h
Low-level I2C peripheral driver interface definition.
errno.h
ds3231_get_time
int ds3231_get_time(const ds3231_t *dev, struct tm *time)
Get date and time from the device.