ds1307.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 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 
20 #ifndef DS1307_H
21 #define DS1307_H
22 
23 #include <stdbool.h>
24 #include <time.h>
25 
26 #include "nvram.h"
27 #include "periph/i2c.h"
28 #include "periph/gpio.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
37 #define DS1307_I2C_ADDRESS (0x68)
38 
48 #ifndef DS1307_I2C_MAX_CLK
49 #define DS1307_I2C_MAX_CLK (I2C_SPEED_FAST)
50 #endif
51 
56 #define DS1307_NVRAM_MAX_SIZE (56U)
57 
61 typedef struct {
64 } ds1307_t;
65 
69 typedef struct {
72 
76 typedef enum {
84 
94 int ds1307_init(ds1307_t *dev, const ds1307_params_t *params);
95 
105 int ds1307_set_time(const ds1307_t *dev, const struct tm *time);
106 
116 int ds1307_get_time(const ds1307_t *dev, struct tm *time);
117 
128 int ds1307_halt(const ds1307_t *dev);
129 
141 int ds1307_set_sqw_mode(const ds1307_t *dev, ds1307_sqw_mode_t mode);
142 
154 int ds1307_get_sqw_mode(const ds1307_t *dev);
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif /* DS1307_H */
161 
ds1307_get_sqw_mode
int ds1307_get_sqw_mode(const ds1307_t *dev)
Get current mode of square wave / output driver.
ds1307_params_t::i2c
i2c_t i2c
I2C bus the device is connected to.
Definition: ds1307.h:70
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
nvram.h
Generic non-volatile RAM driver interface.
ds1307_set_time
int ds1307_set_time(const ds1307_t *dev, const struct tm *time)
Set RTC to a given time.
ds1307_sqw_mode_t
ds1307_sqw_mode_t
Modes for the DS1307 square wave / output driver.
Definition: ds1307.h:76
DS1307_SQW_MODE_4096HZ
@ DS1307_SQW_MODE_4096HZ
SQW: 4.096 kHz.
Definition: ds1307.h:79
ds1307_t::nvram
nvram_t nvram
on-chip NVRAM (see nvram.h)
Definition: ds1307.h:63
ds1307_halt
int ds1307_halt(const ds1307_t *dev)
Halt clock.
DS1307_SQW_MODE_1000HZ
@ DS1307_SQW_MODE_1000HZ
SQW: 1kHz.
Definition: ds1307.h:78
ds1307_init
int ds1307_init(ds1307_t *dev, const ds1307_params_t *params)
Initialize the given DS1307 device.
ds1307_t
Device descriptor for DS1307 devices.
Definition: ds1307.h:61
nvram
Device descriptor for generic NVRAM devices.
Definition: nvram.h:48
DS1307_SQW_MODE_32768HZ
@ DS1307_SQW_MODE_32768HZ
SQW: 32.768 kHz.
Definition: ds1307.h:81
DS1307_SQW_MODE_0
@ DS1307_SQW_MODE_0
OUT: 0.
Definition: ds1307.h:77
DS1307_SQW_MODE_8192HZ
@ DS1307_SQW_MODE_8192HZ
SQW: 8.192 kHz.
Definition: ds1307.h:80
ds1307_t::i2c
i2c_t i2c
I2C bus the device is connected to.
Definition: ds1307.h:62
gpio.h
Low-level GPIO peripheral driver interface definitions.
ds1307_params_t
Set of configuration parameters for DS1307 devices.
Definition: ds1307.h:69
DS1307_SQW_MODE_1
@ DS1307_SQW_MODE_1
OUT: 1.
Definition: ds1307.h:82
ds1307_get_time
int ds1307_get_time(const ds1307_t *dev, struct tm *time)
Get current RTC time.
i2c.h
Low-level I2C peripheral driver interface definition.
ds1307_set_sqw_mode
int ds1307_set_sqw_mode(const ds1307_t *dev, ds1307_sqw_mode_t mode)
Set mode of square wave / output driver.