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
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define RTC21_REG_SECOND 0x00
74#define RTC21_REG_MINUTE 0x01
75#define RTC21_REG_HOUR 0x02
76#define RTC21_REG_DAY_OF_WEEK 0x03
77#define RTC21_REG_DATE 0x04
78#define RTC21_REG_MONTH 0x05
79#define RTC21_REG_YEAR 0x06
80#define RTC21_REG_CONTROL 0x07
81#define RTC21_REG_RAM_BOTTOM 0x08
82#define RTC21_REG_RAM_TOP 0x3F
83
84 // rtc21_reg
85
100#define RTC21_MONDAY 0x01
101#define RTC21_TUESDAY 0x02
102#define RTC21_WEDNESDAY 0x03
103#define RTC21_THURSDAY 0x04
104#define RTC21_FRIDAY 0x05
105#define RTC21_SATURDAY 0x06
106#define RTC21_SUNDAY 0x07
107
113#define RTC21_DEVICE_ADDRESS 0x68
114
115 // rtc21_set
116
131#define RTC21_MAP_MIKROBUS( cfg, mikrobus ) \
132 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
133 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
134 cfg.ft = MIKROBUS( mikrobus, MIKROBUS_INT )
135
136 // rtc21_map
137 // rtc21
138
143typedef struct
144{
145 // Input pins
146 digital_in_t ft;
148 // Modules
149 i2c_master_t i2c;
151 // I2C slave address
154} rtc21_t;
155
160typedef struct
161{
162 pin_name_t scl;
163 pin_name_t sda;
165 pin_name_t ft;
167 uint32_t i2c_speed;
168 uint8_t i2c_address;
171
177typedef struct
178{
179 uint8_t second;
180 uint8_t minute;
181 uint8_t hour;
182
184
190typedef struct
191{
192 uint8_t day_of_week;
193 uint8_t day;
194 uint8_t month;
195 uint8_t year;
196
198
203typedef enum
204{
206 RTC21_ERROR = -1
207
209
226
240err_t rtc21_init ( rtc21_t *ctx, rtc21_cfg_t *cfg );
241
256err_t rtc21_generic_write ( rtc21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
257
272err_t rtc21_generic_read ( rtc21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
273
286err_t rtc21_write_register ( rtc21_t *ctx, uint8_t reg, uint8_t data_in );
287
300err_t rtc21_read_register ( rtc21_t *ctx, uint8_t reg, uint8_t *data_out );
301
310uint8_t rtc21_get_ft_pin ( rtc21_t *ctx );
311
324err_t rtc21_set_time ( rtc21_t *ctx, rtc21_time_t *time );
325
339
352err_t rtc21_set_date ( rtc21_t *ctx, rtc21_date_t *date );
353
367
368#ifdef __cplusplus
369}
370#endif
371#endif // RTC21_H
372
373 // rtc21
374
375// ------------------------------------------------------------------------ END
err_t rtc21_generic_write(rtc21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 21 I2C writing function.
err_t rtc21_read_register(rtc21_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 21 read register function.
uint8_t rtc21_get_ft_pin(rtc21_t *ctx)
RTC 21 get ft pin function.
err_t rtc21_write_register(rtc21_t *ctx, uint8_t reg, uint8_t data_in)
RTC 21 write register function.
err_t rtc21_set_time(rtc21_t *ctx, rtc21_time_t *time)
RTC 21 set time function.
err_t rtc21_read_date(rtc21_t *ctx, rtc21_date_t *date)
RTC 21 read date function.
err_t rtc21_generic_read(rtc21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 21 I2C reading function.
err_t rtc21_set_date(rtc21_t *ctx, rtc21_date_t *date)
RTC 21 set date function.
err_t rtc21_read_time(rtc21_t *ctx, rtc21_time_t *time)
RTC 21 read time function.
err_t rtc21_init(rtc21_t *ctx, rtc21_cfg_t *cfg)
RTC 21 initialization function.
void rtc21_cfg_setup(rtc21_cfg_t *cfg)
RTC 21 configuration object setup function.
rtc21_return_value_t
RTC 21 Click return value data.
Definition rtc21.h:204
@ RTC21_OK
Definition rtc21.h:205
@ RTC21_ERROR
Definition rtc21.h:206
RTC 21 Click configuration object.
Definition rtc21.h:161
uint32_t i2c_speed
Definition rtc21.h:167
pin_name_t scl
Definition rtc21.h:162
pin_name_t sda
Definition rtc21.h:163
pin_name_t ft
Definition rtc21.h:165
uint8_t i2c_address
Definition rtc21.h:168
RTC 21 Click date object.
Definition rtc21.h:191
uint8_t month
Definition rtc21.h:194
uint8_t day
Definition rtc21.h:193
uint8_t year
Definition rtc21.h:195
uint8_t day_of_week
Definition rtc21.h:192
RTC 21 Click context object.
Definition rtc21.h:144
i2c_master_t i2c
Definition rtc21.h:149
uint8_t slave_address
Definition rtc21.h:152
digital_in_t ft
Definition rtc21.h:146
RTC 21 Click time object.
Definition rtc21.h:178
uint8_t second
Definition rtc21.h:179
uint8_t minute
Definition rtc21.h:180
uint8_t hour
Definition rtc21.h:181