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  */
32 // ----------------------------------------------------------------------------
33 
34 #ifndef RTC10_H
35 #define RTC10_H
36 
37 #include "drv_digital_out.h"
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define RTC10_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define RTC10_RETVAL uint8_t
64 
65 #define RTC10_OK 0x00
66 #define RTC10_INIT_ERROR 0xFF
67 
73 #define RTC10_I2C_SLAVE_ADDRESS 0x68
74 
80 #define RTC10_RTCSEC 0x00
81 #define RTC10_RTCMIN 0x01
82 #define RTC10_RTCHOUR 0x02
83 #define RTC10_RTCWKDAY 0x03
84 #define RTC10_RTCDATE 0x04
85 #define RTC10_RTCMTH 0x05
86 #define RTC10_RTCYEAR 0x06
87 #define RTC10_ALM1SEC 0x07
88 #define RTC10_ALM1MIN 0x08
89 #define RTC10_ALM1HOUR 0x09
90 #define RTC10_ALM1DATE 0x0A
91 #define RTC10_ALM2MIN 0x0B
92 #define RTC10_ALM2HOUR 0x0C
93 #define RTC10_ALM2DATE 0x0D
94 #define RTC10_CONTROL 0x0E
95 #define RTC10_STATUS 0x0F
96 #define RTC10_AGING 0x10
97 #define RTC10_TEMPERATURE_MSB 0x11
98 #define RTC10_TEMPERATURE_LSB 0x12
99 
105 #define RTC10_DISABLE_ALARMS 0x00
106 #define RTC10_ENABLE_ALARM_1 0x01
107 #define RTC10_ENABLE_ALARM_2 0x02
108 #define RTC10_ENABLE_INTERRUPT 0x04
109  // End group macro
112 // --------------------------------------------------------------- PUBLIC TYPES
121 typedef struct
122 {
123  // Output pins
124 
125  digital_out_t rst;
126 
127  // Input pins
128 
129  digital_in_t an;
130  digital_in_t int_pin;
131 
132  // Modules
133 
134  i2c_master_t i2c;
135 
136  // ctx variable
137 
138  uint8_t slave_address;
139 
140 } rtc10_t;
141 
145 typedef struct
146 {
147  // Communication gpio pins
148 
149  pin_name_t scl;
150  pin_name_t sda;
151 
152  // Additional gpio pins
153 
154  pin_name_t an;
155  pin_name_t rst;
156  pin_name_t int_pin;
157 
158  // static variable
159 
160  uint32_t i2c_speed;
161  uint8_t i2c_address;
162 
163 } rtc10_cfg_t;
164  // End types group
166 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
167 
173 #ifdef __cplusplus
174 extern "C"{
175 #endif
176 
185 void rtc10_cfg_setup ( rtc10_cfg_t *cfg );
186 
196 
204 void rtc10_default_cfg ( rtc10_t *ctx );
205 
216 void rtc10_generic_write ( rtc10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
217 
228 void rtc10_generic_read ( rtc10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
229 
240 void rtc10_hw_reset ( rtc10_t *ctx );
241 
249 uint8_t rtc10_check_interrupt ( rtc10_t *ctx );
250 
259 uint8_t rtc10_read_byte ( rtc10_t *ctx, uint8_t reg_address );
260 
270 void rtc10_write_byte ( rtc10_t *ctx, uint8_t reg_address, uint8_t write_data );
271 
280 uint8_t rtc10_get_time_seconds ( rtc10_t *ctx );
281 
291 void rtc10_set_time_seconds ( rtc10_t *ctx, uint8_t seconds );
292 
301 uint8_t rtc10_get_time_minutes ( rtc10_t *ctx );
302 
312 void rtc10_set_time_minutes ( rtc10_t *ctx, uint8_t minutes );
313 
322 uint8_t rtc10_get_century_flag ( rtc10_t *ctx );
323 
332 void rtc10_set_century_flag ( rtc10_t *ctx );
333 
342 uint8_t rtc10_get_time_hours ( rtc10_t *ctx );
343 
353 void rtc10_set_time_hours( rtc10_t *ctx, uint8_t hours );
354 
363 uint8_t rtc10_get_day_of_the_week ( rtc10_t *ctx );
364 
381 void rtc10_set_day_of_the_week ( rtc10_t *ctx, uint8_t w_day );
382 
391 uint8_t rtc10_get_date_day ( rtc10_t *ctx );
392 
402 void rtc10_set_date_day ( rtc10_t *ctx, uint8_t date_day );
403 
412 uint8_t rtc10_get_date_month ( rtc10_t *ctx );
413 
423 void rtc10_set_date_month( rtc10_t *ctx, uint8_t date_month );
424 
433 uint8_t rtc10_get_date_year ( rtc10_t *ctx );
434 
444 void rtc10_set_date_year ( rtc10_t *ctx, uint16_t date_year );
445 
458 void rtc10_set_time ( rtc10_t *ctx, uint8_t time_hours, uint8_t time_minutes, uint8_t time_seconds );
459 
472 void rtc10_get_time ( rtc10_t *ctx, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
473 
487 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 );
488 
502 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 );
503 
512 uint8_t rtc10_get_alarm_time_seconds ( rtc10_t *ctx );
513 
523 void rtc10_set_alarm_time_seconds ( rtc10_t *ctx, uint8_t seconds );
524 
533 uint8_t rtc10_get_alarm_time_minutes ( rtc10_t *ctx );
534 
544 void rtc10_set_alarm_time_minutes( rtc10_t *ctx, uint8_t minutes );
545 
554 uint8_t rtc10_get_alarm_time_hours ( rtc10_t *ctx );
555 
565 void rtc10_set_alarm_time_hours ( rtc10_t *ctx, uint8_t hours );
566 
575 uint8_t rtc10_get_alarm_date_day ( rtc10_t *ctx );
576 
586 void rtc10_set_alarm_date_day ( rtc10_t *ctx, uint8_t date_day );
587 
601 void rtc10_set_first_alarm ( rtc10_t *ctx, uint8_t time_days, uint8_t time_hours, uint8_t time_minutes, uint8_t time_seconds );
602 
616 void rtc10_get_first_alarm ( rtc10_t *ctx, uint8_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
617 
631 void rtc10_set_second_alarm( rtc10_t *ctx, uint8_t time_days, uint8_t time_hours, uint8_t time_minutes );
632 
646 void rtc10_get_second_alarm ( rtc10_t *ctx, uint8_t *time_days, uint8_t *time_hours, uint8_t *time_minutes );
647 
657 void rtc10_enable_counting ( rtc10_t *ctx );
658 
700 void rtc10_set_config( rtc10_t *ctx, uint8_t config_data );
701 
745 uint8_t rtc10_get_status ( rtc10_t *ctx );
746 
756 float rtc10_get_temperature ( rtc10_t *ctx );
757 
758 
759 
760 #ifdef __cplusplus
761 }
762 #endif
763 #endif // _RTC10_H_
764  // End public_function group
767 
768 // ------------------------------------------------------------------------- END
rtc10_cfg_t::an
pin_name_t an
Definition: rtc10.h:154
rtc10_get_date_year
uint8_t rtc10_get_date_year(rtc10_t *ctx)
Get year function.
rtc10_set_alarm_time_seconds
void rtc10_set_alarm_time_seconds(rtc10_t *ctx, uint8_t seconds)
Set alarm time seconds function.
rtc10_get_date
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.
rtc10_hw_reset
void rtc10_hw_reset(rtc10_t *ctx)
Hardware reset function.
rtc10_generic_read
void rtc10_generic_read(rtc10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
rtc10_init
RTC10_RETVAL rtc10_init(rtc10_t *ctx, rtc10_cfg_t *cfg)
Initialization function.
rtc10_set_day_of_the_week
void rtc10_set_day_of_the_week(rtc10_t *ctx, uint8_t w_day)
Set day of the week function.
rtc10_set_time_minutes
void rtc10_set_time_minutes(rtc10_t *ctx, uint8_t minutes)
Generic read function.
rtc10_get_alarm_time_hours
uint8_t rtc10_get_alarm_time_hours(rtc10_t *ctx)
Get alarm time hours function.
rtc10_get_date_month
uint8_t rtc10_get_date_month(rtc10_t *ctx)
Get month function.
rtc10_t::an
digital_in_t an
Definition: rtc10.h:129
rtc10_set_time_hours
void rtc10_set_time_hours(rtc10_t *ctx, uint8_t hours)
Set hours function.
rtc10_get_time_seconds
uint8_t rtc10_get_time_seconds(rtc10_t *ctx)
Get seconds function.
rtc10_generic_write
void rtc10_generic_write(rtc10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
rtc10_default_cfg
void rtc10_default_cfg(rtc10_t *ctx)
Click Default Configuration function.
rtc10_cfg_t::sda
pin_name_t sda
Definition: rtc10.h:150
rtc10_t
Click ctx object definition.
Definition: rtc10.h:121
rtc10_cfg_t::i2c_address
uint8_t i2c_address
Definition: rtc10.h:161
rtc10_get_time_hours
uint8_t rtc10_get_time_hours(rtc10_t *ctx)
Get hours function.
rtc10_set_date_year
void rtc10_set_date_year(rtc10_t *ctx, uint16_t date_year)
Set month function.
rtc10_get_day_of_the_week
uint8_t rtc10_get_day_of_the_week(rtc10_t *ctx)
Get day of the week function.
rtc10_get_date_day
uint8_t rtc10_get_date_day(rtc10_t *ctx)
Get date function.
rtc10_t::i2c
i2c_master_t i2c
Definition: rtc10.h:134
rtc10_get_alarm_time_seconds
uint8_t rtc10_get_alarm_time_seconds(rtc10_t *ctx)
Get alarm time seconds function.
rtc10_t::int_pin
digital_in_t int_pin
Definition: rtc10.h:130
rtc10_cfg_setup
void rtc10_cfg_setup(rtc10_cfg_t *cfg)
Config Object Initialization function.
rtc10_set_alarm_time_hours
void rtc10_set_alarm_time_hours(rtc10_t *ctx, uint8_t hours)
Set alarm time seconds function.
rtc10_set_second_alarm
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.
rtc10_get_second_alarm
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.
rtc10_set_time
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.
rtc10_get_century_flag
uint8_t rtc10_get_century_flag(rtc10_t *ctx)
Get century flag function.
rtc10_get_first_alarm
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.
rtc10_set_date
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.
rtc10_set_first_alarm
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.
rtc10_cfg_t::rst
pin_name_t rst
Definition: rtc10.h:155
rtc10_enable_counting
void rtc10_enable_counting(rtc10_t *ctx)
Enable counting function.
rtc10_write_byte
void rtc10_write_byte(rtc10_t *ctx, uint8_t reg_address, uint8_t write_data)
Generic read function.
rtc10_t::rst
digital_out_t rst
Definition: rtc10.h:125
rtc10_cfg_t
Click configuration structure definition.
Definition: rtc10.h:145
rtc10_get_time_minutes
uint8_t rtc10_get_time_minutes(rtc10_t *ctx)
Get seconds function.
rtc10_set_century_flag
void rtc10_set_century_flag(rtc10_t *ctx)
Set century flag function.
rtc10_check_interrupt
uint8_t rtc10_check_interrupt(rtc10_t *ctx)
Check the state of interrupt function.
rtc10_get_time
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.
rtc10_get_temperature
float rtc10_get_temperature(rtc10_t *ctx)
Get temperature function.
rtc10_get_alarm_date_day
uint8_t rtc10_get_alarm_date_day(rtc10_t *ctx)
Get alarm days function.
rtc10_cfg_t::int_pin
pin_name_t int_pin
Definition: rtc10.h:156
rtc10_cfg_t::scl
pin_name_t scl
Definition: rtc10.h:149
rtc10_set_config
void rtc10_set_config(rtc10_t *ctx, uint8_t config_data)
Set configuration function.
rtc10_get_alarm_time_minutes
uint8_t rtc10_get_alarm_time_minutes(rtc10_t *ctx)
Get alarm time minutes function.
rtc10_set_date_month
void rtc10_set_date_month(rtc10_t *ctx, uint8_t date_month)
Set month function.
rtc10_set_alarm_date_day
void rtc10_set_alarm_date_day(rtc10_t *ctx, uint8_t date_day)
Set alarm days function.
rtc10_read_byte
uint8_t rtc10_read_byte(rtc10_t *ctx, uint8_t reg_address)
Generic read function.
rtc10_set_date_day
void rtc10_set_date_day(rtc10_t *ctx, uint8_t date_day)
Set date function.
rtc10_set_alarm_time_minutes
void rtc10_set_alarm_time_minutes(rtc10_t *ctx, uint8_t minutes)
Set alarm time seconds function.
rtc10_set_time_seconds
void rtc10_set_time_seconds(rtc10_t *ctx, uint8_t seconds)
Generic read function.
RTC10_RETVAL
#define RTC10_RETVAL
Definition: rtc10.h:63
rtc10_get_status
uint8_t rtc10_get_status(rtc10_t *ctx)
Get configuration status function.
rtc10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc10.h:160
rtc10_t::slave_address
uint8_t slave_address
Definition: rtc10.h:138