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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define RTC19_REG_STATUS 0x00
60 #define RTC19_REG_INT_EN 0x01
61 #define RTC19_REG_RTC_RESET 0x02
62 #define RTC19_REG_RTC_CONFIG1 0x03
63 #define RTC19_REG_RTC_CONFIG2 0x04
64 #define RTC19_REG_TIMESTAMP_CONFIG 0x05
65 #define RTC19_REG_TIMER_CONFIG 0x06
66 #define RTC19_REG_SLEEP_CONFIG 0x07
67 #define RTC19_REG_SECONDS_1_128 0x08
68 #define RTC19_REG_SECONDS 0x09
69 #define RTC19_REG_MINUTES 0x0A
70 #define RTC19_REG_HOURS 0x0B
71 #define RTC19_REG_DAY 0x0C
72 #define RTC19_REG_DATE 0x0D
73 #define RTC19_REG_MONTH 0x0E
74 #define RTC19_REG_YEAR 0x0F
75 #define RTC19_REG_ALM1_SEC 0x10
76 #define RTC19_REG_ALM1_MIN 0x11
77 #define RTC19_REG_ALM1_HRS 0x12
78 #define RTC19_REG_ALM1_DAY_DATE 0x13
79 #define RTC19_REG_ALM1_MON 0x14
80 #define RTC19_REG_ALM1_YEAR 0x15
81 #define RTC19_REG_ALM2_MIN 0x16
82 #define RTC19_REG_ALM2_HRS 0x17
83 #define RTC19_REG_ALM2_DAY_DATE 0x18
84 #define RTC19_REG_TIMER_COUNT2 0x19
85 #define RTC19_REG_TIMER_COUNT1 0x1A
86 #define RTC19_REG_TIMER_INIT2 0x1B
87 #define RTC19_REG_TIMER_INIT1 0x1C
88 #define RTC19_REG_PWR_MGMT 0x1D
89 #define RTC19_REG_TRICKLE_REG 0x1E
90 #define RTC19_REG_OFFSET_HIGH 0x20
91 #define RTC19_REG_OFFSET_LOW 0x21
92 
97 #define RTC19_REG_TS0_SEC_1_128 0x30
98 #define RTC19_REG_TS0_SEC 0x31
99 #define RTC19_REG_TS0_MIN 0x32
100 #define RTC19_REG_TS0_HOUR 0x33
101 #define RTC19_REG_TS0_DATE 0x34
102 #define RTC19_REG_TS0_MONTH 0x35
103 #define RTC19_REG_TS0_YEAR 0x36
104 #define RTC19_REG_TS0_FLAGS 0x37
105 #define RTC19_REG_TS1_SEC_1_128 0x38
106 #define RTC19_REG_TS1_SEC 0x39
107 #define RTC19_REG_TS1_MIN 0x3A
108 #define RTC19_REG_TS1_HOUR 0x3B
109 #define RTC19_REG_TS1_DATE 0x3C
110 #define RTC19_REG_TS1_MONTH 0x3D
111 #define RTC19_REG_TS1_YEAR 0x3E
112 #define RTC19_REG_TS1_FLAGS 0x3F
113 #define RTC19_REG_TS2_SEC_1_128 0x40
114 #define RTC19_REG_TS2_SEC 0x41
115 #define RTC19_REG_TS2_MIN 0x42
116 #define RTC19_REG_TS2_HOUR 0x43
117 #define RTC19_REG_TS2_DATE 0x44
118 #define RTC19_REG_TS2_MONTH 0x45
119 #define RTC19_REG_TS2_YEAR 0x46
120 #define RTC19_REG_TS2_FLAGS 0x47
121 #define RTC19_REG_TS3_SEC_1_128 0x48
122 #define RTC19_REG_TS3_SEC 0x49
123 #define RTC19_REG_TS3_MIN 0x4A
124 #define RTC19_REG_TS3_HOUR 0x4B
125 #define RTC19_REG_TS3_DATE 0x4C
126 #define RTC19_REG_TS3_MONTH 0x4D
127 #define RTC19_REG_TS3_YEAR 0x4E
128 #define RTC19_REG_TS3_FLAGS 0x4F
129  // rtc19_reg
131 
146 #define RTC19_RTC_RESET_CLEAR 0x00
147 #define RTC19_RTC_RESET_SET 0x01
148 
153 #define RTC19_INT_EN_DOSF 0x40
154 #define RTC19_INT_EN_PFAILE 0x20
155 #define RTC19_INT_EN_VBATLOWIE 0x10
156 #define RTC19_INT_EN_DIE 0x08
157 #define RTC19_INT_EN_TIE 0x04
158 #define RTC19_INT_EN_A2IE 0x02
159 #define RTC19_INT_EN_A1IE 0x01
160 
165 #define RTC19_TIMER_CONFIG_TE 0x10
166 #define RTC19_TIMER_CONFIG_TPAUSE 0x08
167 #define RTC19_TIMER_CONFIG_TRPT 0x04
168 #define RTC19_TIMER_CONFIG_TFS_1024HZ 0x00
169 #define RTC19_TIMER_CONFIG_TFS_256HZ 0x01
170 #define RTC19_TIMER_CONFIG_TFS_64HZ 0x02
171 #define RTC19_TIMER_CONFIG_TFS_16HZ 0x03
172 #define RTC19_TIMER_CONFIG_TFS_MASK 0x03
173 
178 #define RTC19_TIMER_INIT_16CNT 0x000F
179 
184 #define RTC19_MONDAY 0x01
185 #define RTC19_TUESDAY 0x02
186 #define RTC19_WEDNESDAY 0x03
187 #define RTC19_THURSDAY 0x04
188 #define RTC19_FRIDAY 0x05
189 #define RTC19_SATURDAY 0x06
190 #define RTC19_SUNDAY 0x07
191 
197 #define RTC19_DEVICE_ADDRESS 0x68
198  // rtc19_set
200 
215 #define RTC19_MAP_MIKROBUS( cfg, mikrobus ) \
216  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
217  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
218  cfg.psw = MIKROBUS( mikrobus, MIKROBUS_CS ); \
219  cfg.intb = MIKROBUS( mikrobus, MIKROBUS_AN ); \
220  cfg.din = MIKROBUS( mikrobus, MIKROBUS_RST ); \
221  cfg.inta = MIKROBUS( mikrobus, MIKROBUS_INT )
222  // rtc19_map // rtc19
225 
230 typedef struct
231 {
232  // Output pins
233  digital_out_t din;
235  // Input pins
236  digital_in_t psw;
237  digital_in_t intb;
238  digital_in_t inta;
240  // Modules
241  i2c_master_t i2c;
243  // I2C slave address
244  uint8_t slave_address;
246 } rtc19_t;
247 
252 typedef struct
253 {
254  pin_name_t scl;
255  pin_name_t sda;
257  pin_name_t psw;
258  pin_name_t intb;
259  pin_name_t din;
260  pin_name_t inta;
262  uint32_t i2c_speed;
263  uint8_t i2c_address;
265 } rtc19_cfg_t;
266 
272 typedef struct
273 {
274  uint16_t sub_second;
275  uint8_t second;
276  uint8_t minute;
277  uint8_t hour;
278 
279 } rtc19_time_t;
280 
286 typedef struct
287 {
288  uint8_t day_of_week;
289  uint8_t day;
290  uint8_t month;
291  uint8_t year;
292 
293 } rtc19_date_t;
294 
299 typedef enum
300 {
301  RTC19_OK = 0,
302  RTC19_ERROR = -1
303 
305 
322 
336 err_t rtc19_init ( rtc19_t *ctx, rtc19_cfg_t *cfg );
337 
350 err_t rtc19_default_cfg ( rtc19_t *ctx );
351 
366 err_t rtc19_generic_write ( rtc19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
367 
382 err_t rtc19_generic_read ( rtc19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
383 
396 err_t rtc19_write_register ( rtc19_t *ctx, uint8_t reg, uint8_t data_in );
397 
410 err_t rtc19_read_register ( rtc19_t *ctx, uint8_t reg, uint8_t *data_out );
411 
421 void rtc19_set_din_pin ( rtc19_t *ctx, uint8_t state );
422 
431 uint8_t rtc19_get_psw_pin ( rtc19_t *ctx );
432 
441 uint8_t rtc19_get_inta_pin ( rtc19_t *ctx );
442 
451 uint8_t rtc19_get_intb_pin ( rtc19_t *ctx );
452 
465 err_t rtc19_set_time ( rtc19_t *ctx, rtc19_time_t *time );
466 
479 err_t rtc19_read_time ( rtc19_t *ctx, rtc19_time_t *time );
480 
493 err_t rtc19_set_date ( rtc19_t *ctx, rtc19_date_t *date );
494 
507 err_t rtc19_read_date ( rtc19_t *ctx, rtc19_date_t *date );
508 
520 
532 
533 #ifdef __cplusplus
534 }
535 #endif
536 #endif // RTC19_H
537  // rtc19
539 
540 // ------------------------------------------------------------------------ END
rtc19_t::slave_address
uint8_t slave_address
Definition: rtc19.h:244
rtc19_init
err_t rtc19_init(rtc19_t *ctx, rtc19_cfg_t *cfg)
RTC 19 initialization function.
rtc19_time_t::sub_second
uint16_t sub_second
Definition: rtc19.h:274
rtc19_time_t::second
uint8_t second
Definition: rtc19.h:275
rtc19_t::inta
digital_in_t inta
Definition: rtc19.h:238
rtc19_t::psw
digital_in_t psw
Definition: rtc19.h:236
rtc19_date_t::day_of_week
uint8_t day_of_week
Definition: rtc19.h:288
rtc19_cfg_t::i2c_address
uint8_t i2c_address
Definition: rtc19.h:263
rtc19_t::intb
digital_in_t intb
Definition: rtc19.h:237
rtc19_cfg_setup
void rtc19_cfg_setup(rtc19_cfg_t *cfg)
RTC 19 configuration object setup function.
rtc19_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc19.h:262
rtc19_read_register
err_t rtc19_read_register(rtc19_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 19 read register function.
rtc19_clear_interrupts
err_t rtc19_clear_interrupts(rtc19_t *ctx)
RTC 19 clear interrupts function.
rtc19_t::i2c
i2c_master_t i2c
Definition: rtc19.h:241
rtc19_cfg_t::inta
pin_name_t inta
Definition: rtc19.h:260
rtc19_set_date
err_t rtc19_set_date(rtc19_t *ctx, rtc19_date_t *date)
RTC 19 set date function.
rtc19_set_din_pin
void rtc19_set_din_pin(rtc19_t *ctx, uint8_t state)
RTC 19 set din pin function.
rtc19_date_t::day
uint8_t day
Definition: rtc19.h:289
rtc19_read_date
err_t rtc19_read_date(rtc19_t *ctx, rtc19_date_t *date)
RTC 19 read date function.
rtc19_generic_write
err_t rtc19_generic_write(rtc19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 19 I2C writing function.
rtc19_date_t::month
uint8_t month
Definition: rtc19.h:290
rtc19_cfg_t::din
pin_name_t din
Definition: rtc19.h:259
rtc19_time_t
RTC 19 Click time object.
Definition: rtc19.h:273
RTC19_ERROR
@ RTC19_ERROR
Definition: rtc19.h:302
rtc19_cfg_t::psw
pin_name_t psw
Definition: rtc19.h:257
rtc19_get_intb_pin
uint8_t rtc19_get_intb_pin(rtc19_t *ctx)
RTC 19 get intb pin function.
rtc19_cfg_t::sda
pin_name_t sda
Definition: rtc19.h:255
rtc19_return_value_t
rtc19_return_value_t
RTC 19 Click return value data.
Definition: rtc19.h:300
RTC19_OK
@ RTC19_OK
Definition: rtc19.h:301
rtc19_date_t::year
uint8_t year
Definition: rtc19.h:291
rtc19_default_cfg
err_t rtc19_default_cfg(rtc19_t *ctx)
RTC 19 default configuration function.
rtc19_t
RTC 19 Click context object.
Definition: rtc19.h:231
rtc19_date_t
RTC 19 Click date object.
Definition: rtc19.h:287
rtc19_reset_device
err_t rtc19_reset_device(rtc19_t *ctx)
RTC 19 reset device function.
rtc19_cfg_t::scl
pin_name_t scl
Definition: rtc19.h:254
rtc19_t::din
digital_out_t din
Definition: rtc19.h:233
rtc19_set_time
err_t rtc19_set_time(rtc19_t *ctx, rtc19_time_t *time)
RTC 19 set time function.
rtc19_cfg_t::intb
pin_name_t intb
Definition: rtc19.h:258
rtc19_cfg_t
RTC 19 Click configuration object.
Definition: rtc19.h:253
rtc19_read_time
err_t rtc19_read_time(rtc19_t *ctx, rtc19_time_t *time)
RTC 19 read time function.
rtc19_get_inta_pin
uint8_t rtc19_get_inta_pin(rtc19_t *ctx)
RTC 19 get inta pin function.
rtc19_get_psw_pin
uint8_t rtc19_get_psw_pin(rtc19_t *ctx)
RTC 19 get psw pin function.
rtc19_time_t::minute
uint8_t minute
Definition: rtc19.h:276
rtc19_generic_read
err_t rtc19_generic_read(rtc19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 19 I2C reading function.
rtc19_time_t::hour
uint8_t hour
Definition: rtc19.h:277
rtc19_write_register
err_t rtc19_write_register(rtc19_t *ctx, uint8_t reg, uint8_t data_in)
RTC 19 write register function.