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 
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  // 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  // 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  // rtc21_map // rtc21
138 
143 typedef struct
144 {
145  // Input pins
146  digital_in_t ft;
148  // Modules
149  i2c_master_t i2c;
151  // I2C slave address
152  uint8_t slave_address;
154 } rtc21_t;
155 
160 typedef 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;
170 } rtc21_cfg_t;
171 
177 typedef struct
178 {
179  uint8_t second;
180  uint8_t minute;
181  uint8_t hour;
182 
183 } rtc21_time_t;
184 
190 typedef struct
191 {
192  uint8_t day_of_week;
193  uint8_t day;
194  uint8_t month;
195  uint8_t year;
196 
197 } rtc21_date_t;
198 
203 typedef enum
204 {
205  RTC21_OK = 0,
206  RTC21_ERROR = -1
207 
209 
226 
240 err_t rtc21_init ( rtc21_t *ctx, rtc21_cfg_t *cfg );
241 
256 err_t rtc21_generic_write ( rtc21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
257 
272 err_t rtc21_generic_read ( rtc21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
273 
286 err_t rtc21_write_register ( rtc21_t *ctx, uint8_t reg, uint8_t data_in );
287 
300 err_t rtc21_read_register ( rtc21_t *ctx, uint8_t reg, uint8_t *data_out );
301 
310 uint8_t rtc21_get_ft_pin ( rtc21_t *ctx );
311 
324 err_t rtc21_set_time ( rtc21_t *ctx, rtc21_time_t *time );
325 
338 err_t rtc21_read_time ( rtc21_t *ctx, rtc21_time_t *time );
339 
352 err_t rtc21_set_date ( rtc21_t *ctx, rtc21_date_t *date );
353 
366 err_t rtc21_read_date ( rtc21_t *ctx, rtc21_date_t *date );
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 #endif // RTC21_H
372  // rtc21
374 
375 // ------------------------------------------------------------------------ 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:191
rtc21_time_t::hour
uint8_t hour
Definition: rtc21.h:181
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:178
rtc21_cfg_t::ft
pin_name_t ft
Definition: rtc21.h:165
RTC21_ERROR
@ RTC21_ERROR
Definition: rtc21.h:206
rtc21_time_t::minute
uint8_t minute
Definition: rtc21.h:180
rtc21_t::slave_address
uint8_t slave_address
Definition: rtc21.h:152
rtc21_time_t::second
uint8_t second
Definition: rtc21.h:179
rtc21_return_value_t
rtc21_return_value_t
RTC 21 Click return value data.
Definition: rtc21.h:204
RTC21_OK
@ RTC21_OK
Definition: rtc21.h:205
rtc21_date_t::day_of_week
uint8_t day_of_week
Definition: rtc21.h:192
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:161
rtc21_t
RTC 21 Click context object.
Definition: rtc21.h:144
rtc21_cfg_t::sda
pin_name_t sda
Definition: rtc21.h:163
rtc21_date_t::month
uint8_t month
Definition: rtc21.h:194
rtc21_t::ft
digital_in_t ft
Definition: rtc21.h:146
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:149
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:168
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:162
rtc21_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc21.h:167
rtc21_date_t::year
uint8_t year
Definition: rtc21.h:195
rtc21_date_t::day
uint8_t day
Definition: rtc21.h:193