rtc10  2.0.0.0
rtc10.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 RTC10_H
36 #define RTC10_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define RTC10_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define RTC10_RETVAL uint8_t
65 
66 #define RTC10_OK 0x00
67 #define RTC10_INIT_ERROR 0xFF
68 
74 #define RTC10_I2C_SLAVE_ADDRESS 0x68
75 
81 #define RTC10_RTCSEC 0x00
82 #define RTC10_RTCMIN 0x01
83 #define RTC10_RTCHOUR 0x02
84 #define RTC10_RTCWKDAY 0x03
85 #define RTC10_RTCDATE 0x04
86 #define RTC10_RTCMTH 0x05
87 #define RTC10_RTCYEAR 0x06
88 #define RTC10_ALM1SEC 0x07
89 #define RTC10_ALM1MIN 0x08
90 #define RTC10_ALM1HOUR 0x09
91 #define RTC10_ALM1DATE 0x0A
92 #define RTC10_ALM2MIN 0x0B
93 #define RTC10_ALM2HOUR 0x0C
94 #define RTC10_ALM2DATE 0x0D
95 #define RTC10_CONTROL 0x0E
96 #define RTC10_STATUS 0x0F
97 #define RTC10_AGING 0x10
98 #define RTC10_TEMPERATURE_MSB 0x11
99 #define RTC10_TEMPERATURE_LSB 0x12
100 
106 #define RTC10_DISABLE_ALARMS 0x00
107 #define RTC10_ENABLE_ALARM_1 0x01
108 #define RTC10_ENABLE_ALARM_2 0x02
109 #define RTC10_ENABLE_INTERRUPT 0x04
110  // End group macro
113 // --------------------------------------------------------------- PUBLIC TYPES
122 typedef struct
123 {
124  // Output pins
125 
126  digital_out_t rst;
127 
128  // Input pins
129 
130  digital_in_t an;
131  digital_in_t int_pin;
132 
133  // Modules
134 
135  i2c_master_t i2c;
136 
137  // ctx variable
138 
139  uint8_t slave_address;
140 
141 } rtc10_t;
142 
146 typedef struct
147 {
148  // Communication gpio pins
149 
150  pin_name_t scl;
151  pin_name_t sda;
152 
153  // Additional gpio pins
154 
155  pin_name_t an;
156  pin_name_t rst;
157  pin_name_t int_pin;
158 
159  // static variable
160 
161  uint32_t i2c_speed;
162  uint8_t i2c_address;
163 
164 } rtc10_cfg_t;
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
174 #ifdef __cplusplus
175 extern "C"{
176 #endif
177 
186 void rtc10_cfg_setup ( rtc10_cfg_t *cfg );
187 
197 
205 void rtc10_default_cfg ( rtc10_t *ctx );
206 
217 void rtc10_generic_write ( rtc10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
218 
229 void rtc10_generic_read ( rtc10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
230 
241 void rtc10_hw_reset ( rtc10_t *ctx );
242 
250 uint8_t rtc10_check_interrupt ( rtc10_t *ctx );
251 
260 uint8_t rtc10_read_byte ( rtc10_t *ctx, uint8_t reg_address );
261 
271 void rtc10_write_byte ( rtc10_t *ctx, uint8_t reg_address, uint8_t write_data );
272 
281 uint8_t rtc10_get_time_seconds ( rtc10_t *ctx );
282 
292 void rtc10_set_time_seconds ( rtc10_t *ctx, uint8_t seconds );
293 
302 uint8_t rtc10_get_time_minutes ( rtc10_t *ctx );
303 
313 void rtc10_set_time_minutes ( rtc10_t *ctx, uint8_t minutes );
314 
323 uint8_t rtc10_get_century_flag ( rtc10_t *ctx );
324 
333 void rtc10_set_century_flag ( rtc10_t *ctx );
334 
343 uint8_t rtc10_get_time_hours ( rtc10_t *ctx );
344 
354 void rtc10_set_time_hours( rtc10_t *ctx, uint8_t hours );
355 
364 uint8_t rtc10_get_day_of_the_week ( rtc10_t *ctx );
365 
382 void rtc10_set_day_of_the_week ( rtc10_t *ctx, uint8_t w_day );
383 
392 uint8_t rtc10_get_date_day ( rtc10_t *ctx );
393 
403 void rtc10_set_date_day ( rtc10_t *ctx, uint8_t date_day );
404 
413 uint8_t rtc10_get_date_month ( rtc10_t *ctx );
414 
424 void rtc10_set_date_month( rtc10_t *ctx, uint8_t date_month );
425 
434 uint8_t rtc10_get_date_year ( rtc10_t *ctx );
435 
445 void rtc10_set_date_year ( rtc10_t *ctx, uint16_t date_year );
446 
459 void rtc10_set_time ( rtc10_t *ctx, uint8_t time_hours, uint8_t time_minutes, uint8_t time_seconds );
460 
473 void rtc10_get_time ( rtc10_t *ctx, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
474 
488 void rtc10_set_date( rtc10_t *ctx, uint8_t day_of_the_week, uint8_t date_day, uint8_t date_month, uint16_t date_year );
489 
503 void rtc10_get_date( rtc10_t *ctx, uint8_t *day_of_the_week, uint8_t *date_day, uint8_t *date_month, uint8_t *date_year );
504 
513 uint8_t rtc10_get_alarm_time_seconds ( rtc10_t *ctx );
514 
524 void rtc10_set_alarm_time_seconds ( rtc10_t *ctx, uint8_t seconds );
525 
534 uint8_t rtc10_get_alarm_time_minutes ( rtc10_t *ctx );
535 
545 void rtc10_set_alarm_time_minutes( rtc10_t *ctx, uint8_t minutes );
546 
555 uint8_t rtc10_get_alarm_time_hours ( rtc10_t *ctx );
556 
566 void rtc10_set_alarm_time_hours ( rtc10_t *ctx, uint8_t hours );
567 
576 uint8_t rtc10_get_alarm_date_day ( rtc10_t *ctx );
577 
587 void rtc10_set_alarm_date_day ( rtc10_t *ctx, uint8_t date_day );
588 
602 void rtc10_set_first_alarm ( rtc10_t *ctx, uint8_t time_days, uint8_t time_hours, uint8_t time_minutes, uint8_t time_seconds );
603 
617 void rtc10_get_first_alarm ( rtc10_t *ctx, uint8_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
618 
632 void rtc10_set_second_alarm( rtc10_t *ctx, uint8_t time_days, uint8_t time_hours, uint8_t time_minutes );
633 
647 void rtc10_get_second_alarm ( rtc10_t *ctx, uint8_t *time_days, uint8_t *time_hours, uint8_t *time_minutes );
648 
658 void rtc10_enable_counting ( rtc10_t *ctx );
659 
701 void rtc10_set_config( rtc10_t *ctx, uint8_t config_data );
702 
746 uint8_t rtc10_get_status ( rtc10_t *ctx );
747 
757 float rtc10_get_temperature ( rtc10_t *ctx );
758 
759 
760 
761 #ifdef __cplusplus
762 }
763 #endif
764 #endif // _RTC10_H_
765  // End public_function group
768 
769 // ------------------------------------------------------------------------- END
uint8_t rtc10_get_date_month(rtc10_t *ctx)
Get month function.
void rtc10_generic_write(rtc10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t slave_address
Definition: rtc10.h:139
void rtc10_enable_counting(rtc10_t *ctx)
Enable counting function.
void rtc10_get_date(rtc10_t *ctx, uint8_t *day_of_the_week, uint8_t *date_day, uint8_t *date_month, uint8_t *date_year)
Get time hours, minutes and seconds function.
void rtc10_default_cfg(rtc10_t *ctx)
Click Default Configuration function.
uint32_t i2c_speed
Definition: rtc10.h:161
pin_name_t rst
Definition: rtc10.h:156
Click configuration structure definition.
Definition: rtc10.h:146
digital_in_t int_pin
Definition: rtc10.h:131
void rtc10_get_second_alarm(rtc10_t *ctx, uint8_t *time_days, uint8_t *time_hours, uint8_t *time_minutes)
Set Alarm 2 time: hours, minutes and seconds function.
void rtc10_set_alarm_date_day(rtc10_t *ctx, uint8_t date_day)
Set alarm days function.
uint8_t rtc10_get_date_day(rtc10_t *ctx)
Get date function.
pin_name_t an
Definition: rtc10.h:155
void rtc10_set_alarm_time_minutes(rtc10_t *ctx, uint8_t minutes)
Set alarm time seconds function.
uint8_t rtc10_get_date_year(rtc10_t *ctx)
Get year function.
uint8_t i2c_address
Definition: rtc10.h:162
uint8_t rtc10_get_alarm_date_day(rtc10_t *ctx)
Get alarm days function.
void rtc10_set_date(rtc10_t *ctx, uint8_t day_of_the_week, uint8_t date_day, uint8_t date_month, uint16_t date_year)
Set date hours, minutes and seconds function.
uint8_t rtc10_get_day_of_the_week(rtc10_t *ctx)
Get day of the week function.
float rtc10_get_temperature(rtc10_t *ctx)
Get temperature function.
void rtc10_set_time_hours(rtc10_t *ctx, uint8_t hours)
Set hours function.
void rtc10_set_time(rtc10_t *ctx, uint8_t time_hours, uint8_t time_minutes, uint8_t time_seconds)
Set time: hours, minutes and seconds function.
i2c_master_t i2c
Definition: rtc10.h:135
void rtc10_set_date_year(rtc10_t *ctx, uint16_t date_year)
Set month function.
void rtc10_set_alarm_time_seconds(rtc10_t *ctx, uint8_t seconds)
Set alarm time seconds function.
uint8_t rtc10_get_time_hours(rtc10_t *ctx)
Get hours function.
uint8_t rtc10_get_alarm_time_hours(rtc10_t *ctx)
Get alarm time hours function.
Click ctx object definition.
Definition: rtc10.h:122
uint8_t rtc10_get_alarm_time_minutes(rtc10_t *ctx)
Get alarm time minutes function.
uint8_t rtc10_read_byte(rtc10_t *ctx, uint8_t reg_address)
Generic read function.
void rtc10_get_first_alarm(rtc10_t *ctx, uint8_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds)
Get Alarm 1 time hours, minutes and seconds function.
void rtc10_get_time(rtc10_t *ctx, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds)
Get time hours, minutes and seconds function.
digital_out_t rst
Definition: rtc10.h:126
void rtc10_set_time_minutes(rtc10_t *ctx, uint8_t minutes)
Generic read function.
uint8_t rtc10_check_interrupt(rtc10_t *ctx)
Check the state of interrupt function.
RTC10_RETVAL rtc10_init(rtc10_t *ctx, rtc10_cfg_t *cfg)
Initialization function.
pin_name_t sda
Definition: rtc10.h:151
uint8_t rtc10_get_alarm_time_seconds(rtc10_t *ctx)
Get alarm time seconds function.
void rtc10_set_first_alarm(rtc10_t *ctx, uint8_t time_days, uint8_t time_hours, uint8_t time_minutes, uint8_t time_seconds)
Set Alarm 1 time: hours, minutes and seconds function.
uint8_t rtc10_get_time_seconds(rtc10_t *ctx)
Get seconds function.
void rtc10_generic_read(rtc10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void rtc10_set_time_seconds(rtc10_t *ctx, uint8_t seconds)
Generic read function.
void rtc10_write_byte(rtc10_t *ctx, uint8_t reg_address, uint8_t write_data)
Generic read function.
uint8_t rtc10_get_status(rtc10_t *ctx)
Get configuration status function.
digital_in_t an
Definition: rtc10.h:130
void rtc10_set_century_flag(rtc10_t *ctx)
Set century flag function.
void rtc10_set_second_alarm(rtc10_t *ctx, uint8_t time_days, uint8_t time_hours, uint8_t time_minutes)
Set Alarm 2 time: hours, minutes and seconds function.
pin_name_t scl
Definition: rtc10.h:150
void rtc10_set_day_of_the_week(rtc10_t *ctx, uint8_t w_day)
Set day of the week function.
uint8_t rtc10_get_century_flag(rtc10_t *ctx)
Get century flag function.
#define RTC10_RETVAL
Definition: rtc10.h:64
void rtc10_set_config(rtc10_t *ctx, uint8_t config_data)
Set configuration function.
void rtc10_set_date_day(rtc10_t *ctx, uint8_t date_day)
Set date function.
uint8_t rtc10_get_time_minutes(rtc10_t *ctx)
Get seconds function.
pin_name_t int_pin
Definition: rtc10.h:157
void rtc10_set_date_month(rtc10_t *ctx, uint8_t date_month)
Set month function.
void rtc10_set_alarm_time_hours(rtc10_t *ctx, uint8_t hours)
Set alarm time seconds function.
void rtc10_cfg_setup(rtc10_cfg_t *cfg)
Config Object Initialization function.
void rtc10_hw_reset(rtc10_t *ctx)
Hardware reset function.