rtc3 2.0.0.0
rtc3.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef RTC3_H
36#define RTC3_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define RTC3_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define RTC3_I2C_ADDRESS 0x68
83#define RTC3_REG_TIME_SEC 0x00
84#define RTC3_REG_TIME_MIN 0x01
85#define RTC3_REG_TIME_HOUR 0x02
86#define RTC3_REG_TIME_DAY_OF_THE_WEEK 0x03
87#define RTC3_REG_TIME_DATE_DAY 0x04
88#define RTC3_REG_TIME_DATE_MONTH 0x05
89#define RTC3_REG_TIME_DATE_YEAR 0x06
90#define RTC3_REG_CONFIG1 0x07
91#define RTC3_REG_TRICKLE_CHARGE2 0x08
92#define RTC3_REG_CONFIG2 0x09
93#define RTC3_REG_SF_KEY1 0x20
94#define RTC3_REG_SF_KEY2 0x21
95#define RTC3_REG_SFR 0x22
102#define RTC3_ENABLE_COUNTING 0x7F
103#define RTC3_DISABLE_COUNTING 0x80
104#define RTC3_CONFIG1_INITIAL 0x80
105#define RTC3_TCH2_OPEN 0x00
106#define RTC3_TCH2_CLOSED 0x20
107#define RTC3_TCFE_OPEN 0x00
108#define RTC3_TCFE_CLOSED 0x20
109#define RTC3_FTF_NORMAL_512_HZ 0x00
110#define RTC3_FTF_1_HZ 0x01
117#define RTC3_OK 0
118#define RTC3_ERROR -1
121 // End group macro
122// --------------------------------------------------------------- PUBLIC TYPES
131typedef struct
132{
134 uint8_t date_day;
135 uint8_t date_month;
136 uint8_t date_year;
137
139
143typedef struct
144{
145 uint8_t time_hours;
148
150
154typedef struct
155{
156 // Input pins
157 digital_in_t int_pin;
158
159 // Modules
160 i2c_master_t i2c;
161
162 // ctx variable
164
165 // time and date data
168
169} rtc3_t;
170
174typedef struct
175{
176 // Communication gpio pins
177 pin_name_t scl;
178 pin_name_t sda;
179
180 // Additional gpio pins
181 pin_name_t int_pin;
182
183 // static variable
184 uint32_t i2c_speed;
185 uint8_t i2c_address;
186
187} rtc3_cfg_t;
188
189 // End types group
190// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
191
197#ifdef __cplusplus
198extern "C"{
199#endif
200
210
219err_t rtc3_init ( rtc3_t *ctx, rtc3_cfg_t *cfg );
220
231void rtc3_generic_write ( rtc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
232
243void rtc3_generic_read ( rtc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
244
252void rtc3_set_counting ( rtc3_t *ctx, uint8_t en_dis );
253
262void rtc3_set_time ( rtc3_t *ctx );
263
272void rtc3_get_time ( rtc3_t *ctx );
273
282void rtc3_set_date ( rtc3_t *ctx );
283
292void rtc3_get_date ( rtc3_t *ctx );
293
310void rtc3_set_calibration ( rtc3_t *ctx, uint8_t cal_sign, uint8_t cal_mumber );
311
327void rtc3_set_trickle_charge ( rtc3_t *ctx, uint8_t tch2 );
328
343void rtc3_set_trickle_charge_bypass ( rtc3_t *ctx, uint8_t tcfe );
344
358void rtc3_set_special_function_key1 ( rtc3_t *ctx, uint8_t sfkey1 );
359
373void rtc3_set_special_function_key2 ( rtc3_t *ctx, uint8_t sfkey2 );
374
394void rtc3_set_frequency_calibration ( rtc3_t *ctx, uint8_t ftf );
395
409
410#ifdef __cplusplus
411}
412#endif
413#endif // _RTC3_H_
414
415 // End public_function group
417
418// ------------------------------------------------------------------------- END
void rtc3_set_counting(rtc3_t *ctx, uint8_t en_dis)
Enable/Disable counting function.
void rtc3_set_time(rtc3_t *ctx)
Set time hours, minutes, seconds function.
void rtc3_set_frequency_calibration(rtc3_t *ctx, uint8_t ftf)
Set frequency calibration control function.
uint8_t rtc3_get_interrupt(rtc3_t *ctx)
Get state of interrupt pin function.
void rtc3_set_trickle_charge_bypass(rtc3_t *ctx, uint8_t tcfe)
Set trickle charge bypass control function.
err_t rtc3_init(rtc3_t *ctx, rtc3_cfg_t *cfg)
Initialization function.
void rtc3_set_date(rtc3_t *ctx)
Set day of the week, day, month and year function.
void rtc3_set_calibration(rtc3_t *ctx, uint8_t cal_sign, uint8_t cal_mumber)
Set calibration function.
void rtc3_get_time(rtc3_t *ctx)
Get time hours, minutes, seconds function.
void rtc3_set_trickle_charge(rtc3_t *ctx, uint8_t tch2)
Set trickle charge control function.
void rtc3_generic_write(rtc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void rtc3_set_special_function_key1(rtc3_t *ctx, uint8_t sfkey1)
Set special function key byte 1 function.
void rtc3_generic_read(rtc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void rtc3_get_date(rtc3_t *ctx)
Get day of the week, day, month and year function.
void rtc3_set_special_function_key2(rtc3_t *ctx, uint8_t sfkey2)
Set special function key byte 2 function.
void rtc3_cfg_setup(rtc3_cfg_t *cfg)
Config Object Initialization function.
Date data structure.
Definition rtc3.h:132
uint8_t date_month
Definition rtc3.h:135
uint8_t day_of_the_week
Definition rtc3.h:133
uint8_t date_day
Definition rtc3.h:134
uint8_t date_year
Definition rtc3.h:136
Click configuration structure definition.
Definition rtc3.h:175
uint32_t i2c_speed
Definition rtc3.h:184
pin_name_t scl
Definition rtc3.h:177
pin_name_t int_pin
Definition rtc3.h:181
pin_name_t sda
Definition rtc3.h:178
uint8_t i2c_address
Definition rtc3.h:185
Click ctx object definition.
Definition rtc3.h:155
time_data_t time
Definition rtc3.h:167
date_data_t date
Definition rtc3.h:166
digital_in_t int_pin
Definition rtc3.h:157
i2c_master_t i2c
Definition rtc3.h:160
uint8_t slave_address
Definition rtc3.h:163
Time data structure.
Definition rtc3.h:144
uint8_t time_hours
Definition rtc3.h:145
uint8_t time_minutes
Definition rtc3.h:146
uint8_t time_seconds
Definition rtc3.h:147