rtc10  2.0.0.0
rtc10.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 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 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define RTC10_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
59 
65 #define RTC10_RETVAL uint8_t
66 
67 #define RTC10_OK 0x00
68 #define RTC10_INIT_ERROR 0xFF
69 
75 #define RTC10_I2C_SLAVE_ADDRESS 0x68
76 
82 #define RTC10_RTCSEC 0x00
83 #define RTC10_RTCMIN 0x01
84 #define RTC10_RTCHOUR 0x02
85 #define RTC10_RTCWKDAY 0x03
86 #define RTC10_RTCDATE 0x04
87 #define RTC10_RTCMTH 0x05
88 #define RTC10_RTCYEAR 0x06
89 #define RTC10_ALM1SEC 0x07
90 #define RTC10_ALM1MIN 0x08
91 #define RTC10_ALM1HOUR 0x09
92 #define RTC10_ALM1DATE 0x0A
93 #define RTC10_ALM2MIN 0x0B
94 #define RTC10_ALM2HOUR 0x0C
95 #define RTC10_ALM2DATE 0x0D
96 #define RTC10_CONTROL 0x0E
97 #define RTC10_STATUS 0x0F
98 #define RTC10_AGING 0x10
99 #define RTC10_TEMPERATURE_MSB 0x11
100 #define RTC10_TEMPERATURE_LSB 0x12
101 
107 #define RTC10_DISABLE_ALARMS 0x00
108 #define RTC10_ENABLE_ALARM_1 0x01
109 #define RTC10_ENABLE_ALARM_2 0x02
110 #define RTC10_ENABLE_INTERRUPT 0x04
111  // End group macro
114 // --------------------------------------------------------------- PUBLIC TYPES
123 typedef struct
124 {
125  // Output pins
126 
127  digital_out_t rst;
128 
129  // Input pins
130 
131  digital_in_t an;
132  digital_in_t int_pin;
133 
134  // Modules
135 
136  i2c_master_t i2c;
137 
138  // ctx variable
139 
140  hal_i2c_address_t slave_address;
141 
142 } rtc10_t;
143 
147 typedef struct
148 {
149  // Communication gpio pins
150 
151  pin_name_t scl;
152  pin_name_t sda;
153 
154  // Additional gpio pins
155 
156  pin_name_t an;
157  pin_name_t rst;
158  pin_name_t int_pin;
159 
160  // static variable
161 
162  hal_i2c_speed_t i2c_speed;
163  hal_i2c_address_t i2c_address;
164 
165 } rtc10_cfg_t;
166  // End types group
168 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
169 
175 #ifdef __cplusplus
176 extern "C"{
177 #endif
178 
187 void rtc10_cfg_setup ( rtc10_cfg_t *cfg );
188 
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 
230 void rtc10_generic_read ( rtc10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
231 
243 void rtc10_hw_reset ( rtc10_t *ctx );
244 
253 uint8_t rtc10_check_interrupt ( rtc10_t *ctx );
254 
264 uint8_t rtc10_read_byte ( rtc10_t *ctx, uint8_t reg_address );
265 
276 void rtc10_write_byte ( rtc10_t *ctx, uint8_t reg_address, uint8_t write_data );
277 
287 uint8_t rtc10_get_time_seconds ( rtc10_t *ctx );
288 
299 void rtc10_set_time_seconds ( rtc10_t *ctx, uint8_t seconds );
300 
310 uint8_t rtc10_get_time_minutes ( rtc10_t *ctx );
311 
322 void rtc10_set_time_minutes ( rtc10_t *ctx, uint8_t minutes );
323 
333 uint8_t rtc10_get_century_flag ( rtc10_t *ctx );
334 
344 void rtc10_set_century_flag ( rtc10_t *ctx );
345 
355 uint8_t rtc10_get_time_hours ( rtc10_t *ctx );
356 
367 void rtc10_set_time_hours( rtc10_t *ctx, uint8_t hours );
368 
378 uint8_t rtc10_get_day_of_the_week ( rtc10_t *ctx );
379 
397 void rtc10_set_day_of_the_week ( rtc10_t *ctx, uint8_t w_day );
398 
408 uint8_t rtc10_get_date_day ( rtc10_t *ctx );
409 
420 void rtc10_set_date_day ( rtc10_t *ctx, uint8_t date_day );
421 
431 uint8_t rtc10_get_date_month ( rtc10_t *ctx );
432 
443 void rtc10_set_date_month( rtc10_t *ctx, uint8_t date_month );
444 
454 uint8_t rtc10_get_date_year ( rtc10_t *ctx );
455 
466 void rtc10_set_date_year ( rtc10_t *ctx, uint16_t date_year );
467 
481 void rtc10_set_time ( rtc10_t *ctx, uint8_t time_hours, uint8_t time_minutes, uint8_t time_seconds );
482 
496 void rtc10_get_time ( rtc10_t *ctx, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
497 
512 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 );
513 
528 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 );
529 
539 uint8_t rtc10_get_alarm_time_seconds ( rtc10_t *ctx );
540 
551 void rtc10_set_alarm_time_seconds ( rtc10_t *ctx, uint8_t seconds );
552 
562 uint8_t rtc10_get_alarm_time_minutes ( rtc10_t *ctx );
563 
574 void rtc10_set_alarm_time_minutes( rtc10_t *ctx, uint8_t minutes );
575 
585 uint8_t rtc10_get_alarm_time_hours ( rtc10_t *ctx );
586 
597 void rtc10_set_alarm_time_hours ( rtc10_t *ctx, uint8_t hours );
598 
608 uint8_t rtc10_get_alarm_date_day ( rtc10_t *ctx );
609 
620 void rtc10_set_alarm_date_day ( rtc10_t *ctx, uint8_t date_day );
621 
636 void rtc10_set_first_alarm ( rtc10_t *ctx, uint8_t time_days, uint8_t time_hours, uint8_t time_minutes, uint8_t time_seconds );
637 
652 void rtc10_get_first_alarm ( rtc10_t *ctx, uint8_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
653 
668 void rtc10_set_second_alarm( rtc10_t *ctx, uint8_t time_days, uint8_t time_hours, uint8_t time_minutes );
669 
684 void rtc10_get_second_alarm ( rtc10_t *ctx, uint8_t *time_days, uint8_t *time_hours, uint8_t *time_minutes );
685 
696 void rtc10_enable_counting ( rtc10_t *ctx );
697 
740 void rtc10_set_config( rtc10_t *ctx, uint8_t config_data );
741 
786 uint8_t rtc10_get_status ( rtc10_t *ctx );
787 
798 float rtc10_get_temperature ( rtc10_t *ctx );
799 
800 
801 
802 #ifdef __cplusplus
803 }
804 #endif
805 #endif // _RTC10_H_
806  // End public_function group
809 
810 // ------------------------------------------------------------------------- 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.
void rtc10_enable_counting(rtc10_t *ctx)
Enable counting function.
hal_i2c_speed_t i2c_speed
Definition: rtc10.h:162
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.
pin_name_t rst
Definition: rtc10.h:157
Click configuration structure definition.
Definition: rtc10.h:147
digital_in_t int_pin
Definition: rtc10.h:132
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.
hal_i2c_address_t i2c_address
Definition: rtc10.h:163
uint8_t rtc10_get_date_day(rtc10_t *ctx)
Get date function.
pin_name_t an
Definition: rtc10.h:156
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 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:136
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:123
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:127
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:152
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:131
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:151
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:65
void rtc10_set_config(rtc10_t *ctx, uint8_t config_data)
Set configuration function.
hal_i2c_address_t slave_address
Definition: rtc10.h:140
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:158
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.