Loading...
Searching...
No Matches
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/gpio.h"
38#include "periph/i2c.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
47#define DS3231_I2C_ADDR 0x68
48
53#define DS3231_FLAG_ALARM_1 0x01
54#define DS3231_FLAG_ALARM_2 0x02
60enum {
64};
65
76
86
90typedef struct {
92#if IS_USED(MODULE_DS3231_INT)
93 gpio_t int_pin;
94#endif /* MODULE_DS3231_INT */
95} ds3231_t;
96
100typedef struct {
102 uint8_t opt;
103#if IS_USED(MODULE_DS3231_INT)
104 gpio_t int_pin;
105#endif /* MODULE_DS3231_INT */
107
108#if IS_USED(MODULE_DS3231_INT)
109typedef void (*ds3231_alarm_cb_t)(void *);
110
111#endif /* MODULE_DS3231_INT */
112
122int ds3231_init(ds3231_t *dev, const ds3231_params_t *params);
123
124#if IS_USED(MODULE_DS3231_INT)
139int ds3231_await_alarm(ds3231_t *dev);
140#endif /* MODULE_DS3231_INT */
141
151int ds3231_get_time(const ds3231_t *dev, struct tm *time);
152
162int ds3231_set_time(const ds3231_t *dev, const struct tm *time);
163
174int ds3231_set_alarm_1(const ds3231_t *dev, struct tm *time,
175 ds3231_alm_1_mode_t trigger);
176
187int ds3231_set_alarm_2(const ds3231_t *dev, struct tm *time,
188 ds3231_alm_2_mode_t trigger);
189
199
209
221int ds3231_get_alarm_1_flag(const ds3231_t *dev, bool *flag);
222
234int ds3231_get_alarm_2_flag(const ds3231_t *dev, bool *flag);
235
245int ds3231_toggle_alarm_1(const ds3231_t *dev, bool enable);
246
256int ds3231_toggle_alarm_2(const ds3231_t *dev, bool enable);
257
267int ds3231_get_aging_offset(const ds3231_t *dev, int8_t *offset);
268
278int ds3231_set_aging_offset(const ds3231_t *dev, int8_t offset);
279
289int ds3231_get_temp(const ds3231_t *dev, int16_t *temp);
290
300
310
311#ifdef __cplusplus
312}
313#endif
314
315#endif /* DS3231_H */
Low-level GPIO peripheral driver interface definitions.
int ds3231_clear_alarm_2_flag(const ds3231_t *dev)
Clear alarm 2 flag (A2F)
int ds3231_toggle_alarm_2(const ds3231_t *dev, bool enable)
Enable/Disable alarm 2 interrupt on the device.
int ds3231_set_time(const ds3231_t *dev, const struct tm *time)
Set date and time of the device.
int ds3231_get_temp(const ds3231_t *dev, int16_t *temp)
Get temperature from the device.
int ds3231_enable_bat(const ds3231_t *dev)
Enable the backup battery.
int ds3231_get_aging_offset(const ds3231_t *dev, int8_t *offset)
Get the configured aging offset (see datasheet for more information)
int ds3231_toggle_alarm_1(const ds3231_t *dev, bool enable)
Enable/Disable alarm 1 interrupt on the device.
int ds3231_set_alarm_2(const ds3231_t *dev, struct tm *time, ds3231_alm_2_mode_t trigger)
Set alarm 2 of the device.
ds3231_alm_1_mode_t
Alarm trigger type of alarm 1 for DS3231 devices.
Definition ds3231.h:69
int ds3231_get_time(const ds3231_t *dev, struct tm *time)
Get date and time from the device.
int ds3231_get_alarm_2_flag(const ds3231_t *dev, bool *flag)
Get the state of alarm 2 flag (A2F)
int ds3231_init(ds3231_t *dev, const ds3231_params_t *params)
Initialize the given DS3231 device.
int ds3231_set_alarm_1(const ds3231_t *dev, struct tm *time, ds3231_alm_1_mode_t trigger)
Set alarm 1 of the device.
ds3231_alm_2_mode_t
Alarm trigger type of alarm 2 for DS3231 devices.
Definition ds3231.h:80
int ds3231_get_alarm_1_flag(const ds3231_t *dev, bool *flag)
Get the state of alarm 1 flag (A1F)
int ds3231_set_aging_offset(const ds3231_t *dev, int8_t offset)
Set the aging offset (see datasheet for more information)
int ds3231_clear_alarm_1_flag(const ds3231_t *dev)
Clear alarm 1 flag (A1F)
int ds3231_disable_bat(const ds3231_t *dev)
Disable the backup battery.
@ DS3231_AL1_TRIG_PER_S
alarm once per second
Definition ds3231.h:70
@ DS3231_AL1_TRIG_S
alarm when seconds match
Definition ds3231.h:71
@ DS3231_AL1_TRIG_D_H_M_S
alarm when D/H/M/S match
Definition ds3231.h:74
@ DS3231_AL1_TRIG_H_M_S
alarm when H/M/S match
Definition ds3231.h:73
@ DS3231_AL1_TRIG_M_S
alarm when minutes and seconds match
Definition ds3231.h:72
@ DS3231_OPT_INTER_ENABLE
enable the interrupt control
Definition ds3231.h:63
@ DS3221_OPT_32KHZ_ENABLE
enable 32KHz output
Definition ds3231.h:62
@ DS3231_OPT_BAT_ENABLE
enable backup battery on startup
Definition ds3231.h:61
@ DS3231_AL2_TRIG_H_M
alarm when hours and minutes match
Definition ds3231.h:83
@ DS3231_AL2_TRIG_D_H_M_S
alarm when D/H/M match
Definition ds3231.h:84
@ DS3231_AL2_TRIG_M
alarm when minutes match
Definition ds3231.h:82
@ DS3231_AL2_TRIG_PER_M
alarm once per minute
Definition ds3231.h:81
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:151
Low-level I2C peripheral driver interface definition.
Set of configuration parameters for DS3231 devices.
Definition ds3231.h:100
i2c_t bus
I2C bus the device is connected to.
Definition ds3231.h:101
uint8_t opt
additional options
Definition ds3231.h:102
Device descriptor for DS3231 devices.
Definition ds3231.h:90
i2c_t bus
I2C bus the device is connected to.
Definition ds3231.h:91