rtc 2.0.0.0
rtc.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 RTC_C_H
36#define RTC_C_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define RTC_C_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
77#define RTC_C_OK 0
78#define RTC_C_ERROR -1
85#define RTC_C_I2C_ADDRESS_0 0x50
86#define RTC_C_I2C_ADDRESS_1 0x51
93#define RTC_C_REG_CONTROL 0x00
94#define RTC_C_REG_TIME_HUN_SEC 0x01
95#define RTC_C_REG_TIME_SEC 0x02
96#define RTC_C_REG_TIME_MIN 0x03
97#define RTC_C_REG_TIME_HOUR 0x04
98#define RTC_C_REG_TIME_DATE_DAY_AND_YEAR 0x05
99#define RTC_C_REG_TIME_DAY_OF_THE_WEEK_AND_MONTH 0x06
100#define RTC_C_REG_TIMER 0x07
101#define RTC_C_REG_TIME_ALARM_CONTROL 0x08
102#define RTC_C_REG_TIME_ALARM_HUN_SEC 0x09
103#define RTC_C_REG_TIME_ALARM_SEC 0x0A
104#define RTC_C_REG_TIME_ALARM_MIN 0x0B
105#define RTC_C_REG_TIME_ALARM_HOUR 0x0C
106#define RTC_C_REG_TIME_ALARM_DATE_DAY_AND_YEAR 0x0D
107#define RTC_C_REG_TIME_ALARM_DAY_OF_THE_WEEK_AND_MONTH 0x0E
108#define RTC_C_REG_TIME_ALARM_TIMER 0x0F
111 // End group macro
112// --------------------------------------------------------------- PUBLIC TYPES
121typedef struct
122{
124 uint8_t date_day;
125 uint8_t date_month;
126 uint16_t date_year;
127
129
133typedef struct
134{
135 uint8_t time_hours;
139
141
145typedef struct
146{
147 // Input pins
148 digital_in_t int_pin;
149
150 // Modules
151 i2c_master_t i2c;
152
153 // I2C slave address
156 // time and date data
159
160} rtc_c_t;
161
165typedef struct
166{
167 // Communication gpio pins
168 pin_name_t scl;
169 pin_name_t sda;
170
171 // Additional gpio pins
172 pin_name_t int_pin;
173
174 // static variable
175 uint32_t i2c_speed;
176 uint8_t i2c_address;
179
180
181
182 // End types group
183// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
184
190#ifdef __cplusplus
191extern "C"{
192#endif
193
203
211err_t rtc_c_init ( rtc_c_t *ctx, rtc_c_cfg_t *cfg );
212
227err_t rtc_c_generic_write ( rtc_c_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
228
243err_t rtc_c_generic_read ( rtc_c_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
244
253void rtc_c_enable_disable_counting ( rtc_c_t *ctx, uint8_t en_dis );
254
264
274
287uint8_t rtc_c_get_time_value ( rtc_c_t *ctx, uint8_t time_part );
288
299void rtc_c_set_time_value ( rtc_c_t *ctx, uint8_t time_part, uint8_t time_addr );
300
312
322void rtc_c_set_date_day ( rtc_c_t *ctx, uint8_t date_day );
323
335
345void rtc_c_set_date_year ( rtc_c_t *ctx, uint16_t date_year );
346
362
374
393void rtc_c_set_day_of_the_week ( rtc_c_t *ctx, uint8_t w_day );
394
406
416void rtc_c_set_date_month ( rtc_c_t *ctx, uint8_t date_month );
417
427
437
447
457
467void rtc_c_enable_disable_alarm ( rtc_c_t *ctx, uint8_t en_dis );
468
479void rtc_c_set_alarm_value ( rtc_c_t *ctx, uint8_t al_time_val, uint8_t al_time_type );
480
493uint8_t rtc_c_get_alarm_value ( rtc_c_t *ctx, uint8_t alarm_addr );
494
504
514
524void rtc_c_enable_disable_interrupt( rtc_c_t *ctx, uint8_t flag );
525
539
540#ifdef __cplusplus
541}
542#endif
543#endif // _RTC_C_H_
544
545 // End public_function group
547
548// ------------------------------------------------------------------------- END
void rtc_c_set_date(rtc_c_t *ctx)
Set date hours, minutes and seconds function.
uint8_t rtc_c_get_date_year(rtc_c_t *ctx)
Get year function.
void rtc_c_set_time(rtc_c_t *ctx)
Set time hours, minutes, seconds and hundredth of a seconds function.
void rtc_c_set_day_of_the_week(rtc_c_t *ctx, uint8_t w_day)
Set day of the week function.
void rtc_c_set_time_alarm(rtc_c_t *ctx)
Set alarm time - minutes function.
uint8_t rtc_c_get_date_day(rtc_c_t *ctx)
Get day function.
void rtc_c_get_time_alarm(rtc_c_t *ctx)
Get the alarm time hours, minutes, seconds and hundredth of a seconds function.
err_t rtc_c_generic_read(rtc_c_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC I2C reading function.
void rtc_c_set_date_day(rtc_c_t *ctx, uint8_t date_day)
Set day function.
void rtc_c_read_time(rtc_c_t *ctx)
Set control register to read time function.
uint8_t rtc_c_get_day_of_the_week(rtc_c_t *ctx)
Get day of the week function.
uint8_t rtc_c_get_interrupt(rtc_c_t *ctx)
Get state of interrupt pin function.
uint8_t rtc_c_check_leap_year(rtc_c_t *ctx)
Check if it's a leap year function.
uint8_t rtc_c_get_date_month(rtc_c_t *ctx)
Get month function.
void rtc_c_set_date_month(rtc_c_t *ctx, uint8_t date_month)
Set month function.
void rtc_c_enable_disable_counting(rtc_c_t *ctx, uint8_t en_dis)
Enable/Disable counting function.
err_t rtc_c_init(rtc_c_t *ctx, rtc_c_cfg_t *cfg)
Initialization function.
void rtc_c_set_alarm_value(rtc_c_t *ctx, uint8_t al_time_val, uint8_t al_time_type)
Set alarm time value.
void rtc_c_enable_disable_alarm(rtc_c_t *ctx, uint8_t en_dis)
Enable/Disable alarm function.
void rtc_c_read_date(rtc_c_t *ctx)
Set control register to read date function.
void rtc_c_set_time_value(rtc_c_t *ctx, uint8_t time_part, uint8_t time_addr)
Set time values function.
void rtc_c_cfg_setup(rtc_c_cfg_t *cfg)
Config Object Initialization function.
uint8_t rtc_c_get_time_value(rtc_c_t *ctx, uint8_t time_part)
Get time value function.
err_t rtc_c_generic_write(rtc_c_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC I2C writing function.
void rtc_c_get_date(rtc_c_t *ctx)
Get time hours, minutes and seconds function.
uint8_t rtc_c_get_alarm_value(rtc_c_t *ctx, uint8_t alarm_addr)
Get alarm time value function.
void rtc_c_enable_disable_interrupt(rtc_c_t *ctx, uint8_t flag)
Enable alarm interrupt function.
void rtc_c_get_time(rtc_c_t *ctx)
Get time hours, minutes, seconds and hundredth of a seconds function.
void rtc_c_set_date_year(rtc_c_t *ctx, uint16_t date_year)
Set year function.
Click configuration structure definition.
Definition rtc.h:166
uint32_t i2c_speed
Definition rtc.h:175
pin_name_t scl
Definition rtc.h:168
pin_name_t int_pin
Definition rtc.h:172
pin_name_t sda
Definition rtc.h:169
uint8_t i2c_address
Definition rtc.h:176
Date data structure.
Definition rtc.h:122
uint8_t date_month
Definition rtc.h:125
uint16_t date_year
Definition rtc.h:126
uint8_t day_of_the_week
Definition rtc.h:123
uint8_t date_day
Definition rtc.h:124
Click ctx object definition.
Definition rtc.h:146
rtc_c_date_t date
Definition rtc.h:157
digital_in_t int_pin
Definition rtc.h:148
i2c_master_t i2c
Definition rtc.h:151
uint8_t slave_address
Definition rtc.h:154
rtc_c_time_t time
Definition rtc.h:158
Time data structure.
Definition rtc.h:134
uint8_t time_hours
Definition rtc.h:135
int8_t time_hun_sec
Definition rtc.h:138
uint8_t time_minutes
Definition rtc.h:136
uint8_t time_seconds
Definition rtc.h:137