rtc4  2.0.0.0
rtc4.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef RTC4_H
29 #define RTC4_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_one_wire.h"
38 
59 #define RTC4_CMD_READ_CLOCK 0x66
60 #define RTC4_CMD_WRITE_CLOCK 0x99
61  // rtc4_cmd
63 
78 #define RTC4_SEC_PER_MINUTE 60
79 #define RTC4_SEC_PER_HOUR 3600
80 #define RTC4_SEC_PER_DAY 86400
81 #define RTC4_START_YEAR 1970
82 #define RTC4_DAYS_PER_LEAP_YEAR 366
83 #define RTC4_DAYS_PER_YEAR 365
84 #define RTC4_DAYS_IN_FEB 29
85  // rtc4_time
87 
102 #define RTC4_DCB_INT_ENABLE 0x80
103 #define RTC4_DCB_OSC_ENABLE 0x0C
104 #define RTC4_DCB_INTERVAL_1S 0x00
105 #define RTC4_DCB_INTERVAL_4S 0x10
106 #define RTC4_DCB_INTERVAL_32S 0x20
107 #define RTC4_DCB_INTERVAL_64S 0x30
108 #define RTC4_DCB_INTERVAL_2048S 0x40
109 #define RTC4_DCB_INTERVAL_4096S 0x50
110 #define RTC4_DCB_INTERVAL_65536S 0x60
111 #define RTC4_DCB_INTERVAL_131072S 0x70
112 
117 #define RTC4_FAMILY_CODE 0x27
118  // rtc4_set
120 
135 #define RTC4_MAP_MIKROBUS( cfg, mikrobus ) \
136  cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
137  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
138  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
139  // rtc4_map
141  // rtc4
143 
148 typedef struct
149 {
150  uint32_t hours;
151  uint32_t min;
152  uint32_t sec;
153 
154 } rtc4_time_t;
155 
160 typedef struct
161 {
162  uint32_t year;
163  uint32_t month;
164  uint32_t day;
165 
166 } rtc4_date_t;
167 
172 typedef enum
173 {
175  RTC4_GPIO_1
178 
183 typedef struct
184 {
185  //Input pins
186  digital_in_t int_pin;
188  //Modules
189  one_wire_t ow;
191  one_wire_rom_address_t rom_addr;
192  uint8_t address;
194 } rtc4_t;
195 
200 typedef struct
201 {
202  // Communication gpio pins
203  pin_name_t gp0;
204  pin_name_t gp1;
206  // Additional gpio pins
207  pin_name_t int_pin;
211 } rtc4_cfg_t;
212 
217 typedef enum
218 {
219  RTC4_OK = 0,
220  RTC4_ERROR = -1
221 
223 
240 
256 
268 err_t rtc4_init ( rtc4_t *ctx, rtc4_cfg_t *cfg );
269 
282 
292 uint8_t rtc4_get_interrupt ( rtc4_t *ctx );
293 
305 err_t rtc4_set_unix_and_int ( rtc4_t *ctx, uint32_t unix_time, uint8_t int_interval );
306 
319 err_t rtc4_get_unix_time ( rtc4_t *ctx, uint32_t *unix_time );
320 
332 void rtc4_unix_to_date_time ( uint32_t unix_time, rtc4_time_t *time, rtc4_date_t *date );
333 
345 void rtc4_date_time_to_unix ( rtc4_date_t *date, rtc4_time_t *time, uint32_t *unix_time );
346 
360 err_t rtc4_set_date_time ( rtc4_t *ctx, rtc4_date_t *date, rtc4_time_t *time, uint8_t int_interval );
361 
375 
376 #ifdef __cplusplus
377 }
378 #endif
379 #endif // RTC4_H
380  // rtc4
382 
383 // ------------------------------------------------------------------------ END
rtc4_cfg_setup
void rtc4_cfg_setup(rtc4_cfg_t *cfg)
RTC 4 configuration object setup function.
rtc4_cfg_t::gp0
pin_name_t gp0
Definition: rtc4.h:203
rtc4_gpio_sel_t
rtc4_gpio_sel_t
RTC 4 Click gpio selector.
Definition: rtc4.h:173
rtc4_date_t::day
uint32_t day
Definition: rtc4.h:164
rtc4_time_t::sec
uint32_t sec
Definition: rtc4.h:152
rtc4_init
err_t rtc4_init(rtc4_t *ctx, rtc4_cfg_t *cfg)
RTC 4 initialization function.
rtc4_set_unix_and_int
err_t rtc4_set_unix_and_int(rtc4_t *ctx, uint32_t unix_time, uint8_t int_interval)
RTC 4 set unix and interrupt interval function.
rtc4_time_t
RTC 4 Click time object.
Definition: rtc4.h:149
rtc4_cfg_t::int_pin
pin_name_t int_pin
Definition: rtc4.h:207
rtc4_get_interrupt
uint8_t rtc4_get_interrupt(rtc4_t *ctx)
RTC 4 get interrupt function.
rtc4_unix_to_date_time
void rtc4_unix_to_date_time(uint32_t unix_time, rtc4_time_t *time, rtc4_date_t *date)
RTC 4 unix to date time function.
time
rtc4_time_t time
Definition: main.c:30
rtc4_check_communication
err_t rtc4_check_communication(rtc4_t *ctx)
RTC 4 check communication function.
rtc4_set_date_time
err_t rtc4_set_date_time(rtc4_t *ctx, rtc4_date_t *date, rtc4_time_t *time, uint8_t int_interval)
RTC 4 set date time function.
rtc4_cfg_t::gp1
pin_name_t gp1
Definition: rtc4.h:204
rtc4_get_unix_time
err_t rtc4_get_unix_time(rtc4_t *ctx, uint32_t *unix_time)
RTC 4 get unix time function.
rtc4_t::address
uint8_t address
Definition: rtc4.h:192
rtc4_time_t::min
uint32_t min
Definition: rtc4.h:151
RTC4_GPIO_0
@ RTC4_GPIO_0
Definition: rtc4.h:174
rtc4_cfg_t
RTC 4 Click configuration object.
Definition: rtc4.h:201
rtc4_date_t::month
uint32_t month
Definition: rtc4.h:163
RTC4_ERROR
@ RTC4_ERROR
Definition: rtc4.h:220
RTC4_GPIO_1
@ RTC4_GPIO_1
Definition: rtc4.h:175
RTC4_OK
@ RTC4_OK
Definition: rtc4.h:219
rtc4_date_t
RTC 4 Click date object.
Definition: rtc4.h:161
rtc4_cfg_t::gpio_sel
rtc4_gpio_sel_t gpio_sel
Definition: rtc4.h:209
rtc4_return_value_t
rtc4_return_value_t
RTC 4 Click return value data.
Definition: rtc4.h:218
date
rtc4_date_t date
Definition: main.c:31
rtc4_get_date_time
err_t rtc4_get_date_time(rtc4_t *ctx, rtc4_date_t *date, rtc4_time_t *time)
RTC 4 get date time function.
rtc4_t::int_pin
digital_in_t int_pin
Definition: rtc4.h:186
rtc4_t::ow
one_wire_t ow
Definition: rtc4.h:189
rtc4_date_t::year
uint32_t year
Definition: rtc4.h:162
rtc4_gpio_selection
void rtc4_gpio_selection(rtc4_cfg_t *cfg, rtc4_gpio_sel_t gpio_sel)
RTC 4 driver interface setup function.
rtc4_t
RTC 4 Click context object.
Definition: rtc4.h:184
rtc4_t::rom_addr
one_wire_rom_address_t rom_addr
Definition: rtc4.h:191
rtc4_time_t::hours
uint32_t hours
Definition: rtc4.h:150
rtc4_date_time_to_unix
void rtc4_date_time_to_unix(rtc4_date_t *date, rtc4_time_t *time, uint32_t *unix_time)
RTC 4 date time to unix function.