rtc19 2.1.0.0
rtc19.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef RTC19_H
29#define RTC19_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define RTC19_REG_STATUS 0x00
74#define RTC19_REG_INT_EN 0x01
75#define RTC19_REG_RTC_RESET 0x02
76#define RTC19_REG_RTC_CONFIG1 0x03
77#define RTC19_REG_RTC_CONFIG2 0x04
78#define RTC19_REG_TIMESTAMP_CONFIG 0x05
79#define RTC19_REG_TIMER_CONFIG 0x06
80#define RTC19_REG_SLEEP_CONFIG 0x07
81#define RTC19_REG_SECONDS_1_128 0x08
82#define RTC19_REG_SECONDS 0x09
83#define RTC19_REG_MINUTES 0x0A
84#define RTC19_REG_HOURS 0x0B
85#define RTC19_REG_DAY 0x0C
86#define RTC19_REG_DATE 0x0D
87#define RTC19_REG_MONTH 0x0E
88#define RTC19_REG_YEAR 0x0F
89#define RTC19_REG_ALM1_SEC 0x10
90#define RTC19_REG_ALM1_MIN 0x11
91#define RTC19_REG_ALM1_HRS 0x12
92#define RTC19_REG_ALM1_DAY_DATE 0x13
93#define RTC19_REG_ALM1_MON 0x14
94#define RTC19_REG_ALM1_YEAR 0x15
95#define RTC19_REG_ALM2_MIN 0x16
96#define RTC19_REG_ALM2_HRS 0x17
97#define RTC19_REG_ALM2_DAY_DATE 0x18
98#define RTC19_REG_TIMER_COUNT2 0x19
99#define RTC19_REG_TIMER_COUNT1 0x1A
100#define RTC19_REG_TIMER_INIT2 0x1B
101#define RTC19_REG_TIMER_INIT1 0x1C
102#define RTC19_REG_PWR_MGMT 0x1D
103#define RTC19_REG_TRICKLE_REG 0x1E
104#define RTC19_REG_OFFSET_HIGH 0x20
105#define RTC19_REG_OFFSET_LOW 0x21
106
111#define RTC19_REG_TS0_SEC_1_128 0x30
112#define RTC19_REG_TS0_SEC 0x31
113#define RTC19_REG_TS0_MIN 0x32
114#define RTC19_REG_TS0_HOUR 0x33
115#define RTC19_REG_TS0_DATE 0x34
116#define RTC19_REG_TS0_MONTH 0x35
117#define RTC19_REG_TS0_YEAR 0x36
118#define RTC19_REG_TS0_FLAGS 0x37
119#define RTC19_REG_TS1_SEC_1_128 0x38
120#define RTC19_REG_TS1_SEC 0x39
121#define RTC19_REG_TS1_MIN 0x3A
122#define RTC19_REG_TS1_HOUR 0x3B
123#define RTC19_REG_TS1_DATE 0x3C
124#define RTC19_REG_TS1_MONTH 0x3D
125#define RTC19_REG_TS1_YEAR 0x3E
126#define RTC19_REG_TS1_FLAGS 0x3F
127#define RTC19_REG_TS2_SEC_1_128 0x40
128#define RTC19_REG_TS2_SEC 0x41
129#define RTC19_REG_TS2_MIN 0x42
130#define RTC19_REG_TS2_HOUR 0x43
131#define RTC19_REG_TS2_DATE 0x44
132#define RTC19_REG_TS2_MONTH 0x45
133#define RTC19_REG_TS2_YEAR 0x46
134#define RTC19_REG_TS2_FLAGS 0x47
135#define RTC19_REG_TS3_SEC_1_128 0x48
136#define RTC19_REG_TS3_SEC 0x49
137#define RTC19_REG_TS3_MIN 0x4A
138#define RTC19_REG_TS3_HOUR 0x4B
139#define RTC19_REG_TS3_DATE 0x4C
140#define RTC19_REG_TS3_MONTH 0x4D
141#define RTC19_REG_TS3_YEAR 0x4E
142#define RTC19_REG_TS3_FLAGS 0x4F
143
144 // rtc19_reg
145
160#define RTC19_RTC_RESET_CLEAR 0x00
161#define RTC19_RTC_RESET_SET 0x01
162
167#define RTC19_INT_EN_DOSF 0x40
168#define RTC19_INT_EN_PFAILE 0x20
169#define RTC19_INT_EN_VBATLOWIE 0x10
170#define RTC19_INT_EN_DIE 0x08
171#define RTC19_INT_EN_TIE 0x04
172#define RTC19_INT_EN_A2IE 0x02
173#define RTC19_INT_EN_A1IE 0x01
174
179#define RTC19_TIMER_CONFIG_TE 0x10
180#define RTC19_TIMER_CONFIG_TPAUSE 0x08
181#define RTC19_TIMER_CONFIG_TRPT 0x04
182#define RTC19_TIMER_CONFIG_TFS_1024HZ 0x00
183#define RTC19_TIMER_CONFIG_TFS_256HZ 0x01
184#define RTC19_TIMER_CONFIG_TFS_64HZ 0x02
185#define RTC19_TIMER_CONFIG_TFS_16HZ 0x03
186#define RTC19_TIMER_CONFIG_TFS_MASK 0x03
187
192#define RTC19_TIMER_INIT_16CNT 0x000F
193
198#define RTC19_MONDAY 0x01
199#define RTC19_TUESDAY 0x02
200#define RTC19_WEDNESDAY 0x03
201#define RTC19_THURSDAY 0x04
202#define RTC19_FRIDAY 0x05
203#define RTC19_SATURDAY 0x06
204#define RTC19_SUNDAY 0x07
205
211#define RTC19_DEVICE_ADDRESS 0x68
212
213 // rtc19_set
214
229#define RTC19_MAP_MIKROBUS( cfg, mikrobus ) \
230 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
231 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
232 cfg.psw = MIKROBUS( mikrobus, MIKROBUS_CS ); \
233 cfg.intb = MIKROBUS( mikrobus, MIKROBUS_AN ); \
234 cfg.din = MIKROBUS( mikrobus, MIKROBUS_RST ); \
235 cfg.inta = MIKROBUS( mikrobus, MIKROBUS_INT )
236
237 // rtc19_map
238 // rtc19
239
244typedef struct
245{
246 // Output pins
247 digital_out_t din;
249 // Input pins
250 digital_in_t psw;
251 digital_in_t intb;
252 digital_in_t inta;
254 // Modules
255 i2c_master_t i2c;
257 // I2C slave address
260} rtc19_t;
261
266typedef struct
267{
268 pin_name_t scl;
269 pin_name_t sda;
271 pin_name_t psw;
272 pin_name_t intb;
273 pin_name_t din;
274 pin_name_t inta;
276 uint32_t i2c_speed;
277 uint8_t i2c_address;
280
286typedef struct
287{
288 uint16_t sub_second;
289 uint8_t second;
290 uint8_t minute;
291 uint8_t hour;
292
294
300typedef struct
301{
302 uint8_t day_of_week;
303 uint8_t day;
304 uint8_t month;
305 uint8_t year;
306
308
313typedef enum
314{
316 RTC19_ERROR = -1
317
319
336
350err_t rtc19_init ( rtc19_t *ctx, rtc19_cfg_t *cfg );
351
365
380err_t rtc19_generic_write ( rtc19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
381
396err_t rtc19_generic_read ( rtc19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
397
410err_t rtc19_write_register ( rtc19_t *ctx, uint8_t reg, uint8_t data_in );
411
424err_t rtc19_read_register ( rtc19_t *ctx, uint8_t reg, uint8_t *data_out );
425
435void rtc19_set_din_pin ( rtc19_t *ctx, uint8_t state );
436
445uint8_t rtc19_get_psw_pin ( rtc19_t *ctx );
446
456
466
479err_t rtc19_set_time ( rtc19_t *ctx, rtc19_time_t *time );
480
494
507err_t rtc19_set_date ( rtc19_t *ctx, rtc19_date_t *date );
508
522
534
546
547#ifdef __cplusplus
548}
549#endif
550#endif // RTC19_H
551
552 // rtc19
553
554// ------------------------------------------------------------------------ END
err_t rtc19_default_cfg(rtc19_t *ctx)
RTC 19 default configuration function.
err_t rtc19_clear_interrupts(rtc19_t *ctx)
RTC 19 clear interrupts function.
err_t rtc19_read_register(rtc19_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 19 read register function.
err_t rtc19_write_register(rtc19_t *ctx, uint8_t reg, uint8_t data_in)
RTC 19 write register function.
err_t rtc19_generic_read(rtc19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 19 I2C reading function.
err_t rtc19_read_date(rtc19_t *ctx, rtc19_date_t *date)
RTC 19 read date function.
err_t rtc19_set_time(rtc19_t *ctx, rtc19_time_t *time)
RTC 19 set time function.
err_t rtc19_read_time(rtc19_t *ctx, rtc19_time_t *time)
RTC 19 read time function.
err_t rtc19_reset_device(rtc19_t *ctx)
RTC 19 reset device function.
err_t rtc19_set_date(rtc19_t *ctx, rtc19_date_t *date)
RTC 19 set date function.
err_t rtc19_generic_write(rtc19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 19 I2C writing function.
uint8_t rtc19_get_intb_pin(rtc19_t *ctx)
RTC 19 get intb pin function.
void rtc19_set_din_pin(rtc19_t *ctx, uint8_t state)
RTC 19 set din pin function.
uint8_t rtc19_get_inta_pin(rtc19_t *ctx)
RTC 19 get inta pin function.
err_t rtc19_init(rtc19_t *ctx, rtc19_cfg_t *cfg)
RTC 19 initialization function.
void rtc19_cfg_setup(rtc19_cfg_t *cfg)
RTC 19 configuration object setup function.
uint8_t rtc19_get_psw_pin(rtc19_t *ctx)
RTC 19 get psw pin function.
rtc19_return_value_t
RTC 19 Click return value data.
Definition rtc19.h:314
@ RTC19_ERROR
Definition rtc19.h:316
@ RTC19_OK
Definition rtc19.h:315
RTC 19 Click configuration object.
Definition rtc19.h:267
pin_name_t psw
Definition rtc19.h:271
pin_name_t intb
Definition rtc19.h:272
pin_name_t din
Definition rtc19.h:273
uint32_t i2c_speed
Definition rtc19.h:276
pin_name_t scl
Definition rtc19.h:268
pin_name_t sda
Definition rtc19.h:269
pin_name_t inta
Definition rtc19.h:274
uint8_t i2c_address
Definition rtc19.h:277
RTC 19 Click date object.
Definition rtc19.h:301
uint8_t month
Definition rtc19.h:304
uint8_t day
Definition rtc19.h:303
uint8_t year
Definition rtc19.h:305
uint8_t day_of_week
Definition rtc19.h:302
RTC 19 Click context object.
Definition rtc19.h:245
digital_in_t inta
Definition rtc19.h:252
digital_out_t din
Definition rtc19.h:247
digital_in_t psw
Definition rtc19.h:250
i2c_master_t i2c
Definition rtc19.h:255
uint8_t slave_address
Definition rtc19.h:258
digital_in_t intb
Definition rtc19.h:251
RTC 19 Click time object.
Definition rtc19.h:287
uint8_t second
Definition rtc19.h:289
uint8_t minute
Definition rtc19.h:290
uint16_t sub_second
Definition rtc19.h:288
uint8_t hour
Definition rtc19.h:291