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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define RTC3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define RTC3_I2C_ADDRESS 0x68
73 
79 #define RTC3_REG_TIME_SEC 0x00
80 #define RTC3_REG_TIME_MIN 0x01
81 #define RTC3_REG_TIME_HOUR 0x02
82 #define RTC3_REG_TIME_DAY_OF_THE_WEEK 0x03
83 #define RTC3_REG_TIME_DATE_DAY 0x04
84 #define RTC3_REG_TIME_DATE_MONTH 0x05
85 #define RTC3_REG_TIME_DATE_YEAR 0x06
86 #define RTC3_REG_CONFIG1 0x07
87 #define RTC3_REG_TRICKLE_CHARGE2 0x08
88 #define RTC3_REG_CONFIG2 0x09
89 #define RTC3_REG_SF_KEY1 0x20
90 #define RTC3_REG_SF_KEY2 0x21
91 #define RTC3_REG_SFR 0x22
92 
98 #define RTC3_ENABLE_COUNTING 0x7F
99 #define RTC3_DISABLE_COUNTING 0x80
100 #define RTC3_CONFIG1_INITIAL 0x80
101 #define RTC3_TCH2_OPEN 0x00
102 #define RTC3_TCH2_CLOSED 0x20
103 #define RTC3_TCFE_OPEN 0x00
104 #define RTC3_TCFE_CLOSED 0x20
105 #define RTC3_FTF_NORMAL_512_HZ 0x00
106 #define RTC3_FTF_1_HZ 0x01
107 
113 #define RTC3_OK 0
114 #define RTC3_ERROR -1
115  // End group macro
118 // --------------------------------------------------------------- PUBLIC TYPES
127 typedef struct
128 {
130  uint8_t date_day;
131  uint8_t date_month;
132  uint8_t date_year;
133 
134 } date_data_t;
135 
139 typedef struct
140 {
141  uint8_t time_hours;
142  uint8_t time_minutes;
143  uint8_t time_seconds;
144 
145 } time_data_t;
146 
150 typedef struct
151 {
152  // Input pins
153  digital_in_t int_pin;
154 
155  // Modules
156  i2c_master_t i2c;
157 
158  // ctx variable
159  uint8_t slave_address;
160 
161  // time and date data
164 
165 } rtc3_t;
166 
170 typedef struct
171 {
172  // Communication gpio pins
173  pin_name_t scl;
174  pin_name_t sda;
175 
176  // Additional gpio pins
177  pin_name_t int_pin;
178 
179  // static variable
180  uint32_t i2c_speed;
181  uint8_t i2c_address;
182 
183 } rtc3_cfg_t;
184  // End types group
186 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
187 
193 #ifdef __cplusplus
194 extern "C"{
195 #endif
196 
206 
215 err_t rtc3_init ( rtc3_t *ctx, rtc3_cfg_t *cfg );
216 
227 void rtc3_generic_write ( rtc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
228 
239 void rtc3_generic_read ( rtc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
240 
248 void rtc3_set_counting ( rtc3_t *ctx, uint8_t en_dis );
249 
258 void rtc3_set_time ( rtc3_t *ctx );
259 
268 void rtc3_get_time ( rtc3_t *ctx );
269 
278 void rtc3_set_date ( rtc3_t *ctx );
279 
288 void rtc3_get_date ( rtc3_t *ctx );
289 
306 void rtc3_set_calibration ( rtc3_t *ctx, uint8_t cal_sign, uint8_t cal_mumber );
307 
323 void rtc3_set_trickle_charge ( rtc3_t *ctx, uint8_t tch2 );
324 
339 void rtc3_set_trickle_charge_bypass ( rtc3_t *ctx, uint8_t tcfe );
340 
354 void rtc3_set_special_function_key1 ( rtc3_t *ctx, uint8_t sfkey1 );
355 
369 void rtc3_set_special_function_key2 ( rtc3_t *ctx, uint8_t sfkey2 );
370 
390 void rtc3_set_frequency_calibration ( rtc3_t *ctx, uint8_t ftf );
391 
404 uint8_t rtc3_get_interrupt( rtc3_t *ctx );
405 
406 #ifdef __cplusplus
407 }
408 #endif
409 #endif // _RTC3_H_
410  // End public_function group
413 
414 // ------------------------------------------------------------------------- END
rtc3_get_interrupt
uint8_t rtc3_get_interrupt(rtc3_t *ctx)
Get state of interrupt pin function.
rtc3_get_date
void rtc3_get_date(rtc3_t *ctx)
Get day of the week, day, month and year function.
time_data_t
Time data structure.
Definition: rtc3.h:140
rtc3_cfg_t::int_pin
pin_name_t int_pin
Definition: rtc3.h:177
time_data_t::time_seconds
uint8_t time_seconds
Definition: rtc3.h:143
rtc3_set_calibration
void rtc3_set_calibration(rtc3_t *ctx, uint8_t cal_sign, uint8_t cal_mumber)
Set calibration function.
time_data_t::time_minutes
uint8_t time_minutes
Definition: rtc3.h:142
rtc3_get_time
void rtc3_get_time(rtc3_t *ctx)
Get time hours, minutes, seconds function.
rtc3_t::slave_address
uint8_t slave_address
Definition: rtc3.h:159
rtc3_cfg_t::scl
pin_name_t scl
Definition: rtc3.h:173
rtc3_cfg_setup
void rtc3_cfg_setup(rtc3_cfg_t *cfg)
Config Object Initialization function.
rtc3_set_counting
void rtc3_set_counting(rtc3_t *ctx, uint8_t en_dis)
Enable/Disable counting function.
date_data_t
Date data structure.
Definition: rtc3.h:128
date_data_t::date_year
uint8_t date_year
Definition: rtc3.h:132
rtc3_t::int_pin
digital_in_t int_pin
Definition: rtc3.h:153
date_data_t::day_of_the_week
uint8_t day_of_the_week
Definition: rtc3.h:129
rtc3_set_special_function_key2
void rtc3_set_special_function_key2(rtc3_t *ctx, uint8_t sfkey2)
Set special function key byte 2 function.
rtc3_t::i2c
i2c_master_t i2c
Definition: rtc3.h:156
rtc3_cfg_t
Click configuration structure definition.
Definition: rtc3.h:171
rtc3_generic_read
void rtc3_generic_read(rtc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
rtc3_set_trickle_charge_bypass
void rtc3_set_trickle_charge_bypass(rtc3_t *ctx, uint8_t tcfe)
Set trickle charge bypass control function.
rtc3_set_time
void rtc3_set_time(rtc3_t *ctx)
Set time hours, minutes, seconds function.
rtc3_set_trickle_charge
void rtc3_set_trickle_charge(rtc3_t *ctx, uint8_t tch2)
Set trickle charge control function.
time_data_t::time_hours
uint8_t time_hours
Definition: rtc3.h:141
rtc3_generic_write
void rtc3_generic_write(rtc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
rtc3_set_frequency_calibration
void rtc3_set_frequency_calibration(rtc3_t *ctx, uint8_t ftf)
Set frequency calibration control function.
rtc3_set_special_function_key1
void rtc3_set_special_function_key1(rtc3_t *ctx, uint8_t sfkey1)
Set special function key byte 1 function.
rtc3_set_date
void rtc3_set_date(rtc3_t *ctx)
Set day of the week, day, month and year function.
rtc3_cfg_t::i2c_address
uint8_t i2c_address
Definition: rtc3.h:181
rtc3_t::time
time_data_t time
Definition: rtc3.h:163
date_data_t::date_day
uint8_t date_day
Definition: rtc3.h:130
date_data_t::date_month
uint8_t date_month
Definition: rtc3.h:131
rtc3_init
err_t rtc3_init(rtc3_t *ctx, rtc3_cfg_t *cfg)
Initialization function.
rtc3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc3.h:180
rtc3_cfg_t::sda
pin_name_t sda
Definition: rtc3.h:174
rtc3_t::date
date_data_t date
Definition: rtc3.h:162
rtc3_t
Click ctx object definition.
Definition: rtc3.h:151