rtc21  2.1.0.0
rtc21.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 RTC21_H
29 #define RTC21_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define RTC21_REG_SECOND 0x00
70 #define RTC21_REG_MINUTE 0x01
71 #define RTC21_REG_HOUR 0x02
72 #define RTC21_REG_DAY_OF_WEEK 0x03
73 #define RTC21_REG_DATE 0x04
74 #define RTC21_REG_MONTH 0x05
75 #define RTC21_REG_YEAR 0x06
76 #define RTC21_REG_CONTROL 0x07
77 #define RTC21_REG_RAM_BOTTOM 0x08
78 #define RTC21_REG_RAM_TOP 0x3F
79  // rtc21_reg
81 
96 #define RTC21_MONDAY 0x01
97 #define RTC21_TUESDAY 0x02
98 #define RTC21_WEDNESDAY 0x03
99 #define RTC21_THURSDAY 0x04
100 #define RTC21_FRIDAY 0x05
101 #define RTC21_SATURDAY 0x06
102 #define RTC21_SUNDAY 0x07
103 
109 #define RTC21_DEVICE_ADDRESS 0x68
110  // rtc21_set
112 
127 #define RTC21_MAP_MIKROBUS( cfg, mikrobus ) \
128  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
129  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
130  cfg.ft = MIKROBUS( mikrobus, MIKROBUS_INT )
131  // rtc21_map // rtc21
134 
139 typedef struct
140 {
141  // Input pins
142  digital_in_t ft;
144  // Modules
145  i2c_master_t i2c;
147  // I2C slave address
148  uint8_t slave_address;
150 } rtc21_t;
151 
156 typedef struct
157 {
158  pin_name_t scl;
159  pin_name_t sda;
161  pin_name_t ft;
163  uint32_t i2c_speed;
164  uint8_t i2c_address;
166 } rtc21_cfg_t;
167 
173 typedef struct
174 {
175  uint8_t second;
176  uint8_t minute;
177  uint8_t hour;
178 
179 } rtc21_time_t;
180 
186 typedef struct
187 {
188  uint8_t day_of_week;
189  uint8_t day;
190  uint8_t month;
191  uint8_t year;
192 
193 } rtc21_date_t;
194 
199 typedef enum
200 {
201  RTC21_OK = 0,
202  RTC21_ERROR = -1
203 
205 
222 
236 err_t rtc21_init ( rtc21_t *ctx, rtc21_cfg_t *cfg );
237 
252 err_t rtc21_generic_write ( rtc21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
253 
268 err_t rtc21_generic_read ( rtc21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
269 
282 err_t rtc21_write_register ( rtc21_t *ctx, uint8_t reg, uint8_t data_in );
283 
296 err_t rtc21_read_register ( rtc21_t *ctx, uint8_t reg, uint8_t *data_out );
297 
306 uint8_t rtc21_get_ft_pin ( rtc21_t *ctx );
307 
320 err_t rtc21_set_time ( rtc21_t *ctx, rtc21_time_t *time );
321 
334 err_t rtc21_read_time ( rtc21_t *ctx, rtc21_time_t *time );
335 
348 err_t rtc21_set_date ( rtc21_t *ctx, rtc21_date_t *date );
349 
362 err_t rtc21_read_date ( rtc21_t *ctx, rtc21_date_t *date );
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 #endif // RTC21_H
368  // rtc21
370 
371 // ------------------------------------------------------------------------ END
rtc21_set_date
err_t rtc21_set_date(rtc21_t *ctx, rtc21_date_t *date)
RTC 21 set date function.
rtc21_read_register
err_t rtc21_read_register(rtc21_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 21 read register function.
rtc21_cfg_setup
void rtc21_cfg_setup(rtc21_cfg_t *cfg)
RTC 21 configuration object setup function.
rtc21_date_t
RTC 21 Click date object.
Definition: rtc21.h:187
rtc21_time_t::hour
uint8_t hour
Definition: rtc21.h:177
rtc21_set_time
err_t rtc21_set_time(rtc21_t *ctx, rtc21_time_t *time)
RTC 21 set time function.
rtc21_time_t
RTC 21 Click time object.
Definition: rtc21.h:174
rtc21_cfg_t::ft
pin_name_t ft
Definition: rtc21.h:161
RTC21_ERROR
@ RTC21_ERROR
Definition: rtc21.h:202
rtc21_time_t::minute
uint8_t minute
Definition: rtc21.h:176
rtc21_t::slave_address
uint8_t slave_address
Definition: rtc21.h:148
rtc21_time_t::second
uint8_t second
Definition: rtc21.h:175
rtc21_return_value_t
rtc21_return_value_t
RTC 21 Click return value data.
Definition: rtc21.h:200
RTC21_OK
@ RTC21_OK
Definition: rtc21.h:201
rtc21_date_t::day_of_week
uint8_t day_of_week
Definition: rtc21.h:188
rtc21_get_ft_pin
uint8_t rtc21_get_ft_pin(rtc21_t *ctx)
RTC 21 get ft pin function.
rtc21_read_date
err_t rtc21_read_date(rtc21_t *ctx, rtc21_date_t *date)
RTC 21 read date function.
rtc21_cfg_t
RTC 21 Click configuration object.
Definition: rtc21.h:157
rtc21_t
RTC 21 Click context object.
Definition: rtc21.h:140
rtc21_cfg_t::sda
pin_name_t sda
Definition: rtc21.h:159
rtc21_date_t::month
uint8_t month
Definition: rtc21.h:190
rtc21_t::ft
digital_in_t ft
Definition: rtc21.h:142
rtc21_generic_write
err_t rtc21_generic_write(rtc21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 21 I2C writing function.
rtc21_init
err_t rtc21_init(rtc21_t *ctx, rtc21_cfg_t *cfg)
RTC 21 initialization function.
rtc21_t::i2c
i2c_master_t i2c
Definition: rtc21.h:145
rtc21_write_register
err_t rtc21_write_register(rtc21_t *ctx, uint8_t reg, uint8_t data_in)
RTC 21 write register function.
rtc21_read_time
err_t rtc21_read_time(rtc21_t *ctx, rtc21_time_t *time)
RTC 21 read time function.
rtc21_cfg_t::i2c_address
uint8_t i2c_address
Definition: rtc21.h:164
rtc21_generic_read
err_t rtc21_generic_read(rtc21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 21 I2C reading function.
rtc21_cfg_t::scl
pin_name_t scl
Definition: rtc21.h:158
rtc21_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc21.h:163
rtc21_date_t::year
uint8_t year
Definition: rtc21.h:191
rtc21_date_t::day
uint8_t day
Definition: rtc21.h:189