rtc2  2.0.0.0
rtc2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef RTC2_H
36 #define RTC2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define RTC2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define RTC2_RETVAL uint8_t
64 
65 #define RTC2_OK 0x00
66 #define RTC2_INIT_ERROR 0xFF
67 
73 #define RTC2_I2C_ADDRESS 0x68
74 #define RTC2_REG_TIME_SEC 0x00
75 #define RTC2_REG_TIME_MIN 0x01
76 #define RTC2_REG_TIME_HOUR 0x02
77 #define RTC2_REG_TIME_DAY_OF_THE_WEEK 0x03
78 #define RTC2_REG_TIME_DATE_DAY 0x04
79 #define RTC2_REG_TIME_DATE_MONTH 0x05
80 #define RTC2_REG_TIME_DATE_YEAR 0x06
81 #define RTC2_REG_CONTROL 0x07
82 
88 #define RTC2_ENABLE_COUNTING 0x7F
89 #define RTC2_DISABLE_COUNTING 0x80
90 #define RTC2_CONFIG_RATE_LOW 0x00
91 #define RTC2_CONFIG_RATE_HIGH 0x80
92 #define RTC2_CONFIG_RATE_SELECT_1_HZ 0x10
93 #define RTC2_CONFIG_RATE_SELECT_4_096_kHZ 0x11
94 #define RTC2_CONFIG_RATE_SELECT_8_192_kHZ 0x12
95 #define RTC2_CONFIG_RATE_SELECT_32_768_kHZ 0x13
96  // End group macro
99 // --------------------------------------------------------------- PUBLIC TYPES
108 typedef struct
109 {
110  // Output pins
111 
112  // Input pins
113 
114  digital_in_t int_pin;
115 
116  // Modules
117 
118  i2c_master_t i2c;
119 
120  // ctx variable
121 
122  hal_i2c_address_t slave_address;
123 
124 } rtc2_t;
125 
129 typedef struct
130 {
132  uint8_t date_day;
133  uint8_t date_month;
134  uint16_t date_year;
135 } rtc2_data_t;
136 
140 typedef struct
141 {
142  // Communication gpio pins
143 
144  pin_name_t scl;
145  pin_name_t sda;
146 
147  // Additional gpio pins
148 
149  pin_name_t int_pin;
150 
151  // static variable
152 
153  hal_i2c_speed_t i2c_speed;
154  hal_i2c_address_t i2c_address;
155 
156 } rtc2_cfg_t;
157  // End types group
159 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
160 
166 #ifdef __cplusplus
167 extern "C"{
168 #endif
169 
178 void rtc2_cfg_setup ( rtc2_cfg_t *cfg );
179 
187 RTC2_RETVAL rtc2_init ( rtc2_t *ctx, rtc2_cfg_t *cfg );
188 
199 void rtc2_generic_write ( rtc2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
200 
212 void rtc2_generic_read ( rtc2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
213 uint8_t rtc2_read_byte ( rtc2_t *ctx, uint8_t reg_address );
224 
225 void rtc2_write_byte ( rtc2_t *ctx, uint8_t reg_address, uint8_t write_data );
237 void rtc2_enable_counting ( rtc2_t *ctx );
245 void rtc2_disable_counting ( rtc2_t *ctx );
254 uint8_t rtc2_get_time_seconds ( rtc2_t *ctx ) ;
264 void rtc2_set_time_seconds ( rtc2_t *ctx, uint8_t seconds );
275 uint8_t rtc2_get_time_minutes ( rtc2_t *ctx );
285 void rtc2_set_time_minutes ( rtc2_t *ctx, uint8_t minutes );
296 
297 uint8_t rtc2_get_time_hours ( rtc2_t *ctx );
307 void rtc2_set_time_hours ( rtc2_t *ctx, uint8_t hours );
318 uint8_t rtc2_get_day_of_the_week ( rtc2_t *ctx );
328 void rtc2_set_day_of_the_week ( rtc2_t *ctx, uint8_t w_day );
339 uint8_t rtc2_get_date_day ( rtc2_t *ctx );
349 void rtc2_set_date_day ( rtc2_t *ctx, uint8_t date_day );
360 uint8_t rtc2_get_date_month ( rtc2_t *ctx );
370 void rtc2_set_date_month ( rtc2_t *ctx, uint8_t date_month );
381 uint8_t rtc2_get_date_year ( rtc2_t *ctx );
391 void rtc2_set_date_year ( rtc2_t *ctx, uint16_t date_year );
402 void rtc2_set_time ( rtc2_t *ctx, uint8_t time_hours, uint8_t time_minutes, uint8_t time_seconds );
415 void rtc2_get_time ( rtc2_t *ctx, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
427 void rtc2_set_date ( rtc2_t *ctx, rtc2_data_t *date );
438 void rtc2_get_date ( rtc2_t *ctx, rtc2_data_t *date );
449 void rtc2_set_frequency_sqwe ( rtc2_t *ctx, uint8_t rate_select );
459 
460 
461 
462 #ifdef __cplusplus
463 }
464 #endif
465 #endif // _RTC2_H_
466  // End public_function group
469 
470 // ------------------------------------------------------------------------- END
uint8_t rtc2_get_date_day(rtc2_t *ctx)
Get day function.
uint8_t time_hours
Definition: main.c:42
void rtc2_set_frequency_sqwe(rtc2_t *ctx, uint8_t rate_select)
Set frequency of square-wave output function.
uint16_t date_year
Definition: main.c:48
void rtc2_disable_counting(rtc2_t *ctx)
Disable counting function.
pin_name_t sda
Definition: rtc2.h:145
void rtc2_set_time_hours(rtc2_t *ctx, uint8_t hours)
Set hours function.
uint8_t rtc2_get_time_minutes(rtc2_t *ctx)
Get hours function.
hal_i2c_address_t i2c_address
Definition: rtc2.h:154
Click configuration structure definition.
Definition: rtc2.h:140
uint8_t rtc2_get_time_hours(rtc2_t *ctx)
Set hours function.
void rtc2_get_date(rtc2_t *ctx, rtc2_data_t *date)
Generic read function.
void rtc2_set_time(rtc2_t *ctx, uint8_t time_hours, uint8_t time_minutes, uint8_t time_seconds)
Set time hours, minutes and seconds function.
uint8_t rtc2_read_byte(rtc2_t *ctx, uint8_t reg_address)
Generic read byte of data function.
void rtc2_set_date(rtc2_t *ctx, rtc2_data_t *date)
Generic read function.
uint8_t rtc2_get_day_of_the_week(rtc2_t *ctx)
Set day of the week function.
uint8_t day_of_the_week
Definition: rtc2.h:131
uint8_t date_day
Definition: main.c:46
void rtc2_enable_counting(rtc2_t *ctx)
Enable counting function.
void rtc2_set_date_month(rtc2_t *ctx, uint8_t date_month)
Set month function.
uint8_t time_minutes
Definition: main.c:43
pin_name_t scl
Definition: rtc2.h:144
hal_i2c_speed_t i2c_speed
Definition: rtc2.h:153
void rtc2_cfg_setup(rtc2_cfg_t *cfg)
Config Object Initialization function.
uint16_t date_year
Definition: rtc2.h:134
Click ctx object definition.
Definition: rtc2.h:108
uint8_t rtc2_get_time_seconds(rtc2_t *ctx)
Get seconds function.
void rtc2_set_date_day(rtc2_t *ctx, uint8_t date_day)
Set day function.
void rtc2_get_time(rtc2_t *ctx, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds)
Get time hours, minutes and seconds function.
uint8_t rtc2_get_date_month(rtc2_t *ctx)
Get month function.
uint8_t date_day
Definition: rtc2.h:132
i2c_master_t i2c
Definition: rtc2.h:118
uint8_t date_month
Definition: rtc2.h:133
uint8_t date_month
Definition: main.c:47
void rtc2_set_day_of_the_week(rtc2_t *ctx, uint8_t w_day)
Generic read function.
void rtc2_generic_read(rtc2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
#define RTC2_RETVAL
Definition: rtc2.h:63
void rtc2_set_date_year(rtc2_t *ctx, uint16_t date_year)
Set year function.
void rtc2_generic_write(rtc2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
hal_i2c_address_t slave_address
Definition: rtc2.h:122
uint8_t rtc2_get_date_year(rtc2_t *ctx)
Get year function.
Data structure definition.
Definition: rtc2.h:129
void rtc2_set_time_minutes(rtc2_t *ctx, uint8_t minutes)
Set minutes function.
void rtc2_write_byte(rtc2_t *ctx, uint8_t reg_address, uint8_t write_data)
Generic write byte of data function.
RTC2_RETVAL rtc2_init(rtc2_t *ctx, rtc2_cfg_t *cfg)
Initialization function.
uint8_t time_seconds
Definition: main.c:44
void rtc2_set_time_seconds(rtc2_t *ctx, uint8_t seconds)
Set seconds function.
digital_in_t int_pin
Definition: rtc2.h:114
pin_name_t int_pin
Definition: rtc2.h:149